Преглед на файлове

Add some scripts to handler dynamic code generation (without doc)

Yann Weber преди 8 години
родител
ревизия
6df3b4d5ce
променени са 4 файла, в които са добавени 47 реда и са изтрити 0 реда
  1. Двоични данни
      examples/em_test.pickle
  2. 0
    0
      scripts/__init__.py
  3. 21
    0
      scripts/admin.py
  4. 26
    0
      scripts/refreshdyn.py

Двоични данни
examples/em_test.pickle Целия файл


+ 0
- 0
scripts/__init__.py Целия файл


+ 21
- 0
scripts/admin.py Целия файл

@@ -0,0 +1,21 @@
1
+#-*- coding: utf-8 -*-
2
+
3
+import sys
4
+import os, os.path
5
+
6
+sys.path.append(os.path.dirname(os.getcwd()+'/..'))
7
+
8
+def generate_dyncode(model_file, translator):
9
+    from lodel.editorial_model.model import EditorialModel
10
+    from lodel.leapi import lefactory
11
+
12
+    model = EditorialModel.load(translator, filename  = model_file)
13
+    dyncode = lefactory.dyncode_from_em(model)
14
+    return dyncode
15
+
16
+def refresh_dyncode(model_file, translator, output_filename):
17
+    dyncode = generate_dyncode(model_file, translator)
18
+    with open(output_filename, 'w+') as out_fd:
19
+        out_fd.write(dyncode)
20
+    out_fd.close()
21
+

+ 26
- 0
scripts/refreshdyn.py Целия файл

@@ -0,0 +1,26 @@
1
+#-*- coding: utf-8 -*-
2
+
3
+import sys
4
+import admin
5
+
6
+def usage():
7
+    print("""Usage : %s em_filename [output_filename] [translator]
8
+
9
+    em_filename \tThe file where the editorial model is stored
10
+    output_filename \tThe file where we should write the dynamic leapi code. If - print to stdout
11
+    translator \t\tThe translator to use to read the editorial model file em_filename
12
+""" % sys.argv[0])
13
+
14
+if __name__ == '__main__':
15
+    if len(sys.argv) < 2 or len(sys.argv) > 4:
16
+        usage()
17
+        exit(1)
18
+    filename = sys.argv[1]
19
+    output_file = 'lodel/leapi/dyncode.py' if len(sys.argv) < 3 else sys.argv[2]
20
+    translator = 'picklefile' if len(sys.argv) < 4 else sys.argv[3]
21
+
22
+    if output_file == '-':
23
+        print(admin.generate_dyncode(filename, translator))
24
+    else:
25
+        admin.refresh_dyncode(filename, translator, output_file)
26
+

Loading…
Отказ
Запис