Example #1
0
 def _exec(self, command, **kwargs):
     p = pexpect.spawn(command, timeout=1)
     p.setecho(False)
     outlist = []
     while True:
         i = p.expect([pexpect.EOF, pexpect.TIMEOUT,
                       r"assword:", r"passphrase for key '.*':",
                       r"\(yes/no\)?"])
         if i == 0:
             outlist.append(p.before)
             break
         elif i == 1:
             outlist.append(p.before)
         elif i == 2 or i == 3:
             if self.password:
                 password = self.password
             elif self.getpassword:
                 password = self.getpassword()
             else:
                 raise Error, _("SSH asked for password, "
                                "but no password is available")
             p.sendline(password)
             outlist = []
         elif i == 4:
             p.sendline("yes")
             outlist = []
     while p.isalive():
         try:
             time.sleep(1)
         except (pexpect.TIMEOUT, pexpect.EOF):
             # Continue until the child dies
             pass
     while outlist and outlist[0].startswith("Warning:"):
         outlist.pop(0)
     return p.exitstatus, "".join(outlist).strip()
Example #2
0
 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
Example #3
0
 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
Example #4
0
    def __call__(self, data):
        for line in data.splitlines():
            what, pkgname, status = line.split(":", 2)
            what = what.strip()
            pkgname = pkgname.strip()
            status = status.strip()
            if what != "status":
                return
            if self.op is CONFIG and status == "unpacked":  # odd duplicate
                return
            if not pkgname in self.pkgs:
                return

            op = self.op
            pkg = self.pkgs[pkgname]
            subkey = "%s:%s" % (op, pkgname)
            if op is REMOVE:
                self.prog.setSubTopic(subkey, _("Removing %s") % pkg.name)
                if status == "installed" and subkey not in self.seen:
                    self.seen[subkey] = True
                    self.prog.setSub(subkey, 0, 1, 1)
                elif status == "config-files" and subkey in self.seen:
                    del self.seen[subkey]
                    self.prog.setSubDone(subkey)
                self.prog.show()
            elif op is PURGE:
                self.prog.setSubTopic(subkey, _("Purging %s") % pkg.name)
                if status == "installed" and subkey not in self.seen:
                    self.seen[subkey] = True
                    self.prog.setSub(subkey, 0, 1, 1)
                elif status == "not-installed" and subkey in self.seen:
                    del self.seen[subkey]
                    self.prog.setSubDone(subkey)
                self.prog.show()
            elif op is UNPACK:
                self.prog.setSubTopic(subkey, _("Unpacking %s") % pkg.name)
                if status == "half-installed" and subkey not in self.seen:
                    self.seen[subkey] = True
                    self.prog.setSub(subkey, 0, 1, 1)
                elif status == "unpacked" and subkey in self.seen:
                    del self.seen[subkey]
                    self.prog.setSubDone(subkey)
                self.prog.show()
            elif op is CONFIG:
                self.prog.setSubTopic(subkey, _("Configuring %s") % pkg.name)
                if status == "half-configured" and subkey not in self.seen:
                    self.seen[subkey] = True
                    self.prog.setSub(subkey, 0, 1, 1)
                elif status == "installed" and subkey in self.seen:
                    del self.seen[subkey]
                    self.prog.setSubDone(subkey)
                self.prog.show()
Example #5
0
File: pm.py Project: pombreda/smart
    def __call__(self, data):
        for line in data.splitlines():
            what, pkgname, status = line.split(':', 2)
            what = what.strip()
            pkgname = pkgname.strip()
            status = status.strip()
            if what != "status":
                return
            if self.op is CONFIG and status == "unpacked":  # odd duplicate
                return
            if not pkgname in self.pkgs:
                return

            op = self.op
            pkg = self.pkgs[pkgname]
            subkey = "%s:%s" % (op, pkgname)
            if op is REMOVE:
                self.prog.setSubTopic(subkey, _("Removing %s") % pkg.name)
                if status == "installed" and subkey not in self.seen:
                    self.seen[subkey] = True
                    self.prog.setSub(subkey, 0, 1, 1)
                elif status == "config-files" and subkey in self.seen:
                    del self.seen[subkey]
                    self.prog.setSubDone(subkey)
                self.prog.show()
            elif op is PURGE:
                self.prog.setSubTopic(subkey, _("Purging %s") % pkg.name)
                if status == "installed" and subkey not in self.seen:
                    self.seen[subkey] = True
                    self.prog.setSub(subkey, 0, 1, 1)
                elif status == "not-installed" and subkey in self.seen:
                    del self.seen[subkey]
                    self.prog.setSubDone(subkey)
                self.prog.show()
            elif op is UNPACK:
                self.prog.setSubTopic(subkey, _("Unpacking %s") % pkg.name)
                if status == "half-installed" and subkey not in self.seen:
                    self.seen[subkey] = True
                    self.prog.setSub(subkey, 0, 1, 1)
                elif status == "unpacked" and subkey in self.seen:
                    del self.seen[subkey]
                    self.prog.setSubDone(subkey)
                self.prog.show()
            elif op is CONFIG:
                self.prog.setSubTopic(subkey, _("Configuring %s") % pkg.name)
                if status == "half-configured" and subkey not in self.seen:
                    self.seen[subkey] = True
                    self.prog.setSub(subkey, 0, 1, 1)
                elif status == "installed" and subkey in self.seen:
                    del self.seen[subkey]
                    self.prog.setSubDone(subkey)
                self.prog.show()
Example #6
0
def postParse(data):
    import re
    withre = re.compile("\s+with\s+", re.I)
    if withre.search(data["baseurl"]):
        if "hdlurl" in data:
            raise Error, _("Base URL has 'with', but Header List URL "
                           "was provided")
        tokens = withre.split(data["baseurl"])
        if len(tokens) != 2:
            raise Error, _("Base URL has invalid 'with' pattern")
        data["baseurl"] = tokens[0].strip()
        if tokens[1].strip():
            data["hdlurl"] = tokens[1].strip()
    return data
Example #7
0
def postParse(data):
    import re
    withre = re.compile("\s+with\s+", re.I)
    if withre.search(data["baseurl"]):
        if "hdlurl" in data:
            raise Error, _("Base URL has 'with', but Header List URL "
                           "was provided")
        tokens = withre.split(data["baseurl"])
        if len(tokens) != 2:
            raise Error, _("Base URL has invalid 'with' pattern")
        data["baseurl"] = tokens[0].strip()
        if tokens[1].strip():
            data["hdlurl"] = tokens[1].strip()
    return data
Example #8
0
def speedToStr(speed):
    if speed < 1:
        return _("Stalled")
    elif speed < 1024:
        return "%dB/s" % speed
    elif speed < 1024000:
        return "%.1fkB/s" % (speed / 1024.)
    else:
        return "%.1fMB/s" % (speed / 1024000.)
def sizeToStr(bytes):
    if bytes is None:
        return _("Unknown")
    if bytes < 1024:
        return "%dB" % bytes
    elif bytes < 1024000:
        return "%.1fkB" % (bytes/1024.)
    else:
        return "%.1fMB" % (bytes/1024000.)
def speedToStr(speed):
    if speed < 1:
        return _("Stalled")
    elif speed < 1024:
        return "%dB/s" % speed
    elif speed < 1024000:
        return "%.1fkB/s" % (speed/1024.)
    else:
        return "%.1fMB/s" % (speed/1024000.)
def secondsToStr(time):
    if not time:
        return _("Unknown")
    elif time == 0:
        return "0s"
    elif time < 1:
        return "1s"
    else:
        minutes, seconds = divmod(time, 60)
        hours, minutes = divmod(minutes, 60)
        if hours > 99:
            return _("Stalled")
        elif hours > 0:
            return "%02ih%02im%02is" % (hours, minutes, seconds)
        elif minutes > 0:
            return "%02im%02is" % (minutes, seconds)
        else:
            return "%02is" % seconds
Example #12
0
def secondsToStr(time):
    if not time:
        return _("Unknown")
    elif time == 0:
        return "0s"
    elif time < 1:
        return "1s"
    else:
        minutes, seconds = divmod(time, 60)
        hours, minutes = divmod(minutes, 60)
        if hours > 99:
            return _("Stalled")
        elif hours > 0:
            return "%02ih%02im%02is" % (hours, minutes, seconds)
        elif minutes > 0:
            return "%02im%02is" % (minutes, seconds)
        else:
            return "%02is" % seconds
Example #13
0
def sizeToStr(bytes):
    if bytes is None:
        return _("Unknown")
    if bytes < 1024:
        return "%dB" % bytes
    elif bytes < 1024000:
        return "%.1fkB" % (bytes / 1024.)
    else:
        return "%.1fMB" % (bytes / 1024000.)
Example #14
0
    def _process_short_opts(self, rargs, values):
        arg = rargs.pop(0)
        stop = False
        i = 1
        for ch in arg[1:]:
            opt = "-" + ch
            option = self._short_opt.get(opt)
            i += 1  # we have consumed a character

            if not option:
                # That's the reason to change this function. We must
                # raise an error so that the argument is post-processed
                # when using skipunknown.
                raise optparse.BadOptionError, _("no such option: %s") % opt
            if option.takes_value():
                # Any characters left in arg?  Pretend they're the
                # next arg, and stop consuming characters of arg.
                if i < len(arg):
                    rargs.insert(0, arg[i:])
                    stop = True

                nargs = option.nargs
                if len(rargs) < nargs:
                    if nargs == 1:
                        self.error(_("%s option requires an argument") % opt)
                    else:
                        self.error(
                            _("%s option requires %d arguments") %
                            (opt, nargs))
                elif nargs == 1:
                    value = rargs.pop(0)
                else:
                    value = tuple(rargs[0:nargs])
                    del rargs[0:nargs]

            else:  # option doesn't take a value
                value = None

            option.process(opt, value, values, self)

            if stop:
                break
Example #15
0
    def _process_short_opts(self, rargs, values):
        arg = rargs.pop(0)
        stop = False
        i = 1
        for ch in arg[1:]:
            opt = "-" + ch
            option = self._short_opt.get(opt)
            i += 1                      # we have consumed a character

            if not option:
                # That's the reason to change this function. We must
                # raise an error so that the argument is post-processed
                # when using skipunknown.
                raise optparse.BadOptionError, _("no such option: %s") % opt
            if option.takes_value():
                # Any characters left in arg?  Pretend they're the
                # next arg, and stop consuming characters of arg.
                if i < len(arg):
                    rargs.insert(0, arg[i:])
                    stop = True

                nargs = option.nargs
                if len(rargs) < nargs:
                    if nargs == 1:
                        self.error(_("%s option requires an argument") % opt)
                    else:
                        self.error(_("%s option requires %d arguments")
                                   % (opt, nargs))
                elif nargs == 1:
                    value = rargs.pop(0)
                else:
                    value = tuple(rargs[0:nargs])
                    del rargs[0:nargs]

            else:                       # option doesn't take a value
                value = None

            option.process(opt, value, values, self)

            if stop:
                break
Example #16
0
 def __fetchFile(self, file, fetcher, progress, uncompress=False):
     fetcher.reset()
     item = fetcher.enqueue(file,uncomp=uncompress)
     fetcher.run(progress=progress)
     failed = item.getFailedReason()
     if failed:
         progress.add(self.getFetchSteps()-1)
         progress.show()
         if fetcher.getCaching() is NEVER:
             lines = [_("Failed acquiring information for '%s':") % self,
                      "%s: %s" % (item.getURL(), failed)]
             raise Error, "\n".join(lines)
     return item
Example #17
0
 def __fetchFile(self, file, fetcher, progress, uncompress=False):
     fetcher.reset()
     item = fetcher.enqueue(file, uncomp=uncompress)
     fetcher.run(progress=progress)
     failed = item.getFailedReason()
     if failed:
         progress.add(self.getFetchSteps() - 1)
         progress.show()
         if fetcher.getCaching() is NEVER:
             lines = [
                 _("Failed acquiring information for '%s':") % self,
                 "%s: %s" % (item.getURL(), failed)
             ]
             raise Error, "\n".join(lines)
     return item
Example #18
0
 def _exec(self, command, **kwargs):
     p = pexpect.spawn(command, timeout=1)
     p.setecho(False)
     outlist = []
     while True:
         i = p.expect([
             pexpect.EOF, pexpect.TIMEOUT, r"assword:",
             r"passphrase for key '.*':", r"\(yes/no\)?"
         ])
         if i == 0:
             outlist.append(p.before)
             break
         elif i == 1:
             outlist.append(p.before)
         elif i == 2 or i == 3:
             if self.password:
                 password = self.password
             elif self.getpassword:
                 password = self.getpassword()
             else:
                 raise Error, _("SSH asked for password, "
                                "but no password is available")
             p.sendline(password)
             outlist = []
         elif i == 4:
             p.sendline("yes")
             outlist = []
     while p.isalive():
         try:
             time.sleep(1)
         except (pexpect.TIMEOUT, pexpect.EOF):
             # Continue until the child dies
             pass
     while outlist and outlist[0].startswith("Warning:"):
         outlist.pop(0)
     return p.exitstatus, "".join(outlist).strip()
Example #19
0
def strToBool(s, default=False):
    if type(s) in (bool, int):
        return bool(s)
    if not s:
        return default
    s = s.strip().lower()
    if s in ("y", "yes", "true", "1", _("y"), _("yes"), _("true")):
        return True
    if s in ("n", "no", "false", "0", _("n"), _("no"), _("false")):
        return False
    return default
def strToBool(s, default=False):
    if type(s) in (bool, int):
        return bool(s)
    if not s:
        return default
    s = s.strip().lower()
    if s in ("y", "yes", "true", "1", _("y"), _("yes"), _("true")):
        return True
    if s in ("n", "no", "false", "0", _("n"), _("no"), _("false")):
        return False
    return default
