5 # Author: Sergey Satskiy
12 """ Deletes the compiled python files """
15 from optparse
import OptionParser
18 ext
= [ '.pyc', '.out', '.pyo', '.o' ]
22 """ Counter main function """
24 parser
= OptionParser(
27 Deletes the compiled python files
30 options
, args
= parser
.parse_args()
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
)
48 def processDir( path
):
49 " Recursively deletes files in the given directory "
53 for item
in os
.listdir( path
):
54 if os
.path
.isdir( path
+ '/' + item
):
55 files
+= processDir( path
+ '/' + item
)
58 if item
.endswith( ex
):
60 os
.remove( path
+ '/' + item
)
65 # The script execution entry point
66 if __name__
== "__main__":
69 returnCode
= mainClean()
70 except Exception, exception
:
71 print >> sys
.stderr
, str( exception
)
72 sys
.exit( returnCode
)