From 40cc8216a422b3d7575a9c8fad57bcae12f275c4 Mon Sep 17 00:00:00 2001 From: Buddy Sandidge Date: Sun, 8 Nov 2020 16:04:34 -0800 Subject: [PATCH] Prettier on autolink --- autolink | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/autolink b/autolink index be2e02c..23641ed 100755 --- a/autolink +++ b/autolink @@ -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()