Example #1
0
def main():
    try:
        parser = argparse.ArgumentParser()
        parser.add_argument("--package", "-p", help="The package to process.")
        parser.add_argument("--version",
                            "-v",
                            help="The package version.",
                            default=None)
        parser.add_argument("--requirements",
                            "-r",
                            help="The pypi requirements file.")
        parser.add_argument("--extras",
                            "-e",
                            action="store_true",
                            help="Generate recipes for extras.")
        parser.add_argument("--outdir",
                            "-o",
                            help="The recipe directory.",
                            default="./")
        parser.add_argument(
            "--python",
            "-y",
            help="The python version to use.",
            default="python",
            choices=["python", "python3"],
        )
        parser.add_argument(
            "--licenses",
            "-l",
            action="store_true",
            help="Output an updated license map upon completion.",
        )
        parser.add_argument(
            "--default-license",
            "-d",
            help=
            "The default license to use when the package license cannot be mapped.",
            default=None,
        )
        parser.add_argument("--pypi",
                            "-s",
                            action="store_true",
                            help="Use oe pypi class for recipe")
        args = parser.parse_args()

        print("Gathering info:")
        packages = []
        if args.requirements:
            packages = parse_requirements(
                args.requirements,
                follow_extras=args.extras,
                default_license=args.default_license,
            )
        elif args.package:
            packages = get_package_info(
                args.package,
                args.version,
                follow_extras=args.extras,
                default_license=args.default_license,
            )
        else:
            raise Exception("No packages provided!")

        print("Generating recipes:")
        generate_recipes(packages, args.outdir, args.python, args.extras,
                         args.pypi)

        version_file = os.path.join(args.outdir,
                                    "{}-versions.inc".format(args.python))
        write_preferred_versions(packages, version_file, args.python)

        print()
        if args.licenses:
            license_file = os.path.join(args.outdir, "licenses.py")
            with open(license_file, "w") as outfile:
                outfile.write("LICENSES = " + pformat(licenses.LICENSES))

            print("License mappings are available in: {}".format(license_file))

        print("PREFERRED_VERSIONS are available in: {}".format(version_file))

    except Exception as e:
        print(str(e))
        sys.exit(1)
    except KeyboardInterrupt:
        os._exit(1)
Example #2
0
def main():
    try:
        parser = argparse.ArgumentParser()
        parser.add_argument("--package", "-p", help="The package to process.")
        parser.add_argument("--version",
                            "-v",
                            help="The package version.",
                            default=None)
        parser.add_argument("--requirements",
                            "-r",
                            help="The pypi requirements file.")
        parser.add_argument("--extras",
                            "-e",
                            action="store_true",
                            help="Generate recipes for extras.")
        parser.add_argument("--outdir",
                            "-o",
                            help="The recipe directory.",
                            default="./")
        parser.add_argument(
            "--python",
            "-y",
            help="The python version to use.",
            default="python",
            choices=["python", "python3"],
        )
        parser.add_argument(
            "--licenses",
            "-l",
            action="store_true",
            help="Output an updated license map upon completion.",
        )
        parser.add_argument(
            "--default-license",
            "-d",
            help=
            "The default license to use when the package license cannot be mapped.",
            default=None,
        )
        parser.add_argument("--pypi",
                            "-s",
                            action="store_true",
                            help="Use oe pypi class for recipe")
        parser.add_argument(
            "--upgrade",
            "-u",
            action="store_true",
            help="Remove any old versions of the recipe in outdir, if any")
        parser.add_argument("--ignore-list",
                            "-i",
                            help="List of packages to ignore",
                            type=argparse.FileType('r'))
        parser.add_argument(
            "--build-rdepends-file",
            action="store_true",
            help="Build a file with rdepends with exact versions",
        )
        args = parser.parse_args()

        if args.ignore_list:
            ignore_list = [i.strip() for i in args.ignore_list.readlines()]
        else:
            ignore_list = []

        print("Gathering info:")
        packages = []
        if args.requirements:
            packages = parse_requirements(
                args.requirements,
                follow_extras=args.extras,
                default_license=args.default_license,
                ignore_list=ignore_list,
            )
        elif args.package:
            packages = get_package_info(
                args.package,
                args.version,
                follow_extras=args.extras,
                default_license=args.default_license,
            )
        else:
            raise Exception("No packages provided!")

        print("Generating recipes:")
        generate_recipes(packages, args.outdir, args.python, args.extras,
                         args.pypi, args.upgrade, ignore_list)

        version_file = os.path.join(args.outdir,
                                    "{}-versions.inc".format(args.python))
        write_preferred_versions(packages, version_file, args.python)
        if args.build_rdepends_file:
            rdeps_file = os.path.join(
                args.outdir, "{}-rdepends-versions.inc".format(args.python))
            write_rdepends_file(packages, rdeps_file, args.python)

        print()
        if args.licenses:
            license_file = os.path.join(args.outdir, "licenses.py")
            with open(license_file, "w") as outfile:
                outfile.write("LICENSES = " + pformat(licenses.LICENSES))

            print("License mappings are available in: {}".format(license_file))

        print("PREFERRED_VERSIONS are available in: {}".format(version_file))
        if args.build_rdepends_file:
            print("RDEPENDS file is: {}".format(rdeps_file))

    except Exception as e:
        print(str(e))
        sys.exit(1)
    except KeyboardInterrupt:
        os._exit(1)