* better implementation for lspisi
* remove i as an alias for info command
This commit is contained in:
@@ -625,7 +625,7 @@ Usage: info <package1> <package2> ... <packagen>
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(Info, self).__init__()
|
super(Info, self).__init__()
|
||||||
|
|
||||||
name = ("info", "i")
|
name = ("info")
|
||||||
|
|
||||||
def options(self):
|
def options(self):
|
||||||
self.parser.add_option("-f", "--files", action="store_true",
|
self.parser.add_option("-f", "--files", action="store_true",
|
||||||
|
|||||||
+11
-60
@@ -10,68 +10,19 @@
|
|||||||
#
|
#
|
||||||
# Please read the COPYING file.
|
# Please read the COPYING file.
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
import sys
|
||||||
import zipfile
|
import pisi
|
||||||
|
|
||||||
def openZip(fileName):
|
|
||||||
if not zipfile.is_zipfile(fileName):
|
|
||||||
usage("ZIP file required...")
|
|
||||||
|
|
||||||
f = zipfile.ZipFile(fileName, "r")
|
|
||||||
|
|
||||||
if [True for file in f.namelist() if file == "files.xml"]:
|
|
||||||
return f
|
|
||||||
else:
|
|
||||||
usage("'%s' is not a PiSi package" % (fileName))
|
|
||||||
|
|
||||||
def fillFileList(zipFile):
|
|
||||||
filelist = []
|
|
||||||
|
|
||||||
for file in zipFile.namelist():
|
|
||||||
filelist.append(file)
|
|
||||||
|
|
||||||
filelist.sort()
|
|
||||||
return filelist
|
|
||||||
|
|
||||||
def uniq(alist):
|
|
||||||
set = {}
|
|
||||||
return [set.setdefault(e, e) for e in alist if e not in set]
|
|
||||||
|
|
||||||
def usage(errmsg):
|
|
||||||
print """
|
|
||||||
Error: %s
|
|
||||||
|
|
||||||
Usage:
|
|
||||||
lspisi PiSi_package.PiSi (lists the content of package)
|
|
||||||
lspisi dirs PiSi_package.PiSi (lists directories in the package for the package developer)
|
|
||||||
""" % (errmsg)
|
|
||||||
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
def main():
|
|
||||||
|
|
||||||
if len(sys.argv) < 2 or ("dirs" in sys.argv and len(sys.argv) < 3):
|
|
||||||
usage("PiSi package required..")
|
|
||||||
|
|
||||||
if sys.argv[1] == "dirs":
|
|
||||||
f = openZip(sys.argv[2])
|
|
||||||
dirlist =[]
|
|
||||||
for file in fillFileList(f):
|
|
||||||
dirlist.append(os.path.dirname(file))
|
|
||||||
|
|
||||||
for dir in uniq(dirlist):
|
|
||||||
print "<Path fileType=\"\">" + dir.replace("install/", "/") + "</Path>"
|
|
||||||
|
|
||||||
else:
|
|
||||||
f = openZip(sys.argv[1])
|
|
||||||
for file in fillFileList(f):
|
|
||||||
if f.getinfo(file).external_attr == 2716663808:
|
|
||||||
print file + " --> " + f.read(file)
|
|
||||||
else:
|
|
||||||
print file
|
|
||||||
|
|
||||||
|
def show_info(filename):
|
||||||
|
pisi.api.init(database=False)
|
||||||
|
metadata, files = pisi.api.info_file(filename)
|
||||||
|
paths = [fileinfo.path for fileinfo in files.list]
|
||||||
|
paths.sort()
|
||||||
|
for path in paths:
|
||||||
|
print '/' + path
|
||||||
|
pisi.api.finalize()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
sys.exit(main())
|
for x in sys.argv[1:]:
|
||||||
|
show_info(x)
|
||||||
|
|||||||
Reference in New Issue
Block a user