Beispiel #1
0
def get_package_archive_name(package_name, version):
  """
  Concatenates the *package_name* and *version* and adds the `.tar.gz`
  suffix. All package distribution archives are supposed to be `.tar.gz`
  files.
  """

  argschema.validate('package_name', package_name,
      {'type': [six.text_type, refstring.Package]})
  if isinstance(package_name, six.text_type):
    package_name = refstring.parse_package(package_name)

  return u'{}-{}.tar.gz'.format(six.text_type(package_name).replace('/', '-'), version)
Beispiel #2
0
  def __init__(self, package, version, module, member):
    argschema.validate('package', package, {'type': [None, Package]})
    argschema.validate('version', version, {'type': [None, str, semver.Selector]})
    argschema.validate('module', module, {'type': [None, str]})
    argschema.validate('member', member, {'type': [None, str]})

    if not package and version:
      raise ValueError('can not specify version without package name')
    if isinstance(version, str):
      version = semver.Selector(version)

    self.package = package
    self.version = version
    self.module = module
    self.member = member
Beispiel #3
0
  def find_package(self, package_name, version_selector):
    """
    Finds the best matching package for the specified *package_name* and
    *version_selector*. If the registry does not provide the package, raises
    a #PackageNotFound exception, otherwise it returns #PackageInfo.
    """

    argschema.validate('package_name', package_name, {'type': six.text_type})
    argschema.validate('version_selector', version_selector,
        {'type': semver.Selector})

    response = self.api.find(package_name, version_selector).GET()
    try:
      data = self._handle_response(response)
    except Error as exc:
      if exc.message == 'Package not found':
        raise PackageNotFound(package_name, version_selector)
      raise

    try:
      # TODO: Pass config props to parse_dict()
      return manifest.parse_dict(data, [], None, None, copy=False)
    except manifest.InvalidPackageManifest as exc:
      raise Error(response, 'Invalid package manifest ({})'.format(exc), data)
Beispiel #4
0
  def upload(self, package_name, version, filename, force=False):
    """
    Upload a file for the specified package version. Note that a file that is
    not the package distribution can only be uploaded when the package
    distribution has already been uploaded. If *force* is #True, the file will
    be uploaded and overwritten if it already exists in the registry.
    """

    argschema.validate('package_name', package_name, {'type': six.text_type})
    argschema.validate('version', version, {'type': semver.Version})
    argschema.validate('filename', filename, {'type': six.text_type})
    argschema.validate('force', force, {'type': bool})

    with open(filename, 'rb') as fp:
      files = {os.path.basename(filename): fp}
      params = {'force': 'true' if force else 'false'}
      response = self.api.upload(package_name, version).POST(
          files=files, params=params, auth=(self.username, self.password))

    data = self._handle_response(response)
    return data.get('message')
Beispiel #5
0
  def download(self, package_name, version, filename=None):
    """
    Download the package archive for the specified *package_name* and *version*.
    If *filename* is not specified, the package-archive name is used which is
    generated with #get_package_archive_name(). Note that the file must
    previously be uploaded with `upm upload`.

    Returns a #requests.Response object. The status code of the returned
    response must be checked!
    """

    argschema.validate('package_name', package_name, {'type': six.text_type})
    argschema.validate('version', version, {'type': semver.Version})
    argschema.validate('filename', filename, {'type': [six.text_type, None]})

    if not filename:
      filename = get_package_archive_name(package_name, version)

    url = self.api.download(package_name, version, filename)
    response = url.GET()
    response.raise_for_status()
    return response