Refactoring and some tweaks.

This commit is contained in:
Artem Sapegin
2012-10-22 12:01:42 +04:00
parent 12548e9a90
commit 41cefe2dc1
13 changed files with 25 additions and 11 deletions

24
sync.py
View File

@@ -2,34 +2,39 @@
"""
Dotfiles syncronization.
Makes symlinks for all files: ./bashrc will by available as ~/.bashrc.
Source: https://gist.github.com/490016
Makes symlinks for all files: ./tilde/bashrc.bash => ~/.bashrc.
Based on https://gist.github.com/490016
"""
import os
import glob
import shutil
SOURCE_DIR = 'tilde'
EXCLUDE = []
NO_DOT_PREFIX = []
EXCLUDE = ['tools', 'color', 'setup', 'sublime', ' sync.py', 'Readme.md', '.gitignore']
NO_DOT_PREFIX = ['bin']
def force_remove(path):
if os.path.isdir(path) and not os.path.islink(path):
shutil.rmtree(path, False, on_error)
shutil.rmtree(path, False)
else:
os.unlink(path)
def is_link_to(link, dest):
def is_link_to(link, dest):
is_link = os.path.islink(link)
is_link = is_link and os.readlink(link).rstrip('/') == dest.rstrip('/')
return is_link
def main():
os.chdir(os.path.dirname(os.path.abspath(__file__)))
os.chdir(os.path.join(os.path.dirname(os.path.abspath(__file__)), SOURCE_DIR))
for filename in [file for file in glob.glob('*') if file not in EXCLUDE]:
dotfile = filename
if filename not in NO_DOT_PREFIX:
dotfile = '.' + dotfile
dotfile = os.path.join(os.path.expanduser('~'), dotfile)
dotfile = os.path.join(os.path.expanduser('~'), os.path.splitext(dotfile)[0])
source = os.path.relpath(filename, os.path.dirname(dotfile))
# Check that we aren't overwriting anything
@@ -47,5 +52,6 @@ def main():
os.symlink(source, dotfile)
print "%s => %s" % (dotfile, source)
if __name__ == '__main__':
main()
main()