mirror of
https://github.com/yweber/lodel2.git
synced 2025-10-26 09:39:01 +01:00
Add some scripts to handler dynamic code generation (without doc)
This commit is contained in:
parent
747205a0fe
commit
6df3b4d5ce
4 changed files with 47 additions and 0 deletions
BIN
examples/em_test.pickle
Normal file
BIN
examples/em_test.pickle
Normal file
Binary file not shown.
0
scripts/__init__.py
Normal file
0
scripts/__init__.py
Normal file
21
scripts/admin.py
Normal file
21
scripts/admin.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#-*- coding: utf-8 -*-
|
||||
|
||||
import sys
|
||||
import os, os.path
|
||||
|
||||
sys.path.append(os.path.dirname(os.getcwd()+'/..'))
|
||||
|
||||
def generate_dyncode(model_file, translator):
|
||||
from lodel.editorial_model.model import EditorialModel
|
||||
from lodel.leapi import lefactory
|
||||
|
||||
model = EditorialModel.load(translator, filename = model_file)
|
||||
dyncode = lefactory.dyncode_from_em(model)
|
||||
return dyncode
|
||||
|
||||
def refresh_dyncode(model_file, translator, output_filename):
|
||||
dyncode = generate_dyncode(model_file, translator)
|
||||
with open(output_filename, 'w+') as out_fd:
|
||||
out_fd.write(dyncode)
|
||||
out_fd.close()
|
||||
|
||||
26
scripts/refreshdyn.py
Normal file
26
scripts/refreshdyn.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#-*- coding: utf-8 -*-
|
||||
|
||||
import sys
|
||||
import admin
|
||||
|
||||
def usage():
|
||||
print("""Usage : %s em_filename [output_filename] [translator]
|
||||
|
||||
em_filename \tThe file where the editorial model is stored
|
||||
output_filename \tThe file where we should write the dynamic leapi code. If - print to stdout
|
||||
translator \t\tThe translator to use to read the editorial model file em_filename
|
||||
""" % sys.argv[0])
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) < 2 or len(sys.argv) > 4:
|
||||
usage()
|
||||
exit(1)
|
||||
filename = sys.argv[1]
|
||||
output_file = 'lodel/leapi/dyncode.py' if len(sys.argv) < 3 else sys.argv[2]
|
||||
translator = 'picklefile' if len(sys.argv) < 4 else sys.argv[3]
|
||||
|
||||
if output_file == '-':
|
||||
print(admin.generate_dyncode(filename, translator))
|
||||
else:
|
||||
admin.refresh_dyncode(filename, translator, output_file)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue