Browse Source

Added new lodel commands and deleted an obsolete package

Roland Haroutiounian 7 years ago
parent
commit
a1612a731e

+ 2
- 0
lodel_app/__init__.py View File

@@ -13,5 +13,7 @@ lodel_app.config.update(ini_to_dict(os.path.join(os.path.dirname(os.path.abspath
13 13
 # Lodelsites
14 14
 register_lodelsites(lodel_app)
15 15
 
16
+print(lodel_app.config)
17
+
16 18
 # Main views
17 19
 from .views import *

+ 20
- 1
lodel_app/config.ini View File

@@ -1,2 +1,21 @@
1 1
 [lodel]
2
-sitename = Lodel2
2
+sitename = Lodel2
3
+datasource_connectors = dummy_datasource
4
+session_handler = filesystem_session
5
+
6
+[lodel.datasources.default]
7
+identifier = dummy_datasource.default
8
+
9
+[lodel.datasource.dummy_datasource.default]
10
+dummy =
11
+
12
+[lodel.logging.stderr]
13
+level = ERROR
14
+filename = -
15
+context = True
16
+
17
+[lodel.editorialmodel]
18
+groups = 
19
+emfile = examples/em_test.pickle
20
+dyncode = leapi_dyncode.py
21
+editormode = True

+ 0
- 3
lodelsites/Makefile.am View File

@@ -1,3 +0,0 @@
1
-lodelsites_PYTHON = *.py
2
-
3
-lodelsitesdir=$(pkgpythondir)/../lodelsites/

+ 0
- 0
lodelsites/__init__.py View File


+ 21
- 0
management/commands/generate_dyncode.py View File

@@ -0,0 +1,21 @@
1
+from flask_script import Command, Option
2
+
3
+from lodel.editorial_model.model import EditorialModel
4
+from lodel.leapi import lefactory
5
+from lodel.management.utils import generate_dyncode
6
+
7
+class LodelCommand(Command):
8
+
9
+    option_list = (
10
+        Option('--model', '-m', dest='model_file'),
11
+        Option('--translator', '-t', dest='translator'),
12
+    )
13
+    
14
+    ## @brief Generates the dynamic code corresponding to an editorial model
15
+    # @param model_file str : file path corresponding to a given editorial model
16
+    # @param translator
17
+    # @return module
18
+    def run(self, model_file, translator):
19
+        dyncode = generate_dyncode(model_file, translator)        
20
+        print("Dyncode successfully generated for the editorial model from the file %s" % model_file)
21
+        return dyncode

+ 22
- 0
management/commands/refresh_dyncode.py View File

@@ -0,0 +1,22 @@
1
+from flask_script import Command, Option
2
+from lodel.management.utils import generate_dyncode
3
+
4
+class LodelCommand(Command):
5
+
6
+    option_list = (
7
+        Option('--model', '-m', dest='model_file'),
8
+        Option('--translator', '-t', dest='translator'),
9
+        Option('--output', '-o', dest='output_filename'),
10
+    )
11
+    
12
+    ## @brief Refreshes the dynamic code in a given output file
13
+    # @param model_file str : file path corresponding to a given editorial model
14
+    # @param translator
15
+    # @param output_filename str : output file for the updated editorial model
16
+    def run(self, 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
+        print("The dynamic code %s has been updated to %s" % (model_file, output_filename)) 
22
+

+ 14
- 0
management/commands/settings_validators.py View File

@@ -0,0 +1,14 @@
1
+import sys
2
+import os.path, os.getcwd
3
+
4
+from flask_script import Command
5
+
6
+from lodel.validator.validator import Validator
7
+
8
+class LodelCommand(Command):
9
+
10
+    ## @brief Prints the list of the settings validators available in Lodel
11
+    def run(self):
12
+        sys.path.append(os.path.dirname(os.getcwd() + '/..'))
13
+        print(Validator.validators_list_str())
14
+

+ 10
- 1
management/utils.py View File

@@ -1,9 +1,18 @@
1 1
 import pkgutil
2 2
 import os
3
+from lodel.editorial_model.model import EditorialModel
4
+from lodel.leapi import lefactory
3 5
 LODEL_COMMANDS_PATH = os.path.join(__package__, "commands")
4 6
 
5 7
 
6 8
 def register_commands(manager):
7 9
     for _, modulename, _ in pkgutil.iter_modules([LODEL_COMMANDS_PATH]):
8 10
         command_module = __import__("%s.%s" % (LODEL_COMMANDS_PATH.replace("/","."),modulename), fromlist=['LodelCommand'])
9
-        manager.add_command(modulename, getattr(command_module, 'LodelCommand')())
11
+        manager.add_command(modulename, getattr(command_module, 'LodelCommand')())
12
+
13
+##
14
+# @todo move this method in the corresponding module and change its calls in the corresponding commands
15
+def generate_dyncode(model_file, translator):
16
+    model = EditorialModel.load(translator, filename=model_file)
17
+    dyncode = lefactory.dyncode_from_em(model)
18
+    return dyncode

Loading…
Cancel
Save