#430 [cli] print friendlier error when trying to upload a nonexisting file
Merged 5 years ago by praiskup. Opened 5 years ago by frostyx.
copr/ frostyx/copr apiv3-cli-upload  into  master

file modified
+7 -6
@@ -13,9 +13,9 @@ 

  

  import logging

  if six.PY2:

-     from urlparse import urljoin

+     from urlparse import urljoin, urlparse

  else:

-     from urllib.parse import urljoin

+     from urllib.parse import urljoin, urlparse

  

  if sys.version_info < (2, 7):

      class NullHandler(logging.Handler):
@@ -200,11 +200,7 @@ 

          """

          self.client.build_proxy.auth_check()

  

-         bar = None

-         progress_callback = None

-         build_function = self.client.build_proxy.create_from_url

          builds = []

- 

          for pkg in args.pkgs:

              if os.path.exists(pkg):

                  bar = ProgressBar(max=os.path.getsize(pkg))
@@ -216,7 +212,12 @@ 

                      bar.next(n=8192)

  

                  print('Uploading package {0}'.format(pkg))

+             elif not urlparse(pkg).scheme:

+                 raise CoprException("File {0} not found".format(pkg))

              else:

+                 bar = None

+                 progress_callback = None

+                 build_function = self.client.build_proxy.create_from_url

                  data = {"url": pkg}

  

              builds.append(self.process_build(args, build_function, data, bar=bar, progress_callback=progress_callback))

Can we consider this as a fix for #429?

Originally this condition was handled by API client code, not copr-cli, but I don't want that anymore. There was a generic Client.create_new_build doing

if urlparse(pkgs[0]).scheme != "":
    Submit every package as URL
else:
    Upload the package

I'd prefer a simple File {srpm} not found.

Why not to use the urlparse on client side, then?

rebased onto 077642d

5 years ago

I'd prefer a simple File {srpm} not found.

Sure, done

Why not to use the urlparse on client side, then?

I thought that it was an overkill and "//" not in pkg is simplier and equal to it, but sure, we can use urlparse.

Pull-Request has been merged by praiskup

5 years ago
Metadata