]> git.saurik.com Git - apt.git/blame - cmdline/apt-mark
add https options which default to the ones from http for the https
[apt.git] / cmdline / apt-mark
CommitLineData
b1a8717a
MV
1#!/usr/bin/python
2
3from optparse import OptionParser
4
5try:
6 import apt_pkg
7except ImportError:
8 print "Error importing apt_pkg, is python-apt installed?"
9
10import sys
11import os.path
12
13actions = { "markauto" : 1,
14 "unmarkauto": 0
15 }
16
a9b5e24b
MV
17def show_automatic(filename):
18 if not os.path.exists(STATE_FILE):
19 return
20 auto = set()
21 tagfile = apt_pkg.ParseTagFile(open(STATE_FILE))
22 while tagfile.Step():
23 pkgname = tagfile.Section.get("Package")
24 autoInst = tagfile.Section.get("Auto-Installed")
25 if int(autoInst):
26 auto.add(pkgname)
27 print "\n".join(sorted(auto))
28
b1a8717a 29
a9b5e24b
MV
30def mark_unmark_automatic(filename, action, pkgs):
31 " mark or unmark automatic flag"
b1a8717a
MV
32 # open the statefile
33 if os.path.exists(STATE_FILE):
d8c6a87a
DK
34 try:
35 tagfile = apt_pkg.ParseTagFile(open(STATE_FILE))
36 outfile = open(STATE_FILE+".tmp","w")
37 except IOError, msg:
38 print "%s, are you root?" % (msg)
39 sys.exit(1)
b1a8717a
MV
40 while tagfile.Step():
41 pkgname = tagfile.Section.get("Package")
42 autoInst = tagfile.Section.get("Auto-Installed")
43 if pkgname in pkgs:
44 if options.verbose:
45 print "changing %s to %s" % (pkgname,action)
46 newsec = apt_pkg.RewriteSection(tagfile.Section,
47 [],
48 [ ("Auto-Installed",str(action)) ]
49 )
50 outfile.write(newsec+"\n")
51 else:
52 outfile.write(str(tagfile.Section)+"\n")
53 # all done, rename the tmpfile
54eda6ae 54 os.chmod(outfile.name, 0644)
b1a8717a 55 os.rename(outfile.name, STATE_FILE)
526d4369 56 os.chmod(STATE_FILE, 0644)
a9b5e24b
MV
57
58
59if __name__ == "__main__":
60 apt_pkg.init()
61
62 # option parsing
63 parser = OptionParser()
64 parser.usage = "%prog [options] {markauto|unmarkauto} packages..."
65 parser.add_option("-f", "--file", action="store", type="string",
66 dest="filename",
67 help="read/write a different file")
68 parser.add_option("-v", "--verbose",
69 action="store_true", dest="verbose", default=False,
70 help="print verbose status messages to stdout")
71 (options, args) = parser.parse_args()
72
73 # get the state-file
74 if not options.filename:
75 STATE_FILE = apt_pkg.Config.FindDir("Dir::State") + "extended_states"
76 else:
77 STATE_FILE=options.filename
78
79 if args[0] == "showauto":
80 show_automatic(STATE_FILE)
81 else:
82 # get pkgs to change
83 if args[0] not in actions.keys():
84 parser.error("first argument must be 'markauto', 'unmarkauto' or 'showauto'")
85 pkgs = args[1:]
86 action = actions[args[0]]
87 mark_unmark_automatic(STATE_FILE, action, pkgs)