Beispiel #1
0
 def __init__(self):
     self.ctrl = init()
     initDistro(self.ctrl)
     initPlugins()
     initPsyco()
     self.ctrl.reloadChannels()
     self.cache = self.ctrl.getCache()
     self.trans = Transaction(self.cache, PolicyInstall)
Beispiel #2
0
 def __init__(self):
     self.ctrl = init()
     initDistro(self.ctrl)
     initPlugins()
     initPsyco()
     self.ctrl.reloadChannels()
     self.cache = self.ctrl.getCache()
     self.trans = Transaction(self.cache, PolicyInstall)
Beispiel #3
0
def main(argv):
    # Get the right $HOME, even when using sudo.
    #    if os.getuid() == 0:
    #        os.environ["HOME"] = pwd.getpwuid(0)[5]
    opts = None
    ctrl = None
    exitcode = 1
    try:
        opts = parse_options(argv)
        opts.data_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "datadir"))
        opts.config_file = os.path.join(opts.data_dir, "config")
        opts.interface = "text"
        opts.ignore_locks = True
        opts.option = ["remove-packages=False"]
        ctrl = init(
            command=opts.command,
            argv=opts.argv,
            datadir=opts.data_dir,
            configfile=opts.config_file,
            gui=opts.gui,
            shell=opts.shell,
            interface=opts.interface,
            forcelocks=opts.ignore_locks,
            loglevel=opts.log_level,
        )

        if os.name == "posix":
            baseurl = "http://127.0.0.1/~bertrand/packages.xml"
        elif os.name == "nt":
            baseurl = "http://127.0.0.1/~bertrand/packages.xml"
        # path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'packages.xml'))
        # baseurl = 'file://%s' % path
        data = {"baseurl": baseurl, "type": "pacman", "name": "pacman"}
        ctrl._channels["pacman"] = pacman_site.create("pacman", data)
        if opts.option:
            set_config_options(opts.option)
        initDistro(ctrl)
        initPlugins()
        initPsyco()
        exitcode = iface.run(opts.command, opts.argv)
        if exitcode is None:
            exitcode = 0
        ctrl.saveSysConf()
        ctrl.restoreMediaState()
    except Error, e:
        if opts and opts.log_level == "debug":
            import traceback

            traceback.print_exc()
        if iface.object:
            iface.error(unicode(e))
        else:
            sys.stderr.write(_("error: %s\n") % e)
        if ctrl:
            ctrl.saveSysConf()
            ctrl.restoreMediaState()
Beispiel #4
0
def main(argv):
    # Get the right $HOME, even when using sudo.
#    if os.getuid() == 0:
#        os.environ["HOME"] = pwd.getpwuid(0)[5]
    opts = None
    ctrl = None
    exitcode = 1
    try:
        opts = parse_options(argv)
        opts.data_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), 'datadir'))
        opts.config_file = os.path.join(opts.data_dir, 'config')
        opts.interface = 'text'
        opts.ignore_locks=True
        opts.option = ['remove-packages=False']
        ctrl = init(command=opts.command, argv=opts.argv,
                    datadir=opts.data_dir, configfile=opts.config_file,
                    gui=opts.gui, shell=opts.shell, interface=opts.interface,
                    forcelocks=opts.ignore_locks, loglevel=opts.log_level)
                    
        if os.name == 'posix':
            from user import home
        #    baseurl = 'file://' + os.path.join(home, 'Workspace/WinLibre/winlibrepacman/','test.xml')
            baseurl = "http://127.0.0.1/~bertrand/packages.xml"
        if os.name == 'nt':
            baseurl = "http://127.0.0.1/winlibrepacman/packages.xml"
        #path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'packages.xml'))
        #baseurl = 'file://%s' % path
        data = {'baseurl': baseurl,
                'type':"pacman",
                'name':'pacman'
                }
        ctrl._channels['pacman'] = pacman_site.create('pacman', data)
        if opts.option:
            set_config_options(opts.option)
        initDistro(ctrl)
        initPlugins()
        initPsyco()
        exitcode = iface.run(opts.command, opts.argv)
        if exitcode is None:
            exitcode = 0
        ctrl.saveSysConf()
        ctrl.restoreMediaState()
    except Error, e:
        if opts and opts.log_level == "debug":
            import traceback
            traceback.print_exc()
        if iface.object:
            iface.error(unicode(e))
        else:
            sys.stderr.write(_("error: %s\n") % e)
        if ctrl:
            ctrl.saveSysConf()
            ctrl.restoreMediaState()
