summaryrefslogtreecommitdiff
path: root/yarns/lib.py
diff options
context:
space:
mode:
Diffstat (limited to 'yarns/lib.py')
-rw-r--r--yarns/lib.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/yarns/lib.py b/yarns/lib.py
new file mode 100644
index 0000000..b7df3a7
--- /dev/null
+++ b/yarns/lib.py
@@ -0,0 +1,29 @@
+import errno
+import os
+import time
+
+import cliapp
+
+import yarnutils
+
+datadir = os.environ['DATADIR']
+srcdir = os.environ['SRCDIR']
+
+vars = yarnutils.Variables(datadir)
+
+
+MAX_CAT_TIME = 5 # seconds
+def cat(filename):
+ start = time.time()
+ while time.time() - start < MAX_CAT_TIME:
+ try:
+ with open(filename) as f:
+ data = f.read()
+ if len(data) == 0:
+ continue
+ return data
+ except (IOError, OSError) as e:
+ if e.errno == errno.ENOENT:
+ continue
+ raise
+ raise Exception("cat took more then %s seconds" % MAX_CAT_TIME)