예제 #1
0
파일: tools.py 프로젝트: remram44/Unipath
def dict2dir(dir, dic, mode="w"):
    dir = Path(dir)
    if not dir.exists():
        dir.mkdir()
    for filename, content in dic.items():
        p = Path(dir, filename)
        if isinstance(content, dict):
            dict2dir(p, content)
            continue
        f = open(p, mode)
        f.write(content)
        f.close()
예제 #2
0
def folder_source_clean_path(folder_source):
    if folder_source.path is not None:
        path = Path(folder_source.path)
        if not path.exists():
            raise ValidationError({
                "path": "The folder does not exist."
                })
        elif path.islink():
            raise ValidationError({
                "path": "Symbolic links not allowed."
                })
        elif not path.isdir():
            raise ValidationError({
                "path": "Not a folder."
                })
예제 #3
0
def file_source_clean_path(file_source):
    if file_source.path is not None:
        path = Path(file_source.path)
        if not path.exists():
            raise ValidationError({
                "path": "The file does not exist."
                })
        elif path.islink():
            raise ValidationError({
                "path": "Symbolic links not allowed."
                })
        elif not path.isfile():
            raise ValidationError({
                "path": "Not a file."
                })
        elif not is_valid_file(path):
            raise ValidationError({
                "path": "Not a valid file."
                })
예제 #4
0
def location_exists(location):
    path = Path(location)
    return path.exists()