Beispiel #5
0
def main(argv):
    # Get the right $HOME, even when using sudo.
    if os.getuid() == 0:
        os.environ["HOME"] = pwd.getpwuid(0)[5]
    opts = None
    ctrl = None
    exitcode = 1
    try:
        opts = parse_options(argv)
        if opts.rootfs_dir:
            datadir = opts.rootfs_dir + DATADIR
        else:
            datadir = opts.data_dir

        ctrl = init(command=opts.command,
                    argv=opts.argv,
                    datadir=datadir,
                    configfile=opts.config_file,
                    gui=opts.gui,
                    shell=opts.shell,
                    quiet=opts.quiet,
                    interface=opts.interface,
                    forcelocks=opts.ignore_locks,
                    loglevel=opts.log_level)
        if opts.option:
            set_config_options(opts.option)
        initDistro(ctrl)
        initPlugins()
        initPycurl()
        initPsyco()
        exitcode = iface.run(opts.command, opts.argv)
        if exitcode is None:
            exitcode = 0
        ctrl.saveSysConf()
        ctrl.restoreMediaState()
    except Error, e:
        if opts and opts.log_level == "debug":
            import traceback
            traceback.print_exc()
        if iface.object:
            iface.error(unicode(e))
        else:
            sys.stderr.write(_("error: %s\n") % e)
        if ctrl:
            ctrl.saveSysConf()
            ctrl.restoreMediaState()
def main(argv):
    # Get the right $HOME, even when using sudo.
    if os.getuid() == 0:
        os.environ["HOME"] = pwd.getpwuid(0)[5]
    opts = None
    ctrl = None
    exitcode = 1
    try:
        opts = parse_options(argv)
        ctrl = init(command=opts.command, argv=opts.argv,
                    datadir=opts.data_dir, configfile=opts.config_file,
                    gui=opts.gui, shell=opts.shell, quiet=opts.quiet,
                    interface=opts.interface, forcelocks=opts.ignore_locks,
                    loglevel=opts.log_level)
        if opts.option:
            set_config_options(opts.option)
        initDistro(ctrl)
        initPlugins()
        initPycurl()
        initPsyco()
        exitcode = iface.run(opts.command, opts.argv)
        if exitcode is None:
            exitcode = 0
        ctrl.saveSysConf()
        ctrl.restoreMediaState()
    except Error, e:
        if opts and opts.log_level == "debug":
            import traceback
            traceback.print_exc()
        if iface.object:
            iface.error(unicode(e))
        else:
            sys.stderr.write(_("error: %s\n") % e)
        if ctrl:
            ctrl.saveSysConf()
            ctrl.restoreMediaState()
Beispiel #7
0
def run_commands(commands_list, args_list, reload_channels=True):
    """ Run Smart commands
    Args:
        commands_list (list): list of commands. commands = newer, query, channel
        args_list (list): list of arguments list
        reload_channels (bool): reload channel or not

    Returns:
        string: string representing the list of string of results. Each list item is separated by #smart_opts_list#
    """
    global std_out_redirected
    str_result_list = ''
    result = ''

    if len(args_list) != len(commands_list):
        print 'Error For Smart_ops.py: args and commands have different lengths!'
        return str_result_list

    try:
        if os.getuid() == 0:
            os.environ["HOME"] = pwd.getpwuid(0)[5]

        with redirect_std_out(
        ) as output:  # Doing this, we can discard the stdout message.
            ctrl = smart.init(command=None)
            smart.initDistro(ctrl)
            smart.initPlugins()
            smart.initPycurl()
            smart.initPsyco()
            if reload_channels:
                ctrl.reloadChannels()

        for index in range(len(args_list)):
            args = args_list[index]
            command = commands_list[index]

            # Prepare for options
            opts = None
            if command == 'newer':
                opts = smart.commands.newer.parse_options(args)
            elif command == 'channel':
                opts = smart.commands.channel.parse_options(args)
            elif command == 'query':
                opts = smart.commands.query.parse_options(args)
            elif command == 'upgrade':
                opts = smart.commands.upgrade.parse_options(args)
            else:
                print 'Error For Smart_ops.py: ' + command + ' is not supported.'

            # Run the command
            if opts is not None:
                if command == 'newer':
                    with redirect_std_out() as output:
                        smart.commands.newer.main(ctrl,
                                                  opts,
                                                  reloadchannels=False)
                    result = std_out_redirected
                elif command == 'channel':
                    with redirect_std_out() as output:
                        smart.commands.channel.main(ctrl, opts)
                    result = std_out_redirected
                elif command == 'query':
                    with redirect_std_out() as output:
                        smart.commands.query.main(ctrl,
                                                  opts,
                                                  reloadchannels=False)
                    result = std_out_redirected
                elif command == 'upgrade':
                    with redirect_std_out() as output:
                        smart.commands.upgrade.main(ctrl, opts)
                    result = std_out_redirected
                else:
                    print 'Error For Smart_ops.py: ' + command + ' is not supported.'
                    result = ''

            if index == (len(args_list) - 1):
                str_result_list += result
            else:
                str_result_list += (result + '#smart_opts_list#')

        ctrl.saveSysConf()
        ctrl.restoreMediaState()
        smart.deinit()
    except Exception as e1:
        print 'Error For Smart_ops.py: ' + str(e1)
        smart.deinit()
    return str_result_list
Beispiel #8
0
    def setup(self, command=None, argv=None):
        iutil.mkdirChain(self.smart_dir)
        iutil.mkdirChain(self.anaconda.backend.instPath + "/install/tmp")

        buf = """#!/bin/bash

export PATH="${PATH}"
export D="%s"
export OFFLINE_ROOT="$D"
export IPKG_OFFLINE_ROOT="$D"
export OPKG_OFFLINE_ROOT="$D"
export INTERCEPT_DIR="/"
export NATIVE_ROOT="/"

exec 1>>/tmp/scriptlet.log 2>&1 

echo $2 $1/$3 $4
if [ $2 = "/bin/sh" ]; then
  $2 -x $1/$3 $4
else
  $2 $1/$3 $4
fi
if [ $? -ne 0 ]; then
  if [ $4 -eq 1 ]; then
    mkdir -p $1/etc/rpm-postinsts
    num=100
    while [ -e $1/etc/rpm-postinsts/${num}-* ]; do num=$((num + 1)); done
    name=`head -1 $1/$3 | cut -d' ' -f 2`
    echo "#!$2" > $1/etc/rpm-postinsts/${num}-${name}
    echo "# Arg: $4" >> $1/etc/rpm-postinsts/${num}-${name}
    cat $1/$3 >> $1/etc/rpm-postinsts/${num}-${name}
    chmod +x $1/etc/rpm-postinsts/${num}-${name}
  else
    echo "Error: pre/post remove scriptlet failed"
  fi
fi
""" % (self.anaconda.backend.instPath)

        fd = open(
            self.anaconda.backend.instPath + "/install/scriptlet_wrapper", "w")
        fd.write(buf)
        fd.close()
        os.chmod(self.anaconda.backend.instPath + "/install/scriptlet_wrapper",
                 0755)

        self.smart_ctrl = init(command,
                               argv=argv,
                               datadir=self.smart_dir,
                               configfile=None,
                               gui=False,
                               shell=False,
                               quiet=True,
                               interface=None,
                               forcelocks=False,
                               loglevel=None)

        # Override the dummy interface with the locally defined one
        iface.object = AnacondaInterface(self.smart_ctrl, self.anaconda)

        initDistro(self.smart_ctrl)
        initPlugins()
        initPycurl()
        initPsyco()

        sysconf.set("rpm-root", self.anaconda.backend.instPath, soft=True)
        sysconf.set("rpm-extra-macros._tmppath", "/install/tmp", soft=True)
        sysconf.set("rpm-extra-macros._cross_scriptlet_wrapper",
                    self.anaconda.backend.instPath +
                    "/install/scriptlet_wrapper",
                    soft=True)

        sysconf.set("rpm-nolinktos", "1")
        sysconf.set("rpm-noparentdirs", "1")

        if self.anaconda.upgrade:
            # Note:
            # This is a fix, we didn't remove the channels that we added in
            # previous installs, so remove them here.
            #FIXME: Do we need disable user's channels ?
            self.removeWrlLoclRepo()

            # Enable the installed RPM DB
            channels = sysconf.get("channels") or {}
            if 'rpmsys' not in channels:
                self.runSmart('channel',
                              ['--add', 'rpmsys', 'type=rpm-sys', '-y'])
                iface.object.hideStatus()
        else:
            # Ensure we start with a blank channel set...
            sysconf.remove("channels")

        self.repos = AnacondaSmartRepo("anaconda-config", self.anaconda)

        # Setup repository
        for localpath in [
                "/mnt/install/source", "/mnt/install/cdimage",
                "/mnt/install/isodir", ""
        ]:
            if os.path.isdir("%s/Packages" % localpath) and os.access(
                    "%s/Packages/.feedpriority" % localpath, os.R_OK):
                f = open("%s/Packages/.feedpriority" % localpath)
                for line in f:
                    (priority, feed) = line.split()
                    if os.path.isdir("%s/Packages/%s/repodata" %
                                     (localpath, feed)):
                        repo = SmartRepo("media_%s" % feed)
                        repo.name = "Install Media feed for %s" % feed
                        repo.cost = priority
                        repo.baseurl = [
                            "file://%s/Packages/%s" % (localpath, feed)
                        ]
                        self.repos.add(repo)
                f.close()

        if self.anaconda.ksdata:
            for ksrepo in self.anaconda.ksdata.repo.repoList:
                # If no location was given, this must be a repo pre-configured
                # repo that we just want to enable.
                if not ksrepo.baseurl and not ksrepo.mirrorlist:
                    self.repos.enable(ksrepo.name)
                    continue

                anacondaBaseURLs = [ksrepo.baseurl]

                # smart doesn't understand nfs:// and doesn't want to. We need
                # to first do the mount, then translate it into a file:// that
                # smart does understand.
                # "nfs:" and "nfs://" prefixes are accepted in ks_repo --baseurl
                if ksrepo.baseurl and ksrepo.baseurl.startswith("nfs:"):
                    #if not network.hasActiveNetDev() and not self.anaconda.intf.enableNetwork():
                    #    self.anaconda.intf.messageWindow(_("No Network Available"),
                    #        _("Some of your software repositories require "
                    #          "networking, but there was an error enabling the "
                    #          "network on your system."),
                    #        type="custom", custom_icon="error",
                    #        custom_buttons=[_("_Exit installer")])
                    #    sys.exit(1)

                    dest = tempfile.mkdtemp("", ksrepo.name.replace(" ", ""),
                                            "/mnt")

                    # handle "nfs://" prefix
                    if ksrepo.baseurl[4:6] == '//':
                        ksrepo.baseurl = ksrepo.baseurl.replace('//', '', 1)
                        anacondaBaseURLs = [ksrepo.baseurl]
                    try:
                        isys.mount(ksrepo.baseurl[4:], dest, "nfs")
                    except Exception as e:
                        log.error("error mounting NFS repo: %s" % e)

                    ksrepo.baseurl = "file://%s" % dest

                repo = SmartRepo(ksrepo.name)
                repo.mirrorlist = ksrepo.mirrorlist
                repo.name = ksrepo.name

                if not ksrepo.baseurl:
                    repo.baseurl = []
                else:
                    repo.baseurl = [ksrepo.baseurl]
                repo.anacondaBaseURLs = anacondaBaseURLs

                if ksrepo.cost:
                    repo.cost = ksrepo.cost

                if ksrepo.excludepkgs:
                    repo.exclude = ksrepo.excludepkgs

                if ksrepo.includepkgs:
                    repo.includepkgs = ksrepo.includepkgs

                if ksrepo.noverifyssl:
                    repo.sslverify = False

                if ksrepo.proxy:
                    self.setProxy(ksrepo, repo)

                self.repos.add(repo)

        self.smart_ctrl.saveSysConf()
        self.smart_ctrl.restoreMediaState()
        self.doRepoSetup(self.anaconda)
    def _initSmart(self, command=None, argv=None):
        iutil.mkdirChain(self.smart_dir)
        iutil.mkdirChain(self.wrapper_dir)

        buf = """#!/bin/bash

export PATH="${PATH}"
export D="%s"
export OFFLINE_ROOT="$D"
export IPKG_OFFLINE_ROOT="$D"
export OPKG_OFFLINE_ROOT="$D"
export INTERCEPT_DIR="/"
export NATIVE_ROOT="/"

exec 1>>/tmp/scriptlet.log 2>&1

echo $2 $1/$3 $4
if [ $2 = "/bin/sh" ]; then
  $2 -x $1/$3 $4
else
  $2 $1/$3 $4
fi
if [ $? -ne 0 ]; then
  if [ $4 -eq 1 ]; then
    mkdir -p $1/etc/rpm-postinsts
    num=100
    while [ -e $1/etc/rpm-postinsts/${num}-* ]; do num=$((num + 1)); done
    name=`head -1 $1/$3 | cut -d' ' -f 2`
    echo "#!$2" > $1/etc/rpm-postinsts/${num}-${name}
    echo "# Arg: $4" >> $1/etc/rpm-postinsts/${num}-${name}
    cat $1/$3 >> $1/etc/rpm-postinsts/${num}-${name}
    chmod +x $1/etc/rpm-postinsts/${num}-${name}
  else
    echo "Error: pre/post remove scriptlet failed"
  fi
fi
""" % (self.sysroot)

        fd = open(self.wrapper_dir + "/scriptlet_wrapper", "w")
        fd.write(buf)
        fd.close()
        os.chmod(self.wrapper_dir + "/scriptlet_wrapper", 0755)

        self.smart_ctrl = init(command,
                               argv=argv,
                               datadir=self.smart_dir,
                               configfile=None,
                               gui=False,
                               shell=False,
                               quiet=True,
                               interface=None,
                               forcelocks=False,
                               loglevel=None)

        # Override the dummy interface with the locally defined one
        iface.object = AnacondaInterface(self.smart_ctrl)

        initDistro(self.smart_ctrl)
        initPlugins()
        initPycurl()
        initPsyco()

        sysconf.set("rpm-root", self.sysroot, soft=True)
        sysconf.set("rpm-extra-macros._tmppath", "/install/tmp", soft=True)
        sysconf.set("rpm-extra-macros._cross_scriptlet_wrapper",
                    self.wrapper_dir + "/scriptlet_wrapper",
                    soft=True)
        sysconf.set("rpm-nolinktos", "1")
        sysconf.set("rpm-noparentdirs", "1")

        sysconf.remove("channels")

        self.repo_manager = SmartRepoManager(self.runSmart)
