Exemplo n.º 1
0
    def iter_parse(self, path: str,
                   factory: PackageFactory) -> Iterable[PackageMaker]:
        normalize_version = VersionStripper().strip_right('.p')

        for versionfile in walk_tree(path, name='package-version.txt'):
            pkgpath = os.path.dirname(versionfile)
            with factory.begin(pkgpath) as pkg:
                pkg.add_name(os.path.basename(pkgpath), NameType.SAGEMATH_NAME)

                projectname = os.path.basename(pkgpath)
                if os.path.exists(os.path.join(pkgpath,
                                               'install-requires.txt')):
                    projectname = 'python:' + projectname

                pkg.add_name(projectname, NameType.SAGEMATH_PROJECT_NAME)

                with open(versionfile) as fd:
                    pkg.set_version(fd.read().strip(), normalize_version)

                if upstream_url := _parse_upstream_url(pkgpath):
                    pkg.add_downloads(
                        upstream_url.replace('VERSION', pkg.rawversion))

                add_patch_files(pkg, os.path.join(pkgpath, 'patches'),
                                '*.patch')

                yield pkg
Exemplo n.º 2
0
    def iter_parse(self, path: str, factory: PackageFactory,
                   transformer: PackageTransformer) -> Iterable[PackageMaker]:
        for category in os.listdir(path):
            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

                for recipe in os.listdir(package_path):
                    if not recipe.endswith('.recipe'):
                        continue

                    pkg = factory.begin()

                    pkg.add_name(package, NameType.HAIKUPORTS_NAME)
                    pkg.add_name(f'{category}/{package}',
                                 NameType.HAIKUPORTS_FULL_NAME)
                    pkg.add_categories(category)

                    # may want to shadow haiku-only ports
                    #if pkg.category.startswith('haiku-'):
                    #    pkg.shadow = True

                    # it seems to be guaranteed there's only one hyphen in recipe filename
                    name, version = recipe[:-7].split('-', 1)

                    if package.replace('-', '_') != name:
                        pkg.log(
                            'mismatch for package directory and recipe name: {} != {}'
                            .format(package, name),
                            severity=Logger.WARNING)

                    pkg.set_version(version)

                    with open(os.path.join(category_path, package, recipe),
                              'r',
                              encoding='utf-8') as fd:
                        recipefile = fd.read()

                        # XXX: we rely on the fact that no substitutions happen in these
                        # variables. That's true as of 2018-05-14.
                        if (match := re.search('^HOMEPAGE="([^"]+)"',
                                               recipefile, re.MULTILINE)):
                            pkg.add_homepages(match.group(1).split())

                        # XXX: this is not really precise, as we list all patches if there's
                        # suspiction that a recipe uses any of them
                        if re.search('^PATCHES=', recipefile, re.MULTILINE):
                            add_patch_files(
                                pkg, os.path.join(package_path, 'patches'))

                    yield pkg
Exemplo n.º 3
0
    def iter_parse(self, path: str,
                   factory: PackageFactory) -> Iterable[PackageMaker]:
        for version_path_abs in walk_tree(path, name='version'):
            version_path_rel = os.path.relpath(version_path_abs, path)

            package_path_abs = os.path.dirname(version_path_abs)
            package_path_rel = os.path.relpath(package_path_abs, path)
            package_path_rel_comps = os.path.split(package_path_rel)

            sources_path_abs = os.path.join(package_path_abs, 'sources')

            meta_path_abs = os.path.join(package_path_abs, 'meta')

            patches_path_abs = os.path.join(package_path_abs, 'patches')

            with factory.begin(package_path_rel) as pkg:
                pkg.add_name(package_path_rel_comps[-1], NameType.KISS_NAME)
                pkg.set_version(read_version(version_path_abs))

                if not os.path.exists(sources_path_abs):
                    pkg.log('skipping sourceless package', Logger.ERROR)
                    continue

                pkg.add_downloads(iter_sources(sources_path_abs))

                pkg.set_extra_field('path', package_path_rel)
                pkg.set_subrepo(package_path_rel_comps[0])

                if self._maintainer_from_git:
                    command = [
                        'git', 'log', '-1', '--format=tformat:%ae',
                        version_path_rel
                    ]
                    with subprocess.Popen(command,
                                          stdout=subprocess.PIPE,
                                          encoding='utf-8',
                                          errors='ignore',
                                          cwd=path) as git:
                        lastauthor, _ = git.communicate()

                    pkg.add_maintainers(extract_maintainers(lastauthor))

                if self._use_meta and os.path.exists(meta_path_abs):
                    meta = read_carbs_meta(meta_path_abs)
                    pkg.set_summary(meta.get('description'))
                    pkg.add_licenses(meta.get('license', '').split(','))
                    pkg.add_maintainers(
                        extract_maintainers(meta.get('maintainer')))

                add_patch_files(pkg, patches_path_abs)

                yield pkg
Exemplo n.º 4
0
    def iter_parse(self, path: str, factory: PackageFactory, transformer: PackageTransformer) -> Iterable[PackageMaker]:
        for versionpath in walk_tree(path, name='version'):
            rootdir = os.path.dirname(versionpath)
            with factory.begin(os.path.relpath(rootdir, path)) as pkg:
                pkg.add_name(os.path.basename(rootdir), NameType.KISS_NAME)

                with open(versionpath) as f:
                    version, revision = f.read().strip().split()
                    pkg.set_version(version)

                sources_path = os.path.join(rootdir, 'sources')
                if not os.path.exists(sources_path):
                    pkg.log('skipping sourceless package', Logger.ERROR)
                    continue

                with open(sources_path) as f:
                    for line in f:
                        line = line.strip()
                        if not line or line.startswith('#'):
                            continue

                        url, *rest = line.split()

                        if '://' in url:
                            pkg.add_downloads(url)

                pkgpath = os.path.relpath(rootdir, path)

                subrepo = os.path.split(pkgpath)[0]

                pkg.set_extra_field('path', pkgpath)
                pkg.set_subrepo(subrepo)

                if self._maintainer_from_git:
                    command = ['git', 'log', '-1', '--format=tformat:%ae', os.path.relpath(versionpath, path)]
                    with subprocess.Popen(command,
                                          stdout=subprocess.PIPE,
                                          encoding='utf-8',
                                          errors='ignore',
                                          cwd=path) as git:
                        lastauthor, _ = git.communicate()

                    pkg.add_maintainers(extract_maintainers(lastauthor))

                add_patch_files(pkg, os.path.join(rootdir, 'patches'))

                yield pkg
Exemplo n.º 5
0
    def iter_parse(self, path: str, factory: PackageFactory,
                   transformer: PackageTransformer) -> Iterable[PackageMaker]:
        for desc_path in walk_tree(path, suffix='.desc'):
            rel_desc_path = os.path.relpath(desc_path, path)
            with factory.begin(rel_desc_path) as pkg:
                pkgpath = os.path.dirname(rel_desc_path)
                name = os.path.basename(pkgpath)

                if name + '.desc' != os.path.basename(rel_desc_path):
                    raise RuntimeError(
                        'Path inconsistency (expected .../foo/foo.desc)')

                data = _parse_descfile(desc_path, pkg)

                pkg.add_name(name, NameType.T2_NAME)
                pkg.add_name(pkgpath, NameType.T2_FULL_NAME)
                pkg.set_version(data['version'][0])
                pkg.set_summary(data['title'][0])

                pkg.add_homepages(
                    (url.split()[0] for url in data.get('url', []) if url))
                #pkg.add_homepages(data.get('cv-url'))  # url used by version checker; may be garbage
                pkg.add_licenses(data['license'])
                pkg.add_maintainers(
                    map(extract_maintainers, data['maintainer']))
                pkg.add_categories(data['category'])

                for cksum, filename, url, *rest in (
                        line.split() for line in data.get('download', [])):
                    url = url.lstrip('-!')

                    if url.endswith('/'):
                        url += filename

                    if url.startswith('cvs') or url.startswith(
                            'git') or url.startswith('svn') or url.startswith(
                                'hg'):
                        # snapshots basically
                        pkg.set_flags(PackageFlags.UNTRUSTED)

                    pkg.add_downloads(url)

                add_patch_files(pkg, os.path.dirname(desc_path), '*.patch')

                yield pkg
