1999-10-01 15:15:25 +08:00
|
|
|
#############################################################################
|
|
|
|
# File : rpmlint.py
|
|
|
|
# Package : rpmlint
|
|
|
|
# Author : Frederic Lepied
|
|
|
|
# Created on : Mon Sep 27 19:20:18 1999
|
|
|
|
# Version : $Id$
|
|
|
|
# Purpose : main entry point: process options, load the checks and run
|
|
|
|
# the checks.
|
|
|
|
#############################################################################
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import AbstractCheck
|
|
|
|
import imp
|
|
|
|
import getopt
|
|
|
|
import Pkg
|
1999-10-16 19:14:24 +08:00
|
|
|
import Config
|
|
|
|
import os
|
1999-11-16 02:28:50 +08:00
|
|
|
from Filter import *
|
1999-10-01 15:15:25 +08:00
|
|
|
|
2000-08-25 17:16:39 +08:00
|
|
|
version="0.20"
|
1999-10-01 15:15:25 +08:00
|
|
|
|
|
|
|
# Print usage information
|
|
|
|
def usage(name):
|
|
|
|
print "usage:", name, "[<options>] <rpm files>"
|
|
|
|
print " options in:"
|
|
|
|
print "\t[-c|--check <check>]\n\t[-C|--checkdir <checkdir>]\n\t[-h|--help]\n\t[-v|--verbose]\n\t[-E|--extractdir <dir>]\n\t[-V|--version]"
|
|
|
|
|
|
|
|
# Print version information
|
|
|
|
def printVersion():
|
2000-02-23 14:42:35 +08:00
|
|
|
print "rpmlint version", version, "Copyright (C) 1999-2000 Frederic Lepied"
|
1999-10-01 15:15:25 +08:00
|
|
|
|
|
|
|
# Load a python module from its file name
|
|
|
|
def loadCheck(name):
|
1999-10-16 19:14:24 +08:00
|
|
|
(file, pathname, description)=imp.find_module(name, Config.checkDirs())
|
1999-10-01 15:15:25 +08:00
|
|
|
imp.load_module(name, file, pathname, description)
|
|
|
|
|
1999-10-16 19:14:24 +08:00
|
|
|
# Load a file
|
|
|
|
def loadFile(name):
|
|
|
|
file=os.fdopen(os.open(os.path.expanduser(name), os.O_RDONLY))
|
|
|
|
imp.load_source("", name, file)
|
|
|
|
|
1999-10-01 15:15:25 +08:00
|
|
|
#############################################################################
|
|
|
|
# main program
|
|
|
|
#############################################################################
|
|
|
|
|
|
|
|
sys.argv[0] = os.path.basename(sys.argv[0])
|
|
|
|
|
|
|
|
# parse options
|
|
|
|
try:
|
|
|
|
(opt, args)=getopt.getopt(sys.argv[1:], "c:C:hVvE:", ["check=",
|
|
|
|
"checkdir=",
|
|
|
|
"help",
|
|
|
|
"version",
|
|
|
|
"verbose",
|
|
|
|
"extractdir="])
|
|
|
|
except getopt.error:
|
|
|
|
print "bad option"
|
|
|
|
usage(sys.argv[0])
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
# process options
|
|
|
|
checkdir="/usr/share/rpmlint"
|
|
|
|
verbose=0
|
2000-08-16 17:25:23 +08:00
|
|
|
extract_dir=Config.getOption('ExtractDir', "/tmp")
|
1999-10-01 15:15:25 +08:00
|
|
|
|
1999-10-16 19:14:24 +08:00
|
|
|
# load global config file
|
|
|
|
try:
|
|
|
|
loadFile("/etc/rpmlint/config")
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
# load user config file
|
|
|
|
try:
|
|
|
|
loadFile("~/.rpmlintrc")
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
# process command line options
|
1999-10-01 15:15:25 +08:00
|
|
|
for o in opt:
|
|
|
|
if o[0] == '-c' or o[0] == "--check":
|
1999-10-16 19:14:24 +08:00
|
|
|
Config.addCheck(o[1])
|
1999-10-01 15:15:25 +08:00
|
|
|
elif o[0] == '-h' or o[0] == "--help":
|
|
|
|
usage(sys.argv[0])
|
|
|
|
sys.exit(0)
|
|
|
|
elif o[0] == '-C' or o[0] == "--checkdir":
|
1999-10-16 19:14:24 +08:00
|
|
|
Config.addCheckDir(o[1])
|
1999-10-01 15:15:25 +08:00
|
|
|
elif o[0] == '-v' or o[0] == "--verbose":
|
|
|
|
verbose=1
|
|
|
|
elif o[0] == '-V' or o[0] == "--version":
|
|
|
|
printVersion()
|
|
|
|
sys.exit(0)
|
|
|
|
elif o[0] == '-E' or o[0] == "--extractdir":
|
|
|
|
extract_dir=o[1]
|
2000-08-16 17:25:23 +08:00
|
|
|
Config.setOption('ExtractDir', extract_dir)
|
1999-10-01 15:15:25 +08:00
|
|
|
else:
|
|
|
|
print "unknown option", o
|
|
|
|
|
|
|
|
# if no argument print usage
|
|
|
|
if args == []:
|
|
|
|
usage(sys.argv[0])
|
|
|
|
sys.exit(0)
|
|
|
|
|
1999-10-16 19:14:24 +08:00
|
|
|
# Load all the tests
|
|
|
|
for c in Config.allChecks():
|
|
|
|
loadCheck(c)
|
1999-10-01 15:15:25 +08:00
|
|
|
|
|
|
|
try:
|
|
|
|
# Loop over all file names given in arguments
|
|
|
|
for f in args:
|
2000-08-16 17:25:23 +08:00
|
|
|
try:
|
|
|
|
pkg=Pkg.Pkg(f, extract_dir)
|
|
|
|
except:
|
|
|
|
sys.stderr.write("Error while reading " + f + "\n")
|
|
|
|
pkg=None
|
|
|
|
continue
|
|
|
|
|
|
|
|
if verbose:
|
|
|
|
printInfo(pkg, "checking")
|
|
|
|
for c in AbstractCheck.AbstractCheck.checks:
|
|
|
|
c.check(pkg, verbose)
|
|
|
|
|
|
|
|
pkg.cleanup()
|
1999-10-06 21:05:08 +08:00
|
|
|
finally:
|
|
|
|
pkg and pkg.cleanup()
|
1999-10-01 15:15:25 +08:00
|
|
|
|
|
|
|
# rpmlint.py ends here
|