1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-11-09 22:36:14 +01:00

Make source validator moduler, execute all scripts in directory

This commit is contained in:
Adrian Schröter 2010-05-20 12:02:53 +02:00
parent e9b5ca869a
commit 7e0abcd805
4 changed files with 27 additions and 26 deletions

2
NEWS
View File

@ -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
#

View File

@ -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')

View File

@ -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

View File

@ -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: