diff --git a/osc/commandline.py b/osc/commandline.py index 9102f48e..e0c0f95a 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -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'))) diff --git a/osc/core.py b/osc/core.py index 71a518fa..52a70b84 100644 --- a/osc/core.py +++ b/osc/core.py @@ -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))