Prettier on autolink

main
Buddy Sandidge 4 years ago
parent 2d436b859f
commit 40cc8216a4

@ -8,12 +8,15 @@ SCRIPT_NAME = path.basename(SCRIPT_ABS_PATH)
DOT_FILES_DIR = path.dirname(SCRIPT_ABS_PATH)
HOME_DIR = path.expanduser('~')
class ExistingFileError(OSError):
pass
class ExistingSymlinkError(OSError):
pass
def main(*, dot_files=DOT_FILES_DIR, home_dir=HOME_DIR):
for directory in walk_directories(dot_files):
hidden_dir = path.join(home_dir, '.' + directory)
@ -40,6 +43,7 @@ def walk_directories(directory):
yield rel_dir
visited.add(rel_dir)
def walk_files(directory):
visited = set()
for root, _, files in os.walk(directory):
@ -52,19 +56,25 @@ def walk_files(directory):
yield relative_file
visited.add(relative_file)
def make_directory(directory):
if path.isdir(directory):
return
if path.exists(directory):
raise ExistingFileError('expected no file or directory: {0}'.format(directory))
raise (
ExistingFileError('expected no file or directory: {0}'.format(directory))
)
os.mkdir(directory, mode=0o755)
def link_to(src, dest):
if path.islink(dest):
if path.realpath(src) == path.realpath(dest):
return
if path.exists(dest):
raise ExistingSymlinkError('found unexpected symlink: {0}'.format(dest))
raise (
ExistingSymlinkError('found unexpected symlink: {0}'.format(dest))
)
# we have a broken symlink, remove it
os.remove(dest)
if path.isfile(dest):
@ -73,6 +83,7 @@ def link_to(src, dest):
dir_fd = os.open(path.dirname(dest), os.O_RDONLY)
os.symlink(src_rel, dest, dir_fd=dir_fd)
def path_contains(directory, *strings):
directories = directory.split(os.sep)
for s in strings:
@ -80,5 +91,6 @@ def path_contains(directory, *strings):
return True
return False
if __name__ == '__main__':
main()

Loading…
Cancel
Save