Example #1
0
def git_clone(requires):
    from git import Repo

    if sys.platform != "win32":
        # Unfortunately for windows user, the following function
        # needs shell=True, which expose security risk. I would
        # rather not to trade it with its marginal benefit
        make_sure_git_is_available()

    moban_home = get_moban_home()
    file_system.mkdir_p(moban_home)

    for require in requires:
        repo_name = get_repo_name(require.git_url)
        local_repo_folder = file_system.path_join(moban_home, repo_name)
        if file_system.exists(local_repo_folder):
            reporter.report_git_pull(repo_name)
            repo = Repo(local_repo_folder)
            repo.git.pull()
            if require.reference:
                repo.git.checkout(require.reference)
            elif require.branch:
                repo.git.checkout(require.branch)
            if require.submodule:
                reporter.report_info_message("updating submodule")
                repo.git.submodule("update")
        else:
            reporter.report_git_clone(require.git_url)
            repo = Repo.clone_from(require.git_url, local_repo_folder,
                                   **require.clone_params())
            if require.submodule:
                reporter.report_info_message("checking out submodule")
                repo.git.submodule("update", "--init")
 def setUp(self):
     self.source_template = file_system.path_join("tests", "fixtures",
                                                  "a.jj2")
     self.fixture = (
         "test.out",
         "test content".encode("utf-8"),
         self.source_template,
     )
Example #3
0
def deprecated_moban_path_notation(directory):
    translated_directory = None
    library_or_repo_name, relative_path = directory.split(":")
    potential_repo_path = file_system.path_join(repo.get_moban_home(),
                                                library_or_repo_name)
    if file_system.exists(potential_repo_path):
        # expand repo template path
        if relative_path:
            translated_directory = file_system.path_join(
                potential_repo_path, relative_path)
        else:
            translated_directory = potential_repo_path
    else:
        # expand pypi template path
        library_path = LIBRARIES.resource_path_of(library_or_repo_name)
        if relative_path:
            translated_directory = file_system.path_join(
                library_path, relative_path)
        else:
            translated_directory = library_path
    return translated_directory
LABEL_OVERRIDES = "overrides"
LABEL_MOBANFILE = "mobanfile"
LABEL_FORCE = "force"
LABEL_VERSION = "version"
LABEL_GROUP = "group"
LABEL_DEFINE = "define"
LABEL_EXTENSION = "extension"
CLI_DICT = "user_dict"
EXTENSION_DICT = "user_extensions"

DEFAULT_CONFIGURATION_DIRNAME = ".%s.cd" % PROGRAM_NAME
DEFAULT_TEMPLATE_DIRNAME = ".%s.td" % PROGRAM_NAME
DEFAULT_OPTIONS = {
    # .moban.cd, default configuration dir
    LABEL_CONFIG_DIR: file_system.path_join(
        ".", DEFAULT_CONFIGURATION_DIRNAME
    ),
    # .moban.td, default template dirs
    LABEL_TMPL_DIRS: [
        ".",
        file_system.path_join(".", DEFAULT_TEMPLATE_DIRNAME),
    ],
    # moban.output, default output file name
    LABEL_OUTPUT: "%s.output" % PROGRAM_NAME,
    # data.yml, default data input file
    LABEL_CONFIG: "data%s" % DEFAULT_YAML_SUFFIX,
    LABEL_TEMPLATE_TYPE: DEFAULT_TEMPLATE_TYPE,
}

# moban file version
MOBAN_VERSION = "moban_file_spec_version"
Example #5
0
def get_moban_home():
    from appdirs import user_cache_dir

    home_dir = user_cache_dir(appname=constants.PROGRAM_NAME)
    return file_system.path_join(home_dir, constants.MOBAN_REPOS_DIR_NAME)