1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-11-10 06:46:15 +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:
Marcus Huewe 2014-07-02 22:07:01 +02:00
parent ee15c4cb11
commit a8d0b948af
2 changed files with 36 additions and 16 deletions

View File

@ -5398,36 +5398,35 @@ Please submit there instead, or use --nodevelproject to force direct submission.
# store list of repos for potential offline use
repolistfile = os.path.join(os.getcwd(), osc.core.store, "_build_repositories")
if noinit:
if os.path.exists(repolistfile):
f = open(repolistfile, 'r')
repositories = [ l.strip()for l in f.readlines()]
f.close()
repositories = Repo.fromfile(repolistfile)
else:
project = alternative_project or store_read_project('.')
apiurl = self.get_api_url()
repositories = get_repositories_of_project(apiurl, project)
repositories = list(get_repos_of_project(apiurl, project))
if not len(repositories):
raise oscerr.WrongArgs('no repositories defined for project \'%s\'' % project)
try:
f = open(repolistfile, 'w')
f.write('\n'.join(repositories) + '\n')
f.close()
except:
pass
if alternative_project is None:
# only persist our own repos
Repo.tofile(repolistfile, repositories)
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
# 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'):
if repository in repositories:
if repository in repo_names:
arg_repository = repository
break
if not arg_repository:
raise oscerr.WrongArgs('please specify a repository')
elif noinit == False and not arg_repository in repositories:
raise oscerr.WrongArgs('%s is not a valid repository, use one of: %s' % (arg_repository, ', '.join(repositories)))
if not noinit:
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
# reduce(lambda x, y: x + y, (glob.glob(x) for x in ('*.spec', '*.dsc', '*.kiwi')))

View File

@ -5113,6 +5113,27 @@ class Repo:
def __str__(self):
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):
f = show_project_meta(apiurl, prj)
root = ET.fromstring(''.join(f))