diff --git a/makelinks.py b/makelinks.py index 5ab6ed95b68b7f6574975c5e42df7a18a5b450a8..13be05230084e3fd8db2620d1017d4428c79ea25 100755 --- a/makelinks.py +++ b/makelinks.py @@ -1,10 +1,10 @@ -#!/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__)), "/")