Skip to content

Commit

Permalink
copr: allow only 2 arguments with copr enable command
Browse files Browse the repository at this point in the history
resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1801017

Closes: #415
Approved by: lukash
  • Loading branch information
schlupov authored and rh-atomic-bot committed Jan 5, 2021
1 parent d07d002 commit b8390f8
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions plugins/copr.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,15 @@ def run(self):
'copr command are required'))
try:
chroot = self.opts.arg[1]
if len(self.opts.arg) > 2:
raise dnf.exceptions.Error(_('Too many arguments.'))
self.chroot_parts = chroot.split("-")
if len(self.chroot_parts) < 3:
raise dnf.exceptions.Error(_('Bad format of optional chroot. The format is '
'distribution-version-architecture.'))
except IndexError:
chroot = self._guess_chroot()
self.chroot_parts = chroot.split("-")

# commands without defined copr_username/copr_projectname
if subcommand == "search":
Expand Down Expand Up @@ -267,7 +274,7 @@ def run(self):
copr_projectname])
msg = "Do you really want to enable {0}?".format(project)
self._ask_user(info, msg)
self._download_repo(project_name, repo_filename, chroot)
self._download_repo(project_name, repo_filename)
logger.info(_("Repository successfully enabled."))
self._runtime_deps_warning(copr_username, copr_projectname)
elif subcommand == "disable":
Expand Down Expand Up @@ -453,11 +460,9 @@ def _guess_chroot(self):
chroot = ("epel-%s-x86_64" % dist[1].split(".", 1)[0])
return chroot

def _download_repo(self, project_name, repo_filename, chroot=None):
if chroot is None:
chroot = self._guess_chroot()
short_chroot = '-'.join(chroot.split('-')[:2])
arch = chroot.split('-')[2]
def _download_repo(self, project_name, repo_filename):
short_chroot = '-'.join(self.chroot_parts[:-1])
arch = self.chroot_parts[-1]
api_path = "/coprs/{0}/repo/{1}/dnf.repo?arch={2}".format(project_name, short_chroot, arch)

try:
Expand Down Expand Up @@ -660,7 +665,7 @@ def _cmd_enable(self, chroot):
f.close()
if (output2 and ("output" in output2)
and (output2["output"] == "ok")):
self._download_repo(project_name, repo_filename, chroot)
self._download_repo(project_name, repo_filename)
except dnf.exceptions.Error:
# likely 404 and that repo does not exist
pass
Expand Down

0 comments on commit b8390f8

Please sign in to comment.