Пример #1
0
def init(options, argv):
    global _default_config
    global _istatus

    apt_pkg.InitConfig()

    for key in _default_config.keys():
        apt_pkg.Config[key] = _default_config[key]

    args = apt_pkg.ParseCommandLine(apt_pkg.Config, options, argv)

    apt_pkg.InitSystem()

    istatus_path = _retrieve_config_dir_path("Dir::Comps::InstalledState")
    if os.path.exists(istatus_path):
        istatus_f = open(istatus_path)
        _istatus = pickle.load(istatus_f)
        istatus_f.close()
    else:
        _quick_status("No installed status file found; creating one.")
        update_installed()

    return args
Пример #2
0
#!/usr/bin/python

# This is a simple clone of tests/versiontest.cc
import apt_pkg, sys, re, string
apt_pkg.InitConfig()
apt_pkg.InitSystem()

TestFile = apt_pkg.ParseCommandLine(apt_pkg.Config, [], sys.argv)
if len(TestFile) != 1:
    print "Must have exactly 1 file name"
    sys.exit(0)

# Go over the file..
List = open(TestFile[0], "r")
CurLine = 0
while (1):
    Line = List.readline()
    CurLine = CurLine + 1
    if Line == "":
        break
    Line = string.strip(Line)
    if len(Line) == 0 or Line[0] == '#':
        continue

    Split = re.split("[ \n]", Line)

    # Check forward
    if apt_pkg.VersionCompare(Split[0], Split[1]) != int(Split[2]):
        print "Comparision failed on line %u. '%s' ? '%s' %i != %i" % (
            CurLine, Split[0], Split[1],
            apt_pkg.VersionCompare(Split[0], Split[1]), int(Split[2]))
Пример #3
0
# whenever possible..
Cnf = apt_pkg.Configuration()

print "Command line is", sys.argv

# Load the default configuration file, InitConfig() does this better..
Cnf.Set("config-file", "/etc/apt/apt.conf")  # or Cnf["config-file"] = ".."
if posixpath.exists(Cnf.FindFile("config-file")):
    apt_pkg.ReadConfigFile(Cnf, "/etc/apt/apt.conf")

# Merge the command line arguments into the configuration space
Arguments = [('h', "help", "help"), ('v', "version", "version"),
             ('q', "quiet", "quiet", "IntLevel"),
             ('c', "config-file", "", "ConfigFile"),
             ('o', "option", "", "ArbItem")]
print "FileNames", apt_pkg.ParseCommandLine(Cnf, Arguments, sys.argv)

print "Quiet level selected is", Cnf.FindI("quiet", 0)

# Do some stuff with it
if Cnf.FindB("version", 0) == 1:
    print "Version selected - 1.1"

if Cnf.FindB("help", 0) == 1:
    print "python-apt", apt_pkg.Version, \
          "compiled on", apt_pkg.Date, apt_pkg.Time
    print "Hi, I am the help text for this program"
    sys.exit(0)

print "No help for you, try -h"