Esempio n. 1
0
 def _retry_twine(self, twine_command, server, filenames):
     twine_args = (twine_command, '-r', server)
     if twine_command == 'register':
         pass
     elif twine_command == 'upload':
         twine_args += ('--skip-existing', )
     else:
         print(Fore.RED + "Unknown twine command: %s" % twine_command)
         sys.exit(1)
     twine_args += tuple(filenames)
     try:
         twine_dispatch(twine_args)
         return
     except requests.HTTPError as e:
         # Something went wrong.  Close repository.
         response = e.response
         # Some errors reported by PyPI after register or upload may be
         # fine.  The register command is not really needed anymore with the
         # new PyPI.  See https://github.com/pypa/twine/issues/200
         # This might change, but for now the register command fails.
         if (twine_command == 'register'
                 and response.reason == 'This API is no longer supported, '
                 'instead simply upload the file.'):
             return
         # Show the error.
         print(Fore.RED + "Response status code: %s" % response.status_code)
         print(Fore.RED + "Reason: %s" % response.reason)
     print(Fore.RED + "There were errors or warnings.")
     logger.exception("Package %s has failed.", twine_command)
     retry = utils.retry_yes_no(['twine', twine_command])
     if retry:
         logger.info("Retrying.")
         return self._retry_twine(twine_command, server, filenames)
Esempio n. 2
0
 def _retry_twine(self, twine_command, server, filenames):
     twine_args = (twine_command, '-r', server)
     if twine_command == 'register':
         pass
     elif twine_command == 'upload':
         twine_args += ('--skip-existing', )
     else:
         print(Fore.RED + "Unknown twine command: %s" % twine_command)
         sys.exit(1)
     twine_args += tuple(filenames)
     try:
         twine_dispatch(twine_args)
         return
     except requests.HTTPError as e:
         # Something went wrong.  Close repository.
         response = e.response
         # Some errors reported by PyPI after register or upload may be
         # fine.  The register command is not really needed anymore with the
         # new PyPI.  See https://github.com/pypa/twine/issues/200
         # This might change, but for now the register command fails.
         if (twine_command == 'register'
                 and response.reason == 'This API is no longer supported, '
                 'instead simply upload the file.'):
             return
         # Show the error.
         print(Fore.RED + "Response status code: %s" % response.status_code)
         print(Fore.RED + "Reason: %s" % response.reason)
     print(Fore.RED + "There were errors or warnings.")
     logger.exception("Package %s has failed.", twine_command)
     retry = utils.retry_yes_no(['twine', twine_command])
     if retry:
         logger.info("Retrying.")
         return self._retry_twine(twine_command, server, filenames)
Esempio n. 3
0
 def _retry_twine(self, twine_command, server, filename):
     repository = self._get_repository(server)
     package_file = PackageFile.from_filename(filename, comment=None)
     if twine_command == 'register':
         # Register the package.
         twine_function = repository.register
         twine_args = (package_file, )
     elif twine_command == 'upload':
         try:
             already_uploaded = repository.package_is_uploaded(package_file)
         except ValueError:
             # For a new package, the call fails, at least with twine 1.8.1.
             # This is the same as when calling `twine --skip-existing` on
             # the command line.  See
             # https://github.com/pypa/twine/issues/220
             logger.warning('Error calling package_is_uploaded from twine. '
                            'Probably new project. Will try uploading.')
             already_uploaded = False
         if already_uploaded:
             logger.warning(
                 'A file %s has already been uploaded. Ignoring.', filename)
             return
         twine_function = repository.upload
         twine_args = (package_file, )
     else:
         print(Fore.RED + "Unknown twine command: %s" % twine_command)
         sys.exit(1)
     response = twine_function(*twine_args)
     if response is not None and response.status_code == codes.OK:
         return
     # if we get 409 that's conflict (which I'm going to interpret as the package has already been uploaded
     if response is not None and response.status_code == codes.CONFLICT:
         return
     # Something went wrong.  Close repository.
     repository.close()
     self._drop_repository(server)
     if response is not None:
         # Some errors reported by PyPI after register or upload may be
         # fine.  The register command is not really needed anymore with the
         # new PyPI.  See https://github.com/pypa/twine/issues/200
         # This might change, but for now the register command fails.
         if (twine_command == 'register'
                 and response.reason == 'This API is no longer supported, '
                 'instead simply upload the file.'):
             return
         # Show the error.
         print(Fore.RED + "Response status code: %s" % response.status_code)
         print(Fore.RED + "Reason: %s" % response.reason)
     print(Fore.RED + "There were errors or warnings.")
     logger.exception("Package %s has failed.", twine_command)
     retry = utils.retry_yes_no(['twine', twine_command])
     if retry:
         logger.info("Retrying.")
         # Reload the pypi config so changes that the user has made to
         # influence the retry can take effect.
         self.pypiconfig.reload()
         return self._retry_twine(twine_command, server, filename)
