[LNT] r308341 - views/ImportData: Move flask/ui independent part of importing to ImportData; NFC

Matthias Braun via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 18 11:56:24 PDT 2017


Author: matze
Date: Tue Jul 18 11:56:24 2017
New Revision: 308341

URL: http://llvm.org/viewvc/llvm-project?rev=308341&view=rev
Log:
views/ImportData: Move flask/ui independent part of importing to ImportData; NFC

Modified:
    lnt/trunk/lnt/server/ui/views.py
    lnt/trunk/lnt/util/ImportData.py

Modified: lnt/trunk/lnt/server/ui/views.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/ui/views.py?rev=308341&r1=308340&r2=308341&view=diff
==============================================================================
--- lnt/trunk/lnt/server/ui/views.py (original)
+++ lnt/trunk/lnt/server/ui/views.py Tue Jul 18 11:56:24 2017
@@ -2,7 +2,6 @@ import datetime
 import json
 import os
 import re
-import tempfile
 from collections import namedtuple, defaultdict
 from urlparse import urlparse, urljoin
 
@@ -118,28 +117,7 @@ def _do_submit():
     else:
         data_value = input_data
 
-    # Stash a copy of the raw submission.
-    #
-    # To keep the temporary directory organized, we keep files in
-    # subdirectories organized by (database, year-month).
-    utcnow = datetime.datetime.utcnow()
-    tmpdir = os.path.join(current_app.old_config.tempDir, g.db_name,
-                          "%04d-%02d" % (utcnow.year, utcnow.month))
-    try:
-        os.makedirs(tmpdir)
-    except OSError:
-        pass
-
-    # Save the file under a name prefixed with the date, to make it easier
-    # to use these files in cases we might need them for debugging or data
-    # recovery.
-    prefix = utcnow.strftime("data-%Y-%m-%d_%H-%M-%S")
-    fd, path = tempfile.mkstemp(prefix=prefix, suffix='.json',
-                                dir=str(tmpdir))
-    os.write(fd, data_value)
-    os.close(fd)
-
-    # The following accommodates old submitters. Note that we explicitly removed
+    # The following accomodates old submitters. Note that we explicitely removed
     # the tag field from the new submission format, this is only here for old
     # submission jobs. The better way of doing it is mentioning the correct
     # test-suite in the URL. So when submitting to suite YYYY use
@@ -160,14 +138,8 @@ def _do_submit():
     # Get a DB connection.
     db = request.get_db()
 
-    # Import the data.
-    #
-    # FIXME: Gracefully handle formats failures and DOS attempts. We
-    # should at least reject overly large inputs.
-
-    result = lnt.util.ImportData.import_and_report(
-        current_app.old_config, g.db_name, db, path, '<auto>',
-        ts_name=g.testsuite_name, commit=commit)
+    result = lnt.util.ImportData.import_from_string(current_app.old_config,
+        g.db_name, db, g.testsuite_name, data_value, commit=commit)
 
     # It is nice to have a full URL to the run, so fixup the request URL
     # here were we know more about the flask instance.

Modified: lnt/trunk/lnt/util/ImportData.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/util/ImportData.py?rev=308341&r1=308340&r2=308341&view=diff
==============================================================================
--- lnt/trunk/lnt/util/ImportData.py (original)
+++ lnt/trunk/lnt/util/ImportData.py Tue Jul 18 11:56:24 2017
@@ -1,11 +1,15 @@
-import os, re, time
-import collections
-import lnt.testing
-import lnt.formats
-import lnt.server.reporting.analysis
 from lnt.util import NTEmailReport
 from lnt.util import async_ops
 from lnt.util import logger
+import collections
+import datetime
+import lnt.formats
+import lnt.server.reporting.analysis
+import lnt.testing
+import os
+import re
+import tempfile
+import time
 
 def import_and_report(config, db_name, db, file, format, ts_name,
                       commit=False, show_sample_count=False,
@@ -284,3 +288,35 @@ def print_report_result(result, out, err
     print >>out, "----------------"
     for kind, count in result_kinds.items():
         print >>out, kind, ":", count
+
+
+def import_from_string(config, db_name, db, ts_name, data, commit=True):
+    # Stash a copy of the raw submission.
+    #
+    # To keep the temporary directory organized, we keep files in
+    # subdirectories organized by (database, year-month).
+    utcnow = datetime.datetime.utcnow()
+    tmpdir = os.path.join(config.tempDir, db_name,
+                          "%04d-%02d" % (utcnow.year, utcnow.month))
+    try:
+        os.makedirs(tmpdir)
+    except OSError,e:
+        pass
+
+    # Save the file under a name prefixed with the date, to make it easier
+    # to use these files in cases we might need them for debugging or data
+    # recovery.
+    prefix = utcnow.strftime("data-%Y-%m-%d_%H-%M-%S")
+    fd,path = tempfile.mkstemp(prefix=prefix, suffix='.json',
+                               dir=str(tmpdir))
+    os.write(fd, data)
+    os.close(fd)
+
+    # Import the data.
+    #
+    # FIXME: Gracefully handle formats failures and DOS attempts. We
+    # should at least reject overly large inputs.
+
+    result = lnt.util.ImportData.import_and_report(config, db_name, db,
+            path, '<auto>', ts_name, commit)
+    return result




More information about the llvm-commits mailing list