コード例 #1
0
def test_remove_trailing_separators():
    """test that split ignores trailing path separators"""
    assert split_all('a/') == ['a']
    assert split_all('a//') == ['a']
    assert split_all('a///') == ['a']
    assert split_all('/a/') == ['/', 'a']
    assert split_all('/a//') == ['/', 'a']
    assert split_all('/a///') == ['/', 'a']
コード例 #2
0
ファイル: template.py プロジェクト: royw/herringlib
    def resolve_template_dir(self, original_path, package_name):
        """
        Remote '.template' from original_path and replace 'package' with package_name.

        :param original_path:  Path to a template file.
        :type original_path: str
        :param package_name: The project's package name.
        :type package_name: str
        :return:  resolved path
        :rtype: str
        """
        new_parts = []
        for part in split_all(original_path):
            if part.endswith('.template'):
                part = part.replace('.template', '')
                part = part.replace('package', package_name)
            new_parts.append(part)
        return os.path.join(*new_parts)
コード例 #3
0
ファイル: docker.py プロジェクト: pombredanne/herringlib
 def containers():
     """
     Build docker containers.
     By default find and build all containers.
     If args are present, build just the containers given as command line arguments."""
     for root, dirs, files in os.walk(os.path.join(Project.docker_dir, Project.docker_containers_dir)):
         # info("root: {root}".format(root=root))
         # info("files: {files}".format(files=repr(files)))
         if DOCKERFILE in files:
             # info("Found Dockerfile in {root}".format(root=root))
             repo_dir = split_all(root)[-1]
             if not task.argv or repo_dir in task.argv:
                 tag = "{project}/{dir}".format(project=Project.docker_project, dir=repo_dir)
                 with cd(root):
                     with LocalShell() as local:
                         local.run("docker build -t {tag} .".format(tag=tag).split(' '), verbose=True)
                         info("built container: {root}".format(root=root))
             else:
                 info("skipping {dir}".format(dir=repo_dir))
コード例 #4
0
def test_split_all_results():
    """test split_all(path)"""
    assert split_all('a') == ['a']
    assert split_all('a/') == ['a']
    assert split_all('/a') == ['/', 'a']
    assert split_all('/a/') == ['/', 'a']
    assert split_all('a/b') == ['a', 'b']
    assert split_all('a/b/') == ['a', 'b']
    assert split_all('/a/b') == ['/', 'a', 'b']
    assert split_all('/a/b/') == ['/', 'a', 'b']
    assert split_all('a/b/c') == ['a', 'b', 'c']
    assert split_all('a/b/c/') == ['a', 'b', 'c']
    assert split_all('/a/b/c') == ['/', 'a', 'b', 'c']
    assert split_all('/a/b/c/') == ['/', 'a', 'b', 'c']
    assert split_all('a/b/c.ext') == ['a', 'b', 'c.ext']
    assert split_all('/a/b/c.ext') == ['/', 'a', 'b', 'c.ext']
コード例 #5
0
def test_round_trip_split_all():
    """test splitting a path then reassembling it using os.path.join()"""
    assert os.path.join(*split_all('a')) == 'a'
    assert os.path.join(*split_all('a/')) == 'a'
    assert os.path.join(*split_all('/a')) == '/a'
    assert os.path.join(*split_all('/a/')) == '/a'
    assert os.path.join(*split_all('a/b')) == 'a/b'
    assert os.path.join(*split_all('a/b/')) == 'a/b'
    assert os.path.join(*split_all('/a/b')) == '/a/b'
    assert os.path.join(*split_all('/a/b/')) == '/a/b'
    assert os.path.join(*split_all('a/b/c')) == 'a/b/c'
    assert os.path.join(*split_all('a/b/c/')) == 'a/b/c'
    assert os.path.join(*split_all('/a/b/c')) == '/a/b/c'
    assert os.path.join(*split_all('/a/b/c/')) == '/a/b/c'
    assert os.path.join(*split_all('a/b/c.ext')) == 'a/b/c.ext'
    assert os.path.join(*split_all('/a/b/c.ext')) == '/a/b/c.ext'