-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpackage
executable file
·85 lines (75 loc) · 2.64 KB
/
package
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
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python
# wrapper around package managers so I don't have to remember differences
# between aptitude, apt-get, yum, etc. for basic operations
import os
import sys
import subprocess
def usage(stream=sys.stdout):
print >>stream, "Usage: package [install|uninstall|update|versions|list|info|files] <package>..."
commands = {}
commands['apt'] = {
'install': ['apt-get', 'install'],
'uninstall': ['apt-get', 'remove'],
'update': ['apt-get', 'update'],
'versions': ['apt-cache', 'policy'],
'search': ['apt-cache', 'search'],
'list': ['dpkg-query', '-W'],
'info': ['dpkg-query', '-s'],
'files': ['dpkg-query', '-L'],
'depends': ['apt-cache', 'depends'],
'rdepends': ['apt-cache', 'rdepends'],
}
commands['aptitude'] = {
'install': ['aptitude', '-q', 'install'],
'uninstall': ['aptitude', '-q', 'remove'],
'update': ['aptitude', '-q', 'update'],
'versions': ['aptitude', '-q', 'versions'],
'search': ['aptitute', 'search'],
'list': ['dpkg-query', '-W'],
'info': ['dpkg-query', '-s'],
'files': ['dpkg-query', '-L'],
'depends': ['apt-cache', 'depends'],
'rdepends': ['apt-cache', 'rdepends'],
}
commands['yum'] = {
'install': ['yum', '-C', 'install'],
'uninstall': ['yum', '-C', 'erase'],
'update': ['yum', 'makecache'],
'versions': ['yum', '-C', 'info'],
'list': ['rpm', '-qa'],
'info': ['rpm', '-qi'],
'files': ['rpm', '-qf'],
'verify': ['rpm', '-V'],
'installlog': ['rpm', '--last'],
'depends': ['yum', '-C', 'deplist'],
'repolist': ['yum', 'repolist']
}
transforms = {}
transforms['aptitude'] = {
'versions': lambda args: [('^' + arg + '$') for arg in args]
}
# prefer aptitude to apt-get
if os.access('/usr/bin/aptitude', os.X_OK):
package_manager = 'aptitude'
elif os.access('/usr/bin/apt-get', os.X_OK):
package_manager = 'apt'
elif os.access('/usr/bin/yum', os.X_OK):
package_manager = 'yum'
else:
print >>sys.stderr, "Unknown package manager"
sys.exit(1)
if len(sys.argv) < 2:
usage(sys.stderr)
sys.exit(2)
command = sys.argv[1]
if not command in commands[package_manager]:
print >>sys.stderr, package_manager, 'does not support', command
sys.exit(1)
command_list = commands[package_manager][command]
try:
transform = transforms[package_manager][command]
except KeyError:
transform = lambda args: args
command_list.extend(transform(sys.argv[2:]))
return_code = subprocess.call(command_list, shell=False)
sys.exit(return_code)