1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-02-10 13:05:46 +01:00

Merge branch 'master' of git://gitorious.org/opensuse/osc

This commit is contained in:
Marcus Huewe 2010-03-02 01:34:58 +01:00
commit 8e7a171cf2
18 changed files with 314 additions and 311 deletions

View File

@ -1,4 +1,4 @@
jw, Tue Oct 20 22:09:16 CEST 2009 jw, Tue Oct 20 22:09:16 CEST 2009
This is a feature suggestion for easier osc commandline handling. This is a feature suggestion for easier osc commandline handling.
Many commands require specifying Project and/or Package names. Many commands require specifying Project and/or Package names.
@ -12,19 +12,19 @@ The current situation is not satisfying for the following reasons:
Examples as of osc version 0.123: Examples as of osc version 0.123:
osc maintainer PRJ [PKG] osc maintainer PRJ [PKG]
- does not look in the current directory. - does not look in the current directory.
- need at least PRJ. - need at least PRJ.
osc list [PRJ [PKG]] osc list [PRJ [PKG]]
- Never looks at the current directory. - Never looks at the current directory.
- lists all projects, if run without parameters. - lists all projects, if run without parameters.
osc checkout [PRJ] PKG osc checkout [PRJ] PKG
osc checkout PRJ osc checkout PRJ
- takes project from current directory, if inside a checkout tree - takes project from current directory, if inside a checkout tree
- else operates on an entire project. - else operates on an entire project.
osc checkin [ARG] osc checkin [ARG]
- defaults to current project and package, - defaults to current project and package,
- if arg is a subdirectory, project is taken from current directory - if arg is a subdirectory, project is taken from current directory
- if arg is a file, both project and package are taken from current - if arg is a file, both project and package are taken from current
directory. directory.
osc results [PRJ PKG] osc results [PRJ PKG]
- takes either both or none from current directory. - takes either both or none from current directory.
- many commands do not look into the current directory, - many commands do not look into the current directory,
@ -53,22 +53,22 @@ osc shall support aliases, to save typing. Some implicit aliases exist,
with well defined magic effects. Aliases substitution is literal. with well defined magic effects. Aliases substitution is literal.
They can replace options including their parameters, or just the option, or They can replace options including their parameters, or just the option, or
just the parameters. just the parameters.
- (a dash) expands to --prj openSUSE:Factory - (a dash) expands to --prj openSUSE:Factory
(or --prj followed by any other project as defined in (or --prj followed by any other project as defined in
~/.oscrc:default_project ) ~/.oscrc:default_project )
--prj - is synonymous to just -, for consistency. --prj - is synonymous to just -, for consistency.
. (a dot) evaluates the current working directory, searching for . (a dot) evaluates the current working directory, searching for
.osc/_apiurl, .osc/_project, and .osc/_package .osc/_apiurl, .osc/_project, and .osc/_package
Implicit --apiurl, --prj, or --pkg options are constructed as far Implicit --apiurl, --prj, or --pkg options are constructed as far
as available from the current directory and as far as not already as available from the current directory and as far as not already
present in the command line. present in the command line.
If a dot is used as parameter to an option, it has a more If a dot is used as parameter to an option, it has a more
deterministic meaning. deterministic meaning.
--apiurl . Substitute only the current apiurl, --apiurl . Substitute only the current apiurl,
--prj . Substitute the current project name, and provides --prj . Substitute the current project name, and provides
a default for --apiurl unless given. a default for --apiurl unless given.
--pkg . Substitures current package name likewise. --pkg . Substitures current package name likewise.
./. expands to --prj . --pkg . ./. expands to --prj . --pkg .
./PKG expands to --prj . --pkg PKG ./PKG expands to --prj . --pkg PKG
@ -83,10 +83,10 @@ printed as debug output.
online help of osc commands shall refer to the above syntax like this: online help of osc commands shall refer to the above syntax like this:
osc CMD ... PROJ/PACK osc CMD ... PROJ/PACK
An additional help entry An additional help entry
osc help 'PROJ/PACK' osc help 'PROJ/PACK'
shall explain the relevant details as presented herein. shall explain the relevant details as presented herein.

33
README
View File

