def remove(pkgs): print "Removing packages %s" % pkgs import smart.commands.remove as remove del_pkgs = [] for (pkg, data) in pkgs: del_pkgs.append(pkg[0]) ctrl = init() opts = remove.parse_options([]) opts.args = del_pkgs opts.yes = True print pkgs, del_pkgs try: remove.main(ctrl, opts) refresh_list() except Exception, e: msg = "Package remove failed" if e.args: msg += ": %s" msg %= str(e.args[0]) data = {'version': 0, 'name': 'solarispkgs.remove'} return (100, msg, data)
def refresh_list(): command = {"action": "packages"} ctrl = init(command, interface="up2date") exitdata = iface.run(command) #return exitdata return (0, "package list refresh successfully", {})
def install(pkgs): print "Installing packages %s" % pkgs import smart.commands.install as install inst_pkgs = [] for (pkg, data) in pkgs: inst_pkgs.append("%s-%s-%s" % (pkg[0], pkg[1], pkg[2])) if data.has_key('answerfile'): # FIXME (20050426): Handle answer file pass ctrl = init() opts = install.parse_options([]) opts.args = inst_pkgs opts.yes = True try: install.main(ctrl, opts) refresh_list() except Exception, e: msg = "Package install failed" if e.args: msg += ": %s" msg %= str(e.args[0]) data = {'version': 0, 'name': 'solarispkgs.install'} return (101, msg, data)
def patchRemove(pkgs): print "Removing patches %s" % pkgs import smart.commands.remove as remove del_pkgs = [] for (pkg, data) in pkgs: # name-version-release (skip epoch) pkgname = '-'.join(pkg[:-1]) del_pkgs.append(pkgname) ctrl = init() opts = remove.parse_options([]) opts.args = del_pkgs opts.yes = True print pkgs, del_pkgs try: remove.main(ctrl, opts) refresh_list() except Exception, e: msg = "Patch remove failed" if e.args: msg += ": %s" msg %= str(e.args[0]) data = {'version': 0, 'name': 'solarispkgs.patchRemove'} return (103, msg, data)
def patchClusterInstall(pkgs): print "Installing patch cluster: ", pkgs import smart.commands.install as install inst_pkgs = [] for (pkg, data) in pkgs: inst_pkgs.append("%s-%s-%s" % (pkg[0], pkg[1], pkg[2])) ctrl = init() opts = install.parse_options([]) opts.args = inst_pkgs opts.yes = True try: install.main(ctrl, opts) refresh_list() except Exception, e: msg = "Patch cluster install failed" if e.args: msg += ": %s" msg %= str(e.args[0]) data = {'version': 0, 'name': 'solarispkgs.patchClusterInstall'} # FIXME (20050613): What is the proper return value here? return (102, msg, data)
def patchClusterInstall(pkgs): print "Installing patch cluster: ", pkgs import smart.commands.install as install inst_pkgs = [] for (pkg, data) in pkgs: inst_pkgs.append("%s-%s-%s" % (pkg[0], pkg[1], pkg[2])) ctrl = init() opts = install.parse_options([]) opts.args = inst_pkgs opts.yes = True try: install.main(ctrl, opts) refresh_list() except Exception, e: msg = "Patch cluster install failed" if e.args: msg += ": %s" msg %= str(e.args[0]) data = {'version': 0, 'name' : 'solarispkgs.patchClusterInstall'} # FIXME (20050613): What is the proper return value here? return (102, msg, data)
def patchRemove(pkgs): print "Removing patches %s" % pkgs import smart.commands.remove as remove del_pkgs = [] for (pkg, data) in pkgs: # name-version-release (skip epoch) pkgname = '-'.join(pkg[:-1]) del_pkgs.append(pkgname) ctrl = init() opts = remove.parse_options([]) opts.args = del_pkgs opts.yes = True print pkgs, del_pkgs try: remove.main(ctrl, opts) refresh_list() except Exception, e: msg = "Patch remove failed" if e.args: msg += ": %s" msg %= str(e.args[0]) data = {'version': 0, 'name' : 'solarispkgs.patchRemove'} return (103, msg, data)
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, interface=opts.interface, forcelocks=opts.ignore_locks, loglevel=opts.log_level) if opts.option: set_config_options(opts.option) initPlugins() 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 refresh_list(): command = {"action" : "packages"} ctrl = init(command, interface="up2date") exitdata = iface.run(command) #return exitdata return (0, "package list refresh successfully", {})
def install(pkgs): print "Installing packages %s" % pkgs import smart.commands.install as install inst_pkgs = [] for (pkg, data) in pkgs: inst_pkgs.append("%s-%s-%s" % (pkg[0], pkg[1], pkg[2])) if data.has_key('answerfile'): # FIXME (20050426): Handle answer file pass ctrl = init() opts = install.parse_options([]) opts.args = inst_pkgs opts.yes = True try: install.main(ctrl, opts) refresh_list() except Exception, e: msg = "Package install failed" if e.args: msg += ": %s" msg %= str(e.args[0]) data = {'version': 0, 'name' : 'solarispkgs.install'} return (101, msg, data)
def remove(pkgs): print "Removing packages %s" % pkgs import smart.commands.remove as remove del_pkgs = [] for (pkg, data) in pkgs: del_pkgs.append(pkg[0]) ctrl = init() opts = remove.parse_options([]) opts.args = del_pkgs opts.yes = True print pkgs, del_pkgs try: remove.main(ctrl, opts) refresh_list() except Exception, e: msg = "Package remove failed" if e.args: msg += ": %s" msg %= str(e.args[0]) data = {'version': 0, 'name' : 'solarispkgs.remove'} return (100, msg, data)
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)
def __init__(self): datadir = DATADIR config = os.path.join(PACMANDIR, 'config') self.ctrl = smart.init(datadir=DATADIR, configfile=config) data = {'baseurl': baseurl, 'type':"pacman", 'name':'pacman' } self._channels['pacman'] = pacman_site.create('pacman', data)
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()
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()
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, interface=opts.interface, forcelocks=opts.ignore_locks, loglevel=opts.log_level, ) if opts.option: set_config_options(opts.option) initPlugins() 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 test(): import sys, time import smart # We need sysconf in the progress code. ctrl = smart.init() prog = GtkProgress(True) data = {"item-number": 0} total, subtotal = 100, 100 prog.start() prog.setTopic("Installing packages...") for n in range(1, total + 1): data["item-number"] = n prog.set(n, total) prog.setSubTopic(n, "package-name%d" % n) for i in range(0, subtotal + 1): prog.setSub(n, i, subtotal, subdata=data) prog.show() time.sleep(0.01) prog.stop()
def test(): import sys, time import smart # We need sysconf in the progress code. ctrl = smart.init() prog = GtkProgress(True) data = {"item-number": 0} total, subtotal = 100, 100 prog.start() prog.setTopic("Installing packages...") for n in range(1,total+1): data["item-number"] = n prog.set(n, total) prog.setSubTopic(n, "package-name%d" % n) for i in range(0,subtotal+1): prog.setSub(n, i, subtotal, subdata=data) prog.show() time.sleep(0.01) prog.stop()
def patchInstall(pkgs, keepBackup=None): print "Installing patches %s" % pkgs import smart.commands.install as install inst_pkgs = [] for (pkg, data) in pkgs: inst_pkgs.append("%s-%s-%s" % (pkg[0], pkg[1], pkg[2])) ctrl = init() opts = install.parse_options([]) opts.args = inst_pkgs opts.yes = True try: install.main(ctrl, opts) refresh_list() except Exception, e: msg = "Patch install failed" if e.args: msg += ": %s" msg %= str(e.args[0]) data = {'version': 0, 'name': 'solarispkgs.patchInstall'} return (102, msg, data)
def patchInstall(pkgs, keepBackup=None): print "Installing patches %s" % pkgs import smart.commands.install as install inst_pkgs = [] for (pkg, data) in pkgs: inst_pkgs.append("%s-%s-%s" % (pkg[0], pkg[1], pkg[2])) ctrl = init() opts = install.parse_options([]) opts.args = inst_pkgs opts.yes = True try: install.main(ctrl, opts) refresh_list() except Exception, e: msg = "Patch install failed" if e.args: msg += ": %s" msg %= str(e.args[0]) data = {'version': 0, 'name' : 'solarispkgs.patchInstall'} return (102, msg, data)
NAME = "KDE Applet for Smart" VERSION = "0.1" AUTHORS = ["""Anders F Bjorklund <*****@*****.**>"""] try: from PyKDE4.kdecore import ki18n, KAboutData, KCmdLineArgs from PyKDE4.kdeui import KApplication, KMainWindow, KAboutApplicationDialog, KIcon from PyQt4.QtGui import QSystemTrayIcon, QMenu, QIcon from PyQt4.QtCore import QVariant except RuntimeError: raise Error, _("Could not open a valid X display") except ImportError: import smart from smart.const import DEBUG ctrl = smart.init() if sysconf.get("log-level") == DEBUG: import traceback traceback.print_exc() raise Error, _("System has no support for kde python interface") def exit_applet(*args): # need to detach sysTray, or it will segfault sysTray.hide() sysTray.contextMenu().deleteLater() sysTray.deleteLater() app.quit() SMART_HELPER = ["smart-helper-kde"]
def getControl(self): if not self.control: self.control = smart.init() pass return self.control
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
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 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 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
NAME = "Gnome Applet for Smart" VERSION = "0.1" AUTHORS = ["""Mauricio Teixeira <*****@*****.**>""", """Anders F Bjorklund <*****@*****.**>"""] try: import pygtk pygtk.require("2.0") import gtk except RuntimeError: raise Error, _("Could not open a valid X display") except ImportError: import smart from smart.const import DEBUG ctrl = smart.init() if sysconf.get("log-level") == DEBUG: import traceback traceback.print_exc() raise Error, _("System has no support for gtk python interface") def exit_applet(*args): gtk.main_quit() return def show_popup_menu(icon, button, time, *data): if button == 3: menu.popup(None, None, None, 0, time) return if os.path.exists("/usr/bin/console-helper"):