]>
git.saurik.com Git - apt.git/blob - cmdline/apt-mark
3 from optparse
import OptionParser
8 print "Error importing apt_pkg, is python-apt installed?"
13 actions
= { "markauto" : 1,
17 def show_automatic(filename
):
18 if not os
.path
.exists(STATE_FILE
):
21 tagfile
= apt_pkg
.ParseTagFile(open(STATE_FILE
))
23 pkgname
= tagfile
.Section
.get("Package")
24 autoInst
= tagfile
.Section
.get("Auto-Installed")
27 print "\n".join(sorted(auto
))
30 def mark_unmark_automatic(filename
, action
, pkgs
):
31 " mark or unmark automatic flag"
33 if os
.path
.exists(STATE_FILE
):
34 tagfile
= apt_pkg
.ParseTagFile(open(STATE_FILE
))
35 outfile
= open(STATE_FILE
+".tmp","w")
37 pkgname
= tagfile
.Section
.get("Package")
38 autoInst
= tagfile
.Section
.get("Auto-Installed")
41 print "changing %s to %s" % (pkgname
,action
)
42 newsec
= apt_pkg
.RewriteSection(tagfile
.Section
,
44 [ ("Auto-Installed",str(action
)) ]
46 outfile
.write(newsec
+"\n")
48 outfile
.write(str(tagfile
.Section
)+"\n")
49 # all done, rename the tmpfile
50 os
.chmod(outfile
.name
, 0644)
51 os
.rename(outfile
.name
, STATE_FILE
)
52 os
.chmod(STATE_FILE
, 0644)
55 if __name__
== "__main__":
59 parser
= OptionParser()
60 parser
.usage
= "%prog [options] {markauto|unmarkauto} packages..."
61 parser
.add_option("-f", "--file", action
="store", type="string",
63 help="read/write a different file")
64 parser
.add_option("-v", "--verbose",
65 action
="store_true", dest
="verbose", default
=False,
66 help="print verbose status messages to stdout")
67 (options
, args
) = parser
.parse_args()
70 if not options
.filename
:
71 STATE_FILE
= apt_pkg
.Config
.FindDir("Dir::State") + "extended_states"
73 STATE_FILE
=options
.filename
75 if args
[0] == "showauto":
76 show_automatic(STATE_FILE
)
79 if args
[0] not in actions
.keys():
80 parser
.error("first argument must be 'markauto', 'unmarkauto' or 'showauto'")
82 action
= actions
[args
[0]]
83 mark_unmark_automatic(STATE_FILE
, action
, pkgs
)