Fix install script for old Python versions
This commit is contained in:
parent
477f7dc5a8
commit
efe2113be9
15
mkSymlink.py
15
mkSymlink.py
|
@ -7,27 +7,28 @@ BASE_DIRECTORY = 'files'
|
||||||
HOME_DIRECTORY = os.getenv("HOME")
|
HOME_DIRECTORY = os.getenv("HOME")
|
||||||
|
|
||||||
|
|
||||||
def recurseInstall(path='/'):
|
def recurseInstall(path=''):
|
||||||
def homepath(entry):
|
def homepath(entry):
|
||||||
return HOME_DIRECTORY + path + entry.name
|
return os.path.join(HOME_DIRECTORY, path, entry)
|
||||||
|
|
||||||
def gitpath(entry):
|
def gitpath(entry):
|
||||||
return BASE_DIRECTORY + path + entry.name
|
return os.path.join(BASE_DIRECTORY, path, entry)
|
||||||
|
|
||||||
def link(entry):
|
def link(entry):
|
||||||
os.symlink(os.getcwd()+'/'+gitpath(entry), homepath(entry))
|
os.symlink(os.path.join(os.getcwd(), gitpath(entry)), homepath(entry))
|
||||||
|
|
||||||
for entry in os.scandir(BASE_DIRECTORY+path):
|
for entry in os.listdir(os.path.join(BASE_DIRECTORY, path)):
|
||||||
if os.path.exists(homepath(entry)):
|
if os.path.exists(homepath(entry)):
|
||||||
# The file/directory already exists
|
# The file/directory already exists
|
||||||
if entry.is_dir(): # Directory: recurse on it
|
if os.path.isdir(entry): # Directory: recurse on it
|
||||||
recurseInstall(path+entry.name+'/')
|
recurseInstall(os.path.join(path, entry))
|
||||||
else: # File: backup it, symlink it
|
else: # File: backup it, symlink it
|
||||||
os.rename(homepath(entry), homepath(entry)+'.bck')
|
os.rename(homepath(entry), homepath(entry)+'.bck')
|
||||||
link(entry)
|
link(entry)
|
||||||
else:
|
else:
|
||||||
link(entry)
|
link(entry)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if not HOME_DIRECTORY:
|
if not HOME_DIRECTORY:
|
||||||
print("Couldn't find home directory.", file=sys.stderr)
|
print("Couldn't find home directory.", file=sys.stderr)
|
||||||
|
|
Loading…
Reference in New Issue