added minimum file size arg to find_random_files
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Wed, 15 Jun 2016 09:18:55 +0000 (11:18 +0200)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Wed, 15 Jun 2016 11:18:03 +0000 (13:18 +0200)
should make returned files more realistic

testing/test_multivol_compression_sizes.py

index 70895a9..58f09fc 100644 (file)
@@ -70,13 +70,16 @@ def _get_random_file(dir_name, rec_level):
         return entry
 
 
-def find_random_files():
+def find_random_files(min_file_size=100):
     """ generator over random file names
 
     Checks if files are readable by user (os.access) and excludes dirs with
     most volatile files and mounts; will still yield links or -- with a small
     probablility -- names of dirs with many parents (no '/usr' but maybe
     /usr/local/lib/python/site-packages/deltatar)
+
+    :param int min_file_size: size (in bytes) that returned files have to have
+                              at least
     """
 
     # prepare list of dirs in START_DIR that are not EXCLUDE_DIRS
@@ -102,7 +105,11 @@ def find_random_files():
         if not os.access(next_result, os.R_OK):
             #print('cannot access {}, try next'.format(next_result))
             continue
-        mode = os.stat(next_result).st_mode
+        statres = os.lstat(next_result)
+        if statres.st_size < min_file_size:
+            #print('file {} too small'.format(next_result))
+            continue
+        mode = statres.st_mode
         if not any(mode_test(mode) for mode_test in OK_MODES):
             #print('mode not accepted for {}, try next'.format(next_result))
             continue