Example #21
0
 def format_help(self, formatter=None):
     if formatter is None:
         formatter = self.formatter
     if self._override_help:
         result = self._override_help.strip()
         result += "\n"
     else:
         result = optparse.OptionParser.format_help(self, formatter)
         result = result.strip()
         result += "\n"
         if self._examples:
             result += formatter.format_heading(_("examples"))
             formatter.indent()
             for line in self._examples.strip().splitlines():
                 result += " "*formatter.current_indent
                 result += line+"\n"
             formatter.dedent()
     result += "\n"
     return result
Example #22
0
 def format_help(self, formatter=None):
     if formatter is None:
         formatter = self.formatter
     if self._override_help:
         result = self._override_help.strip()
         result += "\n"
     else:
         result = optparse.OptionParser.format_help(self, formatter)
         result = result.strip()
         result += "\n"
         if self._examples:
             result += formatter.format_heading(_("examples"))
             formatter.indent()
             for line in self._examples.strip().splitlines():
                 result += " " * formatter.current_indent
                 result += line + "\n"
             formatter.dedent()
     result += "\n"
     return result
Example #23
0
# Written by Gustavo Niemeyer <*****@*****.**>
#
# This file is part of Smart Package Manager.
#
# Smart Package Manager is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# Smart Package Manager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Smart Package Manager; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
from smart import _

kind = "package"

name = _("PDK Component")

description = _("""
Local directory with DEB packages.
""")

fields = [("path", _("Directory Path"), str, None,
           _("Path of directory containing DEB packages."))]
Example #24
0
# your option) any later version.
#
# Smart Package Manager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Smart Package Manager; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
from smart import _

kind = "package"

name = _("URPMI Repository")

description = _("""
Repository created for Mandriva's URPMI package manager.
""")

