示例#1
0
def search_file(base_dir, file_name):
    the_file = file_name
    if not file_system.exists(the_file):
        if base_dir:
            file_under_base_dir = file_system.url_join(base_dir, the_file)
            if file_system.exists(file_under_base_dir):
                the_file = file_system.fs_url(file_under_base_dir)
            else:
                raise IOError(constants.ERROR_DATA_FILE_NOT_FOUND %
                              (file_name, the_file))
        else:
            raise IOError(constants.ERROR_DATA_FILE_ABSENT % the_file)
    return the_file
示例#2
0
文件: utils.py 项目: pgajdos/moban
def verify_the_existence_of_directories(dirs):
    if not isinstance(dirs, list):
        dirs = [dirs]

    dirs = [
        directory for directory in dirs
        if not (constants.DEFAULT_CONFIGURATION_DIRNAME in directory
                or constants.DEFAULT_TEMPLATE_DIRNAME in directory)
    ]
    if file_system.exists(constants.DEFAULT_CONFIGURATION_DIRNAME):
        dirs.append(constants.DEFAULT_CONFIGURATION_DIRNAME)

    if file_system.exists(constants.DEFAULT_TEMPLATE_DIRNAME):
        dirs.append(constants.DEFAULT_TEMPLATE_DIRNAME)
    return dirs
def find_default_moban_file():
    for moban_file in constants.DEFAULT_MOBAN_FILES:
        if file_system.exists(moban_file):
            break
    else:
        moban_file = None
    return moban_file
示例#4
0
    def _is_source_updated(self, file_name, file_content, source_template):
        changed = True
        content = file_content
        with_permission = True
        try:
            content = _mix(
                file_content,
                oct(file_system.file_permissions(source_template)),
            )
        except exceptions.NoPermissionsNeeded:
            # HttpFs does not have getsyspath
            # zip, tar have no permission
            # win32 does not work
            with_permission = False
            pass
        content_hash = get_hash(content)
        if file_system.exists(file_name):
            if file_name in self.hashes:
                if content_hash == self.hashes[file_name]:
                    changed = False
        # else the dest file has not been created yet
        # so no need to get content hash at all
        if changed:
            self.hashes[file_name] = content_hash

        return changed, with_permission
示例#5
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")
示例#6
0
 def __init__(self):
     self.cache_file = constants.DEFAULT_MOBAN_CACHE_FILE
     if (file_system.exists(self.cache_file)
             and self.IGNORE_CACHE_FILE is False):
         with file_system.open_file(self.cache_file) as f:
             self.hashes = json.load(f)
     else:
         self.hashes = {}
示例#7
0
    def __init__(self, yehua_file):
        if not exists(yehua_file):
            raise Exception("%s does not exist" % yehua_file)
        if is_dir(yehua_file):
            raise Exception("A yehua file is expected. Not a directory")

        self.project_file = yehua_file
        self.project_name = None
        self.answers = None
        self.name = None
        self.directives = None
        self._ask_questions()
        self._append_magic_variables()
        self._template_yehua_file()
示例#8
0
    def _is_source_updated(self, file_name, file_content, source_template):
        changed = True
        content = _mix(file_content,
                       oct(file_system.file_permissions(source_template)))
        content_hash = get_hash(content)
        if file_system.exists(file_name):
            if file_name in self.hashes:
                if content_hash == self.hashes[file_name]:
                    changed = False
        # else the dest file has not been created yet
        # so no need to get content hash at all
        if changed:
            self.hashes[file_name] = content_hash

        return changed
示例#9
0
文件: __init__.py 项目: pgajdos/moban
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
示例#10
0
def verify_the_existence_of_directories(dirs):
    LOG.debug("Verifying the existence: %s", dirs)
    if not isinstance(dirs, list):
        dirs = [dirs]

    results = []

    for directory in dirs:

        if file_system.exists(directory):
            results.append(directory)
            continue
        should_I_ignore = (constants.DEFAULT_CONFIGURATION_DIRNAME in directory
                           or constants.DEFAULT_TEMPLATE_DIRNAME in directory)
        if should_I_ignore:
            # ignore
            pass
        else:
            raise exceptions.DirectoryNotFound(
                constants.MESSAGE_DIR_NOT_EXIST % directory)
    return results
def test_exists_raise_exception():
    file_system.exists("git2://protocol/abc")
def test_exists():
    for url, expected in TEST_URL_EXITENCE_SPEC:
        status = file_system.exists(url)
        eq_(status, expected)