Exemplo n.º 1
0
    def Parse(self, path):
        result = []

        with open(path, 'r', encoding='utf-8') as jsonfile:
            for packagedata in json.load(jsonfile):
                pkg = Package()
                pkg.name = packagedata['name']
                pkg.version, pkg.origversion = SanitizeVersion(
                    packagedata['version'])

                pkg.comment = packagedata['description']
                pkg.homepage = packagedata['homepage']

                if 'srcurl' in packagedata:
                    pkg.downloads = [packagedata['srcurl']]

                match = re.search(' @([^ ]+)$', packagedata['maintainer'])
                if match:
                    pkg.maintainers = [match.group(1).lower() + '@termux']
                else:
                    pkg.maintainers = extract_maintainers(
                        packagedata['maintainer'])

                result.append(pkg)

        return result
Exemplo n.º 2
0
    def Parse(self, path):
        result = []

        for root, dirs, files in os.walk(path):
            for filename in files:
                jsonpath = os.path.join(root, filename)
                if not jsonpath.endswith('.json'):
                    continue

                jsondata = None
                with open(jsonpath, 'r', encoding='utf-8') as jsonfile:
                    jsondata = json.load(jsonfile, strict=False)

                pkg = Package()

                pkg.name = filename[:-5]
                pkg.version = jsondata['version']

                if 'url' in jsondata:
                    pkg.downloads = jsondata['url'] if isinstance(jsondata['url'], list) else [jsondata['url']]

                if 'homepage' in jsondata:
                    pkg.homepage = jsondata['homepage']

                if 'license' in jsondata:
                    pkg.licenses = [jsondata['license']]

                pkg.extrafields = {'path': os.path.relpath(jsonpath, path)}

                result.append(pkg)

        return result
Exemplo n.º 3
0
    def ParsePackage(self, fmri, pkgdata):
        variables = {}
        for action in pkgdata['actions']:
            tokens = shlex.split(action)

            if not tokens or tokens.pop(0) != 'set':
                print('WARNING: unrecognized action ' + action,
                      file=sys.stderr)
                continue

            key = None
            value = []

            for token in tokens:
                if token.startswith('name='):
                    key = token[5:]
                elif token.startswith('value='):
                    value.append(token[6:])
                elif token.startswith('last-fmri='):
                    pass
                else:
                    print('WARNING: unrecognized token ' + token,
                          file=sys.stderr)
                    continue

            if key and value:
                variables[key] = value

        pkg = Package()

        pkg.extrafields['fmri'] = fmri

        if 'com.oracle.info.name' in variables:
            pkg.name = variables['com.oracle.info.name'][0]

        if 'com.oracle.info.version' in variables:
            pkg.version = variables['com.oracle.info.version'][0]

        if 'pkg.summary' in variables:
            pkg.comment = variables['pkg.summary'][0]

        if 'info.classification' in variables:
            pkg.category = variables['info.classification'][0]
            if pkg.category.startswith('org.opensolaris.category.2008:'):
                pkg.category = pkg.category.split(':', 1)[1]

        if 'info.upstream-url' in variables:
            pkg.homepage = variables['info.upstream-url'][0]

        if 'info.source-url' in variables:
            pkg.downloads = variables['info.source-url']

        # Regarding comment requirement: there are some packages which lack it,
        # however for ALL of them is a counterpart with comment and some
        # additional fields (category, homepage, downloads). Packages without
        # comment look like legacy, and it's OK and desirable to drop them here
        if pkg.name and pkg.version and pkg.comment:
            return pkg

        return None
Exemplo n.º 4
0
    def Parse(self, path):
        result = []

        jsondata = None
        with open(path, 'r', encoding='utf-8') as jsonfile:
            jsondata = json.load(jsonfile)

        for packagedata in jsondata['ravenports']:
            pkg = Package()

            pkg.name = packagedata['namebase']
            pkg.version = packagedata['version']
            pkg.category = packagedata['keywords'][0]
            if 'homepage' in packagedata:
                pkg.homepage = packagedata['homepage']

            pkg.downloads = packagedata['distfile']
            pkg.comment = packagedata['variants'][0]['sdesc']

            pkg.extrafields['bucket'] = packagedata['bucket']
            pkg.extrafields['variant'] = packagedata['variants'][0]['label']

            result.append(pkg)

        return result
