コード例 #1
0
    def get_factory_avro(clazz,
                         version=None,
                         fill_nullables=False,
                         cache=True,
                         **kwargs):
        """
        Returns a generic factory avro to create mock objects
        :param cache:
        :param fill_nullables:
        :param clazz:
        :type clazz: ProtocolElement
        :param version: the build version as of the dependency manager to which the clazz corresponds
        :type version: str
        :return:
        """
        dependency_manager = DependencyManager()
        if version is None:
            version = dependency_manager.get_latest_version()
        if version not in dependency_manager.builds:
            # try removing hotfix version if version is not found
            version = dependency_manager.remove_hotfix_version(version)
        if version not in dependency_manager.builds:
            raise ValueError(
                "Not valid build version '{version}'. Use one of: {valid_versions}"
                .format(version=version,
                        valid_versions=", ".join(dependency_manager.builds)))
        # checks if the factory is already in the cache
        if cache and (clazz, version,
                      fill_nullables) in GenericFactoryAvro.factory_avro_cache:
            return GenericFactoryAvro.factory_avro_cache[(clazz, version,
                                                          fill_nullables)]

        class ClazzFactory(FactoryAvro):
            def __init__(self, *args, **kwargs):
                ClazzFactory.super(self).__init__(*args, **kwargs)

            class Meta:
                model = clazz
                strategy = CREATE_STRATEGY

            _version = version
            _fill_nullables = fill_nullables

        if cache:
            GenericFactoryAvro.factory_avro_cache[(
                clazz, version, fill_nullables)] = ClazzFactory
        return ClazzFactory
コード例 #2
0
def main():
    parser = argparse.ArgumentParser(description='GEL models build',
                                     usage='''build.py [<args>]''')
    parser.add_argument(
        '--version',
        help='A specific build version to run (if not provided runs all)')
    parser.add_argument('--skip-docs',
                        action='store_true',
                        help='Skips the documentation')
    parser.add_argument(
        '--update-docs-index',
        action='store_true',
        help=
        'Updates the documentation index based on the existing documentation')
    parser.add_argument('--skip-java',
                        action='store_true',
                        help='Skips the generation of java source code')
    parser.add_argument(
        '--only-prepare-sandbox',
        action='store_true',
        help=
        'Copies the required IDL schemas in the build folder under schemas/IDLs/build. A version must be specified'
    )
    # parse_args defaults to [1:] for args, but you need to
    # exclude the rest of the args too, or validation will fail
    args = parser.parse_args(sys.argv[1:])

    # builds all builds or just the indicated in version parameter
    run_any = False
    builds = json.loads(open(BUILDS_FILE).read())["builds"]

    # copies builds.json into the resources folder reachable by the dependency manager
    if os.path.exists(RESOURCES_FOLDER):
        distutils.dir_util.remove_tree(RESOURCES_FOLDER)
    os.mkdir(RESOURCES_FOLDER)
    shutil.copyfile(BUILDS_FILE, "{}/{}".format(RESOURCES_FOLDER, BUILDS_FILE))

    if args.only_prepare_sandbox and args.version is None:
        raise ValueError(
            "Please, provide a version to create the build sandbox")

    if not args.skip_docs:
        if os.path.exists(DOCS_FOLDER):
            distutils.dir_util.remove_tree(DOCS_FOLDER)
        conversion_tools.makedir(DOCS_FOLDER)

    if args.only_prepare_sandbox:
        build = __get_build_by_version(builds, args.version)
        packages = build["packages"]
        # copy IDLs from specified packages in build into build folder
        __create_IDLs_build_folder(packages)
        logging.info(
            "The build sandbox has been created under 'schemas/IDLs/build'")
    else:
        try:
            if args.version:
                build = __get_build_by_version(builds, args.version)
                if build is None:
                    build = __get_build_by_version(
                        builds,
                        DependencyManager.remove_hotfix_version(args.version))
                    if build is None:
                        raise ValueError(
                            "Build version '{}' does not exist".format(
                                args.version))
                run_build(build, args.skip_docs, args.skip_java)
                run_any = True
            else:
                for build in builds:
                    if args.version is None or build["version"] == args.version:
                        run_build(build, args.skip_docs, args.skip_java)
                        run_any = True
        finally:
            __delete_IDLs_build_folder()

        if args.update_docs_index:
            __update_documentation_index()

        if not run_any and args.version is not None:
            raise ValueError(
                "Provided build version does not exist [{}]".format(
                    args.version))
        logging.info("Build/s finished succesfully!")