cc1  v2.1
CC1 source code docs
All Classes Namespaces Files Functions Variables Pages
mktest-html.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 # @COPYRIGHT_begin
3 #
4 # Copyright [2010-2014] Institute of Nuclear Physics PAN, Krakow, Poland
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #
18 # @COPYRIGHT_end
19 
20 import sys
21 from mktest import Test
22 import os
23 import settings
24 import traceback
25 # Django templates
26 from django.template import loader, Context
27 from django.conf import settings as django_settings
28 
29 
30 def main():
31  if len(sys.argv) <= 2:
32  print "Usage: %s [html log file] [test_number1|test_name1] [test_number2|test_name2] ..." % sys.argv[0]
33  sys.exit(1)
34 
35  results = []
36  for script in sys.argv[2:]:
37  try:
38  s = None
39  for t in os.listdir(os.path.dirname(sys.argv[0]) + '/scripts/'):
40  if t[-3:] == '.py' and t[0:2] != '__' and (script == t[1:4] or script == t[:-3]):
41  s = t[:-3]
42  break
43 
44  exec("from scripts import %s as scenario" % s)
45  except Exception, e:
46  traceback.print_exc(limit=sys.getrecursionlimit())
47  print "Cannot find test! %s" % str(e)
48  sys.exit(0)
49 
50  try:
51  t = Test(settings.CLM_ADDRESS, scenario)
52  t.results = []
53  t.start()
54  except Exception, e:
55  print "Error: %s" % str(e)
56 
57  results.extend(t.results)
58 
59  # Append actin numbers
60  for i in range(len(results)):
61  results[i]['id'] = i
62 
63  # Create django template
64  loader.settings.configure(TEMPLATE_DIRS=['%s/django-templates' % os.path.dirname(sys.argv[0])], DEBUG=True)
65  template = loader.get_template_from_string(open("%s/django-templates/template.html" % os.path.dirname(sys.argv[0])).read())
66 
67  c = Context({'results': results})
68  t = template.render(c)
69  log = open(sys.argv[1], "w")
70  log.write(t)
71  log.close()
72 
73 
74 if __name__ == '__main__':
75  main()
76