Beispiel #1
0
def install_lib(identifier, dest, pros_cli, overwrite=False):
    if pros_cli is None or not pros_cli:
        pros_cli = CliConfig()
    filename = os.path.join(pros_cli.directory, identifier.depot,
                            '{}-{}'.format(identifier.name, identifier.version),
                            'template.pros')
    if not os.path.isfile(filename):
        click.echo('Error: template.pros not found for {}-{}'.format(identifier.name, identifier.version))
        click.get_current_context().abort()
        sys.exit()
    proj_config = prosconfig.ProjectConfig(dest)
    config = TemplateConfig(file=filename)
    copytree(config.directory, dest, overwrite=overwrite)
    for root, dirs, files in os.walk(dest):
        for d in dirs:
            if any([fnmatch.fnmatch(d, p) for p in config.template_ignore]):
                verbose('Removing {}'.format(d))
                os.rmdir(os.path.join(root, d))
        for f in files:
            if any([fnmatch.fnmatch(f, p) for p in config.template_ignore]):
                verbose('Removing {}'.format(f))
                os.remove(os.path.join(root, f))
    if type(proj_config.libraries) is list:
        proj_config.libraries = dict()
    proj_config.libraries[identifier.name] = identifier.version
    proj_config.save()
Beispiel #2
0
def upgrade_project(identifier: Identifier,
                    dest: str,
                    pros_cli: CliConfig = None):
    if pros_cli is None or not pros_cli:
        pros_cli = CliConfig()
    filename = os.path.join(
        pros_cli.directory, identifier.depot,
        '{}-{}'.format(identifier.name, identifier.version), 'template.pros')

    if not os.path.isfile(filename):
        click.echo('Error: template.pros not found for {}-{}'.format(
            identifier.name, identifier.version))
        click.get_current_context().abort()
        sys.exit()
    proj_config = prosconfig.ProjectConfig(dest, raise_on_error=True)
    config = TemplateConfig(file=filename)

    for root, dirs, files in os.walk(config.directory):
        for d in dirs:
            if any([fnmatch.fnmatch(d, p) for p in config.upgrade_paths]):
                verbose('Upgrading {}'.format(d))
                relpath = os.path.relpath(os.path.join(root, d),
                                          config.directory)
                shutil.copytree(os.path.join(config.directory, relpath),
                                os.path.join(proj_config.directory, relpath))
        for f in files:
            if any([fnmatch.fnmatch(f, p) for p in config.upgrade_paths]):
                verbose('Upgrading {}'.format(f))
                relpath = os.path.relpath(os.path.join(root, f),
                                          config.directory)
                shutil.copyfile(os.path.join(config.directory, relpath),
                                os.path.join(proj_config.directory, relpath))
Beispiel #3
0
def create_project(identifier, dest, pros_cli=None, require_empty=False, overwrite=False):
    if pros_cli is None or not pros_cli:
        pros_cli = CliConfig()
    filename = os.path.join(pros_cli.directory, identifier.depot,
                            '{}-{}'.format(identifier.name, identifier.version),
                            'template.pros')
    if not os.path.isfile(filename):
        click.echo('Error: template.pros not found for {}-{}'.format(identifier.name, identifier.version))
        click.get_current_context().abort()
        sys.exit()
    if require_empty:
        if os.path.isfile(dest) or (os.path.isdir(dest) and len(os.listdir(dest)) > 0):
            click.echo('Error! Destination is a file or a nonempty directory! Delete the file(s) and try again.')
            click.get_current_context().abort()
            sys.exit()
    config = TemplateConfig(file=filename)
    copytree(config.directory, dest, overwrite=overwrite)
    for root, dirs, files in os.walk(dest):
        for d in dirs:
            d = os.path.relpath(os.path.join(root, d), dest)
            if any([fnmatch.fnmatch(d, p) for p in config.template_ignore]):
                verbose('Removing {}'.format(d))
                os.rmdir(os.path.join(root, d))
        for f in files:
            f = os.path.relpath(os.path.join(root, f), dest)
            if any([fnmatch.fnmatch(f, p) for p in config.template_ignore]):
                verbose('Removing {}'.format(f))
                os.remove(os.path.join(root, f))
    proj_config = prosconfig.ProjectConfig(dest, create=True)
    proj_config.kernel = identifier.version
    proj_config.save()
