]>
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 if __name__
== "__main__":
21 parser
= OptionParser()
22 parser
.usage
= "%prog [options] {markauto|unmarkauto} packages..."
23 parser
.add_option("-f", "--file", action
="store", type="string",
25 help="read/write a different file")
26 parser
.add_option("-v", "--verbose",
27 action
="store_true", dest
="verbose", default
=False,
28 help="print verbose status messages to stdout")
29 (options
, args
) = parser
.parse_args()
31 parser
.error("not enough argument")
34 if args
[0] not in actions
.keys():
35 parser
.error("first argument must be 'markauto' or 'unmarkauto'")
37 action
= actions
[args
[0]]
40 if not options
.filename
:
41 STATE_FILE
= apt_pkg
.Config
.FindDir("Dir::State") + "extended_states"
43 STATE_FILE
=options
.state_file
46 if os
.path
.exists(STATE_FILE
):
47 tagfile
= apt_pkg
.ParseTagFile(open(STATE_FILE
))
48 outfile
= open(STATE_FILE
+".tmp","w")
50 pkgname
= tagfile
.Section
.get("Package")
51 autoInst
= tagfile
.Section
.get("Auto-Installed")
54 print "changing %s to %s" % (pkgname
,action
)
55 newsec
= apt_pkg
.RewriteSection(tagfile
.Section
,
57 [ ("Auto-Installed",str(action
)) ]
59 outfile
.write(newsec
+"\n")
61 outfile
.write(str(tagfile
.Section
)+"\n")
62 # all done, rename the tmpfile
63 os
.chmod(outfile
.name
, 0644)
64 os
.rename(outfile
.name
, STATE_FILE
)