]> code.delx.au - mediapc-tools/commitdiff
mythsymlink: generate a random filename if there is a conflict
authorJames Bunton <jamesbunton@delx.net.au>
Sun, 31 Jul 2016 04:58:36 +0000 (14:58 +1000)
committerJames Bunton <jamesbunton@delx.net.au>
Sun, 31 Jul 2016 04:58:36 +0000 (14:58 +1000)
mythsymlink

index c74421093de8eabb4c22fde8e276d0d3fbc7cf04..42a4f9bdf45e04a151387ea1cd9b8009da9b645d 100755 (executable)
@@ -1,6 +1,7 @@
 #!/usr/bin/env python2
 
 import os
+import random
 import re
 import socket
 import sys
@@ -77,6 +78,9 @@ for row in cursor:
     if not os.path.isfile(source):
         continue
 
+    if os.path.isfile(dest):
+        dest = os.path.splitext(dest)[0] + ' - unique' + str(random.randint(1000, 9999)) + extn
+
     dirnames = dest.split("/")[:-1]
     for i in xrange(1, len(dirnames)+1):
         dirname = "/".join(dirnames[:i])