mirror of
https://github.com/openSUSE/osc.git
synced 2025-02-08 20:15:47 +01:00
- parse_repoarchdescr: improved error messages a bit
Moved reading/writing of .osc/_build_repositories into the Repo class.
This commit is contained in:
parent
ee15c4cb11
commit
a8d0b948af
@ -5398,36 +5398,35 @@ Please submit there instead, or use --nodevelproject to force direct submission.
|
|||||||
# store list of repos for potential offline use
|
# store list of repos for potential offline use
|
||||||
repolistfile = os.path.join(os.getcwd(), osc.core.store, "_build_repositories")
|
repolistfile = os.path.join(os.getcwd(), osc.core.store, "_build_repositories")
|
||||||
if noinit:
|
if noinit:
|
||||||
if os.path.exists(repolistfile):
|
repositories = Repo.fromfile(repolistfile)
|
||||||
f = open(repolistfile, 'r')
|
|
||||||
repositories = [ l.strip()for l in f.readlines()]
|
|
||||||
f.close()
|
|
||||||
else:
|
else:
|
||||||
project = alternative_project or store_read_project('.')
|
project = alternative_project or store_read_project('.')
|
||||||
apiurl = self.get_api_url()
|
apiurl = self.get_api_url()
|
||||||
repositories = get_repositories_of_project(apiurl, project)
|
repositories = list(get_repos_of_project(apiurl, project))
|
||||||
if not len(repositories):
|
if not len(repositories):
|
||||||
raise oscerr.WrongArgs('no repositories defined for project \'%s\'' % project)
|
raise oscerr.WrongArgs('no repositories defined for project \'%s\'' % project)
|
||||||
try:
|
if alternative_project is None:
|
||||||
f = open(repolistfile, 'w')
|
# only persist our own repos
|
||||||
f.write('\n'.join(repositories) + '\n')
|
Repo.tofile(repolistfile, repositories)
|
||||||
f.close()
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if not arg_repository and len(repositories):
|
repo_names = [r.name for r in repositories]
|
||||||
|
if not arg_repository and repositories:
|
||||||
# Use a default value from config, but just even if it's available
|
# Use a default value from config, but just even if it's available
|
||||||
# unless try standard, or openSUSE_Factory
|
# unless try standard, or openSUSE_Factory
|
||||||
arg_repository = repositories[-1]
|
arg_repository = repositories[-1].name
|
||||||
for repository in (conf.config['build_repository'], 'standard', 'openSUSE_Factory'):
|
for repository in (conf.config['build_repository'], 'standard', 'openSUSE_Factory'):
|
||||||
if repository in repositories:
|
if repository in repo_names:
|
||||||
arg_repository = repository
|
arg_repository = repository
|
||||||
break
|
break
|
||||||
|
|
||||||
if not arg_repository:
|
if not arg_repository:
|
||||||
raise oscerr.WrongArgs('please specify a repository')
|
raise oscerr.WrongArgs('please specify a repository')
|
||||||
elif noinit == False and not arg_repository in repositories:
|
if not noinit:
|
||||||
raise oscerr.WrongArgs('%s is not a valid repository, use one of: %s' % (arg_repository, ', '.join(repositories)))
|
if not arg_repository in repo_names:
|
||||||
|
raise oscerr.WrongArgs('%s is not a valid repository, use one of: %s' % (arg_repository, ', '.join(repo_names)))
|
||||||
|
arches = [r.arch for r in repositories if r.name == arg_repository and r.arch]
|
||||||
|
if arches and not arg_arch in arches:
|
||||||
|
raise oscerr.WrongArgs('%s is not a valid arch for the repository %s, use one of: %s' % (arg_arch, arg_repository, ', '.join(arches)))
|
||||||
|
|
||||||
# can be implemented using
|
# can be implemented using
|
||||||
# reduce(lambda x, y: x + y, (glob.glob(x) for x in ('*.spec', '*.dsc', '*.kiwi')))
|
# reduce(lambda x, y: x + y, (glob.glob(x) for x in ('*.spec', '*.dsc', '*.kiwi')))
|
||||||
|
21
osc/core.py
21
osc/core.py
@ -5113,6 +5113,27 @@ class Repo:
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.repo_line_templ % (self.name, self.arch)
|
return self.repo_line_templ % (self.name, self.arch)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def fromfile(filename):
|
||||||
|
if not os.path.exists(filename):
|
||||||
|
return []
|
||||||
|
repos = []
|
||||||
|
lines = open(filename, 'r').readlines()
|
||||||
|
for line in lines:
|
||||||
|
data = line.split()
|
||||||
|
if len(data) == 2:
|
||||||
|
repos.append(Repo(data[0], data[1]))
|
||||||
|
elif len(data) == 1:
|
||||||
|
# only for backward compatibility
|
||||||
|
repos.append(Repo(data[0], ''))
|
||||||
|
return repos
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def tofile(filename, repos):
|
||||||
|
with open(filename, 'w') as f:
|
||||||
|
for repo in repos:
|
||||||
|
f.write('%s %s\n' % (repo.name, repo.arch))
|
||||||
|
|
||||||
def get_repos_of_project(apiurl, prj):
|
def get_repos_of_project(apiurl, prj):
|
||||||
f = show_project_meta(apiurl, prj)
|
f = show_project_meta(apiurl, prj)
|
||||||
root = ET.fromstring(''.join(f))
|
root = ET.fromstring(''.join(f))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user