Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

+simple deploy script

  • Loading branch information...
commit 99e6433f7b2ee5604034b84ba1c1daa655c24805 1 parent c5a1416
@puzzlet authored
Showing with 57 additions and 0 deletions.
  1. +57 −0 deploy.py
View
57 deploy.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python3
+import logging
+import os
+import subprocess
+
+
+IGNORE = [
+ '.git',
+ '.gitignore',
+ 'deploy.py',
+]
+
+
+def main():
+ base_dir = os.path.dirname(os.path.abspath(__file__))
+ for root, dirs, files in os.walk(base_dir):
+ _, _, rel_root = root.partition(base_dir)
+ rel_root = rel_root.strip('/')
+ if any(_ in rel_root.split(os.sep) for _ in IGNORE):
+ continue
+ for file_name in files:
+ if file_name in IGNORE:
+ continue
+ make_link(os.path.join(rel_root, file_name))
+
+
+def make_link(rel_path):
+ base_dir = os.path.dirname(os.path.abspath(__file__))
+ source_path = os.path.join(base_dir, rel_path)
+ target_path = os.path.join(os.path.expanduser('~'), rel_path)
+ if os.path.isdir(target_path):
+ logging.info("`{}' is a directory".format(target_path))
+ return
+ if os.path.isfile(target_path):
+ if os.path.islink(target_path):
+ link_path = os.path.join(os.path.dirname(target_path),
+ os.readlink(target_path))
+ if link_path == target_path:
+ return
+ logging.info("`{}' is a symbolic link to {}".format(
+ target_path, link_path))
+ else:
+ if open(source_path).read() != open(target_path).read():
+ subprocess.check_call(['vimdiff', source_path, target_path])
+ while True:
+ ans = input("Keep? (Y/n) ").strip()
+ if not ans or ans in 'yY':
+ return
+ if ans in 'nN':
+ break
+ os.unlink(target_path)
+ os.symlink(source_path, target_path)
+
+
+if __name__ == '__main__':
+ logging.basicConfig(level=logging.INFO)
+ main()
Please sign in to comment.
Something went wrong with that request. Please try again.