Update by ialbert on Fri Oct 20 15:25:57 EDT 2017 from yolo.local
-import hjson as json
-import os, mimetypes, quopri, gzip, tarfile
-
-from biostar.tools.const import *
+import gzip
+import mimetypes
+import os
+import quopri
+import tarfile
import uuid
+from itertools import islice
+
+import hjson as json
def get_uuid(limit=32):
return str(uuid.uuid4())[:limit]
+
def join(*args):
return os.path.abspath(os.path.join(*args))
+
def smart_preview(fname):
CHUNK_SIZE, LINE_COUNT = 1024, 10
try:
@@ -18,8 +24,6 @@ def smart_preview(fname):
# print (mimetype, mimecode)
- stream = open(fname, 'rb')
-
if mimetype == 'application/x-tar' and mimecode == 'gzip':
# A Tar gzip file
tar = tarfile.open(fname, mode='r')
@@ -30,9 +34,12 @@ def smart_preview(fname):
data = gzip.GzipFile(fname, 'r').read(CHUNK_SIZE)
text = quopri.encodestring(data)
elif mimetype == 'text/plain':
- lines = [next(stream) for x in range(LINE_COUNT)]
+ stream = open(fname, 'rt')
+ stream = islice(stream, LINE_COUNT)
+ lines = [ line for line in stream]
text = '\n'.join(lines)
else:
+ stream = open(fname, 'rb')
data = stream.read(CHUNK_SIZE)
text = quopri.encodestring(data)
@@ -41,30 +48,26 @@ def smart_preview(fname):
return text
-def rewrite_specs(new_specs, file):
+def rewrite_specs(new_specs, file):
return
def make_tmp_jsonfile(json_text, analysis_id):
-
return
def check_fields(json_obj):
-
return json_obj
def safe_load(json_file):
-
json_file = check_fields(json.load(open(json_file)))
return json_file
def safe_loads(json_string):
-
json_string = check_fields(json.loads(json_string))
return json_string
