Example #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()
Example #2
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()
Example #3
0
def create_project(identifier, dest, pros_cli=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()
    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)
    distutils.dir_util.copy_tree(config.directory, dest)
    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))
    proj_config = prosconfig.ProjectConfig(dest, create=True)
    proj_config.kernel = identifier.version
    proj_config.save()
Example #4
0
def upgrade_project(identifier, dest, pros_cli=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))
Example #5
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))