Commit 9c90592d authored by Bjoern Broetz's avatar Bjoern Broetz

Clean up

parent 2de1c136
import argparse import argparse
import os import os
def main(basedir, target, cutdir): def main(basedir, target, cutdir):
for root, dirs, files in os.walk(basedir): for root, dirs, files in os.walk(basedir):
...@@ -12,10 +13,6 @@ def main(basedir, target, cutdir): ...@@ -12,10 +13,6 @@ def main(basedir, target, cutdir):
else: else:
nroot = root nroot = root
print(root)
print(nroot)
print(dirs)
print(files)
newdir = '{0}/{1}'.format(target, nroot) newdir = '{0}/{1}'.format(target, nroot)
if not os.path.isdir(newdir): if not os.path.isdir(newdir):
os.mkdir(newdir) os.mkdir(newdir)
...@@ -26,26 +23,47 @@ def main(basedir, target, cutdir): ...@@ -26,26 +23,47 @@ def main(basedir, target, cutdir):
os.mkdir(newdir) os.mkdir(newdir)
for f in files: for f in files:
try: try:
os.symlink('{0}/{1}'.format(root,f),'{0}/{1}/{2}'.format(target, nroot, f)) os.symlink('{0}/{1}'.format(root, f), '{0}/{1}/{2}'.format(
target, nroot, f))
except: except:
pass pass
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Create a link tree that mirrors a given base folder with all content. Directories are real, files are links.') parser = argparse.ArgumentParser(
parser.add_argument('-s','--source', dest='basedir', metavar='BASEDIR', type=str, nargs=1, description=
help='base folder') 'Create a link tree that mirrors a given base folder with all content. Directories are real, files are links.'
parser.add_argument('-t','--target', dest='target', metavar='TARGETDIR', type=str, nargs=1, )
help='target folder') parser.add_argument(
parser.add_argument('-c','--cutdir', dest='cutdir', metavar='CUTDIR', type=str, nargs=1, '-s',
help='folder in the basetree from which the target tree shall start') '--source',
dest='basedir',
metavar='BASEDIR',
type=str,
nargs=1,
help='base folder')
parser.add_argument(
'-t',
'--target',
dest='target',
metavar='TARGETDIR',
type=str,
nargs=1,
help='target folder')
parser.add_argument(
'-c',
'--cutdir',
dest='cutdir',
metavar='CUTDIR',
type=str,
nargs=1,
help='folder in the basetree from which the target tree shall start')
args = parser.parse_args() args = parser.parse_args()
basedir = os.path.abspath(args.basedir[0]) basedir = os.path.abspath(args.basedir[0])
target = args.target[0] target = args.target[0]
cutdir = args.cutdir[0] cutdir = args.cutdir[0]
if not os.path.isdir(basedir): if not os.path.isdir(basedir):
print(basedir)
raise Exception raise Exception
if not os.path.isdir(target): if not os.path.isdir(target):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment