From e5e1b6a0b6aa769df41dfeb5517848226b22a37d Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Wed, 12 Sep 2012 20:05:10 +0200 Subject: [PATCH] [Solo] implement "solo hop" command. --- client/solo/commands/hop.py | 161 ++++++++++++++++++++++++++++++++++++ docs/TODO | 2 - 2 files changed, 161 insertions(+), 2 deletions(-) create mode 100644 client/solo/commands/hop.py diff --git a/client/solo/commands/hop.py b/client/solo/commands/hop.py new file mode 100644 index 000000000..aa83cc478 --- /dev/null +++ b/client/solo/commands/hop.py @@ -0,0 +1,161 @@ +# -*- coding: utf-8 -*- +""" + + @author: Fabio Erculiani + @contact: lxnay@sabayon.org + @copyright: Fabio Erculiani + @license: GPL-2 + + B{Entropy Command Line Client}. + +""" +import sys +import argparse + +from entropy.i18n import _ +from entropy.output import brown, purple, teal, darkred, bold, \ + red, darkgreen + +from solo.commands.descriptor import SoloCommandDescriptor +from solo.commands.command import SoloCommand + +class SoloHop(SoloCommand): + """ + Main Solo Update command. + """ + + NAME = "hop" + ALIASES = [] + + INTRODUCTION = """\ +Upgrade the System to a new branch. +""" + SEE_ALSO = "" + + def __init__(self, args): + SoloCommand.__init__(self, args) + self._branch = None + + def man(self): + """ + Overridden from SoloCommand. + """ + return self._man() + + def _get_parser(self): + """ + Overridden from SoloCommand. + """ + descriptor = SoloCommandDescriptor.obtain_descriptor( + SoloHop.NAME) + parser = argparse.ArgumentParser( + description=descriptor.get_description(), + formatter_class=argparse.RawDescriptionHelpFormatter, + prog="%s %s" % (sys.argv[0], SoloHop.NAME)) + + parser.add_argument( + "branch", metavar="", help=_("branch")) + + return parser + + def parse(self): + """ + Parse command + """ + parser = self._get_parser() + try: + nsargs = parser.parse_args(self._args) + except IOError as err: + sys.stderr.write("%s\n" % (err,)) + return parser.print_help, [] + + self._branch = nsargs.branch + + return self._call_locked, [self._hop] + + def bashcomp(self, last_arg): + """ + Overridden from SoloCommand. + """ + return self._bashcomp(sys.stdout, last_arg, []) + + def _hop(self, entropy_client): + """ + Solo Hop command. + """ + settings = entropy_client.Settings() + inst_repo = entropy_client.installed_repository() + + # set the new branch + if self._branch == settings['repositories']['branch']: + mytxt = "%s: %s" % ( + darkred(_("Already on branch")), + purple(self._branch), + ) + entropy_client.output( + mytxt, level="warning", importance=1, + header=bold(" !!! ")) + return 2 + + old_repo_paths = [] + avail_data = settings['repositories']['available'] + for repoid in sorted(avail_data): + old_repo_paths.append(avail_data[repoid]['dbpath'][:]) + + old_branch = settings['repositories']['branch'][:] + entropy_client.set_branch(self._branch) + status = True + + repo_conf = settings.get_setting_files_data()['repositories'] + try: + repo_intf = entropy_client.Repositories(None, force = False, + fetch_security = False) + except AttributeError as err: + entropy_client.output( + "%s %s [%s]" % ( + purple(_("No repositories specified in")), + teal(repo_conf), + err, + ), + header=darkred(" * "), + level="error", importance=1) + status = False + else: + rc = repo_intf.sync() + if rc and rc != 1: + # rc != 1 means not all the repos have been downloaded + status = False + + if status: + inst_repo.moveSpmUidsToBranch(self._branch) + + mytxt = "%s: %s" % ( + darkgreen(_("Succesfully switched to branch")), + purple(self._branch),) + entropy_client.output( + mytxt, + header=red(" @@ ")) + mytxt = "%s %s" % ( + brown(" ?? "), + darkgreen(_("Now run 'equo upgrade' to " + "upgrade your distribution to")), + ) + entropy_client.output(mytxt) + return 0 + + entropy_client.set_branch(old_branch) + mytxt = "%s: %s" % ( + darkred(_("Unable to switch to branch")), + purple(self._branch),) + entropy_client.output( + mytxt, level="error", + importance=1, header=bold(" !!! ")) + + return 3 + +SoloCommandDescriptor.register( + SoloCommandDescriptor( + SoloHop, + SoloHop.NAME, + _("upgrade the System to a new branch")) + ) diff --git a/docs/TODO b/docs/TODO index 246cafbc8..75b999926 100644 --- a/docs/TODO +++ b/docs/TODO @@ -2,8 +2,6 @@ Backlog (raw) 1.0: - hop - upgrade --ask --fetch