1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-01-27 07:06:13 +01:00

Merge branch 'recipe_type_guessing' of https://github.com/lethliel/osc

This commit is contained in:
Marcus Huewe 2017-02-02 12:52:49 +01:00
commit 025ececfdc
2 changed files with 55 additions and 10 deletions

View File

@ -5743,6 +5743,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
"""helper to parse the repo, arch and build description from args"""
import osc.build
import glob
import tempfile
arg_arch = arg_repository = arg_descr = None
if len(args) < 3:
# some magic, works only sometimes, but people seem to like it :/
@ -5787,15 +5788,18 @@ Please submit there instead, or use --nodevelproject to force direct submission.
# only persist our own repos
Repo.tofile(repolistfile, repositories)
no_repo = False
repo_names = sorted(set([r.name for r in repositories]))
if not arg_repository and repositories:
# XXX: we should avoid hardcoding repository names
# Use a default value from config, but just even if it's available
# unless try standard, or openSUSE_Factory, or openSUSE_Tumbleweed
no_repo = True
arg_repository = repositories[-1].name
for repository in (conf.config['build_repository'], 'standard', 'openSUSE_Factory', 'openSUSE_Tumbleweed'):
if repository in repo_names:
arg_repository = repository
no_repo = False
break
if not arg_repository:
@ -5819,22 +5823,37 @@ Please submit there instead, or use --nodevelproject to force direct submission.
elif not arg_descr:
msg = None
if len(descr) > 1:
# guess/prefer build descrs like the following:
# <pac>-<repo>.<ext> > <pac>.<ext>
# no guessing for arch's PKGBUILD files (the backend does not do any guessing, too)
if no_repo:
raise oscerr.WrongArgs("Repository is missing. Cannot guess build description without repository")
apiurl = self.get_api_url()
project = store_read_project('.')
bc = get_buildconfig(apiurl, project, arg_repository)
with tempfile.NamedTemporaryFile() as f:
f.write(bc)
f.flush()
recipe = return_external('/usr/lib/build/queryconfig', '--dist', f.name, 'type')
recipe = recipe.strip()
if recipe == 'arch':
recipe = 'PKGBUILD'
pac = os.path.basename(os.getcwd())
if is_package_dir(os.getcwd()):
pac = store_read_package(os.getcwd())
extensions = ['spec', 'dsc', 'kiwi', 'livebuild']
cands = [i for i in descr for ext in extensions if i == '%s-%s.%s' % (pac, arg_repository, ext)]
if recipe == 'PKGBUILD':
cands = [d for d in descr if d.startswith(recipe)]
else:
cands = [d for d in descr if d.endswith('.' + recipe)]
if len(cands) > 1:
repo_cands = [d for d in cands if d == '%s-%s.%s' % (pac, arg_repository, recipe)]
if repo_cands:
cands = repo_cands
else:
pac_cands = [d for d in cands if d == '%s.%s' % (pac, recipe)]
if pac_cands:
cands = pac_cands
if len(cands) == 1:
arg_descr = cands[0]
else:
cands = [i for i in descr for ext in extensions if i == '%s.%s' % (pac, ext)]
if len(cands) == 1:
arg_descr = cands[0]
if not arg_descr:
msg = 'Multiple build description files found: %s' % ', '.join(descr)
msg = 'Multiple build description files found: %s' % ', '.join(cands)
elif not ignore_descr:
msg = 'Missing argument: build description (spec, dsc, kiwi or livebuild file)'
try:

View File

@ -7310,6 +7310,32 @@ def run_external(filename, *args, **kwargs):
raise
raise oscerr.ExtRuntimeError(e.strerror, filename)
def return_external(filename, *args, **kwargs):
"""Executes the program filename via subprocess.check_output.
*args are additional arguments which are passed to the
program filename. **kwargs specify additional arguments for
the subprocess.check_output function.
if no args are specified the plain filename is passed
to subprocess.check_output (this can be used to execute a shell
command). Otherwise [filename] + list(args) is passed
to the subprocess.check_output function.
Returns the output of the command.
"""
if args:
cmd = [filename] + list(args)
else:
cmd = filename
try:
return subprocess.check_output(cmd, **kwargs)
except OSError as e:
if e.errno != errno.ENOENT:
raise
raise oscerr.ExtRuntimeError(e.strerror, filename)
# backward compatibility: local role filtering
def filter_role(meta, user, role):
"""