aboutsummaryrefslogtreecommitdiff
path: root/tools/cleantree.py
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2009-11-23 15:53:26 +0000
committermarha <marha@users.sourceforge.net>2009-11-23 15:53:26 +0000
commitebe253cecf81d755b7e1f40598c261f6270d5cd7 (patch)
treebe708bb01678dadbfbe9b5a6d0d19d467c93b977 /tools/cleantree.py
parent3777530f25fdf2bf3ed00d0d5a4a3b1fc29b178d (diff)
downloadvcxsrv-ebe253cecf81d755b7e1f40598c261f6270d5cd7.tar.gz
vcxsrv-ebe253cecf81d755b7e1f40598c261f6270d5cd7.tar.bz2
vcxsrv-ebe253cecf81d755b7e1f40598c261f6270d5cd7.zip
More then 1 directory can now be specified on the command line.
Diffstat (limited to 'tools/cleantree.py')
-rw-r--r--tools/cleantree.py38
1 files changed, 28 insertions, 10 deletions
diff --git a/tools/cleantree.py b/tools/cleantree.py
index ee855d9d0..a02eebcc0 100644
--- a/tools/cleantree.py
+++ b/tools/cleantree.py
@@ -1,23 +1,33 @@
#!/usr/bin/python
+__doc__="""%prog [options] [<directory>]
+
+Removes all unversioned files from a subversion working copy directory
+<directory>.
+When <directory> is not specified the current directory is used.
+<directory can also be a white space seperated list of directories.
+"""
import os,sys,re,shutil
from optparse import OptionParser
-parser = OptionParser()
+parser = OptionParser(__doc__)
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()
+if g_Args:
+ for i in range(len(g_Args)):
+ g_Args[i]=os.path.abspath(g_Args[i])
+ if not os.path.isdir(g_Args[i]):
+ parser.error("%s is not a valid directory"%g_Args[i])
+
################################################################################
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):
@@ -30,19 +40,20 @@ def RunCommand(Command,NoVerbose=None):
Print(line,NoVerbose,'')
################################################################################
-def CleanTree(NoVerbose=None):
+def CleanTree(Dir, NoVerbose=None):
+ Print("Cleaning '"+Dir+"'")
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')
+ NotWorkRe=re.compile("'\.' is not a working copy")
while 1:
line=StdOut.readline()
if not line:
break
if NotWorkRe.search(line):
- Print(line)
+ Print(NotWorkRe.sub("'%s' is not a working copy directory. Not cleaning this directory."%(re.sub(r"\\",r"\\\\",Dir)),line))
sys.exit(1)
if line[0]=='?' or line[0]=='I':
Item=re.sub("^\s+","",line[2:-1])
@@ -52,15 +63,22 @@ def CleanTree(NoVerbose=None):
if Item[:6]=='tools'+os.sep:
continue
if os.path.isdir(Item):
- Print('Deleting directory %s'%Item,NoVerbose)
+ Print('Deleting directory %s'%(os.path.abspath(Item)),NoVerbose)
try:
shutil.rmtree(Item)
except:
print "Error deleting directory %s. Contains read-only files?"%Item
else:
- Print('Deleting file %s'%Item,NoVerbose)
+ Print('Deleting file %s'%(os.path.abspath(Item)),NoVerbose)
try:
os.remove(Item)
except:
print "Error deleting file %s. Is read-only?"%Item
-CleanTree(g_Options.NoVerbose)
+
+################################################################################
+if not g_Args:
+ g_Args=["."]
+
+for Dir in g_Args:
+ os.chdir(Dir)
+ CleanTree(Dir, g_Options.NoVerbose)