@ -14,10 +14,11 @@ RPM packages are here (rpm-md repository):
http://download.opensuse.org/repositories/openSUSE:/Tools/ http://download.opensuse.org/repositories/openSUSE:/Tools/
To install from svn, do To install from svn, do
python setup.py build
python setup.py install python setup.py build
# create a symlink 'osc' in your path pointing to osc.py. python setup.py install
ln -s osc-wrapper.py /usr/bin/osc # create a symlink 'osc' in your path pointing to osc.py.
ln -s osc-wrapper.py /usr/bin/osc
Alternatively, you can directly use osc-wrapper.py from the source dir Alternatively, you can directly use osc-wrapper.py from the source dir
(which is easier if you develop on osc). (which is easier if you develop on osc).
@ -132,21 +133,21 @@ USAGE EXAMPLES:
(online at http://en.opensuse.org/Build_Service/CLI ) (online at http://en.opensuse.org/Build_Service/CLI )
To list existing content on the server To list existing content on the server
osc ls # list projects osc ls # list projects
osc ls Apache # list packages in a project osc ls Apache # list packages in a project
osc ls Apache subversion # list files of package of a project osc ls Apache subversion # list files of package of a project
Check out content Check out content
osc co Apache # entire project osc co Apache # entire project
osc co Apache subversion # a package osc co Apache subversion # a package
osc co Apache subversion foo # single file osc co Apache subversion foo # single file
Update a working copy Update a working copy
osc up osc up
osc up [pac_dir] # update a single package by its path osc up [pac_dir] # update a single package by its path
osc up * # from within a project dir, update all packages osc up * # from within a project dir, update all packages
osc up # from within a project dir, update all packages osc up # from within a project dir, update all packages
AND check out all newly added packages # AND check out all newly added packages
If an update can't be merged automatically, a file is in 'C' (conflict) If an update can't be merged automatically, a file is in 'C' (conflict)
state, and conflicts are marked with special <<<<<<< and >>>>>>> lines. state, and conflicts are marked with special <<<<<<< and >>>>>>> lines.
@ -154,7 +155,7 @@ After manually resolving the problem, use
osc resolved foo osc resolved foo
Upload change content Upload change content
osc ci # current dir osc ci # current dir
osc ci <dir> osc ci <dir>
osc ci file1 file2 ... osc ci file1 file2 ...
@ -171,7 +172,7 @@ Adds all new files in local copy and removes all disappeared files.
osc addremove osc addremove
Generates a diff, to view the changes Generates a diff, to view the changes
osc diff # current dir osc diff # current dir
osc diff file1 file2 ... osc diff file1 file2 ...
Shows the build results of the package Shows the build results of the package

View File

@ -96,8 +96,8 @@ def run(prg):
body = e.read() body = e.read()
if getattr(prg.options, 'debug', None) or \ if getattr(prg.options, 'debug', None) or \
getattr(prg.conf, 'config', {}).get('debug', None): getattr(prg.conf, 'config', {}).get('debug', None):
print >>sys.stderr, e.hdrs print >>sys.stderr, e.hdrs
print >>sys.stderr, body print >>sys.stderr, body
if e.code in [ 400, 403, 404, 500 ]: if e.code in [ 400, 403, 404, 500 ]:
if '<summary>' in body: if '<summary>' in body:
@ -119,7 +119,7 @@ def run(prg):
print >>sys.stderr, e.msg print >>sys.stderr, e.msg
if getattr(prg.options, 'debug', None) or \ if getattr(prg.options, 'debug', None) or \
getattr(prg.conf, 'config', {}).get('debug', None): getattr(prg.conf, 'config', {}).get('debug', None):
print >>sys.stderr, e.e print >>sys.stderr, e.e
return 1 return 1
except (oscerr.WrongOptions, oscerr.WrongArgs), e: except (oscerr.WrongOptions, oscerr.WrongArgs), e:

View File

@ -623,9 +623,9 @@ def main(opts, argv):
os.makedirs(os.path.join(pradir)) os.makedirs(os.path.join(pradir))
if not os.path.exists(tffn): if not os.path.exists(tffn):
if opts.linksources: if opts.linksources:
os.link(sffn, tffn) os.link(sffn, tffn)
else: else:
os.symlink(sffn, tffn) os.symlink(sffn, tffn)
if bi.pacsuffix == 'rpm': if bi.pacsuffix == 'rpm':
if opts.no_verify or opts.noinit: if opts.no_verify or opts.noinit:
@ -654,7 +654,7 @@ def main(opts, argv):
else: else:
print 'WARNING: deb packages get not verified, they can compromise your system !' print 'WARNING: deb packages get not verified, they can compromise your system !'
else: else:
print 'WARNING: unknown packages get not verified, they can compromise your system !' print 'WARNING: unknown packages get not verified, they can compromise your system !'
print 'Writing build configuration' print 'Writing build configuration'

View File

@ -7,96 +7,95 @@ import rpm
import base64 import base64
class KeyError(Exception): class KeyError(Exception):
def __init__(self, key, *args): def __init__(self, key, *args):
Exception.__init__(self) Exception.__init__(self)
self.args = args self.args = args
self.key = key self.key = key
def __str__(self): def __str__(self):
return ''+self.key+' :'+' '.join(self.args) return ''+self.key+' :'+' '.join(self.args)
class Checker: class Checker:
def __init__(self): def __init__(self):
self.dbdir = mkdtemp(prefix='oscrpmdb') self.dbdir = mkdtemp(prefix='oscrpmdb')
self.imported = {} self.imported = {}
rpm.addMacro('_dbpath', self.dbdir) rpm.addMacro('_dbpath', self.dbdir)
self.ts = rpm.TransactionSet() self.ts = rpm.TransactionSet()
self.ts.initDB() self.ts.initDB()
self.ts.openDB() self.ts.openDB()
self.ts.setVSFlags(0) self.ts.setVSFlags(0)
#self.ts.Debug(1) #self.ts.Debug(1)
def readkeys(self, keys=[]): def readkeys(self, keys=[]):
rpm.addMacro('_dbpath', self.dbdir) rpm.addMacro('_dbpath', self.dbdir)
for key in keys: for key in keys:
self.readkey(key) self.readkey(key)
rpm.delMacro("_dbpath") rpm.delMacro("_dbpath")
# python is an idiot # python is an idiot
# def __del__(self): # def __del__(self):
# self.cleanup() # self.cleanup()
def cleanup(self): def cleanup(self):
self.ts.closeDB() self.ts.closeDB()
rmtree(self.dbdir) rmtree(self.dbdir)
def readkey(self, file): def readkey(self, file):
if file in self.imported: if file in self.imported:
return return
fd = open(file, "r") fd = open(file, "r")
line = fd.readline() line = fd.readline()
if line and line[0:14] == "-----BEGIN PGP": if line and line[0:14] == "-----BEGIN PGP":
line = fd.readline() line = fd.readline()
while line and line != "\n": while line and line != "\n":
line = fd.readline() line = fd.readline()
if not line: if not line:
raise KeyError(file, "not a pgp public key") raise KeyError(file, "not a pgp public key")
else: else:
raise KeyError(file, "not a pgp public key") raise KeyError(file, "not a pgp public key")
key = '' key = ''
line = fd.readline() line = fd.readline()
while line: while line:
if line[0:12] == "-----END PGP": if line[0:12] == "-----END PGP":
break break
line = line.rstrip() line = line.rstrip()
key += line key += line
line = fd.readline() line = fd.readline()
fd.close() fd.close()
if not line or line[0:12] != "-----END PGP": if not line or line[0:12] != "-----END PGP":
raise KeyError(file, "not a pgp public key") raise KeyError(file, "not a pgp public key")
bkey = base64.b64decode(key) bkey = base64.b64decode(key)
r = self.ts.pgpImportPubkey(bkey) r = self.ts.pgpImportPubkey(bkey)
if r != 0: if r != 0:
raise KeyError(file, "failed to import pubkey") raise KeyError(file, "failed to import pubkey")
self.imported[file] = 1 self.imported[file] = 1
def check(self, pkg): def check(self, pkg):
fd = os.open(pkg, os.O_RDONLY) fd = os.open(pkg, os.O_RDONLY)
hdr = self.ts.hdrFromFdno(fd) hdr = self.ts.hdrFromFdno(fd)
os.close(fd) os.close(fd)
if __name__ == "__main__": if __name__ == "__main__":
import sys import sys
keyfiles = [] keyfiles = []
pkgs = [] pkgs = []
for arg in sys.argv[1:]: for arg in sys.argv[1:]:
if arg[-4:] == '.rpm': if arg[-4:] == '.rpm':
pkgs.append(arg) pkgs.append(arg)
else: else:
keyfiles.append(arg) keyfiles.append(arg)
checker = Checker()
try:
checker.readkeys(keyfiles)
for pkg in pkgs:
checker.check(pkg)
except Exception, e:
checker.cleanup()
raise e
checker = Checker()
try:
checker.readkeys(keyfiles)
for pkg in pkgs:
checker.check(pkg)
except Exception, e:
checker.cleanup()
raise e
# vim: sw=4 et # vim: sw=4 et

View File

@ -28,11 +28,11 @@ MAN_FOOTER = r"""
Type 'osc help <subcommand>' for more detailed help on a specific subcommand. Type 'osc help <subcommand>' for more detailed help on a specific subcommand.
.PP .PP
For additional information, see For additional information, see
* http://www.opensuse.org/Build_Service_Tutorial * http://en.opensuse.org/Build_Service_Tutorial
* http://www.opensuse.org/Build_Service/CLI * http://en.opensuse.org/Build_Service/CLI
.PP .PP
You can modify osc commands, or roll you own, via the plugin API: You can modify osc commands, or roll you own, via the plugin API:
* http://www.opensuse.org/Build_Service/osc_plugins * http://en.opensuse.org/Build_Service/osc_plugins
.SH AUTHOR .SH AUTHOR
osc was written by several authors. This man page is automatically generated. osc was written by several authors. This man page is automatically generated.
""" """
@ -48,11 +48,11 @@ class Osc(cmdln.Cmdln):
${help_list} ${help_list}
global ${option_list} global ${option_list}
For additional information, see For additional information, see
* http://www.opensuse.org/Build_Service_Tutorial * http://en.opensuse.org/Build_Service_Tutorial
* http://www.opensuse.org/Build_Service/CLI * http://en.opensuse.org/Build_Service/CLI
You can modify osc commands, or roll you own, via the plugin API: You can modify osc commands, or roll you own, via the plugin API:
* http://www.opensuse.org/Build_Service/osc_plugins * http://en.opensuse.org/Build_Service/osc_plugins
""" """
name = 'osc' name = 'osc'
conf = None conf = None
@ -393,7 +393,7 @@ class Osc(cmdln.Cmdln):
print "Creating initial patchinfo..." print "Creating initial patchinfo..."
query='cmd=createpatchinfo' query='cmd=createpatchinfo'
if args and args[0]: if args and args[0]:
query += "&name=" + args[0] query += "&name=" + args[0]
url = makeurl(apiurl, ['source', project], query=query) url = makeurl(apiurl, ['source', project], query=query)
f = http_POST(url) f = http_POST(url)
for p in meta_get_packagelist(apiurl, project): for p in meta_get_packagelist(apiurl, project):
@ -777,8 +777,8 @@ class Osc(cmdln.Cmdln):
for p in pac: for p in pac:
result = create_submit_request(apiurl, project, p) result = create_submit_request(apiurl, project, p)
if not result: if not result:
# sys.exit(result) # sys.exit(result)
sys.exit("submit request creation failed") sys.exit("submit request creation failed")
sr_ids.append(result) sr_ids.append(result)
# create submit requests for all found patchinfos # create submit requests for all found patchinfos
@ -804,7 +804,7 @@ class Osc(cmdln.Cmdln):
print "Requests created: ", print "Requests created: ",
for i in sr_ids: for i in sr_ids:
print i, print i,
sys.exit('Successfull finished') sys.exit('Successfull finished')
elif len(args) <= 2: elif len(args) <= 2:
@ -2698,7 +2698,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
opts.name_filter = None opts.name_filter = None
opts.status_filter = None opts.status_filter = None
opts.vertical = None opts.vertical = None
self.do_prjresults('prjresults', opts, *args); self.do_prjresults('prjresults', opts, *args)
sys.exit(0) sys.exit(0)
else: else:
project = store_read_project(wd) project = store_read_project(wd)
@ -2819,21 +2819,21 @@ Please submit there instead, or use --nodevelproject to force direct submission.
def print_repos(self): def print_repos(self):
wd = os.curdir wd = os.curdir
doprint = False doprint = False
if is_package_dir(wd): if is_package_dir(wd):
str = "package" str = "package"
doprint = True doprint = True
elif is_project_dir(wd): elif is_project_dir(wd):
str = "project" str = "project"
doprint = True doprint = True
if doprint: if doprint:
print 'Valid arguments for this %s are:' % str print 'Valid arguments for this %s are:' % str
print print
self.do_repos(None, None) self.do_repos(None, None)
print print
raise oscerr.WrongArgs('Missing arguments') raise oscerr.WrongArgs('Missing arguments')
@cmdln.alias('rbl') @cmdln.alias('rbl')
@cmdln.alias('rbuildlog') @cmdln.alias('rbuildlog')
@ -2960,9 +2960,9 @@ Please submit there instead, or use --nodevelproject to force direct submission.
if len(args) == 2: # 2 if len(args) == 2: # 2
if is_package_dir('.'): if is_package_dir('.'):
package = store_read_package(wd) package = store_read_package(wd)
else: else:
raise oscerr.WrongArgs('package is not specified.') raise oscerr.WrongArgs('package is not specified.')
project = store_read_project(wd) project = store_read_project(wd)
apiurl = store_read_apiurl(wd) apiurl = store_read_apiurl(wd)
repository = args[0] repository = args[0]
@ -2982,9 +2982,9 @@ Please submit there instead, or use --nodevelproject to force direct submission.
reason = root.find('explain').text reason = root.find('explain').text
print reason print reason
if reason == "meta change": if reason == "meta change":
print "changed keys:" print "changed keys:"
for package in root.findall('packagechange'): for package in root.findall('packagechange'):
print " ", package.get('change'), package.get('key') print " ", package.get('change'), package.get('key')
# FIXME: the new osc syntax should allow to specify multiple packages # FIXME: the new osc syntax should allow to specify multiple packages
@ -3028,9 +3028,9 @@ Please submit there instead, or use --nodevelproject to force direct submission.
if len(args) < 3: # 2 if len(args) < 3: # 2
if is_package_dir('.'): if is_package_dir('.'):
packages = [store_read_package(wd)] packages = [store_read_package(wd)]
elif not is_project_dir('.'): elif not is_project_dir('.'):
raise oscerr.WrongArgs('Project and package is not specified.') raise oscerr.WrongArgs('Project and package is not specified.')
project = store_read_project(wd) project = store_read_project(wd)
apiurl = store_read_apiurl(wd) apiurl = store_read_apiurl(wd)
repository = args[0] repository = args[0]
@ -3058,7 +3058,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
for package in root.findall('package'): for package in root.findall('package'):
print package.get('name'), ":" print package.get('name'), ":"
for dep in package.findall('pkgdep'): for dep in package.findall('pkgdep'):
print " ", dep.text print " ", dep.text
@cmdln.option('-x', '--extra-pkgs', metavar='PAC', action='append', @cmdln.option('-x', '--extra-pkgs', metavar='PAC', action='append',

View File

@ -325,12 +325,12 @@ def init_basicauth(config):
import sys import sys
if sys.version_info < (2, 6): if sys.version_info < (2, 6):
# HTTPS proxy is not supported in old urllib2. It only leads to an error # HTTPS proxy is not supported in old urllib2. It only leads to an error
# or, at best, a warning. # or, at best, a warning.
if 'https_proxy' in os.environ: if 'https_proxy' in os.environ:
del os.environ['https_proxy'] del os.environ['https_proxy']
if 'HTTPS_PROXY' in os.environ: if 'HTTPS_PROXY' in os.environ:
del os.environ['HTTPS_PROXY'] del os.environ['HTTPS_PROXY']
if config['http_debug']: if config['http_debug']:
# brute force # brute force

View File

@ -2139,17 +2139,17 @@ def show_attribute_meta(apiurl, prj, pac, subpac, attribute, with_defaults, with
path.append('source') path.append('source')
path.append(prj) path.append(prj)
if pac: if pac:
path.append(pac) path.append(pac)
if pac and subpac: if pac and subpac:
path.append(subpac) path.append(subpac)
path.append('_attribute') path.append('_attribute')
if attribute: if attribute:
path.append(attribute) path.append(attribute)
query=[] query=[]
if with_defaults: if with_defaults:
query.append("with_default=1") query.append("with_default=1")
if with_project: if with_project:
query.append("with_project=1") query.append("with_project=1")
url = makeurl(apiurl, path, query) url = makeurl(apiurl, path, query)
try: try:
f = http_GET(url) f = http_GET(url)
@ -2547,10 +2547,10 @@ def create_submit_request(apiurl,
# Yes, this kind of xml construction is horrible # Yes, this kind of xml construction is horrible
targetxml = "" targetxml = ""
if dst_project: if dst_project:
packagexml = "" packagexml = ""
if dst_package: if dst_package:
packagexml = """package="%s" """ %( dst_package ) packagexml = """package="%s" """ %( dst_package )
targetxml = """<target project="%s" %s /> """ %( dst_project, packagexml ) targetxml = """<target project="%s" %s /> """ %( dst_project, packagexml )
# XXX: keep the old template for now in order to work with old obs instances # XXX: keep the old template for now in order to work with old obs instances
xml = """\ xml = """\
<request type="submit"> <request type="submit">
@ -3496,7 +3496,9 @@ def get_results(apiurl, prj, package, lastbuild=None, repository=[], arch=[]):
rmap['status'] = '' rmap['status'] = ''
if rmap['status'] in ['expansion error', 'broken', 'blocked', 'finished']: if rmap['status'] in ['expansion error', 'broken', 'blocked', 'finished']:
rmap['status'] += ': ' + statusnode.find('details').text details = statusnode.find('details')
if details != None:
rmap['status'] += ': ' + details.text
if rmap['dirty'] == 'true': if rmap['dirty'] == 'true':
rmap['status'] = 'state is outdated (was: %s)' % rmap['status'] rmap['status'] = 'state is outdated (was: %s)' % rmap['status']

View File

@ -114,9 +114,9 @@ class Fetcher:
pkgq = packagequery.PackageQuery.query(tmpfile, extra_rpmtags=(1044, 1051, 1052)) pkgq = packagequery.PackageQuery.query(tmpfile, extra_rpmtags=(1044, 1051, 1052))
arch = pkgq.arch() arch = pkgq.arch()
# SOURCERPM = 1044 # SOURCERPM = 1044
if pkgq.filename_suffix == 'rpm' and not pkgq.getTag(1044): if pkgq.filename_suffix == 'rpm' and not pkgq.gettag(1044):
# NOSOURCE = 1051, NOPATCH = 1052 # NOSOURCE = 1051, NOPATCH = 1052
if pkgq.getTag(1051) or pkgq.getTag(1052): if pkgq.gettag(1051) or pkgq.gettag(1052):
arch = "nosrc" arch = "nosrc"
else: else:
arch = "src" arch = "src"

View File

@ -2,6 +2,7 @@
class NoSecureSSLError(Exception): class NoSecureSSLError(Exception):
def __init__(self, msg): def __init__(self, msg):
Exception.__init__(self)
self.msg = msg self.msg = msg
def __str__(self): def __str__(self):
return self.msg return self.msg

View File

@ -104,7 +104,7 @@ class DebQuery(packagequery.PackageQuery):
def requires(self): def requires(self):
return self.fields['depends'] return self.fields['depends']
def getTag(self, num): def gettag(self, num):
return self.fields.get(num, None) return self.fields.get(num, None)
@staticmethod @staticmethod

View File

@ -13,8 +13,8 @@ class PackageQueries(dict):
# map debian arches to common obs arches # map debian arches to common obs arches
architectureMap = {'i386': ['i586', 'i686'], 'amd64': ['x86_64']} architectureMap = {'i386': ['i586', 'i686'], 'amd64': ['x86_64']}
def __init__(self, wantedArchitecture): def __init__(self, wanted_architecture):
self.wantedArchitecture = wantedArchitecture self.wanted_architecture = wanted_architecture
super(PackageQueries, self).__init__() super(PackageQueries, self).__init__()
def add(self, query): def add(self, query):
@ -32,13 +32,13 @@ class PackageQueries(dict):
architecture = query.arch() architecture = query.arch()
if (architecture in [self.wantedArchitecture, 'noarch', 'all'] or if (architecture in [self.wanted_architecture, 'noarch', 'all'] or
self.wantedArchitecture in self.architectureMap.get(architecture, self.wanted_architecture in self.architectureMap.get(architecture,
[])): [])):
currentQuery = self.get(name) current_query = self.get(name)
# if current query does not exist or is older than this new query # if current query does not exist or is older than this new query
if currentQuery is None or currentQuery.vercmp(query) <= 0: if current_query is None or current_query.vercmp(query) <= 0:
super(PackageQueries, self).__setitem__(name, query) super(PackageQueries, self).__setitem__(name, query)
class PackageQuery: class PackageQuery:
@ -73,10 +73,10 @@ class PackageQuery:
def requires(self): def requires(self):
raise NotImplementedError raise NotImplementedError
def getTag(self): def gettag(self):
raise NotImplementedError raise NotImplementedError
def vercmp(self, pkgq): def vercmp(self, pkgquery):
raise NotImplementedError raise NotImplementedError
@staticmethod @staticmethod
@ -85,20 +85,20 @@ class PackageQuery:
magic = f.read(7) magic = f.read(7)
f.seek(0) f.seek(0)
extra_tags = () extra_tags = ()
pkgq = None pkgquery = None
if magic[:4] == '\xed\xab\xee\xdb': if magic[:4] == '\xed\xab\xee\xdb':
import rpmquery import rpmquery
pkgq = rpmquery.RpmQuery(f) pkgquery = rpmquery.RpmQuery(f)
extra_tags = extra_rpmtags extra_tags = extra_rpmtags
elif magic == '!<arch>': elif magic == '!<arch>':
import debquery import debquery
pkgq = debquery.DebQuery(f) pkgquery = debquery.DebQuery(f)
extra_tags = extra_debtags extra_tags = extra_debtags
else: else:
raise PackageError('unsupported package type. magic: \'%s\' (%s)' % (magic, filename)) raise PackageError('unsupported package type. magic: \'%s\' (%s)' % (magic, filename))
pkgq.read(all_tags, *extra_tags) pkgquery.read(all_tags, *extra_tags)
f.close() f.close()
return pkgq return pkgquery
if __name__ == '__main__': if __name__ == '__main__':
import sys import sys

View File

@ -20,7 +20,7 @@ class RpmHeader:
def append(self, entry): def append(self, entry):
self.entries.append(entry) self.entries.append(entry)
def getTag(self, tag): def gettag(self, tag):
for i in self.entries: for i in self.entries:
if i.tag == tag: if i.tag == tag:
return i return i
@ -131,7 +131,7 @@ class RpmQuery(packagequery.PackageQuery):
entry.data = entry.data[0] entry.data = entry.data[0]
return return
# get private i18n table # get private i18n table
table = self.header.getTag(100) table = self.header.gettag(100)
# just care about the country code # just care about the country code
lang = lang.split('_', 1)[0] lang = lang.split('_', 1)[0]
cnt = 0 cnt = 0
@ -147,9 +147,9 @@ class RpmQuery(packagequery.PackageQuery):
raise RpmHeaderError('unsupported tag type \'%d\' (tag: \'%s\'' % (entry.type, entry.tag)) raise RpmHeaderError('unsupported tag type \'%d\' (tag: \'%s\'' % (entry.type, entry.tag))
def __reqprov(self, tag, flags, version): def __reqprov(self, tag, flags, version):
pnames = self.header.getTag(tag).data pnames = self.header.gettag(tag).data
pflags = self.header.getTag(flags).data pflags = self.header.gettag(flags).data
pvers = self.header.getTag(version).data pvers = self.header.gettag(version).data
if not (pnames and pflags and pvers): if not (pnames and pflags and pvers):
raise RpmError('cannot get provides/requires, tags are missing') raise RpmError('cannot get provides/requires, tags are missing')
res = [] res = []
@ -179,31 +179,31 @@ class RpmQuery(packagequery.PackageQuery):
# XXX: create dict for the tag => number mapping?! # XXX: create dict for the tag => number mapping?!
def name(self): def name(self):
return self.header.getTag(1000).data return self.header.gettag(1000).data
def version(self): def version(self):
return self.header.getTag(1001).data return self.header.gettag(1001).data
def release(self): def release(self):
return self.header.getTag(1002).data return self.header.gettag(1002).data
def epoch(self): def epoch(self):
epoch = self.header.getTag(1003) epoch = self.header.gettag(1003)
if epoch is None: if epoch is None:
return 0 return 0
return epoch.data[0] return epoch.data[0]
def arch(self): def arch(self):
return self.header.getTag(1022).data return self.header.gettag(1022).data
def summary(self): def summary(self):
return self.header.getTag(1004).data return self.header.gettag(1004).data
def description(self): def description(self):
return self.header.getTag(1005).data return self.header.gettag(1005).data
def url(self): def url(self):
entry = self.header.getTag(1020) entry = self.header.gettag(1020)
if entry is None: if entry is None:
return None return None
return entry.data return entry.data
@ -217,8 +217,8 @@ class RpmQuery(packagequery.PackageQuery):
def requires(self): def requires(self):
return self.__reqprov(1049, 1048, 1050) return self.__reqprov(1049, 1048, 1050)
def getTag(self, num): def gettag(self, num):
return self.header.getTag(num) return self.header.gettag(num)
@staticmethod @staticmethod
def query(filename): def query(filename):