Exemplo n.º 5
0
    def ParsePackage(self, pkgpath, pkgdata):
        variables = {}
        for action in pkgdata['actions']:
            tokens = shlex.split(action)

            if not tokens or tokens.pop(0) != 'set':
                print('WARNING: unrecognized action ' + action,
                      file=sys.stderr)
                continue

            key = None
            value = []

            for token in tokens:
                if token.startswith('name='):
                    key = token[5:]
                elif token.startswith('value='):
                    value.append(token[6:])
                elif token.startswith('last-fmri='):
                    pass
                else:
                    print('WARNING: unrecognized token ' + token,
                          file=sys.stderr)
                    continue

            if key and value:
                variables[key] = value

        pkg = Package()

        pkg.extrafields['path'] = pkgpath

        if 'com.oracle.info.name' in variables:
            pkg.name = variables['com.oracle.info.name'][0]

        if 'com.oracle.info.version' in variables:
            pkg.version = variables['com.oracle.info.version'][0]

        if 'pkg.summary' in variables:
            pkg.comment = variables['pkg.summary'][0]

        if 'info.classification' in variables:
            pkg.category = variables['info.classification'][0]
            if pkg.category.startswith('org.opensolaris.category.2008:'):
                pkg.category = pkg.category.split(':', 1)[1]

        if 'info.upstream-url' in variables:
            pkg.homepage = variables['info.upstream-url'][0]

        if 'info.source-url' in variables:
            pkg.downloads = variables['info.source-url']

        if pkg.name and pkg.version:
            return pkg

        return None
Exemplo n.º 6
0
    def parse_package(fields):
        pkg = Package()

        pkg.name = ensure_str(fields['distribution'])
        pkg.version = ensure_str(fields['version'])
        pkg.maintainers = [ensure_str(fields['author']).lower() + '@cpan']
        pkg.licenses = ensure_list(fields['license'])
        pkg.comment = ensure_str(fields.get('abstract'))
        pkg.homepage = ensure_str(fields.get('resources.homepage'))
        pkg.downloads = ensure_list(fields.get('download_url'))

        return pkg
Exemplo n.º 7
0
    def Parse(self, path):
        result = []

        for row in lxml.html.parse(path).getroot().xpath(
                './/table[@class="Auto"]')[0].xpath('./tr[position()>1]'):
            pkg = Package()

            # name + version
            cell = row.xpath('./th[1]/a[@href]')[0]
            pkg.name = cell.text
            pkg.homepage = cell.attrib['href']

            # summary
            cell = row.xpath('./td[1]/a')[0]
            pkg.version = cell.text
            pkg.downloads = [cell.attrib['href']]

            # summary
            cell = row.xpath('./td[2]')[0]
            pkg.comment = cell.text

            result.append(pkg)

        return result
Exemplo n.º 8
0
    def Parse(self, path):
        result = []

        for category in os.listdir(path):
            if category.startswith('.'):
                continue

            category_path = os.path.join(path, category)
            if not os.path.isdir(category_path):
                continue

            for package in os.listdir(category_path):
                package_path = os.path.join(category_path, package)
                if not os.path.isdir(package_path):
                    continue

                info_path = os.path.join(category_path, package,
                                         package + '.info')
                if not os.path.isfile(info_path):
                    print('WARNING: {} does not exist, package skipped'.format(
                        info_path),
                          file=sys.stderr)
                    continue

                with open(info_path, encoding='utf-8',
                          errors='ignore') as infofile:
                    variables = {}

                    key = None
                    total_value = []

                    for line in infofile:
                        line = line.strip()
                        if not line:
                            continue

                        value = None
                        if key:  # continued
                            value = line
                        else:  # new variable
                            key, value = line.split('=', 1)
                            value = value.lstrip('"').lstrip()

                        if value.endswith('\\'):  # will continue
                            total_value.append(value.rstrip('\\').rstrip())
                        elif value.endswith('"'):
                            total_value.append(value.rstrip('"').rstrip())
                            variables[key] = ' '.join(total_value)
                            key = None
                            total_value = []

                    pkg = Package()
                    pkg.category = category

                    pkg.name = variables['PRGNAM']
                    pkg.version = variables['VERSION']
                    pkg.homepage = variables['HOMEPAGE']
                    pkg.maintainers = GetMaintainers(variables['EMAIL'])
                    pkg.downloads = variables['DOWNLOAD'].split()

                    if pkg.name is not None and pkg.version is not None:
                        result.append(pkg)
                    else:
                        print(
                            'WARNING: {} skipped, likely due to parsing problems'
                            .format(info_path),
                            file=sys.stderr)

        return result