www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

unhide-dotpercent.py (1019B)


      1 #!/usr/bin/env python
      2 # -*- coding: utf-8 -*-
      3 import os
      4 import sys
      5 
      6 # Common functions
      7 
      8 def removePrefix(fileName):
      9 	while fileName[0:2] == ".%":
     10 		fileName = fileName[2:]
     11 	return fileName
     12 
     13 # Code for this utility
     14 
     15 def walk(path):
     16 	#print >> sys.stderr, path
     17 	for f in os.listdir(path):
     18 		fpath = os.path.join(path, f)
     19 		if os.path.isdir(fpath) and not os.path.islink(fpath):
     20 			walk(fpath)
     21 		if f[0:2] == ".%":
     22 			dest = os.path.join(path, removePrefix(f))
     23 			if not os.path.exists(dest):
     24 				print "i-have-moved -i -- '%s' '%s'" % (fpath.replace("'", "'\\''"), dest.replace("'", "'\\''"))
     25 				os.rename(fpath, dest)
     26 
     27 def help():
     28 	print 'Usage : %s directory > "undo-unhide-dotpercent-$(date).sh"' % sys.argv[0]
     29 	sys.exit(1)
     30 
     31 if len(sys.argv) != 2:
     32 	help()
     33 for arg in sys.argv[1:]:
     34 	if arg == '-h' or arg == '--help':
     35 		help()
     36 
     37 print "#!/bin/sh"
     38 print "echo 'Redefine the i-have-moved command at the beginning of this script to undo, e.g.:'"
     39 print "echo 'i-have-moved() { mv -i -- \"$4\" \"$3\"; }'"
     40 walk(sys.argv[1])