Commits

Michał Górny committed 36032d1

Introduce the --allow-downgrade option.

  • Participants
  • Parent commits bce4a02

Comments (0)

Files changed (2)

SmartLiveRebuild/cli.py

 from SmartLiveRebuild.output import out
 from SmartLiveRebuild.vcs import GetVCS
 
+def check_downgrade(opt, optstr, val):
+	if val not in ('always', 'same-pv', 'never'):
+		raise OptionValueError("option %s: incorrect value %s." % (optstr, val))
+	return val
+
 def check_vcslist(opt, optstr, val):
 	val = val.split(',')
 	for vcs in val:
 	return val
 
 class SLROption(Option):
-	TYPES = Option.TYPES + ('vcslist',)
+	TYPES = Option.TYPES + ('downgrade', 'vcslist')
 	TYPE_CHECKER = copy(Option.TYPE_CHECKER)
+	TYPE_CHECKER['downgrade'] = check_downgrade
 	TYPE_CHECKER['vcslist'] = check_vcslist
 
 class CLIConfig(Config):
 		help='Configuration file (default: /etc/portage/smart-live-rebuild.conf)')
 	opt.add_option('-C', '--no-color', action='store_false', dest='color',
 		help='Disable colorful output.')
+	opt.add_option('-D', '--allow-downgrade', action='store', type='downgrade', dest='allow_downgrade',
+		help="When to allow downgrading package (one of 'never', 'same-pv', 'always')")
 	opt.add_option('-E', '--no-erraneous-merge', action='store_false', dest='erraneous_merge',
 		help='Disable emerging packages for which the update has failed.')
 	opt.add_option('-j', '--jobs', action='store', type='int', dest='jobs',

SmartLiveRebuild/core.py

 
 import bz2, errno, fcntl, os.path, pickle, select, shutil, signal, subprocess, sys, tempfile, time
 import portage
+from portage.versions import pkgsplit
 
 try:
 	from configparser import ConfigParser, NoOptionError
 			settings = portage.settings
 
 		self._real_defaults = {
+			'allow_downgrade': 'same-pv',
 			'color': 'True',
 			'config_file': '/etc/portage/smart-live-rebuild.conf',
 			'erraneous_merge': 'True',
 				except ValueError:
 					out.err('Incorrect int value: %s=%s' % (k, v))
 					val[k] = int(self._real_defaults[k])
+			elif k == 'allow_downgrade':
+				if v not in ('always', 'same-pv', 'never'):
+					out.err('Incorrect value: %s=%s' % (k, v))
+					val[k] = self._real_defaults[k]
+				else:
+					val[k] = v
 			elif k == 'type':
 				if v != '':
 					val[k] = []
 			else:
 				os.environ['ESCM_OFFLINE'] = 'true'
 
-		packages = ['>=%s' % x for x in packages]
+		if opts.allow_downgrade == 'always':
+			packages = [pkgsplit(x)[0] for x in packages]
+		else:
+			if opts.allow_downgrade == 'same-pv':
+				packages = ['-'.join(pkgsplit(x)[0:2]) for x in packages]
+			packages = ['>=%s' % x for x in packages]
+
+		print packages
 
 		if len(packages) < 1:
 			out.s1('No updates found')