aboutsummaryrefslogtreecommitdiff
path: root/tools/cleantree.py
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2009-07-29 09:34:50 +0000
committermarha <marha@users.sourceforge.net>2009-07-29 09:34:50 +0000
commitccdcac9d281d71d3062b29fcc809cfbf8ecf1892 (patch)
tree699df1a3b9a1020228af6deaf1001d9298bb1a5b /tools/cleantree.py
parent7ca654bf54c45b42638b4a77930e5de6eab2c54f (diff)
downloadvcxsrv-ccdcac9d281d71d3062b29fcc809cfbf8ecf1892.tar.gz
vcxsrv-ccdcac9d281d71d3062b29fcc809cfbf8ecf1892.tar.bz2
vcxsrv-ccdcac9d281d71d3062b29fcc809cfbf8ecf1892.zip
Added cleantree to remove all unversioned files from a source tree (this is a completely clean)
Diffstat (limited to 'tools/cleantree.py')
-rw-r--r--tools/cleantree.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/tools/cleantree.py b/tools/cleantree.py
new file mode 100644
index 000000000..ee855d9d0
--- /dev/null
+++ b/tools/cleantree.py
@@ -0,0 +1,66 @@
+#!/usr/bin/python
+import os,sys,re,shutil
+from optparse import OptionParser
+
+parser = OptionParser()
+parser.add_option("-r", "--recursive", action='store_true', dest="Recursive", default=False, help="Also clean subdirectories.")
+parser.add_option("-s", "--skiputil", action='store_true', dest="SkipUtil", default=False, help="Skip util and tools directory.")
+parser.add_option("-v", "--noverbose", action='store_true', dest="NoVerbose", default=False, help="No output.")
+
+(g_Options, g_Args) = parser.parse_args()
+
+################################################################################
+
+def Print (Message,NoVerbose=None,Append='\n'):
+# global pLOG
+ if NoVerbose!=1:
+ Message+=Append
+ sys.stdout.write(Message)
+# if NoVerbose!=2:
+# pLOG.write(Message)
+
+################################################################################
+def RunCommand(Command,NoVerbose=None):
+ #Print(Command)
+ StdIn,StdOut=os.popen4(Command)
+ while 1:
+ line=StdOut.readline()
+ if not line:
+ break
+ Print(line,NoVerbose,'')
+
+################################################################################
+def CleanTree(NoVerbose=None):
+ if g_Options.Recursive:
+ Command='svn st --no-ignore'
+ else:
+ Command='svn st -N --no-ignore'
+ StdIn,StdOut=os.popen4(Command)
+ NotWorkRe=re.compile('is not a working copy')
+ while 1:
+ line=StdOut.readline()
+ if not line:
+ break
+ if NotWorkRe.search(line):
+ Print(line)
+ sys.exit(1)
+ if line[0]=='?' or line[0]=='I':
+ Item=re.sub("^\s+","",line[2:-1])
+ if g_Options.SkipUtil:
+ if Item[:5]=='util'+os.sep:
+ continue
+ if Item[:6]=='tools'+os.sep:
+ continue
+ if os.path.isdir(Item):
+ Print('Deleting directory %s'%Item,NoVerbose)
+ try:
+ shutil.rmtree(Item)
+ except:
+ print "Error deleting directory %s. Contains read-only files?"%Item
+ else:
+ Print('Deleting file %s'%Item,NoVerbose)
+ try:
+ os.remove(Item)
+ except:
+ print "Error deleting file %s. Is read-only?"%Item
+CleanTree(g_Options.NoVerbose)