fields = [("baseurl", _("Base URL"), str, None,
           _("Base URL where packages are found under. "
             "Using ' with <hdlurl>' pattern is also supported.")),
          ("directory", _("With directory"), str, "",
           _("Directory path for Base URL")),
          ("hdlurl", _("Header List URL"), str, "",
           _("URL for header list (hdlist or synthesis). If it's hdlist.cz "
             "inside the given base URL, may be left empty. URLs relative "
             "to the Base URL are supported")),
          ("mirrorurl", _("Mirror List URL"), str, "",
Example #25
0
#
# Smart Package Manager is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# Smart Package Manager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Smart Package Manager; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
from smart import _

kind = "package"

name = _("URPMI Repository")

description = _("""
Repository created for Mandrake's URPMI package manager.
""")

fields = [("baseurl", _("Base URL"), str, None,
           _("Base URL where packages are found under.")),
          ("hdlurl", _("Header List URL"), str, "",
           _("URL for header list (hdlist or synthesis). If it's hdlist.cz "
             "inside the given base URL, may be left empty."))]
Example #26
0
#
# This file is part of Smart Package Manager.
#
# Smart Package Manager is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# Smart Package Manager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Smart Package Manager; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
from smart import _

kind = "package"

name = _("RPM MetaData")

description = _("""
Repository created with the rpm-metadata project.
""")

fields = [("baseurl", _("Base URL"), str, None,
           _("URL where repodata/ subdirectory is found"))]

Example #27
0
                for prob in probs:
                    name1 = "%s-%s-%s" % prob[0]
                    name2, version = prob[1]
                    if version:
                        sense = prob[2]
                        name2 += " "
                        if sense & rpm.RPMSENSE_LESS:
                            name2 += "<"
                        elif sense & rpm.RPMSENSE_GREATER:
                            name2 += ">"
                        if sense & rpm.RPMSENSE_EQUAL:
                            name2 += "="
                        name2 += " "
                        name2 += version
                    if prob[4] == rpm.RPMDEP_SENSE_REQUIRES:
                        line = _("%s requires %s") % (name1, name2)
                    else:
                        line = _("%s conflicts with %s") % (name1, name2)
                    problines.append(line)
                raise Error, "\n".join(problines)
        if sysconf.get("rpm-order"):
            ts.order()
        probfilter = rpm.RPMPROB_FILTER_OLDPACKAGE

        if sysconf.get("rpm-ignoresize", False):
            probfilter |= rpm.RPMPROB_FILTER_DISKNODES
            probfilter |= rpm.RPMPROB_FILTER_DISKSPACE

        if force or reinstall:
            probfilter |= rpm.RPMPROB_FILTER_REPLACEPKG
            probfilter |= rpm.RPMPROB_FILTER_REPLACEOLDFILES
Example #28
0
 def format_heading(self, heading):
     heading = _(heading)
     return "\n%*s%s:\n" % (self.current_indent, "", heading.capitalize())
     _("options")
Example #29
0
# Smart Package Manager is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# Smart Package Manager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Smart Package Manager; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
from smart import _

kind = "package"

name = _("Slackware Repository")

description = _("""
Remote repository with slackware packages.
""")

fields = [("baseurl", _("Base URL"), str, None,
           _("Base URL where PACKAGES.TXT is located")),
          ("compressed", _("Compressed"), bool, False,
          _("Whether PACKAGES.TXT is gzip compressed")),
          ("fingerprint", _("Fingerprint"), str, "",
           _("GPG fingerprint of key signing the channel."))]
Example #30
0
 def format_heading(self, heading):
     heading = _(heading)
     return "\n%*s%s:\n" % (self.current_indent, "", heading.capitalize())
     _("options")
Example #31
0
        rpmlogfile = sysconf.get('rpm-log-file')
        if rpmlogfile is not None:
            try:
                rpmlog = open(rpmlogfile, 'w')
                rpm.setLogFile(rpmlog)
            except (IOError, OSError), e:
                raise Error, "%s: %s" % (rpmlogfile, unicode(e))

        # Let's help RPM, since it doesn't do a good
        # ordering job on erasures.
        try:
            sorter = ChangeSetSorter(changeset)
            sorted = sorter.getSorted()
            forcerpmorder = False
        except LoopError:
            lines = [_("Found unbreakable loops:")]
            for path in sorter.getLoopPaths(sorter.getLoops()):
                path = [
                    "%s [%s]" % (pkg, op is INSTALL and "I" or "R")
                    for pkg, op in path
                ]
                lines.append("    " + " -> ".join(path))
            lines.append(_("Will ask RPM to order it."))
            iface.error("\n".join(lines))
            sorted = [(pkg, changeset[pkg]) for pkg in changeset]
            forcerpmorder = True
        del sorter

        packages = 0
        reinstall = False
        for pkg, op in sorted:
Example #32
0
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Smart Package Manager; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
from smart import Error, _
import optparse
import textwrap
import sys, os

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

try:
    optparse.STD_HELP_OPTION.help = \
            _("show this help message and exit")
    optparse.STD_VERSION_OPTION.help = \
            _("show program's version number and exit")
except AttributeError:
    optparse._ = _

OptionValueError = optparse.OptionValueError


class HelpFormatter(optparse.HelpFormatter):
    def __init__(self):
        optparse.HelpFormatter.__init__(self, 2, 24, 79, 1)

    def format_usage(self, usage):
        return _("Usage: %s\n") % usage
Example #33
0
#
# Smart Package Manager is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# Smart Package Manager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Smart Package Manager; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

from smart import _

kind = "package"

name = _("RPM RHN")

description = _("""
An RHN base repo
""")

fields = [("baseurl", _("Base URL"), str, None,
           _("URL where repodata/ subdirectory is found")),
          ("channel_info", _("Channel Info"), list, None,
           _("RHN CHannel information"))]
Example #34
0
    def commit(self, changeset, pkgpaths):

        prog = iface.getProgress(self, True)
        prog.start()
        prog.setTopic(_("Committing transaction..."))
        prog.set(0, len(changeset))
        prog.show()

        # Compute upgrading/upgraded packages
        upgrading = {}
        upgraded = {}
        for pkg in changeset.keys():
            if changeset.get(pkg) is INSTALL:
                upgpkgs = [upgpkg for prv in pkg.provides
                                  for upg in prv.upgradedby
                                  for upgpkg in upg.packages
                                  if upgpkg.installed]
                upgpkgs.extend([prvpkg for upg in pkg.upgrades
                                       for prv in upg.providedby
                                       for prvpkg in prv.packages
                                       if prvpkg.installed])
                if upgpkgs:
                    for upgpkg in upgpkgs:
                        # If any upgraded package will stay in the system,
                        # this is not really an upgrade for rpm.
                        if changeset.get(upgpkg) is not REMOVE:
                            break
                    else:
                        upgrading[pkg] = True
                        for upgpkg in upgpkgs:
                            upgraded[upgpkg] = True
                            if upgpkg in changeset:
                                del changeset[upgpkg]

        ts = getTS(True)

        flags = ts.setFlags(0)
        if sysconf.get("rpm-allfiles", False):
            flags |= rpm.RPMTRANS_FLAG_ALLFILES
        if sysconf.get("rpm-justdb", False):
            flags |= rpm.RPMTRANS_FLAG_JUSTDB
        if sysconf.get("rpm-noconfigs", False):
            flags |= rpm.RPMTRANS_FLAG_NOCONFIGS
        if (sysconf.get("rpm-nodocs", False) or
            sysconf.get("rpm-excludedocs", False)):
            flags |= rpm.RPMTRANS_FLAG_NODOCS
        if sysconf.get("rpm-nomd5", False):
            flags |= rpm.RPMTRANS_FLAG_NOMD5
        if sysconf.get("rpm-noscripts", False):
            flags |= rpm.RPMTRANS_FLAG_NOSCRIPTS
        if sysconf.get("rpm-notriggers", False):
            flags |= rpm.RPMTRANS_FLAG_NOTRIGGERS
        if sysconf.get("rpm-repackage", False):
            flags |= rpm.RPMTRANS_FLAG_REPACKAGE
        if sysconf.get("rpm-test", False):
            flags |= rpm.RPMTRANS_FLAG_TEST
        ts.setFlags(flags)

        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')
        level = {
            'emerg':   rpm.RPMLOG_EMERG,
            'alert':   rpm.RPMLOG_ALERT,
            'crit':    rpm.RPMLOG_CRIT,
            'err':     rpm.RPMLOG_ERR,
            'warning': rpm.RPMLOG_WARNING,
            'notice':  rpm.RPMLOG_NOTICE,
            'info':    rpm.RPMLOG_INFO,
            'debug':   rpm.RPMLOG_DEBUG
        }.get(levelname)
        if level is not None:
            rpm.setVerbosity(level)

        # Set rpm output log file
        rpmlogfile = sysconf.get('rpm-log-file')
        if rpmlogfile is not None:
            try:
                rpmlog = open(rpmlogfile, 'w')
                rpm.setLogFile(rpmlog)
            except (IOError, OSError), e:
                raise Error, "%s: %s" % (rpmlogfile, unicode(e))
Example #35
0
    def __call__(self, what, amount, total, infopath, data):

        if self.rpmout:
            self._process_rpmout()

        if what == rpm.RPMCALLBACK_INST_OPEN_FILE:
            info, path = infopath
            pkgstr = str(info.getPackage())
            iface.debug(_("Processing %s in %s") % (pkgstr, path))
            self.topic = _("Output from %s:") % pkgstr
            self.fd = os.open(path, os.O_RDONLY)
            setCloseOnExec(self.fd)
            return self.fd
        
        elif what == rpm.RPMCALLBACK_INST_CLOSE_FILE:
            if self.fd is not None:
                os.close(self.fd)
                self.fd = None

        elif what == rpm.RPMCALLBACK_INST_START:
            info, path = infopath
            pkg = info.getPackage()
            self.data["item-number"] += 1
            self.prog.add(1)
            self.prog.setSubTopic(infopath, _("Installing %s") % pkg.name)
            self.prog.setSub(infopath, 0, 1, subdata=self.data)
            self.prog.show()

        elif (what == rpm.RPMCALLBACK_TRANS_PROGRESS or
              what == rpm.RPMCALLBACK_INST_PROGRESS):
            self.prog.setSub(infopath or "trans", amount, total,
                             subdata=self.data)
            self.prog.show()

        elif what == rpm.RPMCALLBACK_TRANS_START:
            self.prog.setSubTopic("trans", _("Preparing..."))
            self.prog.setSub("trans", 0, 1)
            self.prog.show()

        elif what == rpm.RPMCALLBACK_TRANS_STOP:
            self.prog.setSubDone("trans")
            self.prog.show()

        elif what == rpm.RPMCALLBACK_UNINST_START:
            self.topic = _("Output from %s:") % infopath
            subkey =  "R*"+infopath
            self.data["item-number"] += 1
            self.prog.add(1)
            if infopath in self.upgradednames:
                topic = _("Cleaning %s") % infopath
            else:
                topic = _("Removing %s") % infopath
            self.prog.setSubTopic(subkey, topic)
            self.prog.setSub(subkey, 0, 1, subdata=self.data)
            self.prog.show()

        elif what == rpm.RPMCALLBACK_UNINST_STOP:
            self.topic = None
            subkey = "R*"+infopath
            if not self.prog.getSub(subkey):
                self.data["item-number"] += 1
                self.prog.add(1)
                if infopath in self.upgradednames:
                    topic = _("Cleaning %s") % infopath
                else:
                    topic = _("Removing %s") % infopath
                self.prog.setSubTopic(subkey, topic)
                self.prog.setSub(subkey, 1, 1, subdata=self.data)
            else:
                self.prog.setSubDone(subkey)
            self.prog.show()
Example #36
0
# your option) any later version.
#
# Smart Package Manager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Smart Package Manager; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
from smart import _

kind = "package"

name = _("URPMI Repository")

description = _(
    """
Repository created for Mandriva's URPMI package manager.
"""
)

fields = [
    (
        "baseurl",
        _("Base URL"),
        str,
        None,
        _(
            "Base URL where packages or the 'list' file are found under. "
Example #37
0
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
from smart.util import optparse
from smart import Error, _
import textwrap
import sys, os

# 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"]

try:
    optparse.STD_HELP_OPTION.help = \
            _("show this help message and exit")
    optparse.STD_VERSION_OPTION.help = \
            _("show program's version number and exit")
except AttributeError:
    optparse._ = _

OptionValueError = optparse.OptionValueError

class HelpFormatter(optparse.HelpFormatter):

    def __init__(self):
        optparse.HelpFormatter.__init__(self, 2, 24, 79, 1)

    def format_usage(self, usage):
        return _("Usage: %s\n") % usage
Example #38
0
File: pm.py Project: rprstop/rootfs
         for prob in probs:
             name1 = "%s-%s-%s" % prob[0]
             name2, version = prob[1]
             if version:
                 sense = prob[2]
                 name2 += " "
                 if sense & rpm.RPMSENSE_LESS:
                     name2 += "<"
                 elif sense & rpm.RPMSENSE_GREATER:
                     name2 += ">"
                 if sense & rpm.RPMSENSE_EQUAL:
                     name2 += "="
                 name2 += " "
                 name2 += version
             if prob[4] == rpm.RPMDEP_SENSE_REQUIRES:
                 line = _("%s requires %s") % (name1, name2)
             else:
                 line = _("%s conflicts with %s") % (name1, name2)
             problines.append(line)
         raise Error, "\n".join(problines)
 if sysconf.get("rpm-order"):
     ts.order()
 probfilter = rpm.RPMPROB_FILTER_OLDPACKAGE
 if force or reinstall:
     probfilter |= rpm.RPMPROB_FILTER_REPLACEPKG
     probfilter |= rpm.RPMPROB_FILTER_REPLACEOLDFILES
     probfilter |= rpm.RPMPROB_FILTER_REPLACENEWFILES
 ts.setProbFilter(probfilter)
 cb = RPMCallback(prog, upgradednames)
 cb.grabOutput(True)
 probs = None
Example #39
0
 def format_usage(self, usage):
     return _("Usage: %s\n") % usage
Example #40
0
File: pm.py Project: rprstop/rootfs
class RPMPackageManager(PackageManager):
    def commit(self, changeset, pkgpaths):

        prog = iface.getProgress(self, True)
        prog.start()
        prog.setTopic(_("Committing transaction..."))
        prog.set(0, len(changeset))
        prog.show()

        # Compute upgrading/upgraded packages
        upgrading = {}
        upgraded = {}
        for pkg in changeset.keys():
            if changeset.get(pkg) is INSTALL:
                upgpkgs = [
                    upgpkg for prv in pkg.provides for upg in prv.upgradedby
                    for upgpkg in upg.packages if upgpkg.installed
                ]
                upgpkgs.extend([
                    prvpkg for upg in pkg.upgrades for prv in upg.providedby
                    for prvpkg in prv.packages if prvpkg.installed
                ])
                if upgpkgs:
                    for upgpkg in upgpkgs:
                        # If any upgraded package will stay in the system,
                        # this is not really an upgrade for rpm.
                        if changeset.get(upgpkg) is not REMOVE:
                            break
                    else:
                        upgrading[pkg] = True
                        for upgpkg in upgpkgs:
                            upgraded[upgpkg] = True
                            if upgpkg in changeset:
                                del changeset[upgpkg]

        ts = getTS(True)

        flags = ts.setFlags(0)
        if sysconf.get("rpm-allfiles", False):
            flags |= rpm.RPMTRANS_FLAG_ALLFILES
        if sysconf.get("rpm-justdb", False):
            flags |= rpm.RPMTRANS_FLAG_JUSTDB
        if sysconf.get("rpm-noconfigs", False):
            flags |= rpm.RPMTRANS_FLAG_NOCONFIGS
        if (sysconf.get("rpm-nodocs", False)
                or sysconf.get("rpm-excludedocs", False)):
            flags |= rpm.RPMTRANS_FLAG_NODOCS
        if sysconf.get("rpm-nomd5", False):
            flags |= rpm.RPMTRANS_FLAG_NOMD5
        if sysconf.get("rpm-noscripts", False):
            flags |= rpm.RPMTRANS_FLAG_NOSCRIPTS
        if sysconf.get("rpm-notriggers", False):
            flags |= rpm.RPMTRANS_FLAG_NOTRIGGERS
        if sysconf.get("rpm-repackage", False):
            flags |= rpm.RPMTRANS_FLAG_REPACKAGE
        if sysconf.get("rpm-test", False):
            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)

        # Set rpm verbosity level.
        levelname = sysconf.get('rpm-log-level')
        level = {
            'emerg': rpm.RPMLOG_EMERG,
            'alert': rpm.RPMLOG_ALERT,
            'crit': rpm.RPMLOG_CRIT,
            'err': rpm.RPMLOG_ERR,
            'warning': rpm.RPMLOG_WARNING,
            'notice': rpm.RPMLOG_NOTICE,
            'info': rpm.RPMLOG_INFO,
            'debug': rpm.RPMLOG_DEBUG
        }.get(levelname)
        if level is not None:
            rpm.setVerbosity(level)

        # Set rpm output log file
        rpmlogfile = sysconf.get('rpm-log-file')
        if rpmlogfile is not None:
            try:
                rpmlog = open(rpmlogfile, 'w')
                rpm.setLogFile(rpmlog)
            except (IOError, OSError), e:
                raise Error, "%s: %s" % (rpmlogfile, unicode(e))

        # Let's help RPM, since it doesn't do a good
        # ordering job on erasures.
        try:
            sorter = ChangeSetSorter(changeset)
            sorted = sorter.getSorted()
            forcerpmorder = False
        except LoopError:
            lines = [_("Found unbreakable loops:")]
            for path in sorter.getLoopPaths(sorter.getLoops()):
                path = [
                    "%s [%s]" % (pkg, op is INSTALL and "I" or "R")
                    for pkg, op in path
                ]
                lines.append("    " + " -> ".join(path))
            lines.append(_("Will ask RPM to order it."))
            iface.error("\n".join(lines))
            sorted = [(pkg, changeset[pkg]) for pkg in changeset]
            forcerpmorder = True
        del sorter

        packages = 0
        reinstall = False
        for pkg, op in sorted:
            if op is INSTALL:
                if pkg.installed:
                    reinstall = True
                loader = [x for x in pkg.loaders if not x.getInstalled()][0]
                info = loader.getInfo(pkg)
                mode = pkg in upgrading and "u" or "i"
                path = pkgpaths[pkg][0]
                fd = os.open(path, os.O_RDONLY)
                try:
                    h = ts.hdrFromFdno(fd)
                    if sysconf.get("rpm-check-signatures", False):
                        if get_public_key(h) == '(none)':
                            raise rpm.error('package is not signed')
                except rpm.error, e:
                    os.close(fd)
                    raise Error, "%s: %s" % (os.path.basename(path), e)
                os.close(fd)
                ts.addInstall(h, (info, path), mode)
                packages += 1
            else:
                loader = [x for x in pkg.loaders if x.getInstalled()][0]
                offset = pkg.loaders[loader]
                try:
                    ts.addErase(offset)
                except rpm.error, e:
                    raise Error, "%s-%s: %s" % \
                                 (pkg.name, pkg.version, unicode(e))
Example #41
0
# This file is part of Smart Package Manager.
#
# Smart Package Manager is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# Smart Package Manager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Smart Package Manager; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
from smart import _

kind = "package"

name = _("RPM Header List")

description = _("""
Packages from an RPM Header List.
""")

fields = [("baseurl", _("Base URL for packages"), str, None,
           _("Base URL where package files are found")),
          ("hdlurl", _("Header List URL"), str, None,
           _("URL for the header list"))]
Example #42
0
    def commit(self, changeset, pkgpaths):

        prog = iface.getProgress(self, True)
        prog.start()
        prog.setTopic(_("Committing transaction..."))
        prog.set(0, len(changeset))
        prog.show()

        # Compute upgrading/upgraded packages
        upgrading = {}
        upgraded = {}
        for pkg in changeset.keys():
            if changeset.get(pkg) is INSTALL:
                upgpkgs = [
                    upgpkg for prv in pkg.provides for upg in prv.upgradedby
                    for upgpkg in upg.packages if upgpkg.installed
                ]
                upgpkgs.extend([
                    prvpkg for upg in pkg.upgrades for prv in upg.providedby
                    for prvpkg in prv.packages if prvpkg.installed
                ])
                if upgpkgs:
                    for upgpkg in upgpkgs:
                        # If any upgraded package will stay in the system,
                        # this is not really an upgrade for rpm.
                        if changeset.get(upgpkg) is not REMOVE:
                            break
                    else:
                        upgrading[pkg] = True
                        for upgpkg in upgpkgs:
                            upgraded[upgpkg] = True
                            if upgpkg in changeset:
                                del changeset[upgpkg]

        ts = getTS(True)

        flags = ts.setFlags(0)
        if sysconf.get("rpm-allfiles", False):
            flags |= rpm.RPMTRANS_FLAG_ALLFILES
        if sysconf.get("rpm-justdb", False):
            flags |= rpm.RPMTRANS_FLAG_JUSTDB
        if sysconf.get("rpm-noconfigs", False):
            flags |= rpm.RPMTRANS_FLAG_NOCONFIGS
        if (sysconf.get("rpm-nodocs", False)
                or sysconf.get("rpm-excludedocs", False)):
            flags |= rpm.RPMTRANS_FLAG_NODOCS
        if sysconf.get("rpm-nomd5", False):
            flags |= rpm.RPMTRANS_FLAG_NOMD5
        if sysconf.get("rpm-noscripts", False):
            flags |= rpm.RPMTRANS_FLAG_NOSCRIPTS
        if sysconf.get("rpm-notriggers", False):
            flags |= rpm.RPMTRANS_FLAG_NOTRIGGERS
        if sysconf.get("rpm-repackage", False):
            flags |= rpm.RPMTRANS_FLAG_REPACKAGE
        if sysconf.get("rpm-test", False):
            flags |= rpm.RPMTRANS_FLAG_TEST
        ts.setFlags(flags)

        try:
            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)
        except AttributeError, ae:
            pass
Example #43
0
File: pm.py Project: rprstop/rootfs
    def __call__(self, what, amount, total, infopath, data):

        if self.rpmout:
            self._process_rpmout()

        if what == rpm.RPMCALLBACK_INST_OPEN_FILE:
            info, path = infopath
            pkgstr = str(info.getPackage())
            iface.debug(_("Processing %s in %s") % (pkgstr, path))
            self.topic = _("Output from %s:") % pkgstr
            self.fd = os.open(path, os.O_RDONLY)
            setCloseOnExec(self.fd)
            return self.fd

        elif what == rpm.RPMCALLBACK_INST_CLOSE_FILE:
            if self.fd is not None:
                os.close(self.fd)
                self.fd = None

        elif what == rpm.RPMCALLBACK_INST_START:
            info, path = infopath
            pkg = info.getPackage()
            self.data["item-number"] += 1
            self.prog.add(1)
            self.prog.setSubTopic(infopath, _("Installing %s") % pkg.name)
            self.prog.setSub(infopath, 0, 1, subdata=self.data)
            self.prog.show()

        elif (what == rpm.RPMCALLBACK_TRANS_PROGRESS
              or what == rpm.RPMCALLBACK_INST_PROGRESS):
            self.prog.setSub(infopath or "trans",
                             amount,
                             total,
                             subdata=self.data)
            self.prog.show()

        elif what == rpm.RPMCALLBACK_TRANS_START:
            self.prog.setSubTopic("trans", _("Preparing..."))
            self.prog.setSub("trans", 0, 1)
            self.prog.show()

        elif what == rpm.RPMCALLBACK_TRANS_STOP:
            self.prog.setSubDone("trans")
            self.prog.show()

        elif what == rpm.RPMCALLBACK_UNINST_START:
            self.topic = _("Output from %s:") % infopath
            subkey = "R*" + infopath
            self.data["item-number"] += 1
            self.prog.add(1)
            if infopath in self.upgradednames:
                topic = _("Cleaning %s") % infopath
            else:
                topic = _("Removing %s") % infopath
            self.prog.setSubTopic(subkey, topic)
            self.prog.setSub(subkey, 0, 1, subdata=self.data)
            self.prog.show()

        elif what == rpm.RPMCALLBACK_UNINST_STOP:
            self.topic = None
            subkey = "R*" + infopath
            if not self.prog.getSub(subkey):
                self.data["item-number"] += 1
                self.prog.add(1)
                if infopath in self.upgradednames:
                    topic = _("Cleaning %s") % infopath
                else:
                    topic = _("Removing %s") % infopath
                self.prog.setSubTopic(subkey, topic)
                self.prog.setSub(subkey, 1, 1, subdata=self.data)
            else:
                self.prog.setSubDone(subkey)
            self.prog.show()
Example #44
0
File: pm.py Project: pombreda/smart
    def commit(self, changeset, pkgpaths):

        prog = iface.getProgress(self, True)
        prog.start()
        prog.setTopic(_("Committing transaction..."))
        prog.show()

        # Compute upgraded packages
        upgraded = {}
        for pkg in changeset.keys():
            if changeset[pkg] is INSTALL:
                upgpkgs = [
                    upgpkg for prv in pkg.provides for upg in prv.upgradedby
                    for upgpkg in upg.packages if upgpkg.installed
                ]
                upgpkgs.extend([
                    prvpkg for upg in pkg.upgrades for prv in upg.providedby
                    for prvpkg in prv.packages if prvpkg.installed
                ])
                if upgpkgs:
                    for upgpkg in upgpkgs:
                        assert changeset.get(upgpkg) is REMOVE, \
                               "Installing %s while %s is kept?" % \
                               (pkg, upgpkg)
                        assert upgpkg not in upgraded, \
                               "Two packages (%s and %s) upgrading the " \
                               "same installed package (%s)!?" % \
                               (pkg, upgraded[upgpkg], upgpkg)
                        upgraded[upgpkg] = pkg

        sorter = DebSorter(changeset)

        sorted = sorter.getSorted()

        prog.set(0, len(sorted))

        baseargs = shlex.split(sysconf.get("dpkg", "dpkg"))

        opt = sysconf.get("deb-root")
        if opt:
            baseargs.append("--root=%s" % opt)
        opt = sysconf.get("deb-admindir")
        if opt:
            baseargs.append("--admindir=%s" % opt)
        opt = sysconf.get("deb-instdir")
        if opt:
            baseargs.append("--instdir=%s" % opt)
        opt = sysconf.get("deb-simulate")
        if opt:
            baseargs.append("--simulate")

        if sysconf.get("deb-purge"):
            for i in range(len(sorted)):
                pkg, op = sorted[i]
                if op is REMOVE and not upgraded.get(pkg):
                    sorted[i] = pkg, PURGE

        if sysconf.get("deb-non-interactive"):
            old_debian_frontend = os.environ.get(DEBIAN_FRONTEND)
            old_apt_lc_frontend = os.environ.get(APT_LISTCHANGES_FRONTEND)
            os.environ[DEBIAN_FRONTEND] = "noninteractive"
            os.environ[APT_LISTCHANGES_FRONTEND] = "none"
            baseargs.append("--force-confold")

        if sysconf.get("pm-iface-output"):
            output = tempfile.TemporaryFile()
        else:
            output = sys.stdout

        print >> output

        done = {}
        error = None
        while sorted:

            pkgs = []
            op = sorted[0][1]
            while (sorted and sorted[0][1] is op
                   and len(pkgs) < self.MAXPKGSPEROP):
                pkg, op = sorted.pop(0)
                if op is REMOVE and upgraded.get(pkg) in done:
                    continue
                done[pkg] = True
                opname = {
                    REMOVE: "remove",
                    PURGE: "purge",
                    CONFIG: "config",
                    UNPACK: "unpack",
                    INSTALL: "install"
                }
                print >> output, "[%s] %s" % (opname[op], pkg)
                pkgs.append(pkg)

            if not pkgs:
                continue

            args = baseargs[:]

            if op is REMOVE:
                args.append("--force-depends")
                args.append("--force-remove-essential")
                args.append("--remove")
            elif op is PURGE:
                args.append("--force-remove-essential")
                args.append("--purge")
            elif op is UNPACK:
                args.append("--unpack")
            elif op is CONFIG:
                args.append("--force-depends")
                args.append("--force-remove-essential")
                args.append("--configure")

            if op is UNPACK:
                for pkg in pkgs:
                    args.append(pkgpaths[pkg][0])
            else:
                for pkg in pkgs:
                    args.append(pkg.name)

            thread_name = threading.currentThread().getName()
            if thread_name == "MainThread":
                quithandler = signal.signal(signal.SIGQUIT, signal.SIG_IGN)
                inthandler = signal.signal(signal.SIGINT, signal.SIG_IGN)

            output.flush()

            cb = DebCallback(prog, op, pkgs)

            status = self.dpkg(args, output, cb)

            if thread_name == "MainThread":
                signal.signal(signal.SIGQUIT, quithandler)
                signal.signal(signal.SIGINT, inthandler)

            if not os.WIFEXITED(status) or os.WEXITSTATUS(status) != 0:
                if os.WIFSIGNALED(status) and os.WTERMSIG(status):
                    error = _("Sub-process %s has received a "
                              "segmentation fault") % args[0]
                elif os.WIFEXITED(status):
                    error = _("Sub-process %s returned an error code "
                              "(%d)") % (args[0], os.WEXITSTATUS(status))
                else:
                    error = _("Sub-process %s exited unexpectedly") % args[0]
                break

        if output != sys.stdout:
            output.flush()
            output.seek(0)
            data = output.read(8192)
            while data:
                iface.showOutput(data)
                data = output.read(8192)
            output.close()

        if sysconf.get("deb-non-interactive"):
            if old_debian_frontend is None:
                del os.environ[DEBIAN_FRONTEND]
            else:
                os.environ[DEBIAN_FRONTEND] = old_debian_frontend
            if old_apt_lc_frontend is None:
                del os.environ[APT_LISTCHANGES_FRONTEND]
            else:
                os.environ[APT_LISTCHANGES_FRONTEND] = old_apt_lc_frontend

        if error:
            iface.error(error)

        prog.setDone()
        prog.stop()
Example #45
0
File: pm.py Project: rprstop/rootfs
    def commit(self, changeset, pkgpaths):

        prog = iface.getProgress(self, True)
        prog.start()
        prog.setTopic(_("Committing transaction..."))
        prog.set(0, len(changeset))
        prog.show()

        # Compute upgrading/upgraded packages
        upgrading = {}
        upgraded = {}
        for pkg in changeset.keys():
            if changeset.get(pkg) is INSTALL:
                upgpkgs = [
                    upgpkg for prv in pkg.provides for upg in prv.upgradedby
                    for upgpkg in upg.packages if upgpkg.installed
                ]
                upgpkgs.extend([
                    prvpkg for upg in pkg.upgrades for prv in upg.providedby
                    for prvpkg in prv.packages if prvpkg.installed
                ])
                if upgpkgs:
                    for upgpkg in upgpkgs:
                        # If any upgraded package will stay in the system,
                        # this is not really an upgrade for rpm.
                        if changeset.get(upgpkg) is not REMOVE:
                            break
                    else:
                        upgrading[pkg] = True
                        for upgpkg in upgpkgs:
                            upgraded[upgpkg] = True
                            if upgpkg in changeset:
                                del changeset[upgpkg]

        ts = getTS(True)

        flags = ts.setFlags(0)
        if sysconf.get("rpm-allfiles", False):
            flags |= rpm.RPMTRANS_FLAG_ALLFILES
        if sysconf.get("rpm-justdb", False):
            flags |= rpm.RPMTRANS_FLAG_JUSTDB
        if sysconf.get("rpm-noconfigs", False):
            flags |= rpm.RPMTRANS_FLAG_NOCONFIGS
        if (sysconf.get("rpm-nodocs", False)
                or sysconf.get("rpm-excludedocs", False)):
            flags |= rpm.RPMTRANS_FLAG_NODOCS
        if sysconf.get("rpm-nomd5", False):
            flags |= rpm.RPMTRANS_FLAG_NOMD5
        if sysconf.get("rpm-noscripts", False):
            flags |= rpm.RPMTRANS_FLAG_NOSCRIPTS
        if sysconf.get("rpm-notriggers", False):
            flags |= rpm.RPMTRANS_FLAG_NOTRIGGERS
        if sysconf.get("rpm-repackage", False):
            flags |= rpm.RPMTRANS_FLAG_REPACKAGE
        if sysconf.get("rpm-test", False):
            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)

        # Set rpm verbosity level.
        levelname = sysconf.get('rpm-log-level')
        level = {
            'emerg': rpm.RPMLOG_EMERG,
            'alert': rpm.RPMLOG_ALERT,
            'crit': rpm.RPMLOG_CRIT,
            'err': rpm.RPMLOG_ERR,
            'warning': rpm.RPMLOG_WARNING,
            'notice': rpm.RPMLOG_NOTICE,
            'info': rpm.RPMLOG_INFO,
            'debug': rpm.RPMLOG_DEBUG
        }.get(levelname)
        if level is not None:
            rpm.setVerbosity(level)

        # Set rpm output log file
        rpmlogfile = sysconf.get('rpm-log-file')
        if rpmlogfile is not None:
            try:
                rpmlog = open(rpmlogfile, 'w')
                rpm.setLogFile(rpmlog)
            except (IOError, OSError), e:
                raise Error, "%s: %s" % (rpmlogfile, unicode(e))
Example #46
0
    def fetch(self, fetcher, progress):

        # Fetch media information file
        # This file contains the timestamp info
        # that says if the repository has changed
        fetchitem = posixpath.join(self._baseurl, "media.1/media")
        fetched = self.__fetchFile(fetchitem, fetcher, progress)
        if fetched.getStatus() == FAILED:
            return False

        digest = getFileDigest(fetched.getTargetPath())
        #if digest == self._digest and getattr(self, "force-yast", False):
        if digest == self._digest:
            return True

        # Find location of description files
        fetchitem = posixpath.join(self._baseurl, "content")
        fetched = self.__fetchFile(fetchitem, fetcher, progress)
        if fetched.getStatus() == FAILED:
            return False

        descrdir = "suse/setup/descr"
        datadir = "RPMS"
        uncompress = self._compressed
        for line in open(fetched.getTargetPath()):
            line = line.strip()
            try:
                key, rest = line.split(None, 1)
            except ValueError:
                continue

            if key == "DESCRDIR":
                descrdir = rest
            elif key == "DATADIR":
                datadir = rest
            elif key == "META":
                # Autodetect compressed/uncompressed SuSEtags metadata.
                if rest.endswith("packages"):
                    uncompress = False
                elif rest.endswith("packages.gz"):
                    uncompress = True

        # Fetch package information (req, dep, prov, etc)
        fetchitem = posixpath.join(self._baseurl, "%s/packages" % descrdir)
        if uncompress:
            fetchitem += ".gz"
        fetched = self.__fetchFile(fetchitem, fetcher, progress, uncompress)
        if fetched.getStatus() == FAILED:
            return False

        self.removeLoaders()

        pkginfofile = fetched.getTargetPath()
        header = open(pkginfofile).readline().strip()
        if header == "=Ver: 2.0":
            fetchitem = posixpath.join(self._baseurl,
                                       "%s/packages.en" % descrdir)
            if uncompress:
                fetchitem += ".gz"

            fetched = self.__fetchFile(fetchitem, fetcher,
                                       progress, uncompress)

            if (fetched.getStatus() == FAILED or
                open(fetched.getTargetPath()).readline().strip() != "=Ver: 2.0"):
                raise Error, "YaST2 package descriptions not loaded."
            else:
                pkgdescfile = fetched.getTargetPath()
                loader = YaST2Loader(self._baseurl, datadir,
                                     pkginfofile, pkgdescfile)

            loader.setChannel(self)
            self._loaders.append(loader)
        else:
            raise Error, _("Invalid package file header (%s)" % header)

        self._digest = digest

        return True
Example #47
0
#
# Written by Gustavo Niemeyer <*****@*****.**>
#
# This file is part of Smart Package Manager.
#
# Smart Package Manager is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# Smart Package Manager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Smart Package Manager; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
from smart import _

kind = "package"

name = _("DPKG Installed Packages")

description = _("""
Installed packages from dpkg status.
""")

fields = []
Example #48
0
# your option) any later version.
#
# Smart Package Manager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Smart Package Manager; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
from smart import _

kind = "package"

name = _("URPMI Repository")

description = _("""
Repository created for Mandriva's URPMI package manager.
""")

fields = [("baseurl", _("Base URL"), str, None,
           _("Base URL where packages are found under. "
             "Using ' with <hdlurl>' pattern is also supported.")),
          ("directory", _("With directory"), str, "",
           _("Directory path for Base URL")),
          ("hdlurl", _("Header List URL"), str, "",
           _("URL for header list (hdlist or synthesis). If it's hdlist.cz "
             "inside the given base URL, may be left empty. URLs relative "
             "to the Base URL are supported")),
          ("mirrorurl", _("Mirror List URL"), str, "",
Example #49
0
#
# Written by Joel Martin <*****@*****.**>
#
# This file is part of Smart Package Manager.
#
# Smart Package Manager is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# Smart Package Manager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Smart Package Manager; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
from smart import _

kind = "package"

name = _("Solaris Installed Packages and Patches")

description = _("""
Installed packages and patches from the local Solaris databases.
""")

fields = []
Example #50
0
# This file is part of Smart Package Manager.
#
# Smart Package Manager is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# Smart Package Manager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Smart Package Manager; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
from smart import _

kind = "package"

name = _("Slackware Directory")

description = _("""
Local directory with Slackware packages.
""")

fields = [("path", _("Directory Path"), str, None,
           _("Path of directory containing Slackware packages.")),
          ("recursive", _("Recursive"), bool, False,
           _("Search for files recursively."))]
Example #51
0
from smart import Rule as _

rules = (
    _("morning lamp").If("week_day", 0, 1, 2, 3, 4).If(
        "later_than", 20,
        00).Not("later_than", 23,
                00).Once("device_online", "Macbook", "iPhone",
                         op="or").Then("plug", "on",
                                       "lamp").Then("plug", "off", "computer"),
    _("leave home button").On("dash", "dash-button-mac-address").Then(
        "plug", "flip", "lamp").Then("plug", "flip", "computer"),
)
Example #52
0
# Smart Package Manager is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# Smart Package Manager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Smart Package Manager; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

from smart import _

kind = "package"

name = _("RPM RHN")

description = _("""
An RHN base repo
""")


fields = [("baseurl", _("Base URL"), str, None,
           _("URL where repodata/ subdirectory is found")),
          ("channel_info", _("Channel Info"), list, None,
           _("RHN CHannel information"))]
Example #53
0
 def format_usage(self, usage):
     return _("Usage: %s\n") % usage
Example #54
0
# your option) any later version.
#
# Smart Package Manager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Smart Package Manager; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
from smart import _

kind = "package"

name = _("APT-DEB Repository")

description = _("""
Repositories created for APT-DEB.
""")

fields = [("baseurl", _("Base URL"), str, None,
           _("Base URL of repository, where dists/ is located.")),
          ("distribution", _("Distribution"), str, None,
           _("Distribution to use.")),
          ("components", _("Components"), str, "",
           _("Space separated list of components.")),
          ("fingerprint", _("Fingerprint"), str, "",
           _("GPG fingerprint of key signing the channel.")),
          ("keyring", _("Keyring"), str, "",
           _("If provided, channel must necessarily be signed by a key "