Skip to content

Commit

Permalink
Merge branch 'upcoming'
Browse files Browse the repository at this point in the history
  • Loading branch information
afb committed Aug 31, 2014
2 parents 2f4de69 + 30593ad commit 54ebe6b
Show file tree
Hide file tree
Showing 13 changed files with 197 additions and 94 deletions.
2 changes: 2 additions & 0 deletions smart/backends/deb/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ def __init__(self, path):
output = os.popen(path).readlines()
for line in output:
line = string.rstrip(line)
if line.startswith(' '):
continue
keyval = string.split(line, ':', 1)
if len(keyval) > 1:
val = string.lstrip(keyval[1])
Expand Down
12 changes: 11 additions & 1 deletion smart/backends/deb/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,16 @@ def load(self):

upgargs = [(Upg, name, '<', version)]

recargs = []
value = section.get("recommends")
if value:
for relation in parserelations(value):
if type(relation) is not list:
n, r, v = relation
recargs.append((Req, intern(n), r, v))
else:
recargs.append((OrReq, tuple(relation)))

cnfargs = []
value = section.get("conflicts")
if value:
Expand All @@ -236,7 +246,7 @@ def load(self):
reqargs = newargs

pkg = self.buildPackage((Pkg, name, version),
prvargs, reqargs, upgargs, cnfargs)
prvargs, reqargs, upgargs, cnfargs, recargs)
pkg.loaders[self] = offset
self._sections[pkg] = intern(section.get("section", ""))

Expand Down
14 changes: 10 additions & 4 deletions smart/backends/rpm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ def getTS(new=False):
if sysconf.get("rpm-dbpath"):
rpm.addMacro('_dbpath', "/" + sysconf.get("rpm-dbpath"))
getTS.ts = rpm.ts(getTS.root)
#if not sysconf.get("rpm-check-signatures", False):
# getTS.ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES)
if not sysconf.get("rpm-check-signatures", False):
if hasattr(rpm, '_RPMVSF_NOSIGNATURES'):
getTS.ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES)
else:
raise Error, _("rpm requires checking signatures")
rpm_dbpath = sysconf.get("rpm-dbpath", "var/lib/rpm")
dbdir = rpm_join_dbpath(getTS.root, rpm_dbpath)
if not os.path.isdir(dbdir):
Expand All @@ -86,8 +89,11 @@ def getTS(new=False):
if sysconf.get("rpm-dbpath"):
rpm.addMacro('_dbpath', "/" + sysconf.get("rpm-dbpath"))
ts = rpm.ts(getTS.root)
#if not sysconf.get("rpm-check-signatures", False):
# ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES)
if not sysconf.get("rpm-check-signatures", False):
if hasattr(rpm, '_RPMVSF_NOSIGNATURES'):
ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES)
else:
raise Error, _("rpm requires checking signatures")
return ts
else:
return getTS.ts
Expand Down
35 changes: 33 additions & 2 deletions smart/backends/rpm/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ def load(self):
# RPMSENSE_SCRIPT_PREUN |
# RPMSENSE_SCRIPT_POST |
# RPMSENSE_SCRIPT_POSTUN == 7744
if (f[i]&rpm.RPMSENSE_MISSINGOK):
hint = (f[i]&1 << 19) # RPMSENSE_MISSINGOK
if hint:
recdict[(f[i]&7744 and PreReq or Req,
intern(ni), r, vi)] = True
else:
Expand All @@ -318,9 +319,39 @@ def load(self):
recargs = collapse_libc_requires(recdict.keys())
reqargs = collapse_libc_requires(reqdict.keys())
else:
recargs = None
recargs = []
reqargs = None

n = h[1156] # RPMTAG_SUGGESTSNAME
if n:
f = h[1158] # RPMTAG_SUGGESTSFLAGS
v = h[1157] # RPMTAG_SUGGESTSVERSION
if f == None:
f = [0]
elif type(f) != list:
f = [f]
recdict = {}
for i in range(len(n)):
ni = n[i]
if ni[:7] not in ("rpmlib(", "config("):
vi = v[i] or None
if vi and vi[:2] == "0:":
vi = vi[2:]
r = CM.get(f[i]&CF)
if not ((r is None or "=" in r) and
(Prv, ni, vi) in prvdict or
system_provides.match(ni, r, vi)):
# RPMSENSE_PREREQ |
# RPMSENSE_SCRIPT_PRE |
# RPMSENSE_SCRIPT_PREUN |
# RPMSENSE_SCRIPT_POST |
# RPMSENSE_SCRIPT_POSTUN == 7744
strong = (f[i]&1 << 27) # RPMSENSE_STRONG
if strong:
recdict[(f[i]&7744 and PreReq or Req,
intern(ni), r, vi)] = True
recargs.extend(recdict.keys())

n = h[1054] # RPMTAG_CONFLICTNAME
if n:
f = h[1053] # RPMTAG_CONFLICTFLAGS
Expand Down
20 changes: 12 additions & 8 deletions smart/backends/rpm/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def load(self):
LICENSE = nstag(NS_RPM, "license")
ENTRY = nstag(NS_RPM, "entry")
REQUIRES = nstag(NS_RPM, "requires")
RECOMMENDS = nstag(NS_RPM, "recommends")
PROVIDES = nstag(NS_RPM, "provides")
CONFLICTS = nstag(NS_RPM, "conflicts")
OBSOLETES = nstag(NS_RPM, "obsoletes")
Expand Down Expand Up @@ -289,16 +290,19 @@ def load(self):

lasttag = queue[-1].tag
if lasttag == REQUIRES:
if elem.get("missingok") == "1":
if elem.get("pre") == "1":
reqdict[(RPMPreRequires,
ename, erelation, eversion)] = True
elif elem.get("hint") == "1" or elem.get("missingok") == "1":
recdict[(RPMRequires,
ename, erelation, eversion)] = True
ename, erelation, eversion)] = True
else:
if elem.get("pre") == "1":
reqdict[(RPMPreRequires,
ename, erelation, eversion)] = True
else:
reqdict[(RPMRequires,
ename, erelation, eversion)] = True
reqdict[(RPMRequires,
ename, erelation, eversion)] = True

elif lasttag == RECOMMENDS:
recdict[(RPMRequires,
ename, erelation, eversion)] = True

elif lasttag == PROVIDES:
if ename[0] == "/":
Expand Down
33 changes: 17 additions & 16 deletions smart/backends/rpm/pm.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,23 @@ def commit(self, changeset, pkgpaths):
flags |= rpm.RPMTRANS_FLAG_TEST
ts.setFlags(flags)

dflags = ts.setDFlags(0)
if sysconf.get("rpm-noupgrade", False):
dflags |= rpm.RPMDEPS_FLAG_NOUPGRADE
if sysconf.get("rpm-norequires", False):
dflags |= rpm.RPMDEPS_FLAG_NOREQUIRES
if sysconf.get("rpm-noconflicts", False):
dflags |= rpm.RPMDEPS_FLAG_NOCONFLICTS
if sysconf.get("rpm-noobsoletes", False):
dflags |= rpm.RPMDEPS_FLAG_NOOBSOLETES
if sysconf.get("rpm-noparentdirs", False):
dflags |= rpm.RPMDEPS_FLAG_NOPARENTDIRS
if sysconf.get("rpm-nolinktos", False):
dflags |= rpm.RPMDEPS_FLAG_NOLINKTOS
if sysconf.get("rpm-nosuggest", False):
dflags |= rpm.RPMDEPS_FLAG_NOSUGGEST
ts.setDFlags(dflags)
if hasattr(ts, 'setDFlags'):
dflags = ts.setDFlags(0)
if sysconf.get("rpm-noupgrade", False):
dflags |= rpm.RPMDEPS_FLAG_NOUPGRADE
if sysconf.get("rpm-norequires", False):
dflags |= rpm.RPMDEPS_FLAG_NOREQUIRES
if sysconf.get("rpm-noconflicts", False):
dflags |= rpm.RPMDEPS_FLAG_NOCONFLICTS
if sysconf.get("rpm-noobsoletes", False):
dflags |= rpm.RPMDEPS_FLAG_NOOBSOLETES
if sysconf.get("rpm-noparentdirs", False):
dflags |= rpm.RPMDEPS_FLAG_NOPARENTDIRS
if sysconf.get("rpm-nolinktos", False):
dflags |= rpm.RPMDEPS_FLAG_NOLINKTOS
if sysconf.get("rpm-nosuggest", False):
dflags |= rpm.RPMDEPS_FLAG_NOSUGGEST
ts.setDFlags(dflags)

# Set rpm verbosity level.
levelname = sysconf.get('rpm-log-level')
Expand Down
80 changes: 79 additions & 1 deletion smart/option.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
from smart import Error, _
import textwrap
import sys, os
import re

