Пример #1
0
def parse_revspec(s: str, ctx_project: Optional[Project] = None) \
        -> Tuple[Dataset, Project]:
    """
    Parses Revision paths. The syntax is:
        - <project path> [ @<rev> ] [ :<target> ]
        - <rev> [ :<target> ]
        - <target>
    The second and the third forms assume an existing "current" project.

    Returns: the dataset and the project from the parsed path.
        The project is only returned when specified in the revpath.
    """

    match = re.fullmatch(r"""
        (?P<proj_path>(?: [^@:] | :[/\\] )+)
        (@(?P<rev>[^:]+))?
        (:(?P<source>.+))?
        """,
                         s,
                         flags=re.VERBOSE)
    if not match:
        raise ValueError("Failed to recognize revspec in '%s'" % s)
    match = match.groupdict()

    proj_path = match["proj_path"]
    rev = match["rev"]
    source = match["source"]

    target_project = None

    assert proj_path
    if rev:
        target_project = load_project(proj_path, readonly=True)
        project = target_project
    # proj_path is either proj_path or rev or source name
    elif Project.find_project_dir(proj_path):
        target_project = load_project(proj_path, readonly=True)
        project = target_project
    elif ctx_project:
        project = ctx_project
        if project.is_ref(proj_path):
            rev = proj_path
        elif not source:
            source = proj_path

    else:
        raise ProjectNotFoundError("Failed to find project at '%s'. " \
            "Specify project path with '-p/--project' or in the "
            "target pathspec." % proj_path)

    if target_project:
        on_error_do(Project.close, target_project, ignore_errors=True)

    tree = project.get_rev(rev)
    return tree.make_dataset(source), target_project
Пример #2
0
def create_command(args):
    project_dir = osp.abspath(args.dst_dir)

    existing_project_dir = Project.find_project_dir(project_dir)
    if existing_project_dir and os.listdir(existing_project_dir):
        if args.overwrite:
            rmtree(existing_project_dir)
        else:
            raise CliException("Directory '%s' already exists "
                               "(pass --overwrite to overwrite)" %
                               existing_project_dir)

    log.info("Creating project at '%s'" % project_dir)

    Project.init(project_dir)

    log.info("Project has been created at '%s'" % project_dir)

    return 0