# HG changeset patch # User Joseph Turian # Date 1215121946 14400 # Node ID 417355f152828f0dd982433e19ee63ff0e04e2be # Parent 9e84e8a20a75d9ecf9e305a2034e351f9c478f72# Parent 00d57d3f33ebf8734f09ebead4941589a70afdf8 merge diff -r 00d57d3f33eb -r 417355f15282 common/__init__.py --- a/common/__init__.py Thu Jul 03 00:14:42 2008 -0400 +++ b/common/__init__.py Thu Jul 03 17:52:26 2008 -0400 @@ -1,5 +1,7 @@ import file import floateq +#import gzipstring import memory import misc -import time +import mytime +import str diff -r 00d57d3f33eb -r 417355f15282 common/file.py --- a/common/file.py Thu Jul 03 00:14:42 2008 -0400 +++ b/common/file.py Thu Jul 03 17:52:26 2008 -0400 @@ -10,3 +10,28 @@ return bz2.open(filename, mode, bufsize) else: return open(filename, mode, bufsize) + +def find_files(dir, shuffle=False): + """ + Find all files in dir by recursively directory walking. + @param shuffle: Randomly shuffle the files before returning them. + """ + files = [] + for root, dirs, files in os.walk(dir): + #sys.stderr.write("Walking %s...\n" % root) + for f in files: + files.append(os.path.join(root, f)) + if shuffle: + import random + random.shuffle(files) + return files + +def ensuredir(dir): + """ + Create dir if it does not exist (including all parents). + Do nothing if it does. + """ + if not os.path.exists(dir): + sys.stderr.write("Creating directory: %s\n" % dir) + os.makedirs(dir) + assert os.path.isdir(dir) diff -r 00d57d3f33eb -r 417355f15282 common/mytime.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/common/mytime.py Thu Jul 03 17:52:26 2008 -0400 @@ -0,0 +1,12 @@ + +import time +#http://www.daniweb.com/code/snippet368.html +def print_timing(func): + def wrapper(*arg): + t1 = time.time() + res = func(*arg) + t2 = time.time() + print '%s took %0.3f ms' % (func.func_name, (t2-t1)*1000.0) + return res + return wrapper + diff -r 00d57d3f33eb -r 417355f15282 common/time.py --- a/common/time.py Thu Jul 03 00:14:42 2008 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ - -import time -#http://www.daniweb.com/code/snippet368.html -def print_timing(func): - def wrapper(*arg): - t1 = time.time() - res = func(*arg) - t2 = time.time() - print '%s took %0.3f ms' % (func.func_name, (t2-t1)*1000.0) - return res - return wrapper -