From 7e0abcd80536ee42ec9d748ae163bd36ac0ad3c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Schr=C3=B6ter?= Date: Thu, 20 May 2010 12:02:53 +0200 Subject: [PATCH] Make source validator moduler, execute all scripts in directory --- NEWS | 2 +- osc/commandline.py | 24 ++++++++++++------------ osc/conf.py | 8 ++++---- osc/core.py | 19 ++++++++++--------- 4 files changed, 27 insertions(+), 26 deletions(-) diff --git a/NEWS b/NEWS index 7e5f817f..7d8be4ea 100644 --- a/NEWS +++ b/NEWS @@ -5,7 +5,7 @@ - fix creation of package link, when target project has the package via linked project - add "osc rq approvenew $PROJECT" command to show and accept all request in new state. This makes sense esp. for projects which work with default reviewers before. - - support external source validator script before commiting + - support external source validator scripts before commiting # # Features which require OBS 2.0 # diff --git a/osc/commandline.py b/osc/commandline.py index cb829862..a4dee1fb 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -2370,8 +2370,8 @@ Please submit there instead, or use --nodevelproject to force direct submission. help='read log message from FILE') @cmdln.option('-f', '--force', default=False, action="store_true", help='force commit - do not tests a file list') - @cmdln.option('--skip-validator', default=False, action="store_true", - help='Skip the source validator') + @cmdln.option('--skip-validation', default=False, action="store_true", + help='Skip the source validation') def do_commit(self, subcmd, opts, *args): """${cmd_name}: Upload content to the repository server @@ -2400,12 +2400,12 @@ Please submit there instead, or use --nodevelproject to force direct submission. args = parseargs(args) msg = '' - validator = conf.config['source_validator'] - if opts.skip_validator: - validator = None - elif not os.path.exists(validator): - print "WARNING: validator", validator, "configured, but not existing. Skipping ..." - validator = None + validators = conf.config['source_validator_directory'] + if opts.skip_validation: + validators = None + elif not os.path.exists(validators): + print "WARNING: validator directory", validators, "configured, but not existing. Skipping ..." + validators = None if opts.message: msg = opts.message @@ -2421,7 +2421,7 @@ Please submit there instead, or use --nodevelproject to force direct submission. if not msg: msg = edit_message() try: - Project(arg).commit(msg=msg, validator=validator) + Project(arg).commit(msg=msg, validators=validators) except oscerr.RuntimeError, e: print >>sys.stderr, "ERROR: source_validator failed", e return 1 @@ -2472,19 +2472,19 @@ Please submit there instead, or use --nodevelproject to force direct submission. single_paths.append(pac.dir) for prj, packages in prj_paths.iteritems(): try: - Project(prj).commit(tuple(packages), msg, files, validator=validator) + Project(prj).commit(tuple(packages), msg, files, validators=validators) except oscerr.RuntimeError, e: print >>sys.stderr, "ERROR: source_validator failed", e return 1 for pac in single_paths: try: - Package(pac).commit(msg, validator=validator) + Package(pac).commit(msg, validators=validators) except oscerr.RuntimeError, e: print >>sys.stderr, "ERROR: source_validator failed", e return 1 else: for p in pacs: - p.commit(msg, validator=validator) + p.commit(msg, validators=validators) store_unlink_file(os.path.abspath('.'), '_commit_msg') diff --git a/osc/conf.py b/osc/conf.py index a9450461..ff2c6990 100644 --- a/osc/conf.py +++ b/osc/conf.py @@ -112,8 +112,8 @@ DEFAULTS = { 'apiurl': 'https://api.opensuse.org', 'request_list_days': 30, # check for unversioned/removed files before commit 'check_filelist': '1', - # External script to validate sources, esp before commit - 'source_validator': '/usr/lib/osc/source_validator', + # External scripts to validate sources, esp before commit. This is a directory + 'source_validator_directory': '/usr/lib/osc/source_validators', # check for pending requests after executing an action (e.g. checkout, update, commit) 'check_for_request_on_action': '0', # what to do with the source package if the submitrequest has been accepted @@ -253,8 +253,8 @@ apiurl = %(apiurl)s #review requests interactively (default: off) #request_show_review = 1 -# Executable to validate sources, esp before committing -#source_validator = /usr/lib/osc/source_validator +# Directory with executables to validate sources, esp before committing +#source_validator_directory = /usr/lib/osc/source_validators [%(apiurl)s] user = %(user)s diff --git a/osc/core.py b/osc/core.py index 9b755844..4152bbb6 100644 --- a/osc/core.py +++ b/osc/core.py @@ -624,7 +624,7 @@ class Project: finally: self.write_packages() - def commit(self, pacs = (), msg = '', files = {}, validator = None): + def commit(self, pacs = (), msg = '', files = {}, validators = None): if len(pacs): try: for pac in pacs: @@ -643,7 +643,7 @@ class Project: else: p = Package(os.path.join(self.dir, pac)) p.todo = todo - p.commit(msg, validator=validator) + p.commit(msg, validators=validators) elif pac in self.pacs_unvers and not is_package_dir(os.path.join(self.dir, pac)): print 'osc: \'%s\' is not under version control' % pac elif pac in self.pacs_broken: @@ -663,7 +663,7 @@ class Project: state = self.get_state(pac) if state == ' ': # do a simple commit - Package(os.path.join(self.dir, pac)).commit(msg, validator=validator) + Package(os.path.join(self.dir, pac)).commit(msg, validators=validators) elif state == 'D': self.commitDelPackage(pac) elif state == 'A': @@ -896,7 +896,7 @@ class Package: shutil.copyfile(os.path.join(self.dir, n), os.path.join(self.storedir, n)) - def commit(self, msg='', validator=None): + def commit(self, msg='', validators=None): # commit only if the upstream revision is the same as the working copy's upstream_rev = self.latest_rev() if self.rev != upstream_rev: @@ -907,11 +907,12 @@ class Package: pathn = getTransActPath(self.dir) - if validator: - import subprocess - p = subprocess.Popen([validator], close_fds=True) - if p.wait() != 0: - raise oscerr.RuntimeError(p.stdout, validator ) + if validators: + for validator in os.listdir(validators): + import subprocess + p = subprocess.Popen([validators+"/"+validator], close_fds=True) + if p.wait() != 0: + raise oscerr.RuntimeError(p.stdout, validator ) have_conflicts = False for filename in self.todo: