# config.py -no-h --no-help --help=no ; Turn off help # config.py -qqq -q=3 ; verbosity to 3 # config.py -c /etc/apt/apt.conf ; include that config file] # config.py -o help=true ; Turn on help by giving a config file string # config.py -no-h -- -help ; Turn off help, specify the file '-help' # -c and -o are standard APT-program options. # This shows how to use the system for configuration and option control. # The other varient is for ISC object config files. See configisc.py. import apt_pkg,sys,posixpath; # Create a new empty Configuration object - there is also the system global # configuration object apt_pkg.Config which is used interally by apt-pkg # routines to control unusual situations. I recommend using the sytem global # whenever possible.. Cnf = apt_pkg.newConfiguration(); 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);
# This parses the given config file in 'ISC' style where the sections # represent object instances and shows how to iterate over the sections. # Pass it the sample apt-ftparchive configuration, # doc/examples/ftp-archive.conf # or a bind8 config file.. import apt_pkg, sys, posixpath ConfigFile = apt_pkg.ParseCommandLine(apt_pkg.Config, [], sys.argv) if len(ConfigFile) != 1: print "Must have exactly 1 file name" sys.exit(0) Cnf = apt_pkg.newConfiguration() apt_pkg.ReadConfigFileISC(Cnf, ConfigFile[0]) # Print the configuration space #print "The Configuration space looks like:"; #for I in Cnf.keys(): # print "%s \"%s\";"%(I,Cnf[I]); # bind8 config file.. if Cnf.has_key("Zone"): print "Zones: ", Cnf.SubTree("zone").List() for I in Cnf.List("zone"): SubCnf = Cnf.SubTree(I) if SubCnf.Find("type") == "slave": print "Masters for %s: %s" % (SubCnf.MyTag(), SubCnf.ValueList("masters"))
def main(): global Cnf, Options, Logger os.umask(0o002) Cnf = utils.get_conf() Arguments = [ ('h', "help", "Generate-Index-Diffs::Options::Help"), ('c', None, "Generate-Index-Diffs::Options::CanonicalPath", "hasArg"), ('p', "patchname", "Generate-Index-Diffs::Options::PatchName", "hasArg"), ('r', "rootdir", "Generate-Index-Diffs::Options::RootDir", "hasArg"), ('d', "tmpdir", "Generate-Index-Diffs::Options::TempDir", "hasArg"), ('m', "maxdiffs", "Generate-Index-Diffs::Options::MaxDiffs", "hasArg"), ('n', "n-act", "Generate-Index-Diffs::Options::NoAct"), ] suites = apt_pkg.parse_commandline(Cnf,Arguments,sys.argv) Options = Cnf.subtree("Generate-Index-Diffs::Options") if Options.has_key("Help"): usage() maxdiffs = Options.get("MaxDiffs::Default", "56") maxpackages = Options.get("MaxDiffs::Packages", maxdiffs) maxcontents = Options.get("MaxDiffs::Contents", maxdiffs) maxsources = Options.get("MaxDiffs::Sources", maxdiffs) if not Options.has_key("PatchName"): format = "%Y-%m-%d-%H%M.%S" Options["PatchName"] = time.strftime( format ) AptCnf = apt_pkg.newConfiguration() apt_pkg.ReadConfigFileISC(AptCnf,utils.which_apt_conf_file()) if Options.has_key("RootDir"): Cnf["Dir::Root"] = Options["RootDir"] if not suites: suites = Cnf.subtree("Suite").list() for suitename in suites: print "Processing: " + suitename SuiteBlock = Cnf.subtree("Suite::" + suitename) suiteobj = get_suite(suitename.lower()) # Use the canonical version of the suite name suite = suiteobj.suite_name if suiteobj.untouchable: print "Skipping: " + suite + " (untouchable)" continue architectures = get_suite_architectures(suite, skipall=True) if SuiteBlock.has_key("Components"): components = SuiteBlock.value_list("Components") else: components = [] suite_suffix = Cnf.find("Dinstall::SuiteSuffix") if components and suite_suffix: longsuite = suite + "/" + suite_suffix else: longsuite = suite tree = SuiteBlock.get("Tree", "dists/%s" % (longsuite)) if AptCnf.has_key("tree::%s" % (tree)): sections = AptCnf["tree::%s::Sections" % (tree)].split() elif AptCnf.has_key("bindirectory::%s" % (tree)): sections = AptCnf["bindirectory::%s::Sections" % (tree)].split() else: aptcnf_filename = os.path.basename(utils.which_apt_conf_file()) print "ALERT: suite %s not in %s, nor untouchable!" % (suite, aptcnf_filename) continue # See if there are Translations which might need a new pdiff cwd = os.getcwd() for component in sections: #print "DEBUG: Working on %s" % (component) workpath=os.path.join(Cnf["Dir::Root"], tree, component, "i18n") if os.path.isdir(workpath): os.chdir(workpath) for dirpath, dirnames, filenames in os.walk(".", followlinks=True, topdown=True): for entry in filenames: if not re_includeinpdiff.match(entry): #print "EXCLUDING %s" % (entry) continue (fname, fext) = os.path.splitext(entry) processfile=os.path.join(workpath, fname) #print "Working: %s" % (processfile) storename="%s/%s_%s_%s" % (Options["TempDir"], suite, component, fname) #print "Storefile: %s" % (storename) genchanges(Options, processfile + ".diff", storename, processfile, maxdiffs) os.chdir(cwd) for archobj in architectures: architecture = archobj.arch_string # use sections instead of components since dak.conf # treats "foo/bar main" as suite "foo", suitesuffix "bar" and # component "bar/main". suck. for component in sections: if architecture == "source": longarch = architecture packages = "Sources" maxsuite = maxsources else: longarch = "binary-%s"% (architecture) packages = "Packages" maxsuite = maxpackages # Process Contents file = "%s/%s/Contents-%s" % (Cnf["Dir::Root"] + tree, component, architecture) storename = "%s/%s_%s_contents_%s" % (Options["TempDir"], suite, component, architecture) genchanges(Options, file + ".diff", storename, file, \ Cnf.get("Suite::%s::Generate-Index-Diffs::MaxDiffs::Contents" % (suite), maxcontents)) file = "%s/%s/%s/%s" % (Cnf["Dir::Root"] + tree, component, longarch, packages) storename = "%s/%s_%s_%s" % (Options["TempDir"], suite, component, architecture) genchanges(Options, file + ".diff", storename, file, \ Cnf.get("Suite::%s::Generate-Index-Diffs::MaxDiffs::%s" % (suite, packages), maxsuite))