Esempio n. 4
0
    def _retry_twine(self, twine_command, server, filenames):
        """Attempt to execute a Twine command.

        Args:
            twine_command: The Twine command to use (eg. register, upload).
            server: The distutils server name from a `.pipyrc` config file.
                If this is `None` the TWINE_REPOSITORY_URL environment variable
                will be used instead of a distutils server name.
            filenames: A list of files which will be uploaded.
        """
        twine_args = (twine_command, )

        if server is not None:
            twine_args += ('-r', server)

        if twine_command == 'register':
            pass
        elif twine_command == 'upload':
            twine_args += ('--skip-existing', )
        else:
            print(Fore.RED + "Unknown twine command: %s" % twine_command)
            sys.exit(1)
        twine_args += tuple(filenames)
        try:
            twine_dispatch(twine_args)
            return
        except requests.HTTPError as e:
            # Something went wrong.  Close repository.
            response = e.response
            # Some errors reported by PyPI after register or upload may be
            # fine.  The register command is not really needed anymore with the
            # new PyPI.  See https://github.com/pypa/twine/issues/200
            # This might change, but for now the register command fails.
            if (twine_command == 'register'
                    and response.reason == 'This API is no longer supported, '
                    'instead simply upload the file.'):
                return
            # Show the error.
            print(Fore.RED + "Response status code: %s" % response.status_code)
            print(Fore.RED + "Reason: %s" % response.reason)
        print(Fore.RED + "There were errors or warnings.")
        logger.exception("Package %s has failed.", twine_command)
        retry = utils.retry_yes_no(['twine', twine_command])
        if retry:
            logger.info("Retrying.")
            return self._retry_twine(twine_command, server, filenames)
Esempio n. 5
0
 def _retry_twine(self, twine_command, server, filename):
     repository = self._get_repository(server)
     package_file = PackageFile.from_filename(filename, comment=None)
     if twine_command == "register":
         # Register the package.
         twine_function = repository.register
         twine_args = (package_file,)
     elif twine_command == "upload":
         # Note: we assume here that calling package_is_uploaded does not
         # give an error, and that there is no reason to retry it.
         if repository.package_is_uploaded(package_file):
             logger.warn("A file %s has already been uploaded. Ignoring.", filename)
             return
         twine_function = repository.upload
         twine_args = (package_file,)
     else:
         print(Fore.RED + "Unknown twine command: %s" % twine_command)
         sys.exit(1)
     response = twine_function(*twine_args)
     if response is not None and response.status_code == codes.OK:
         return
     # Something went wrong.  Close repository.
     repository.close()
     self._drop_repository(server)
     if response is not None:
         # Some errors reported by PyPI after register or upload may be
         # fine.  The register command is not really needed anymore with the
         # new PyPI.  See https://github.com/pypa/twine/issues/200
         # This might change, but for now the register command fails.
         if (
             twine_command == "register"
             and response.reason == "This API is no longer supported, " "instead simply upload the file."
         ):
             return
         # Show the error.
         print(Fore.RED + "Response status code: %s" % response.status_code)
         print(Fore.RED + "Reason: %s" % response.reason)
     print(Fore.RED + "There were errors or warnings.")
     logger.exception("Package %s has failed.", twine_command)
     retry = utils.retry_yes_no("twine %s" % twine_command)
     if retry:
         logger.info("Retrying.")
         return self._retry_twine(twine_command, server, filename)
Esempio n. 6
0
 def _retry_twine(self, twine_command, server, filename):
     repository = self._get_repository(server)
     package_file = PackageFile.from_filename(filename, comment=None)
     if twine_command == 'register':
         # Register the package.
         twine_function = repository.register
         twine_args = (package_file, )
     elif twine_command == 'upload':
         # Note: we assume here that calling package_is_uploaded does not
         # give an error, and that there is no reason to retry it.
         if repository.package_is_uploaded(package_file):
             logger.warn('A file %s has already been uploaded. Ignoring.',
                         filename)
             return
         twine_function = repository.upload
         twine_args = (package_file, )
     else:
         print(Fore.RED + "Unknown twine command: %s" % twine_command)
         sys.exit(1)
     response = twine_function(*twine_args)
     if response is not None and response.status_code == codes.OK:
         return
     # Something went wrong.  Close repository.
     repository.close()
     self._drop_repository(server)
     if response is not None:
         # Some errors reported by PyPI after register or upload may be
         # fine.  The register command is not really needed anymore with the
         # new PyPI.  See https://github.com/pypa/twine/issues/200
         # This might change, but for now the register command fails.
         if (twine_command == 'register'
                 and response.reason == 'This API is no longer supported, '
                 'instead simply upload the file.'):
             return
         # Show the error.
         print(Fore.RED + "Response status code: %s" % response.status_code)
         print(Fore.RED + "Reason: %s" % response.reason)
     print(Fore.RED + "There were errors or warnings.")
     logger.exception("Package %s has failed.", twine_command)
     retry = utils.retry_yes_no('twine %s' % twine_command)
     if retry:
         logger.info("Retrying.")
         return self._retry_twine(twine_command, server, filename)