home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / doc / python-apt / examples / configisc.py < prev    next >
Encoding:
Python Source  |  2006-03-02  |  1.3 KB  |  40 lines

  1. #!/usr/bin/python
  2. # Example demonstrating how to use the configuration/commandline system
  3. # for object setup.
  4.  
  5. # This parses the given config file in 'ISC' style where the sections
  6. # represent object instances and shows how to iterate over the sections.
  7. # Pass it the sample apt-ftparchive configuration,
  8. # doc/examples/ftp-archive.conf
  9. # or a bind8 config file..
  10.  
  11. import apt_pkg,sys,posixpath;
  12.  
  13. ConfigFile = apt_pkg.ParseCommandLine(apt_pkg.Config,[],sys.argv);
  14.  
  15. if len(ConfigFile) != 1:
  16.    print "Must have exactly 1 file name";
  17.    sys.exit(0);
  18.  
  19. Cnf = apt_pkg.newConfiguration();
  20. apt_pkg.ReadConfigFileISC(Cnf,ConfigFile[0]);
  21.  
  22. # Print the configuration space
  23. #print "The Configuration space looks like:";
  24. #for I in Cnf.keys():
  25. #   print "%s \"%s\";"%(I,Cnf[I]);
  26.  
  27. # bind8 config file..
  28. if Cnf.has_key("Zone"):
  29.    print "Zones: ",Cnf.SubTree("zone").List();
  30.    for I in Cnf.List("zone"):
  31.       SubCnf = Cnf.SubTree(I);
  32.       if SubCnf.Find("type") == "slave":
  33.          print "Masters for %s: %s"%(SubCnf.MyTag(),SubCnf.ValueList("masters"));
  34. else:
  35.    print "Tree definitions:";
  36.    for I in Cnf.List("tree"):
  37.       SubCnf = Cnf.SubTree(I);
  38.       # This could use Find which would eliminate the possibility of exceptions.
  39.       print "Subtree %s with sections '%s' and architectures '%s'"%(SubCnf.MyTag(),SubCnf["Sections"],SubCnf["Architectures"]);
  40.