1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76 | #!/usr/bin/env python
##################################################################
# apt-o.py
# Copyright (c) 2007, Anuj Bhatt <anuj.bhatt@gmail.com>, Srichand Pendyala <srichand.pendyala@gmail.com>
# Free to use and distribute under the GPLv3 license terms
##################################################################
import sys,os
import getpass
class AptO:
aptgetlist = ['update','upgrade','install','remove','build-dep','dist-upgrade','dselect-upgrade','clean','autoclean','check']
aptcachelist = ['add','gencaches','showpkg','showsrc','stats','dump','dumpavail','unmet','search','show','depends','rdepends','pkgnames','dotty','xvcg','policy']
helpstr="apt-o is a wrapper tweak over apt-get and apt-cache. You don't have to worry about which <verb> (like install, search, update et cetera) belongs to which of the two: apt-get or apt-cache. The syntax simply becomes: $ apt-o <verb> <noun>. Makes lives easy doesn't it?"
command = None
def usage(self):
print "USAGE: apt-o <verb or 'help' or 'about' > [<noun>]"
sys.exit(1)
def not_supported(self):
print "Your option is not supported by the apt package!"
sys.exit(1)
def prepare_command(self):
if (len(sys.argv) == 2):
if(sys.argv[1]=="help"):
print self.helpstr
sys.exit(1)
elif (sys.argv[1] in self.aptgetlist):
if getpass.getuser() != "root":
print "The option you've asked for seems to require priviliges that are beyond those your username. Try with a sudo prefix?"
sys.exit(1)
else:
self.command = "apt-get "+sys.argv[1]
elif (sys.argv[1] in self.aptcachelist):
self.command = "apt-cache "+sys.argv[1]
else:
self.not_supported()
elif (len(sys.argv) > 2):
if (sys.argv[1] == "source"):
self.command = "apt-get " + sys.argv[1]
elif (sys.argv[1] in self.aptgetlist):
if getpass.getuser() != "root":
print "The option you've asked for seems to require priviliges that are beyond those your username. Try with a sudo prefix?"
sys.exit(1)
else:
self.command = "apt-get"
for i in range (1,len(sys.argv)):
self.command = self.command+" "+sys.argv[i]
#os.system(str)
elif (sys.argv[1] in self.aptcachelist):
self.command = "apt-cache "+sys.argv[1]+" "+sys.argv[2]
#os.system(str2)
else:
print "Your option is not supported by the apt package!"
else:
self.not_supported()
def execute_command(self):
os.system(self.command)
def go_do_what_the_user_wants(self):
self.prepare_command()
self.execute_command()
if __name__ == "__main__":
thing = AptO()
thing.go_do_what_the_user_wants()
sys.exit(0)
|