]>
git.saurik.com Git - apt.git/blob - cmdline/apt-mark
   3 from optparse 
import OptionParser
 
  11     print >> sys
.stderr
, "Error importing apt_pkg, is python-apt installed?" 
  14 actions 
= { "markauto" : 1, 
  18 def show_automatic(filename
): 
  19     if not os
.path
.exists(STATE_FILE
): 
  22     tagfile 
= apt_pkg
.TagFile(open(STATE_FILE
)) 
  23     for section 
in tagfile
: 
  24         pkgname 
= section
.get("Package") 
  25         autoInst 
= section
.get("Auto-Installed") 
  28     print "\n".join(sorted(auto
)) 
  31 def mark_unmark_automatic(filename
, action
, pkgs
): 
  32     " mark or unmark automatic flag" 
  34     if os
.path
.exists(STATE_FILE
): 
  36             tagfile 
= apt_pkg
.TagFile(open(STATE_FILE
)) 
  37             outfile 
= open(STATE_FILE
+".tmp","w") 
  39             print "%s, are you root?" % (msg
) 
  41         for section 
in tagfile
: 
  42             pkgname 
= section
.get("Package") 
  43             autoInst 
= section
.get("Auto-Installed") 
  46                     print "changing %s to %s" % (pkgname
,action
) 
  47                 newsec 
= apt_pkg
.rewrite_section(section
, 
  49                                        [ ("Auto-Installed",str(action
)) ]) 
  51                 outfile
.write(newsec
+"\n") 
  53                 outfile
.write(str(section
)+"\n") 
  57                     print "changing %s to %s" % (pkgname
,action
) 
  58                 outfile
.write("Package: %s\nAuto-Installed: %d\n\n" % (pkgname
, action
)) 
  59         # all done, rename the tmpfile 
  60         os
.chmod(outfile
.name
, 0644) 
  61         os
.rename(outfile
.name
, STATE_FILE
) 
  62         os
.chmod(STATE_FILE
, 0644) 
  65 if __name__ 
== "__main__": 
  69     parser 
= OptionParser() 
  70     parser
.usage 
= "%prog [options] {markauto|unmarkauto} packages..." 
  71     parser
.epilog 
= "apt-mark is deprecated, use apt-get markauto/unmarkauto." 
  72     parser
.add_option("-f", "--file", action
="store", type="string", 
  74                       help="read/write a different file") 
  75     parser
.add_option("-v", "--verbose", 
  76                       action
="store_true", dest
="verbose", default
=False, 
  77                       help="print verbose status messages to stdout") 
  78     (options
, args
) = parser
.parse_args() 
  85     if not options
.filename
: 
  86         STATE_FILE 
= apt_pkg
.config
.find_dir("Dir::State") + "extended_states" 
  88         STATE_FILE
=options
.filename
 
  91         parser
.error("first argument must be 'markauto', 'unmarkauto' or 'showauto'") 
  93     if args
[0] == "showauto": 
  94         show_automatic(STATE_FILE
) 
  97         if args
[0] not in actions
.keys(): 
  98             parser
.error("first argument must be 'markauto', 'unmarkauto' or 'showauto'") 
 100         action 
= actions
[args
[0]] 
 101         mark_unmark_automatic(STATE_FILE
, action
, pkgs
)