Exemplo n.º 6
0
    def iter_parse(self, path: str,
                   factory: PackageFactory) -> Iterable[PackageMaker]:
        has_control_files = False

        for pkgdir in os.listdir(os.path.join(path, 'ports')):
            with factory.begin(pkgdir) as pkg:
                package_path_abs = os.path.join(path, 'ports', pkgdir)
                controlpath = os.path.join(package_path_abs, 'CONTROL')
                manifestpath = os.path.join(package_path_abs, 'vcpkg.json')

                # read either of old-style control (CONTROL) or new-style manifest (vcpkg.json) file
                if os.path.exists(manifestpath):
                    pkgdata = _read_manifest_file(manifestpath)
                elif os.path.exists(controlpath):
                    has_control_files = True
                    pkgdata = _read_control_file(controlpath)
                else:
                    pkg.log('neither control nor manifest file found',
                            Logger.ERROR)
                    continue

                if pkgdata['name'] != pkgdir:
                    raise RuntimeError(
                        f'sanity check failed: source {pkgdata["name"]} != directory {pkgdir}'
                    )

                pkg.add_name(pkgdata['name'], NameType.VCPKG_SOURCE)

                for key in [
                        'version', 'version-string', 'version-semver',
                        'version-date'
                ]:
                    if key in pkgdata:
                        version = pkgdata[key]
                        break
                else:
                    raise RuntimeError(
                        'none of expected version schemes found')

                if re.match('[0-9]{4}[.-][0-9]{1,2}[.-][0-9]{1,2}', version):
                    pkg.set_version(version)
                    pkg.set_flags(PackageFlags.UNTRUSTED)
                else:
                    pkg.set_version(version, _normalize_version)

                # handle description which may be either a string or a list of strings
                description = pkgdata.get('description')

                if isinstance(description, str):
                    pkg.set_summary(description)
                elif isinstance(description, list):
                    pkg.set_summary(description[0])

                pkg.add_homepages(pkgdata.get('homepage'))

                for maintainer in pkgdata.get('maintainers', []):
                    pkg.add_maintainers(extract_maintainers(maintainer))

                # pretty much a hack to shut a bunch of fake versions up
                portfilepath = os.path.join(package_path_abs, 'portfile.cmake')
                if _grep_file(portfilepath, 'libimobiledevice-win32'):
                    pkg.log(
                        'marking as untrusted, https://github.com/libimobiledevice-win32 accused of version faking',
                        severity=Logger.WARNING)
                    pkg.set_flags(PackageFlags.UNTRUSTED)

                add_patch_files(pkg, package_path_abs, '*.patch')

                yield pkg

        if not has_control_files:
            factory.log(
                "No CONTROL files seen in the repository, seems like it's time to refactor vcpkg parser and remove legacy bits"
            )
Exemplo n.º 7
0
    def iter_parse(self, path: str,
                   factory: PackageFactory) -> Iterable[PackageMaker]:
        for recipe_name in os.listdir(path):
            if recipe_name.startswith('.'):
                continue

            pkg = factory.begin()

            pkg.add_name(recipe_name, NameType.GOBOLINUX_RECIPE)

            package_path = os.path.join(path, recipe_name)

            maxversion: str | None = None
            for version_name in os.listdir(package_path):
                if maxversion is None or version_compare(
                        version_name, maxversion) > 0:
                    maxversion = version_name

            if maxversion is None:
                pkg.log('no usable versions found', severity=Logger.ERROR)
                continue

            pkg.set_version(maxversion)

            recipe_path = os.path.join(package_path, maxversion, 'Recipe')
            description_path = os.path.join(package_path, maxversion,
                                            'Resources', 'Description')

            if os.path.isfile(recipe_path):
                with open(recipe_path, 'r', encoding='utf-8',
                          errors='ignore') as recipe:
                    for line in recipe:
                        line = line.strip()
                        if line.startswith('url='):
                            download = _expand_mirrors(line[4:])
                            if '$' not in download:
                                pkg.add_downloads(download.strip('"'))
                            else:
                                factory.log(
                                    'Recipe for {}/{} skipped, unhandled URL substitute found'
                                    .format(recipe_name, maxversion),
                                    severity=Logger.ERROR)

            if os.path.isfile(description_path):
                with open(description_path,
                          'r',
                          encoding='utf-8',
                          errors='ignore') as description:
                    data = {}
                    current_tag = None
                    for line in description:
                        line = line.strip()
                        match = re.match('^\\[([A-Z][a-z]+)\\] *(.*?)$', line)
                        if match:
                            current_tag = match.group(1)
                            data[current_tag] = match.group(2)
                        elif current_tag is None:
                            factory.log(
                                'Description for {}/{} skipped, dumb format'.
                                format(recipe_name, maxversion),
                                severity=Logger.ERROR)
                            break
                        elif line:
                            if data[current_tag]:
                                data[current_tag] += ' '
                            data[current_tag] += line

                    pkg.set_summary(data.get('Summary'))
                    pkg.add_licenses(data.get('License'))
                    pkg.add_homepages(data.get('Homepage', '').strip('"'))

            add_patch_files(pkg, os.path.join(package_path, maxversion),
                            '*.patch*')

            yield pkg