2016-09-04 14:34:28 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
BASE_DIRECTORY = 'files'
|
|
|
|
HOME_DIRECTORY = os.getenv("HOME")
|
|
|
|
|
|
|
|
|
2016-12-13 16:03:10 +01:00
|
|
|
def recurseInstall(path=''):
|
2016-09-04 14:34:28 +02:00
|
|
|
def homepath(entry):
|
2016-12-13 16:03:10 +01:00
|
|
|
return os.path.join(HOME_DIRECTORY, path, entry)
|
2016-09-04 14:34:28 +02:00
|
|
|
|
|
|
|
def gitpath(entry):
|
2016-12-13 16:03:10 +01:00
|
|
|
return os.path.join(BASE_DIRECTORY, path, entry)
|
2016-09-04 14:34:28 +02:00
|
|
|
|
|
|
|
def link(entry):
|
2016-12-13 16:03:10 +01:00
|
|
|
os.symlink(os.path.join(os.getcwd(), gitpath(entry)), homepath(entry))
|
2016-09-04 14:34:28 +02:00
|
|
|
|
2016-12-13 16:03:10 +01:00
|
|
|
for entry in os.listdir(os.path.join(BASE_DIRECTORY, path)):
|
2016-09-04 14:34:28 +02:00
|
|
|
if os.path.exists(homepath(entry)):
|
|
|
|
# The file/directory already exists
|
2016-12-13 16:03:10 +01:00
|
|
|
if os.path.isdir(entry): # Directory: recurse on it
|
|
|
|
recurseInstall(os.path.join(path, entry))
|
2016-09-04 14:34:28 +02:00
|
|
|
else: # File: backup it, symlink it
|
|
|
|
os.rename(homepath(entry), homepath(entry)+'.bck')
|
|
|
|
link(entry)
|
|
|
|
else:
|
|
|
|
link(entry)
|
|
|
|
|
2016-12-13 16:03:10 +01:00
|
|
|
|
2016-09-04 14:34:28 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
if not HOME_DIRECTORY:
|
|
|
|
print("Couldn't find home directory.", file=sys.stderr)
|
|
|
|
sys.exit(1)
|
|
|
|
recurseInstall()
|