[mirrorbrain-commits] r8481 - /trunk/mb/mb/randomfile.py

From: <poeml_at_mirrorbrain.org>
Date: Thu, 20 Feb 2014 01:15:33 -0000
Author: poeml
Date: Thu Feb 20 02:15:32 2014
New Revision: 8481

URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain?rev=8481&view=rev
Log:
mb/mb: add a function to quickly find any file in a local file tree (just picking the first one encountered) for further tests.

Added:
    trunk/mb/mb/randomfile.py   (with props)

Added: trunk/mb/mb/randomfile.py
URL: http://svn.mirrorbrain.org/viewvc/mirrorbrain/trunk/mb/mb/randomfile.py?rev=8481&view=auto
==============================================================================
--- trunk/mb/mb/randomfile.py	(added)
+++ trunk/mb/mb/randomfile.py	Thu Feb 20 02:15:32 2014
_at_@ -0,0 +1,36 @@
+#!/usr/bin/python
+
+import sys
+import os
+import os.path
+
+# python equivalent for this:
+# find /srv/mirrors/openoffice -type f | head -n 1
+
+# needs local file tree and knowledge of base dir
+
+
+def find_first_file_in_tree(bdir):
+    files = None
+    for (path, dirs, files) in os.walk(bdir):
+        #print path
+        #print dirs 
+        #print files 
+        #print "----"
+        if files:
+            break
+    #print '********'
+    if files:
+        found = os.path.join(path, files[0])
+        found = found[len(bdir):]
+        found = found.lstrip('/')
+        return found
+    else:
+        return None
+
+
+if __name__ == '__main__':
+
+    bdir = sys.argv[1]
+    print find_first_file_in_tree(bdir)
+




_______________________________________________
mirrorbrain-commits mailing list
Archive: http://mirrorbrain.org/archive/mirrorbrain-commits/

Note: To remove yourself from this list, send a mail with the content
 	unsubscribe
to the address mirrorbrain-commits-request_at_mirrorbrain.org
Received on Thu Feb 20 2014 - 01:15:38 GMT

This archive was generated by hypermail 2.3.0 : Thu Feb 20 2014 - 01:17:06 GMT