Kaydet (Commit) e7b33db2 authored tarafından Jack Jansen's avatar Jack Jansen

Changed database format to make fields adhere to PEP 241 where

applicable, and use a similar naming scheme for other fields. This
has drastically changed the structure, as the PEP241 names aren't
identifiers.
üst 9eb67ea2
...@@ -28,6 +28,8 @@ _scriptExc_BadInstalled = "pimp._scriptExc_BadInstalled" ...@@ -28,6 +28,8 @@ _scriptExc_BadInstalled = "pimp._scriptExc_BadInstalled"
NO_EXECUTE=0 NO_EXECUTE=0
PIMP_VERSION="0.1"
DEFAULT_FLAVORORDER=['source', 'binary'] DEFAULT_FLAVORORDER=['source', 'binary']
DEFAULT_DOWNLOADDIR='/tmp' DEFAULT_DOWNLOADDIR='/tmp'
DEFAULT_BUILDDIR='/tmp' DEFAULT_BUILDDIR='/tmp'
...@@ -141,11 +143,14 @@ class PimpDatabase: ...@@ -141,11 +143,14 @@ class PimpDatabase:
dict = plistlib.Plist.fromFile(fp) dict = plistlib.Plist.fromFile(fp)
# Test here for Pimp version, etc # Test here for Pimp version, etc
if not included: if not included:
self._version = dict.get('version', '0.1') self._version = dict.get('Version', '0.1')
self._maintainer = dict.get('maintainer', '') if self._version != PIMP_VERSION:
self._description = dict.get('description', '') sys.stderr.write("Warning: database version %s does not match %s\n"
self._appendPackages(dict['packages']) % (self._version, PIMP_VERSION))
others = dict.get('include', []) self._maintainer = dict.get('Maintainer', '')
self._description = dict.get('Description', '')
self._appendPackages(dict['Packages'])
others = dict.get('Include', [])
for url in others: for url in others:
self.appendURL(url, included=1) self.appendURL(url, included=1)
...@@ -155,7 +160,7 @@ class PimpDatabase: ...@@ -155,7 +160,7 @@ class PimpDatabase:
to our internal storage.""" to our internal storage."""
for p in packages: for p in packages:
pkg = PimpPackage(self, **dict(p)) pkg = PimpPackage(self, dict(p))
self._packages.append(pkg) self._packages.append(pkg)
def list(self): def list(self):
...@@ -168,7 +173,7 @@ class PimpDatabase: ...@@ -168,7 +173,7 @@ class PimpDatabase:
rv = [] rv = []
for pkg in self._packages: for pkg in self._packages:
rv.append(_fmtpackagename(pkg)) rv.append(pkg.fullname())
return rv return rv
def dump(self, pathOrFile): def dump(self, pathOrFile):
...@@ -181,10 +186,10 @@ class PimpDatabase: ...@@ -181,10 +186,10 @@ class PimpDatabase:
for pkg in self._packages: for pkg in self._packages:
packages.append(pkg.dump()) packages.append(pkg.dump())
dict = { dict = {
'version': self._version, 'Version': self._version,
'maintainer': self._maintainer, 'Maintainer': self._maintainer,
'description': self._description, 'Description': self._description,
'packages': packages 'Packages': packages
} }
plist = plistlib.Plist(**dict) plist = plistlib.Plist(**dict)
plist.write(pathOrFile) plist.write(pathOrFile)
...@@ -215,82 +220,84 @@ class PimpDatabase: ...@@ -215,82 +220,84 @@ class PimpDatabase:
else: else:
flavor = None flavor = None
else: else:
name = ident['name'] name = ident['Name']
version = ident.get('version') version = ident.get('Version')
flavor = ident.get('flavor') flavor = ident.get('Flavor')
found = None found = None
for p in self._packages: for p in self._packages:
if name == p.name and \ if name == p.name() and \
(not version or version == p.version) and \ (not version or version == p.version()) and \
(not flavor or flavor == p.flavor): (not flavor or flavor == p.flavor()):
if not found or found < p: if not found or found < p:
found = p found = p
return found return found
ALLOWED_KEYS = [
"Name",
"Version",
"Flavor",
"Description",
"Home-page",
"Download-URL",
"Install-test",
"Install-command",
"Pre-install-command",
"Post-install-command",
"Prerequisites",
"MD5Sum"
]
class PimpPackage: class PimpPackage:
"""Class representing a single package.""" """Class representing a single package."""
def __init__(self, db, name, def __init__(self, db, dict):
version=None,
flavor=None,
description=None,
longdesc=None,
downloadURL=None,
installTest=None,
prerequisites=None,
preInstall=None,
postInstall=None,
MD5Sum=None):
self._db = db self._db = db
self.name = name name = dict["Name"]
self.version = version for k in dict.keys():
self.flavor = flavor if not k in ALLOWED_KEYS:
self.description = description sys.stderr.write("Warning: %s: unknown key %s\n" % (name, k))
self.longdesc = longdesc self._dict = dict
self.downloadURL = downloadURL
self._installTest = installTest def __getitem__(self, key):
self._prerequisites = prerequisites return self._dict[key]
self._preInstall = preInstall
self._postInstall = postInstall def name(self): return self._dict['Name']
self._MD5Sum = MD5Sum def version(self): return self._dict['Version']
def flavor(self): return self._dict['Flavor']
def description(self): return self._dict['Description']
def homepage(self): return self._dict['Home-page']
def downloadURL(self): return self._dict['Download-URL']
def fullname(self):
"""Return the full name "name-version-flavor" of a package.
If the package is a pseudo-package, something that cannot be
installed through pimp, return the name in (parentheses)."""
rv = self._dict['Name']
if self._dict.has_key('Version'):
rv = rv + '-%s' % self._dict['Version']
if self._dict.has_key('Flavor'):
rv = rv + '-%s' % self._dict['Flavor']
if not self._dict.get('Download-URL'):
# Pseudo-package, show in parentheses
rv = '(%s)' % rv
return rv
def dump(self): def dump(self):
"""Return a dict object containing the information on the package.""" """Return a dict object containing the information on the package."""
dict = { return self._dict
'name': self.name,
}
if self.version:
dict['version'] = self.version
if self.flavor:
dict['flavor'] = self.flavor
if self.description:
dict['description'] = self.description
if self.longdesc:
dict['longdesc'] = self.longdesc
if self.downloadURL:
dict['downloadURL'] = self.downloadURL
if self._installTest:
dict['installTest'] = self._installTest
if self._prerequisites:
dict['prerequisites'] = self._prerequisites
if self._preInstall:
dict['preInstall'] = self._preInstall
if self._postInstall:
dict['postInstall'] = self._postInstall
if self._MD5Sum:
dict['MD5Sum'] = self._MD5Sum
return dict
def __cmp__(self, other): def __cmp__(self, other):
"""Compare two packages, where the "better" package sorts lower.""" """Compare two packages, where the "better" package sorts lower."""
if not isinstance(other, PimpPackage): if not isinstance(other, PimpPackage):
return cmp(id(self), id(other)) return cmp(id(self), id(other))
if self.name != other.name: if self.name() != other.name():
return cmp(self.name, other.name) return cmp(self.name(), other.name())
if self.version != other.version: if self.version() != other.version():
return -cmp(self.version, other.version) return -cmp(self.version(), other.version())
return self._db.preferences.compareFlavors(self.flavor, other.flavor) return self._db.preferences.compareFlavors(self.flavor(), other.flavor())
def installed(self): def installed(self):
"""Test wheter the package is installed. """Test wheter the package is installed.
...@@ -307,7 +314,7 @@ class PimpPackage: ...@@ -307,7 +314,7 @@ class PimpPackage:
"os": os, "os": os,
"sys": sys, "sys": sys,
} }
installTest = self._installTest.strip() + '\n' installTest = self._dict['Install-test'].strip() + '\n'
try: try:
exec installTest in namespace exec installTest in namespace
except ImportError, arg: except ImportError, arg:
...@@ -319,7 +326,6 @@ class PimpPackage: ...@@ -319,7 +326,6 @@ class PimpPackage:
except _scriptExc_BadInstalled, arg: except _scriptExc_BadInstalled, arg:
return "bad", str(arg) return "bad", str(arg)
except: except:
print 'TEST:', repr(self._installTest)
return "bad", "Package install test got exception" return "bad", "Package install test got exception"
return "yes", "" return "yes", ""
...@@ -333,20 +339,25 @@ class PimpPackage: ...@@ -333,20 +339,25 @@ class PimpPackage:
string should tell the user what to do.""" string should tell the user what to do."""
rv = [] rv = []
if not self.downloadURL: if not self._dict['Download-URL']:
return [(None, "This package needs to be installed manually")] return [(None, "This package needs to be installed manually")]
if not self._prerequisites: if not self._dict['Prerequisites']:
return [] return []
for item in self._prerequisites: for item in self._dict['Prerequisites']:
if type(item) == str: if type(item) == str:
pkg = None pkg = None
descr = str(item) descr = str(item)
else: else:
pkg = self._db.find(item) name = item['Name']
if item.has_key('Version'):
name = name + '-' + item['Version']
if item.has_key('Flavor'):
name = name + '-' + item['Flavor']
pkg = self._db.find(name)
if not pkg: if not pkg:
descr = "Requires unknown %s"%_fmtpackagename(item) descr = "Requires unknown %s"%name
else: else:
descr = pkg.description descr = pkg.description()
rv.append((pkg, descr)) rv.append((pkg, descr))
return rv return rv
...@@ -380,7 +391,7 @@ class PimpPackage: ...@@ -380,7 +391,7 @@ class PimpPackage:
string. string.
""" """
scheme, loc, path, query, frag = urlparse.urlsplit(self.downloadURL) scheme, loc, path, query, frag = urlparse.urlsplit(self._dict['Download-URL'])
path = urllib.url2pathname(path) path = urllib.url2pathname(path)
filename = os.path.split(path)[1] filename = os.path.split(path)[1]
self.archiveFilename = os.path.join(self._db.preferences.downloadDir, filename) self.archiveFilename = os.path.join(self._db.preferences.downloadDir, filename)
...@@ -390,7 +401,7 @@ class PimpPackage: ...@@ -390,7 +401,7 @@ class PimpPackage:
if self._cmd(output, self._db.preferences.downloadDir, if self._cmd(output, self._db.preferences.downloadDir,
"curl", "curl",
"--output", self.archiveFilename, "--output", self.archiveFilename,
self.downloadURL): self._dict['Download-URL']):
return "download command failed" return "download command failed"
if not os.path.exists(self.archiveFilename) and not NO_EXECUTE: if not os.path.exists(self.archiveFilename) and not NO_EXECUTE:
return "archive not found after download" return "archive not found after download"
...@@ -402,12 +413,12 @@ class PimpPackage: ...@@ -402,12 +413,12 @@ class PimpPackage:
if not os.path.exists(self.archiveFilename): if not os.path.exists(self.archiveFilename):
return 0 return 0
if not self._MD5Sum: if not self._dict['MD5Sum']:
sys.stderr.write("Warning: no MD5Sum for %s\n" % _fmtpackagename(self)) sys.stderr.write("Warning: no MD5Sum for %s\n" % self.fullname())
return 1 return 1
data = open(self.archiveFilename, 'rb').read() data = open(self.archiveFilename, 'rb').read()
checksum = md5.new(data).hexdigest() checksum = md5.new(data).hexdigest()
return checksum == self._MD5Sum return checksum == self._dict['MD5Sum']
def unpackSinglePackage(self, output=None): def unpackSinglePackage(self, output=None):
"""Unpack a downloaded package archive.""" """Unpack a downloaded package archive."""
...@@ -433,24 +444,27 @@ class PimpPackage: ...@@ -433,24 +444,27 @@ class PimpPackage:
If output is given it should be a file-like object and it If output is given it should be a file-like object and it
will receive a log of what happened.""" will receive a log of what happened."""
if not self.downloadURL: if not self._dict['Download-URL']:
return "%s: This package needs to be installed manually" % _fmtpackagename(self) return "%s: This package needs to be installed manually" % _fmtpackagename(self)
msg = self.downloadSinglePackage(output) msg = self.downloadSinglePackage(output)
if msg: if msg:
return "download %s: %s" % (_fmtpackagename(self), msg) return "download %s: %s" % (self.fullname(), msg)
msg = self.unpackSinglePackage(output) msg = self.unpackSinglePackage(output)
if msg: if msg:
return "unpack %s: %s" % (_fmtpackagename(self), msg) return "unpack %s: %s" % (self.fullname(), msg)
if self._preInstall: if self._dict.has_key('Pre-install-command'):
if self._cmd(output, self._buildDirname, self._preInstall): if self._cmd(output, self._buildDirname, self._dict['Pre-install-command']):
return "pre-install %s: running \"%s\" failed" % \ return "pre-install %s: running \"%s\" failed" % \
(_fmtpackagename(self), self._preInstall) (self.fullname(), self._dict['Pre-install-command'])
if self._cmd(output, self._buildDirname, sys.executable, "setup.py install"): installcmd = self._dict.get('Install-command')
return "install %s: running \"setup.py install\" failed" % _fmtpackagename(self) if not installcmd:
if self._postInstall: installcmd = '"%s" setup.py install' % sys.executable
if self._cmd(output, self._buildDirname, self._postInstall): if self._cmd(output, self._buildDirname, installcmd):
return "install %s: running \"%s\" failed" % self.fullname()
if self._dict.has_key('Post-install-command'):
if self._cmd(output, self._buildDirname, self._dict['Post-install-command']):
return "post-install %s: running \"%s\" failed" % \ return "post-install %s: running \"%s\" failed" % \
(_fmtpackagename(self), self._postInstall) (self.fullname(), self._dict['Post-install-command'])
return None return None
class PimpInstaller: class PimpInstaller:
...@@ -524,23 +538,6 @@ class PimpInstaller: ...@@ -524,23 +538,6 @@ class PimpInstaller:
return status return status
def _fmtpackagename(dict):
"""Return the full name "name-version-flavor" of a package.
If the package is a pseudo-package, something that cannot be
installed through pimp, return the name in (parentheses)."""
if isinstance(dict, PimpPackage):
dict = dict.dump()
rv = dict['name']
if dict.has_key('version'):
rv = rv + '-%s' % dict['version']
if dict.has_key('flavor'):
rv = rv + '-%s' % dict['flavor']
if not dict.get('downloadURL'):
# Pseudo-package, show in parentheses
rv = '(%s)' % rv
return rv
def _run(mode, verbose, force, args): def _run(mode, verbose, force, args):
"""Engine for the main program""" """Engine for the main program"""
...@@ -560,14 +557,14 @@ def _run(mode, verbose, force, args): ...@@ -560,14 +557,14 @@ def _run(mode, verbose, force, args):
for pkgname in args: for pkgname in args:
pkg = db.find(pkgname) pkg = db.find(pkgname)
if pkg: if pkg:
description = pkg.description description = pkg.description()
pkgname = _fmtpackagename(pkg) pkgname = pkg.fullname()
else: else:
description = 'Error: no such package' description = 'Error: no such package'
print "%-20.20s\t%s" % (pkgname, description) print "%-20.20s\t%s" % (pkgname, description)
if verbose: if verbose:
print "\tHome page:\t", pkg.longdesc print "\tHome page:\t", pkg.homepage()
print "\tDownload URL:\t", pkg.downloadURL print "\tDownload URL:\t", pkg.downloadURL()
elif mode =='status': elif mode =='status':
if not args: if not args:
args = db.listnames() args = db.listnames()
...@@ -577,7 +574,7 @@ def _run(mode, verbose, force, args): ...@@ -577,7 +574,7 @@ def _run(mode, verbose, force, args):
pkg = db.find(pkgname) pkg = db.find(pkgname)
if pkg: if pkg:
status, msg = pkg.installed() status, msg = pkg.installed()
pkgname = _fmtpackagename(pkg) pkgname = pkg.fullname()
else: else:
status = 'error' status = 'error'
msg = 'No such package' msg = 'No such package'
...@@ -588,7 +585,7 @@ def _run(mode, verbose, force, args): ...@@ -588,7 +585,7 @@ def _run(mode, verbose, force, args):
if not pkg: if not pkg:
pkg = '' pkg = ''
else: else:
pkg = _fmtpackagename(pkg) pkg = pkg.fullname()
print "%-20.20s\tRequirement: %s %s" % ("", pkg, msg) print "%-20.20s\tRequirement: %s %s" % ("", pkg, msg)
elif mode == 'install': elif mode == 'install':
if not args: if not args:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment