changeset 364:417355f15282

merge
author Joseph Turian <turian@gmail.com>
date Thu, 03 Jul 2008 17:52:26 -0400
parents 9e84e8a20a75 (diff) 00d57d3f33eb (current diff)
children a04ce1e6ea54 3d5a483fe732
files
diffstat 4 files changed, 40 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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)
--- /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
+
--- 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
-