+def show_automatic(filename):
+ if not os.path.exists(STATE_FILE):
+ return
+ auto = set()
+ tagfile = apt_pkg.TagFile(open(STATE_FILE))
+ for section in tagfile:
+ pkgname = section.get("Package")
+ autoInst = section.get("Auto-Installed")
+ if int(autoInst):
+ auto.add(pkgname)
+ print "\n".join(sorted(auto))
+
+
+def mark_unmark_automatic(filename, action, pkgs):
+ " mark or unmark automatic flag"
+ # open the statefile
+ if os.path.exists(STATE_FILE):
+ try:
+ tagfile = apt_pkg.TagFile(open(STATE_FILE))
+ outfile = open(STATE_FILE+".tmp","w")
+ except IOError, msg:
+ print "%s, are you root?" % (msg)
+ sys.exit(1)
+ for section in tagfile:
+ pkgname = section.get("Package")
+ autoInst = section.get("Auto-Installed")
+ if pkgname in pkgs:
+ if options.verbose:
+ print "changing %s to %s" % (pkgname,action)
+ newsec = apt_pkg.rewrite_section(section,
+ [],
+ [ ("Auto-Installed",str(action)) ])
+ pkgs.remove(pkgname)
+ outfile.write(newsec+"\n")
+ else:
+ outfile.write(str(section)+"\n")
+ if action == 1:
+ for pkgname in pkgs:
+ if options.verbose:
+ print "changing %s to %s" % (pkgname,action)
+ outfile.write("Package: %s\nAuto-Installed: %d\n\n" % (pkgname, action))
+ # all done, rename the tmpfile
+ os.chmod(outfile.name, 0644)
+ os.rename(outfile.name, STATE_FILE)
+ os.chmod(STATE_FILE, 0644)
+
+