More unit tests
[codimension.git] / clean.py
blob1aa4dec631b2f8227c4002e12ee272101c81dca9
1 #!/usr/bin/python
3 # File: clean.py
5 # Author: Sergey Satskiy
7 # Date: Apr 13, 2010
9 # $Id$
12 """ Deletes the compiled python files """
14 import sys, os.path
15 from optparse import OptionParser
18 ext = [ '.pyc', '.out', '.pyo', '.o' ]
21 def mainClean():
22 """ Counter main function """
24 parser = OptionParser(
25 """
26 %prog <dir name>
27 Deletes the compiled python files
28 """ )
30 options, args = parser.parse_args()
32 if len( args ) != 1:
33 raise Exception( "One argument expected" )
36 if not os.path.exists( args[0] ) or \
37 not os.path.isdir( args[0] ):
38 raise Exception( "A directory name is expected" )
40 files = processDir( args[0] )
42 print "Project directory: " + args[0]
43 print "Deleted files: " + str( files )
45 return 0
48 def processDir( path ):
49 " Recursively deletes files in the given directory "
51 files = 0
53 for item in os.listdir( path ):
54 if os.path.isdir( path + '/' + item ):
55 files += processDir( path + '/' + item )
56 continue
57 for ex in ext:
58 if item.endswith( ex ):
59 files += 1
60 os.remove( path + '/' + item )
61 continue
62 return files
65 # The script execution entry point
66 if __name__ == "__main__":
67 returnCode = 1
68 try:
69 returnCode = mainClean()
70 except Exception, exception:
71 print >> sys.stderr, str( exception )
72 sys.exit( returnCode )