Exemple #1
0
def initialize_repo(project_root):
    """This function is used for initializing a popper repository."""

    if pu.is_popperized():
        pu.fail('Repository has already been popperized')
        return

    config = {
        'metadata': {
            'access_right': "open",
            'license': "CC-BY-4.0",
            'upload_type': "publication",
            'publication_type': "article"
        },
        'pipelines': {},
        'popperized': ["github/popperized"]
    }

    pu.write_config(config)

    with open(os.path.join(project_root, '.gitignore'), 'a') as f:
        f.write('.cache\n')
        f.write('popper_logs\n')
        f.write('popper_status\n')

    pu.info('Popperized repository ' + project_root, fg='blue', bold=True)
Exemple #2
0
def initialize_repo(project_root):
    if pu.is_popperized():
        pu.fail('Repository has already been popperized')

    with open(os.path.join(project_root, '.popper.yml'), 'w') as f:
        f.write('{ metadata: { }, pipelines: { } }\n')

    pu.info('Popperized repository ' + project_root, fg='blue', bold=True)
Exemple #3
0
def cli(ctx, name, stages, envs, existing, infer_stages):
    """Initializes a repository or a pipeline. Without an argument, this
    command initializes a popper repository. If an argument is given, a
    pipeline or paper folder is initialized. If the given name is 'paper',
    then a 'paper' folder is created. Otherwise, a pipeline named NAME is
    created and initialized inside the 'pipelines' folder.

    By default, the stages of a pipeline are: setup, run, post-run, validate
    and teardown. To override these, the `--stages` flag can be provided, which
    expects a comma-separated list of stage names.

    The teardown stage is to be provided at the end if the --stages flag is
    being used.

    If the --existing flag is given, the NAME argument is treated as a path to
    a folder, which is assumed to contain bash scripts. --stages must be given.
    """

    # check if the the teardown stage is the last stage of the pipeline
    if stages and 'teardown' in stages and stages.split(',')[-1] != 'teardown':
        raise BadArgumentUsage(
            '--stages = Teardown should be the last stage.' +
            ' Consider renaming it or putting it at the end.')

    project_root = pu.get_project_root()

    # init repo
    if name is None:
        initialize_repo(project_root)
        return

    if not pu.is_popperized():
        pu.fail("Repository has not been popperized yet. See 'init --help'")

    if isdir(os.path.join(project_root, name)) and existing:
        # existing pipeline
        abs_path = os.path.join(project_root, name)
        relative_path = name
        if infer_stages:
            stages = ",".join(
                map(lambda x: x[:-3], sorted(glob.glob1(abs_path, '*.sh'))))
        else:
            initialize_existing_pipeline(abs_path, stages, envs)
    elif name == 'paper':
        # create a paper pipeline
        abs_path = os.path.join(project_root, 'paper')
        relative_path = os.path.join('paper')
        initialize_paper(abs_path, envs)
    else:
        # new pipeline
        abs_path = os.path.join(project_root, 'pipelines', name)
        relative_path = os.path.join('pipelines', name)
        initialize_new_pipeline(abs_path, stages, envs)

    pu.update_config(name, stages, envs, relative_path)

    pu.info('Initialized pipeline ' + name, fg='blue', bold=True)
Exemple #4
0
def initialize_repo(project_root):
    """This function is used for initializing a popper repository."""

    if pu.is_popperized():
        pu.fail('Repository has already been popperized')

    with open(os.path.join(project_root, '.popper.yml'), 'w') as f:
        f.write('{ metadata: { }, pipelines: { } }\n')

    with open(os.path.join(project_root, '.gitignore'), 'a') as f:
        f.write('popper_logs\n')
        f.write('popper_status\n')

    pu.info('Popperized repository ' + project_root, fg='blue', bold=True)