def run_commands(commands_list, args_list, reload_channels=True):
    """ Run Smart commands
    Args:
        commands_list (list): list of commands. commands = newer, query, channel
        args_list (list): list of arguments list
        reload_channels (bool): reload channel or not

    Returns:
        string: string representing the list of string of results. Each list item is separated by #smart_opts_list#
    """
    global std_out_redirected
    str_result_list = ''
    result = ''

    if len(args_list) != len(commands_list):
        print 'Error For Smart_ops.py: args and commands have different lengths!'
        return str_result_list

    try:
        if os.getuid() == 0:
            os.environ["HOME"] = pwd.getpwuid(0)[5]

        with redirect_std_out() as output:  # Doing this, we can discard the stdout message.
            ctrl = smart.init(command=None)
            smart.initDistro(ctrl)
            smart.initPlugins()
            smart.initPycurl()
            smart.initPsyco()
            if reload_channels:
                ctrl.reloadChannels()

        for index in range(len(args_list)):
            args = args_list[index]
            command = commands_list[index]

            # Prepare for options
            opts = None
            if command == 'newer':
                opts = smart.commands.newer.parse_options(args)
            elif command == 'channel':
                opts = smart.commands.channel.parse_options(args)
            elif command == 'query':
                opts = smart.commands.query.parse_options(args)
            elif command == 'upgrade':
                opts = smart.commands.upgrade.parse_options(args)
            else:
                print 'Error For Smart_ops.py: ' + command + ' is not supported.'

            # Run the command
            if opts is not None:
                if command == 'newer':
                    with redirect_std_out() as output:
                        smart.commands.newer.main(ctrl, opts, reloadchannels=False)
                    result = std_out_redirected
                elif command == 'channel':
                    with redirect_std_out() as output:
                        smart.commands.channel.main(ctrl, opts)
                    result = std_out_redirected
                elif command == 'query':
                    with redirect_std_out() as output:
                        smart.commands.query.main(ctrl, opts, reloadchannels=False)
                    result = std_out_redirected
                elif command == 'upgrade':
                    with redirect_std_out() as output:
                        smart.commands.upgrade.main(ctrl, opts)
                    result = std_out_redirected
                else:
                    print 'Error For Smart_ops.py: ' + command + ' is not supported.'
                    result = ''

            if index == (len(args_list) - 1):
                str_result_list += result
            else:
                str_result_list += (result + '#smart_opts_list#')

        ctrl.saveSysConf()
        ctrl.restoreMediaState()
        smart.deinit()
    except Exception as e1:
        print 'Error For Smart_ops.py: ' + str(e1)
        smart.deinit()
    return str_result_list