-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
symlinks.py
45 lines (32 loc) · 1.21 KB
/
symlinks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# find all symlinks in this directory
import os
import sys
# walk through all files in Hydrogen/
# get pwd
pwd = os.getcwd()
args = sys.argv
dirlist = []
# if extra args are only 1 (directory) then generate list of 1
for arg in args:
if arg != args[0]:
dirlist.append(arg)
print(dirlist)
# accept multiple args
def fixsymlink(dirs: list[str]):
for dir in dirs:
os.chdir(dir)
for file in os.listdir("."):
# print(file)
if os.path.islink(file):
# check if the link is broken
if not os.path.exists(file):
print(file, "->", os.readlink(file), "*** BROKEN ***")
# get the link destination
# change the readlink destination
# replace /home/lains/Projects/tau-OS/tau-hydrogen with /home/cappy/Projects/tau-hydrogen in symlink destination
# delete the old symlink
os.system("ln -srf " + os.readlink(file).replace("/home/lains/Projects/tau-OS/tau-hydrogen", "/home/cappy/Projects/tau-hydrogen") + " " + file)
else:
print(file, "->", os.readlink(file))
os.chdir(pwd)
fixsymlink(dirlist)