# NOTICE: The standard optparse module haven't been touched, but since
# this code subclasses it and trusts on a specific interface,
# an internal copy is being used to avoid future breakage.

__all__ = ["OptionParser", "OptionValueError", "append_all"]
__all__ = ["OptionParser", "OptionValueError", "Values", "Option", "append_all"]

try:
optparse.STD_HELP_OPTION.help = \
Expand Down Expand Up @@ -64,17 +65,94 @@ def format_option(self, option):
option.help = help
return result

class Values(optparse.Values):

# Check if the given option has the specified number of arguments
# Raise an error if the option has an invalid number of arguments
# A negative number for 'nargs' means "at least |nargs| arguments are needed"
def check_args_of_option(self, opt, nargs, err=None):
given_opts = getattr(self, "_given_opts", [])
if not opt in given_opts:
return
values = getattr(self, opt, [])
if type(values) != type([]):
return
if nargs < 0:
nargs = -nargs
if len(values) >= nargs:
return
if not err:
if nargs == 1:
err = _("Option '%s' requires at least one argument") % opt
else:
err = _("Option '%s' requires at least %d arguments") % (opt, nargs)
raise Error, err
elif nargs == 0:
if len( values ) == 0:
return
raise Error, err
else:
if len(values) == nargs:
return
if not err:
if nargs == 1:
err = _("Option '%s' requires one argument") % opt
else:
err = _("Option '%s' requires %d arguments") % (opt, nargs)
raise Error, err

# Check that at least one of the options in 'actlist' was given as an argument
# to the command 'cmdname'
def ensure_action(self, cmdname, actlist):
given_opts = getattr(self, "_given_opts", [])
for action in actlist:
if action in given_opts:
return
raise Error, _("No action specified for command '%s'") % cmdname

# Check if there are any other arguments left after parsing the command line and
# raise an error if such arguments are found
def check_remaining_args(self):
if self.args:
raise Error, _("Invalid argument(s) '%s'" % str(self.args))

class Option(optparse.Option):

def take_action(self, action, dest, opt, value, values, parser):
# Keep all the options in the command line in the '_given_opts' array
# This will be used later to validate the command line
given_opts = getattr(parser.values, "_given_opts", [])
user_opt = re.sub(r"^\-*", "", opt).replace("-", "_")
given_opts.append(user_opt)
setattr(parser.values, "_given_opts", given_opts)
optparse.Option.take_action(self, action, dest, opt, value, values, parser)

class OptionParser(optparse.OptionParser):

def __init__(self, usage=None, help=None, examples=None, skipunknown=False,
**kwargs):
if not "formatter" in kwargs:
kwargs["formatter"] = HelpFormatter()
kwargs["option_class"] = Option
optparse.OptionParser.__init__(self, usage, **kwargs)
self._override_help = help
self._examples = examples
self._skipunknown = skipunknown

def get_default_values(self):
if not self.process_default_values:
# Old, pre-Optik 1.5 behaviour.
return Values(self.defaults)

defaults = self.defaults.copy()
for option in self._get_all_options():
default = defaults.get(option.dest)
if isinstance(default, basestring):
opt_str = option.get_opt_string()
defaults[option.dest] = option.check_value(opt_str, default)

return Values(defaults)

def format_help(self, formatter=None):
if formatter is None:
formatter = self.formatter
Expand Down
4 changes: 2 additions & 2 deletions smart/plugins/yumchannelsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def _getreleasever():

rpmroot = sysconf.get("rpm-root", "/")
ts = rpmUtils.transaction.initReadOnlyTransaction(root=rpmroot)
#ts.pushVSFlags(~(rpm._RPMVSF_NOSIGNATURES|rpm._RPMVSF_NODIGESTS))
ts.pushVSFlags(~(rpm._RPMVSF_NODIGESTS))
if hasattr(rpm, '_RPMVSF_NOSIGNATURES') and hasattr(rpm, '_RPMVSF_NODIGESTS'):
ts.pushVSFlags(~(rpm._RPMVSF_NOSIGNATURES|rpm._RPMVSF_NODIGESTS))
releasever = None
# HACK: we're hard-coding the most used distros, will add more if needed
idx = ts.dbMatch('provides', 'fedora-release')
Expand Down
Loading

0 comments on commit 54ebe6b

Please sign in to comment.