Beispiel #4
0
def get_available_templates(pros_cfg: CliConfig = None, template_types: List[TemplateTypes] = None,
                            filters: List[str]=[], offline_only: bool=False) \
        -> Dict[TemplateTypes, Dict[Identifier, List[TemplateDescriptor]]]:
    if pros_cfg is None:
        pros_cfg = CliConfig()
    if template_types is None:
        template_types = [TemplateTypes.kernel, TemplateTypes.library]

    result = dict()  # type: Dict[TemplateTypes, Dict[Identifier, List[TemplateDescriptor]]]
    for template_type in template_types:
        result[template_type] = dict()

    for depot in [depot for depot in get_depots(pros_cfg, filters)]:
        if bool(depot.config.types) and not bool([t for t in template_types if t in depot.config.types]):
            continue  # No intersection between the types declared by the depot and requested types
        templates = dict()
        offline = depot.list_local(template_types)
        if not offline_only:
            online = depot.list_online(template_types)
        else:
            online = {t: set() for t in template_types}
        for key in [k for k in online.keys() if k in offline.keys()]:
            templates[key] = offline[key] | online[key]
        for template_type, identifiers in templates.items():
            for identifier in identifiers:
                if identifier not in result[template_type]:
                    result[template_type][identifier] = list()
                result[template_type][identifier].append(
                    TemplateDescriptor(depot=depot,
                                       online=identifier in online[template_type],
                                       offline=identifier in offline[template_type]))
    return result
Beispiel #5
0
def get_depot_configs(pros_cfg: CliConfig = None, filters: List[str]=None) -> List[DepotConfig]:
    if pros_cfg is None:
        pros_cfg = CliConfig()
    if filters is None or not filters:
        filters = ['.*']
    return [depot for depot in [get_depot_config(d, pros_cfg=pros_cfg) for d in os.listdir(pros_cfg.directory)
                                if os.path.isdir(os.path.join(pros_cfg.directory, d))]
            if depot.name and not all(m is None for m in [re.match(string=depot.name, pattern=f) for f in filters])]
Beispiel #6
0
def get_all_provider_types(pros_cfg: CliConfig = None) -> Dict[str, type]:
    if pros_cfg is None:
        pros_cfg = CliConfig()

    for provider_file in pros_cfg.providers:
        spec = importlib.util.spec_from_file_location('module.name', provider_file)
        mod = importlib.util.module_from_spec(spec)
        spec.loader.exec_module(mod)

    return {x.registrar: x for x in DepotProvider.__subclasses__()}
Beispiel #7
0
def create_template(identifier, location=None, pros_cli=None):
    if pros_cli is None or not pros_cli:
        pros_cli = CliConfig()
    if location is None or not location:
        location = os.path.join(location, identifier.depot,
                                '{}-{}'.format(identifier.name, identifier.version))
    filename = os.path.join(location, 'template.pros')
    config = TemplateConfig(file=filename)
    config.name = identifier.name
    config.version = identifier.version
    config.depot = identifier.depot
    config.save()
    return config
Beispiel #8
0
def create_template(identifier: Identifier,
                    pros_cli: CliConfig = None) -> TemplateConfig:
    if pros_cli is None or not pros_cli:
        pros_cli = CliConfig()
    filename = os.path.join(
        pros_cli.directory, identifier.depot,
        '{}-{}'.format(identifier.name, identifier.version), 'template.pros')
    config = TemplateConfig(file=filename)
    config.name = identifier.name
    config.version = identifier.version
    config.depot = identifier.depot
    config.save()
    return config
Beispiel #9
0
def get_all_provider_types(pros_cfg=None):
    if pros_cfg is None:
        pros_cfg = CliConfig()

    for provider_file in pros_cfg.providers:
        if os.path.isfile(provider_file):
            spec = importlib.util.spec_from_file_location(
                'prosconductor.providers.{}'.format(
                    os.path.basename(provider_file).split('.')[0]),
                provider_file)
            spec.loader.load_module()

    return {x.registrar: x for x in DepotProvider.__subclasses__()}
Beispiel #10
0
def get_depot_config(name: str, pros_cfg: CliConfig = None) -> DepotConfig:
    if pros_cfg is None:
        pros_cfg = CliConfig()

    return DepotConfig(os.path.join(pros_cfg.directory, name, 'depot.pros'))