diff options
author | Eliot Horowitz <eliot@10gen.com> | 2010-02-04 10:21:36 -0500 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2010-02-05 09:45:33 -0500 |
commit | ba4cdb7b4cd03d13744f820ea57e6305e9d06e44 (patch) | |
tree | 275fabbf30e8db718e60d1459987d4b0d157772d | |
parent | 38a924346da737ad1d9c0b7d959f324317f8b0c2 (diff) | |
download | mongo-ba4cdb7b4cd03d13744f820ea57e6305e9d06e44.tar.gz |
bb files
-rw-r--r-- | buildscripts/cleanbb.py | 43 | ||||
-rw-r--r-- | buildscripts/utils.py | 23 |
2 files changed, 66 insertions, 0 deletions
diff --git a/buildscripts/cleanbb.py b/buildscripts/cleanbb.py new file mode 100644 index 00000000000..68a80127525 --- /dev/null +++ b/buildscripts/cleanbb.py @@ -0,0 +1,43 @@ + +import sys +import os +import utils +import time + +def killprocs( signal="" ): + cwd = os.getcwd(); + if cwd.find("buildscripts" ) > 0 : + cwd = cwd.partition( "buildscripts" )[0] + + killed = 0 + + for x in utils.getprocesslist(): + x = x.lstrip() + if x.find( cwd ) < 0: + continue + + pid = x.partition( " " )[0] + print( "killing: " + x ) + utils.execsys( "/bin/kill " + signal + " " + pid ) + killed = killed + 1 + + return killed + + +def cleanup( root ): + + # delete all regular files, directories can stay + # NOTE: if we delete directories later, we can't delete diskfulltest + for ( dirpath , dirnames , filenames ) in os.walk( root , topdown=False ): + for x in filenames: + os.remove( dirpath + "/" + x ) + + if killprocs() > 0: + time.sleep(3) + killprocs("-9") + +if __name__ == "__main__": + root = "/data/db/" + if len( sys.argv ) > 1: + root = sys.argv[1] + cleanup( root ) diff --git a/buildscripts/utils.py b/buildscripts/utils.py new file mode 100644 index 00000000000..06b7fa3c687 --- /dev/null +++ b/buildscripts/utils.py @@ -0,0 +1,23 @@ + +import re + +# various utilities that are handy + +def execsys( args ): + import subprocess + if isinstance( args , str ): + r = re.compile( "\s+" ) + args = r.split( args ) + p = subprocess.Popen( args , stdout=subprocess.PIPE , stderr=subprocess.PIPE ) + r = p.communicate() + return r; + +def getprocesslist(): + raw = "" + try: + raw = execsys( "/bin/ps -ax" )[0] + except Exception,e: + print( "can't get processlist: " + str( e ) ) + + r = re.compile( "[\r\n]+" ) + return r.split( raw ) |