SOURCES: pynapi.py - do one backup by default

arekm arekm at pld-linux.org
Fri Feb 6 23:08:14 CET 2009


Author: arekm                        Date: Fri Feb  6 22:08:14 2009 GMT
Module: SOURCES                       Tag: HEAD
---- Log message:
- do one backup by default

---- Files affected:
SOURCES:
   pynapi.py (1.17 -> 1.18) 

---- Diffs:

================================================================
Index: SOURCES/pynapi.py
diff -u SOURCES/pynapi.py:1.17 SOURCES/pynapi.py:1.18
--- SOURCES/pynapi.py:1.17	Fri Feb  6 21:58:43 2009
+++ SOURCES/pynapi.py	Fri Feb  6 23:08:08 2009
@@ -55,7 +55,9 @@
 	return ''.join(b)
 
 def usage():
-    print >> sys.stderr, "Usage: %s [-l <lang> ] [-s] <file|dir> [<file|dir> ...]" % sys.argv[0]
+    print >> sys.stderr, "Usage: %s [-l|lang <lang> ] [-n|nobackup] <file|dir> [<file|dir> ...]" % sys.argv[0]
+    print >> sys.stderr, "pynapi $Revision$"
+    print >> sys.stderr, "Report bugs to <arekm at pld-linux.org>."
 
 try:
     opts, args = getopt.getopt(sys.argv[1:], "hl:s", ["help", "lang", "skip"])
@@ -66,7 +68,7 @@
 
 output = None
 verbose = False
-skip = False
+nobackup = False
 lang = 'pl'
 for o, a in opts:
     if o == "-v":
@@ -74,8 +76,8 @@
     elif o in ("-h", "--help"):
         usage()
         sys.exit()
-    elif o in ("-s", "--skip"):
-        skip = True
+    elif o in ("-n", "--nobackup"):
+        nobackup = True
     elif o in ("-l", "--lang"):
         if a in languages:
             lang = a
@@ -110,8 +112,13 @@
     if len(file) > 4:
         vfile = file[:-4] + '.txt'
 
-    if skip and os.path.exists(vfile):
-        continue
+    if not nobackup and os.path.exists(vfile):
+        vfile_bak = vfile + '-bak'
+        try:
+            os.rename(vfile, vfile_bak)
+        except (IOError, OSError), e:
+            print sys.stderr, "%s: skipping due to backup of `%s' as `%s' failure: %s" % (prog, vfile, vfile_bak, e)
+            continue
 
     print >> sys.stderr, "%s: %d/%d: Processing subtitle for %s" % (prog, i, i_total, file)
 
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/SOURCES/pynapi.py?r1=1.17&r2=1.18&f=u



More information about the pld-cvs-commit mailing list