forked from marcosmoyano/eix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheix.debian
executable file
·239 lines (221 loc) · 8.06 KB
/
eix.debian
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#!/usr/bin/env python
""" Marcos Moyano - [email protected]
APT/APTITUDE search/install engine with colors and some more info.
Based on the Gentoo eix package.
Copyright (c) 2007 Marcos Moyano
This program is free software; you can REDistribute it and/or modify it
under the terms of the GNU General Public License version 2 as published by
the Free Software Foundation.
"""
import os
import sys
import getopt
from re import match
PRINT_VERSION = "0.1-r5"
####################
# Manage arguments #
####################
def parse():
"""
Manage the command line options.
"""
package = None
if len(sys.argv[1:]) == 0:
print ("To few arguments: %d recieved. At least one is necessary.\n\
\rTry 'eix -h' or 'eix --help' for more information." % \
len(sys.argv[1:]))
sys.exit(1)
else:
try:
optlist, args = getopt.getopt(sys.argv[1:], \
'hvV:iuasp', \
['exact', 'deep', 'installed', 'help', 'version', 'clean', 'update', 'upgrade', 'purge'])
except getopt.GetoptError, error:
print ("eix: Invalid argument.%s\n\
\rTry 'eix -h' or 'eix --help' for more information." % error)
sys.exit(1)
package = " ".join(args)
cmd_ln_work(package, optlist)
#####################################
# Work through the cmd line options #
#####################################
def cmd_ln_work(package, optlist):
"""
Work through the command line options
"""
pdeep = 0
puniq = 0
inst = 0
for arg in optlist:
if arg[0] == "-i":
ecode = os.system("aptitude install %s" % package)
sys.exit(ecode)
elif arg[0] == "-u":
ecode = os.system("aptitude remove %s" % package)
sys.exit(ecode)
elif arg[0] == "-a":
ecode = os.system("apropos %s" % package)
sys.exit(ecode)
elif arg[0] == "-s":
ecode = os.system("apt-get source %s" % package)
sys.exit(ecode)
elif arg[0] == "--exact":
puniq = 1
elif arg[0] == "--deep":
pdeep = 1
elif arg[0] == "--installed":
inst = 1
elif arg[0] == "--update":
ecode = os.system("aptitude update")
sys.exit(ecode)
elif arg[0] == "--upgrade":
ecode = os.system("aptitude safe-upgrade")
sys.exit(ecode)
elif arg[0] == "--clean":
ecode = os.system("aptitude clean")
sys.exit(ecode)
elif arg[0] in ("-h", "--help"):
printhelp()
sys.exit(0)
elif arg[0] in ("-p", "--purge"):
ecode = os.system("aptitude purge %s" % package)
sys.exit(ecode)
elif arg[0] in ("-v", "-V", "--version"):
print ("eix version is: %s \n" % PRINT_VERSION)
sys.exit(0)
search(pdeep, puniq, inst, package)
####################
# Print help info #
####################
def printhelp():
"""
Print help information and exit.
"""
print """APT/Aptitude search/install engine with colors and a little more.
Usage: eix [OPTIONS] EXPRESSION
Options:
--deep Print package dependencies, recommended and suggested packages.
--exact Print the exact match for EXPRESSION.
--installed Print installed packates that matches the search EXPRESSION.
--clean Erase the downloaded archive files.
--update Update APT repository.
--upgrade Upgrade APT repository.
-i Install the selected packages.
-u Uninstall the selected packages.
-a Search the manual page names and descriptions (apropos)
-s Install source code for the selected packages.
-p, --purge Remove packages and their configuration files.
-V, -v, --version Print version information and exit.
-h, --help Print this help and exit.
Report bugs to <[email protected]>."""
return
##################
# Installed? #
##################
def installed(pname):
"""
Look if the package is installed and return the version installed if it is.
"""
try:
cache = os.popen("dpkg --list | grep %s" % pname, "r")
version = None
for line in cache.readlines():
line = line.strip().split()
if line[1] == pname and line[0] == "ii":
version = line[2]
break
return(version)
except:
print "Signal Caught. Stop!"
sys.exit(1)
##################
# APT search #
##################
def search(flag, puniq, inst, package):
"""
APT search for package.
"""
result = os.popen("apt-cache search %s" % package, "r")
for line in result.readlines():
name = line.strip().split(" - ")[0]
desc = " - ".join(line.strip().split(" - ")[1:])
if puniq == 1:
if name == package:
mysearch(name, desc, inst, flag)
break
else:
mysearch(name, desc, inst, flag)
####################
# APT SHOW search #
####################
def mysearch(pname, pdesc, inst, printinfo):
"""
EIX specified search through apt-cache show package.
"""
resul = {"Section" : "", "Homepage" : [],
"Version": [], "Deps": [], "Recommends": [], "Suggests": []}
cache = os.popen("apt-cache show %s" % pname, "r")
try:
for line in cache.readlines():
line = line.strip()
if match("^Section:", line):
resul["Section"] = line.split(": ")[1]
if printinfo == 1:
if match("^Depends:", line):
resul["Deps"].append(":".join(line.split(": ")[1:]))
if match("^Recommends", line):
resul["Recommends"].append(":".join(line.split(": ")[1:]))
if match("^Suggests", line):
resul["Suggests"].append(":".join(line.split(": ")[1:]))
if match("^Version:", line):
resul["Version"].append(line.split(": ")[1])
if "http://" in line:
line = line.split()
for word in line:
if "http://" in word and word not in resul["Homepage"]:
resul["Homepage"].append(word)
myprint(pname, pdesc, resul, inst, printinfo)
except:
sys.exit(1)
######################
# EIX personal print #
######################
def myprint(pname, pdesc, resul, inst, printinfo):
"""
EIX specified print.
"""
# Colors #
RED = "\033[1;31m"
BLUE = "\033[1;34m"
GREEN = "\033[32;02m"
WHITE = "\033[1;00m"
YELLOW = "\033[1;33m"
res = installed(pname)
if res == None and inst == 1:
return
if res == None and inst == 0:
print ("%sPackage: %s%s %s" % (BLUE, RED, pname, WHITE))
else:
print ("%sPackage: %s%s %s[%s %s %s]" % \
(BLUE, RED, pname, WHITE, YELLOW, res, WHITE))
print ("\t%sDescription:\t%s%s\n\t%sSection:\t%s%s" % \
(GREEN, WHITE, pdesc, GREEN, WHITE, resul["Section"]))
if len(resul["Homepage"]) != 0:
print ("\t%sHomepage:\t%s%s" % \
(GREEN, WHITE, " - ".join(x for x in resul["Homepage"])))
print ("\t%sVersion(s):\t%s%s" % \
(GREEN, WHITE, " - ".join(x for x in resul["Version"])))
if printinfo == 1:
for extra in resul["Version"]:
if len(resul["Deps"]) != 0:
print ("\t%sDepends:\t%s%s --> %s" % \
(GREEN, WHITE, extra, resul["Deps"][resul["Version"].index(extra)]))
if len(resul["Recommends"]) != 0:
print ("\t%sRecommends:\t%s%s --> %s" % \
(GREEN, WHITE, extra, resul["Recommends"][resul["Version"].index(extra)]))
if len(resul["Suggests"]) != 0:
print ("\t%sSuggests:\t%s%s --> %s" % \
(GREEN, WHITE, extra, resul["Suggests"][resul["Version"].index(extra)]))
print
if __name__ == "__main__":
parse()