Skip to content
Snippets Groups Projects
Commit a8f61802 authored by Thomas Boettcher's avatar Thomas Boettcher
Browse files

moving to python3

parent 7204d908
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# by Thomas Böttcher
# boettcher@itc.rwth-aachen.de
version="v0.2014.09"
version="v1.2025.04"
import os
import sys
......@@ -40,11 +40,11 @@ def filenamefilter(dirname):
def symlink(opts, src, dst):
linkname = os.path.join(dst, os.path.split(src)[1])
# cut hostname if exists
newlinkname = re.match("^(.*)--%s$" % socket.gethostname(), linkname)
if newlinkname: linkname = newlinkname.group(1)
# check and change path
if not os.path.exists(dst):
if opts.work: os.makedirs(dst)
......@@ -52,46 +52,46 @@ def symlink(opts, src, dst):
try:
os.chdir(dst)
except:
print "*** could not change dir to: %s" % dst
print("*** could not change dir to: %s" % dst)
return
# check for existing file, dir or link
if os.path.islink(linkname):
if os.readlink(linkname) == src:
print "link ok: %s" % linkname
print("link ok: %s" % linkname)
return
if opts.work:
if opts.work:
try:
os.unlink(linkname)
print "unlinked: %s" % linkname
print("unlinked: %s" % linkname)
except:
print "*** could not unlink %s" % linkname
print("*** could not unlink %s" % linkname)
return
else:
print "will renew link: %s" % linkname
print("will renew link: %s" % linkname)
return
if os.path.exists(linkname):
if opts.work:
if opts.work:
try:
os.rename(linkname, linkname + ".old")
print "moved: %s -> %s" % (linkname, linkname + ".old")
print("moved: %s -> %s" % (linkname, linkname + ".old"))
except:
print "*** could not rename: %s" % linkname
print("*** could not rename: %s" % linkname)
return
else:
print "will rename file/dir: %s" % linkname
if opts.work:
print("will rename file/dir: %s" % linkname)
if opts.work:
try:
os.symlink(src, linkname)
print "%s -> %s" % (linkname, src)
print("%s -> %s" % (linkname, src))
except:
print "*** could not symlink: %s -> %s" % (linkname, src)
print("*** could not symlink: %s -> %s" % (linkname, src))
return
else:
print "will symlink: %s -> %s" % (linkname, src)
print("will symlink: %s -> %s" % (linkname, src))
def walk(opts, src, dst):
......@@ -103,7 +103,6 @@ def walk(opts, src, dst):
walk(opts, os.path.join(src, d), os.path.join(dst, d))
for f in files:
symlink(opts, os.path.join(src, f), dst)
walk(readoptions(), os.path.dirname(os.path.realpath(__file__)), "/")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment