extract metadata from a given sdist archive file

    :param archive_filename: a sdist archive file
    :param py_interpreter: The full path to the used python interpreter

    :returns: a json blob with metadata
190209
def from_archive(archive_filename, py_interpreter=sys.executable):
    
    with _extract_to_tempdir(archive_filename) as root_dir:
        data = _setup_py_run_from_dir(root_dir, py_interpreter)
    return data
222355
def load_data_file(filename, encoding='utf-8'):
    
    data = pkgutil.get_data(PACKAGE_NAME, os.path.join(DATA_DIR, filename))
    return data.decode(encoding).splitlines()
136709
def cat(ctx, archive_name, version):
    '''
    
    '''

    _generate_api(ctx)
    var = ctx.obj.api.get_archive(archive_name)

    with var.open('r', version=version) as f:
        for chunk in iter(lambda: f.read(1024 * 1024), ''):
            click.echo(chunk)
93483
def _get_archive_listing(self, archive_name):
        '''
        
        '''

        res = self.collection.find_one({'_id': archive_name})

        if res is None:
            raise KeyError

        return res
614498
def extract_lzma(archive, compression, cmd, verbosity, interactive, outdir):
    """"""
    cmdlist = [util.shell_quote(cmd), '--format=lzma']
    if verbosity > 1:
        cmdlist.append('-v')
    outfile = util.get_single_outfile(outdir, archive)
    cmdlist.extend(['-c', '-d', '--', util.shell_quote(archive), '>',
        util.shell_quote(outfile)])
    return (cmdlist, {'shell': True})
951528
def get_archive_formats():
    
    formats = [(name, registry[2]) for name, registry in
               _ARCHIVE_FORMATS.items()]
    formats.sort()
    return formats
1245731
def update_metadata(ctx, archive_name):
    '''
    
    '''

    _generate_api(ctx)
    args, kwargs = _parse_args_and_kwargs(ctx.args)
    assert len(args) == 0, 'Unrecognized arguments: "{}"'.format(args)

    var = ctx.obj.api.get_archive(archive_name)

    var.update_metadata(metadata=kwargs)
932469
def createArchiveExample(fileName):
    
    print('*' * 80)
    print('Create archive')
    print('*' * 80)

    archive = CombineArchive()
    archive.addFile(
        fileName,  # filename
        "./models/model.xml",  # target file name
        KnownFormats.lookupFormat("sbml"),  # look up identifier for SBML models
        True  # mark file as master
    )

    # add metadata to the archive itself
    description = OmexDescription()
    description.setAbout(".")
    description.setDescription("Simple test archive including one SBML model")
    description.setCreated(OmexDescription.getCurrentDateAndTime())

    creator = VCard()
    creator.setFamilyName("Bergmann")
    creator.setGivenName("Frank")
    creator.setEmail("fbergman@caltech.edu")
    creator.setOrganization("Caltech")

    description.addCreator(creator)

    archive.addMetadata(".", description)

    # add metadata to the added file
    location = "./models/model.xml"
    description = OmexDescription()
    description.setAbout(location)
    description.setDescription("SBML model")
    description.setCreated(OmexDescription.getCurrentDateAndTime())
    archive.addMetadata(location, description)

    # write the archive
    out_file = "out.omex"
    archive.writeToFile(out_file)

    print('Archive created:', out_file)
609616
def create_archive_info(filepath, extracted_path, archive_sha=None):
    

    archive_info = {
        "sha1": archive_sha,
        "filename": os.path.split(filepath)[1],
    }

    with io.open(
        os.path.join(
            extracted_path,
            ".slackviewer_archive_info.json",
        ), 'w+', encoding="utf-8"
    ) as f:
        s = json.dumps(archive_info, ensure_ascii=False)
        s = to_unicode(s)
        f.write(s)
1117337
def get_artifact_metadata(self, package_name):
        

        filename = self.metadata.get(package_name)
        if not filename or not exists(filename):
            return {}
        with open(filename, encoding='utf8') as fd:
            contents = fd.read()

        try:
            is_json_compat(contents)
        except ValueError:
            logger.info("artifact metadata file '%s' is invalid", filename)
            return {}

        return json.loads(contents)
687041
def extract_gzip (archive, compression, cmd, verbosity, interactive, outdir):
    """"""
    targetname = util.get_single_outfile(outdir, archive)
    try:
        with gzip.GzipFile(archive) as gzipfile:
            with open(targetname, 'wb') as targetfile:
                data = gzipfile.read(READ_SIZE_BYTES)
                while data:
                    targetfile.write(data)
                    data = gzipfile.read(READ_SIZE_BYTES)
    except Exception as err:
        msg = "error extracting %s to %s: %s" % (archive, targetname, err)
        raise util.PatoolError(msg)
    return None
1038775
def extract_rar (archive, compression, cmd, verbosity, interactive, outdir):
    """"""
    cmdlist = [cmd, 'x']
    if not interactive:
        cmdlist.extend(['-p-', '-y'])
    cmdlist.extend(['--', os.path.abspath(archive)])
    return (cmdlist, {'cwd': outdir})
162095
def archive_context(filename):
    
    tmpdir = tempfile.mkdtemp()
    log.warn('Extracting in %s', tmpdir)
    old_wd = os.getcwd()
    try:
        os.chdir(tmpdir)
        with ContextualZipFile(filename) as archive:
            archive.extractall()

        # going in the directory
        subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
        os.chdir(subdir)
        log.warn('Now working in %s', subdir)
        yield

    finally:
        os.chdir(old_wd)
        shutil.rmtree(tmpdir)
1289474
def inline_documentation_files(json_spec, src_dir):
    
    # Inline description from a readme file
    if 'description' not in json_spec:
        readme_filename = None
        for filename in 'README.md', 'Readme.md', 'readme.md':
            if os.path.exists(os.path.join(src_dir, filename)):
                readme_filename = filename
                break
        if readme_filename is not None:
            with open(os.path.join(src_dir, readme_filename)) as fh:
                json_spec['description'] = fh.read()

    # Inline developerNotes from Readme.developer.md
    if 'developerNotes' not in json_spec:
        for filename in 'README.developer.md', 'Readme.developer.md', 'readme.developer.md':
            if os.path.exists(os.path.join(src_dir, filename)):
                with open(os.path.join(src_dir, filename)) as fh:
                    json_spec['developerNotes'] = fh.read()
                break
170079
def get_py_source(file):
    
    try:
        response = None
        pysource = ""

        if regexp_py.search(file) is None:
            response = {"error": "Only Python source files are allowed. (*.py)"}
        else:
            with open(file, 'r') as pyfile:
                pysource = pyfile.read()

            response = {"data": pysource}

    except Exception as e:
        response = {"error": str(e)}
    finally:
        return response
960613
def _read_python_source(self, filename):
        
        try:
            f = open(filename, "rb")
        except IOError as err:
            self.log_error("Can't open %s: %s", filename, err)
            return None, None
        try:
            encoding = tokenize.detect_encoding(f.readline)[0]
        finally:
            f.close()
        with _open_with_encoding(filename, "r", encoding=encoding) as f:
            return _from_system_newlines(f.read()), encoding
653719
def _extract(archive, compression, cmd, format, verbosity, outdir):
    """"""
    targetname = util.get_single_outfile(outdir, archive)
    try:
        with lzma.LZMAFile(archive, **_get_lzma_options(format)) as lzmafile:
            with open(targetname, 'wb') as targetfile:
                data = lzmafile.read(READ_SIZE_BYTES)
                while data:
                    targetfile.write(data)
                    data = lzmafile.read(READ_SIZE_BYTES)
    except Exception as err:
        msg = "error extracting %s to %s: %s" % (archive, targetname, err)
        raise util.PatoolError(msg)
    return None