Exemple #5
0
def cli(ctx):
    """Initializes a repository by creating the .popper.yml file.
    """
    project_root = scm.get_root_folder()

    if pu.is_popperized(project_root):
        pu.fail('Repository has already been popperized')
        return

    pu.write_config(project_root, pu.init_config)

    with open(os.path.join(project_root, '.gitignore'), 'a') as f:
        f.write(pu.gitignore_content)

    # write README
    pu.info('Popperized repository {}\n'.format(project_root))
Exemple #6
0
def initialize_repo(project_root):
    """This function is used for initializing a popper repository."""
    content = pt.ReadMe()

    if pu.is_popperized():
        pu.fail('Repository has already been popperized')
        return

    pu.write_config(pu.init_config)

    with open(os.path.join(project_root, '.gitignore'), 'a') as f:
        f.write(pu.gitignore_content)

    # write README
    content.init_project()
    pu.info('Popperized repository ' + project_root, fg='blue', bold=True)
Exemple #7
0
def cli(ctx, name, stages, envs, existing):
    """Initializes a repository or a pipeline. Without an argument, this
    command initializes a popper repository. If an argument is given, a
    pipeline or paper folder is initialized. If the given name is 'paper',
    then a 'paper' folder is created. Otherwise, a pipeline named NAME is
    created and initialized inside the 'pipelines' folder.

    By default, the stages of a pipeline are: setup, run, post-run, validate
    and teardown. To override these, the `--stages` flag can be provided, which
    expects a comma-separated list of stage names.

    If the --existing flag is given, the NAME argument is treated as a path to
    a folder, which is assumed to contain bash scripts. --stages must be given.
    """
    project_root = pu.get_project_root()

    # init repo
    if name is None:
        initialize_repo(project_root)
        return

    if not pu.is_popperized():
        pu.fail("Repository has not been popperized yet. See 'init --help'")

    if isdir(os.path.join(project_root, name)) and existing:
        # existing pipeline
        abs_path = os.path.join(project_root, name)
        relative_path = name
        initialize_existing_pipeline(abs_path, stages, envs)
    elif name == 'paper':
        # create a paper pipeline
        abs_path = os.path.join(project_root, 'paper')
        relative_path = os.path.join('paper')
        initialize_paper(abs_path, envs)
    else:
        # new pipeline
        abs_path = os.path.join(project_root, 'pipelines', name)
        relative_path = os.path.join('pipelines', name)
        initialize_new_pipeline(abs_path, stages, envs)

    pu.update_config(name, stages, envs, relative_path)

    pu.info('Initialized pipeline ' + name, fg='blue', bold=True)
Exemple #8
0
def cli(ctx):
    """Scaffolds a workflow.
    """
    project_root = scm.get_root_folder()

    if not pu.is_popperized(project_root):
        pu.fail('Repository has not been popperized')
        return

    curr_dir = os.getcwd()
    actions_dir = os.path.join(curr_dir, 'actions')

    for filename in os.listdir(project_root):
        if filename.endswith('.workflow'):
            pu.fail('.workflow file already present !')

    if not os.path.exists(actions_dir):
        os.mkdir(actions_dir)
        os.mkdir(os.path.join(actions_dir, 'example'))
    else:
        if not os.path.exists(os.path.join(actions_dir, 'example')):
            os.mkdir(os.path.join(actions_dir, 'example'))

    # Generate actions files
    with open(os.path.join(project_root, 'main.workflow'), 'w') as f:
        f.write(pu.main_workflow_content % os.path.relpath(
            os.path.join(actions_dir, 'example'), project_root)
        )

    with open(os.path.join(actions_dir, 'example/Dockerfile'), 'w') as df:
        df.write(pu.dockerfile_content)

    with open(os.path.join(actions_dir, 'example/entrypoint.sh'), 'w') as ef:
        ef.write(pu.entrypoint_content)

    with open(os.path.join(actions_dir, 'example/README.md'), 'w') as rf:
        rf.write(pu.readme_content)

    pu.info('', '', 'Successfully scaffolded. \n')