Browse Source

Enhancement in deployment with autotools and in README file

Remove duplicate install templates directories (the same directories can be used by SLIM & runtest)
Addapted runtest so it can fetch the install template from the lodel2 datadir
Make lodel_admin.py runnable (add the python3 shebang + chmod +x at install-data target)
And a beautifull ASCII formating for the README
Yann Weber 7 years ago
parent
commit
d7c24fce39

+ 13
- 2
Makefile.am View File

@@ -1,10 +1,13 @@
1 1
 SUBDIRS=lodel progs plugins
2
-EXTRA_DIST=doc plugins runtest tplinstall examples tests
2
+EXTRA_DIST=doc plugins runtest examples tests README
3
+CLEANFILES=runtest
3 4
 
4
-lodel2datadir=$(datadir)/lodel2
5 5
 lodel2_localstate_DATA =
6 6
 lodel2_localstatedir=$(localstatedir)/lodel2
7 7
 
8
+lodel2datadir=$(datadir)/lodel2
9
+install_model_dir = $(lodel2datadir)/install_model
10
+
8 11
 #python=/usr/bin/env python3
9 12
 python=@PYTHON@
10 13
 dyncode_filename='lodel/leapi/dyncode.py'
@@ -19,6 +22,14 @@ generate-doc: clean doc_graphviz
19 22
 doc_graphviz:
20 23
 	cd doc/img/graphviz; make
21 24
 
25
+
26
+do_subst = sed -e 's,\[@\]INSTALLMODEL_DIR\[@\],$(install_model_dir),g' 
27
+
28
+runtest: runtest.sh
29
+	$(do_subst) < $(srcdir)/runtest.sh > runtest
30
+	chmod +x runtest
31
+	
32
+
22 33
 # Test em update ( examples/em_test.pickle )
23 34
 em_test: em_test.py
24 35
 	$(python) em_test.py

+ 67
- 19
README View File

@@ -1,5 +1,8 @@
1 1
 Dependencies :
2
+==============
3
+
2 4
 	lodel2 components :
5
+	-------------------
3 6
 		core :
4 7
 			python3 python3-lxml
5 8
 
@@ -13,10 +16,13 @@ Dependencies :
13 16
 			python3-pymongo
14 17
 
15 18
 	lodel2 utils :
19
+	--------------
16 20
 		mass_deploy dependencies :
17 21
 			pwgen wamerican mongodb-clients
18 22
 
19 23
 Build & install :
24
+=================
25
+
20 26
 	./bootstrap.sh #generate the configure, refresh the Makefile.in files
21 27
 	#--prefix=/usr is mandatory on debian because of a python3.4.2 bug
22 28
 	./configure --sysconfdir=/etc --localstatedir=/var --prefix=/usr
@@ -28,55 +34,96 @@ Build & install :
28 34
 	make uninstall
29 35
 
30 36
 Other make targets :
37
+====================
38
+
31 39
 	Doxygen documentation generation :
40
+	----------------------------------
32 41
 		make doc #or simply run doxygen in the source dir
42
+
33 43
 	Run unit tests :
44
+	----------------
45
+
34 46
 		make check
35 47
 		#or
36 48
 		make unittest
37 49
 
38 50
 Lodel2 instance management utilities :
51
+======================================
52
+
39 53
 	SLIM : Simple Lodel Instance Manager
40
-		create a new instance named foo :
54
+	------------------------------------
55
+
56
+		- create a new instance named foo :
41 57
 			slim -n foo -c
42
-		list instances : 
58
+
59
+		- list instances : 
43 60
 			slim -l
44
-		list instances with details :
61
+
62
+		- list instances with details :
45 63
 			slim -lv[v[v]]
46
-		list instances with output formated for bash processing :
64
+
65
+		- list instances with output formated for bash processing :
47 66
 			slim -l -b [-v[v[v]]
48
-		run make all for instance foo :
67
+
68
+		- run make all for instance foo :
49 69
 			slim -n foo -m
50
-		run make for all existing instances :
70
+
71
+		- run make for all existing instances :
51 72
 			slim --all -m
52
-		start an instance in forground
73
+
74
+		- start an instance in forground
53 75
 			slim -n foo --start -f
54
-		start all instances :
76
+
77
+		- start all instances :
55 78
 			slim -a --start
56
-		generate a nginx conf for all instances :
79
+
80
+		- generate a nginx conf for all instances :
57 81
 			slim -a --nginx-conf
58
-		get some help for more options & actions :
82
+
83
+		- get some help for more options & actions :
59 84
 			slim -h
60 85
 
61
-	mass_deploy.sh : use for easy mass deployment of instances with webui & uwsgi
62
-		the script can be found in $prefix/share/lodel2/scripts/mass_deploy.sh
86
+	mass_deploy.sh :
87
+	----------------
88
+		Use for easy mass deployment of instances with webui & uwsgi
89
+		the script at $prefix/share/lodel2/scripts/mass_deploy.sh
63 90
 
64 91
 		Usage : mass_deploy.sh N #with N the number of instances to deploy
92
+		-------
65 93
 		
66
-		- configuration can be found in /etc/lodel2/mass_deploy.cfg (
67
-		  to indicate mongodb admin credentials)
94
+		Notes :
95
+		-------
96
+
97
+		- configuration can be found in /etc/lodel2/mass_deploy.cfg 
98
+		  to indicate mongodb admin credentials
99
+
68 100
 		- mass deploy create instances directories 
69 101
 		  in /tmp/lodel2_instances
70 102
 
71 103
 Instance operations :
72
-	A Makefile is written to allow running most of operations. Existing targets are for the moment :
104
+=====================
73 105
 
74
-	make dyncode # Leapi dynamic code creation ( in leapi_dyncode.py in lodel2 instance root dir)
75
-	make init_db # Call migration handlers to tell them to init all needed databases. (note : this target has dyncode as dependencie)
76
-    make list_hooks # List all the hooks registered
106
+	- Two utils are available for instances operations :
107
+		* Make for op without parameters
108
+		* lodel_admin.py for op with parameters
77 109
 
110
+	- Makefile available target :
111
+		# Leapi dynamic code creation ( in leapi_dyncode.py in lodel2 
112
+		#instance root dir)
113
+		make dyncode 
114
+
115
+		# Call migration handlers to tell them to init all needed 
116
+		#databases. (note : this target has dyncode as dependencie)
117
+		make init_db 
118
+		make list_hooks # List all the hooks registered
119
+
120
+	- lodel_admin.py : see lodel_admin.py -h
121
+
122
+
123
+##########################################
124
+# Following informations can be obsolete #
125
+##########################################
78 126
 
79
-#Following informations can be obsolete
80 127
 Dynamic code generation :
81 128
 	python3 scripts/refreshdyn.py examples/em_test.pickle OUTPUTFILE.py
82 129
 
@@ -89,3 +136,4 @@ Instance creation :
89 136
 Instance loader uppdate :
90 137
 	If the install/loader.py is updated you can update instance's loader.py using
91 138
 		scripts/create_instance.sh -u INSTANCE_PATH
139
+

+ 1
- 1
progs/mass_deploy.sh View File

@@ -64,7 +64,7 @@ then
64 64
 		echo -e "MONGODB_DB_PREFIX not indicated in $conffile. Using purgedb without prefix is really a bad idea... It will result in a deletion of ALL db.\nexiting."
65 65
 		exit 3
66 66
 	fi
67
-	echo -n "Are you sure you want to delete all mongo database with name begining with '$MONGODB_DB_PREFIX' ? Y/n"
67
+	echo -n "Are you sure you want to delete all mongo database with name begining with '$MONGODB_DB_PREFIX' ? Y/n "
68 68
 	read rep
69 69
 	if [ "$rep" = "Y" ]
70 70
 	then

+ 12
- 7
progs/slim/Makefile.am View File

@@ -4,15 +4,17 @@ EXTRA_DIST = slim.py install_model emfile.pickle
4 4
 
5 5
 lodel2_scripts_dir = $(datadir)/lodel2/scripts
6 6
 
7
-slimdatadir = $(datadir)/lodel2/slim/
7
+lodel2datadir = $(datadir)/lodel2
8
+
9
+slimdatadir = $(lodel2datadir)/slim
8 10
 slimdata_DATA = emfile.pickle
9 11
 
10
-slim_install_model_dir = $(slimdatadir)/install_model
11
-slim_install_model__DATA = 	install_model/loader.py \
12
-				install_model/lodel_admin.py \
13
-				install_model/Makefile 
12
+install_model_dir = $(lodel2datadir)/install_model
13
+install_model__DATA = 	install_model/loader.py \
14
+			install_model/lodel_admin.py \
15
+			install_model/Makefile 
14 16
 
15
-slim_conf_model_dir = $(slim_install_model_dir)/conf.d/
17
+slim_conf_model_dir = $(install_model_dir)/conf.d/
16 18
 slim_conf_model__DATA = install_model/conf.d/lodel2.ini
17 19
 
18 20
 slim_var__DATA = slim_instances.json slim_instances_pid.json
@@ -25,7 +27,7 @@ slim_instances_pid.json:
25 27
 
26 28
 do_subst = sed -e 's,\[@\]LODEL2_PROGSDIR\[@\],$(lodel2_scripts_dir),g' \
27 29
 	-e 's,\[@\]SLIM_DATADIR\[@\],$(slimdatadir),g' \
28
-	-e 's,\[@\]SLIM_INSTALLMODEL_DIR\[@\],$(slim_install_model_dir),g' \
30
+	-e 's,\[@\]INSTALLMODEL_DIR\[@\],$(install_model_dir),g' \
29 31
 	-e 's,\[@\]SLIM_VAR_DIR\[@\],$(slim_var_dir),g' \
30 32
 	-e 's,\[@\]PKGPYTHONDIR\[@\],$(pkgpythondir),g'
31 33
 
@@ -33,3 +35,6 @@ slim: slim.py
33 35
 	$(do_subst) < $(srcdir)/slim.py > slim
34 36
 	chmod +x slim
35 37
 
38
+install-data-hook:
39
+	chmod +x $(install_model_dir)/lodel_admin.py
40
+

+ 1
- 0
progs/slim/install_model/lodel_admin.py View File

@@ -1,3 +1,4 @@
1
+#!/usr/bin/env python3
1 2
 #-*- coding: utf-8 -*-
2 3
 
3 4
 import sys

+ 1
- 1
progs/slim/slim.py View File

@@ -22,7 +22,7 @@ try:
22 22
     STORE_FILE = os.path.join("[@]SLIM_VAR_DIR[@]", 'slim_instances.json')
23 23
     PID_FILE = os.path.join("[@]SLIM_VAR_DIR[@]", 'slim_instances_pid.json')
24 24
     CREATION_SCRIPT = os.path.join("[@]LODEL2_PROGSDIR[@]", 'create_instance')
25
-    INSTALL_TPL = "[@]SLIM_INSTALLMODEL_DIR[@]"
25
+    INSTALL_TPL = "[@]INSTALLMODEL_DIR[@]"
26 26
     EMFILE = os.path.join("[@]SLIM_DATADIR[@]", 'emfile.pickle')
27 27
 
28 28
 except SyntaxError:

runtest → runtest.sh View File

@@ -55,12 +55,11 @@ fi
55 55
 PYTHON='env python3'
56 56
 testdir=$(mktemp -d)
57 57
 rmdir $testdir
58
-./progs/create_instance test_instance $testdir ./tplinstall ./examples/em_file.pickle $(dirname $0)
58
+./progs/create_instance test_instance $testdir "[@]INSTALLMODEL_DIR[@]" ./examples/em_file.pickle $(dirname $0)
59 59
 cp -R examples $testdir
60 60
 cp -R tests $testdir
61 61
 cd $testdir
62
-ls -la
63
-pwd
62
+chmod +x lodel_admin.py
64 63
 rm -R conf.d && mv tests/tests_conf.d conf.d
65 64
 make
66 65
 make refresh_plugins

+ 0
- 15
tplinstall/Makefile View File

@@ -1,15 +0,0 @@
1
-python=python3
2
-
3
-all: dyncode
4
-
5
-dyncode:
6
-	$(python) -c 'import lodel_admin; lodel_admin.refresh_dyncode()'
7
-
8
-init_db: 
9
-	$(python) -c 'import lodel_admin; lodel_admin.init_all_dbs()'
10
-
11
-list_hooks: dyncode
12
-	$(python) -c 'import lodel_admin; lodel_admin.list_registered_hooks()'
13
-
14
-refresh_plugins:
15
-	$(python) -c 'import lodel_admin; lodel_admin.update_plugin_discover_cache()'

+ 0
- 10
tplinstall/conf.d/datasources.ini View File

@@ -1,10 +0,0 @@
1
-[lodel2.datasources.default]
2
-identifier = dummy_datasource.example
3
-
4
-[lodel2.datasources.dummy2]
5
-identifier = dummy_datasource.dummy2
6
-
7
-[lodel2.datasource.dummy_datasource.example]
8
-dummy =
9
-[lodel2.datasource.dummy_datasource.dummy2]
10
-dummy =

+ 0
- 2
tplinstall/conf.d/dummy_plugin.ini View File

@@ -1,2 +0,0 @@
1
-[lodel2.section1]
2
-key1 = 42

+ 0
- 14
tplinstall/conf.d/lodel2.ini View File

@@ -1,14 +0,0 @@
1
-[lodel2]
2
-debug = False
3
-sitename = noname
4
-
5
-[lodel2.logging.stderr]
6
-level = DEBUG
7
-filename = -
8
-context = True
9
-
10
-[lodel2.editorialmodel]
11
-groups = base_group, editorial_abstract, editorial_person
12
-emfile = editorial_model.pickle
13
-dyncode = leapi_dyncode.py
14
-

+ 0
- 8
tplinstall/conf.d/webui_plugin.ini View File

@@ -1,8 +0,0 @@
1
-[lodel2.webui]
2
-standalone=False
3
-#listen_address=127.0.0.1
4
-#listen_port=9090
5
-[lodel2.webui.sessions]
6
-directory=./sessions
7
-expiration=900
8
-file_template=lodel2_%s.sess

+ 0
- 82
tplinstall/loader.py View File

@@ -1,82 +0,0 @@
1
-#-*- coding: utf-8 -*-
2
-
3
-##@brief Lodel2 loader script
4
-#
5
-#@note If you want to avoid settings loading you can set the environment
6
-#variable LODEL2_NO_SETTINGS_LOAD (see @ref install.lodel_admin.update_plugin_discover_cache()
7
-#
8
-
9
-import sys, os, os.path
10
-#
11
-# Bootstraping
12
-#
13
-LODEL2_LIB_ABS_PATH = None
14
-if LODEL2_LIB_ABS_PATH is not None:
15
-    if not os.path.isdir(LODEL2_LIB_ABS_PATH):
16
-        print("FATAL ERROR : the LODEL2_LIB_ABS_PATH variable in loader.py is \
17
-not correct : '%s'" % LODEL2_LIB_ABS_PATH, file=sys.stderr)
18
-    sys.path.append(LODEL2_LIB_ABS_PATH)
19
-
20
-#Set the cwd to the instance dir
21
-instance_dir = os.path.dirname(sys.argv[0])
22
-if len(instance_dir) > 0:
23
-    os.chdir(instance_dir)
24
-
25
-try:
26
-    import lodel
27
-except ImportError as e:
28
-    print("Unable to load lodel module. exiting...")
29
-    print(e)
30
-    exit(1)
31
-
32
-if 'LODEL2_NO_SETTINGS_LOAD' not in os.environ:
33
-    #
34
-    # Loading settings
35
-    #
36
-    from lodel.settings.settings import Settings as settings
37
-    if not settings.started():
38
-        settings('conf.d')
39
-    from lodel.settings import Settings
40
-    
41
-    #Starts hooks
42
-    from lodel.plugin import LodelHook
43
-    from lodel.plugin import core_hooks
44
-    from lodel.plugin import core_scripts
45
-
46
-def start():
47
-    #Load plugins
48
-    from lodel import logger
49
-    from lodel.plugin import Plugin
50
-    logger.debug("Loader.start() called")
51
-    Plugin.load_all()
52
-    LodelHook.call_hook('lodel2_bootstraped', '__main__', None)
53
-
54
-
55
-if __name__ == '__main__':
56
-
57
-    start()
58
-    if Settings.runtest:
59
-        import unittest
60
-        import tests
61
-        loader = unittest.TestLoader()
62
-        test_dir = os.path.join(LODEL2_LIB_ABS_PATH, 'tests')
63
-        suite = loader.discover(test_dir)
64
-        runner = unittest.TextTestRunner(
65
-            failfast = '-f' in sys.argv,
66
-            verbosity = 2 if '-v' in sys.argv else 1)
67
-        runner.run(suite)
68
-        exit()
69
-
70
-    import lodel
71
-    import leapi_dyncode as dyncode
72
-    lodel.dyncode = dyncode
73
-    LodelHook.call_hook('lodel2_dyncode_bootstraped', '__main__', None)
74
-    LodelHook.call_hook('lodel2_loader_main', '__main__', None)
75
-
76
-    #Run interative python
77
-    import code
78
-    print("""
79
-     Running interactive python in Lodel2 %s instance environment
80
-
81
-"""%Settings.sitename)
82
-    code.interact(local=locals())

+ 0
- 132
tplinstall/lodel_admin.py View File

@@ -1,132 +0,0 @@
1
-#-*- coding: utf-8 -*-
2
-
3
-import sys
4
-import os, os.path
5
-import argparse
6
-
7
-##@brief Dirty hack to avoid problems with simlink to lodel2 lib folder
8
-#
9
-#In instance folder we got a loader.py (the one we want to import here when
10
-#writing "import loader". The problem is that lodel_admin.py is a simlink to
11
-#LODEL2LIB_FOLDER/install/lodel_admin.py . In this folder there is the 
12
-#generic loader.py template. And when writing "import loader" its 
13
-#LODEL2LIB_FOLDER/install/loader.py that gets imported.
14
-#
15
-#In order to solve this problem the _simlink_hack() function delete the
16
-#LODEL2LIB_FOLDER/install entry from sys.path
17
-#@note This problem will be solved once lodel lib dir will be in 
18
-#/usr/lib/python3/lodel
19
-def _simlink_hack():
20
-    sys.path[0] = os.getcwd()
21
-
22
-## @brief Utility method to generate python code given an emfile and a
23
-# translator
24
-# @param model_file str : An em file
25
-# @param translator str : a translator name
26
-# @return python code as string
27
-def generate_dyncode(model_file, translator):
28
-    from lodel.editorial_model.model import EditorialModel
29
-    from lodel.leapi import lefactory
30
-
31
-    model = EditorialModel.load(translator, filename  = model_file)
32
-    dyncode = lefactory.dyncode_from_em(model)
33
-    return dyncode
34
-
35
-## @brief Utility method to generate a python file representing leapi dyncode
36
-# given an em file and the associated translator name
37
-#
38
-# @param model_file str : An em file
39
-# @param translator str : a translator name
40
-# @param output_filename str : the output file
41
-def create_dyncode(model_file, translator, output_filename):
42
-    from lodel import logger
43
-    dyncode = generate_dyncode(model_file, translator)
44
-    with open(output_filename, 'w+') as out_fd:
45
-        out_fd.write(dyncode)
46
-    out_fd.close()
47
-    logger.info("Dynamic leapi code written in %s", output_filename)
48
-
49
-
50
-## @brief Refresh dynamic leapi code from settings
51
-def refresh_dyncode():
52
-    import loader
53
-    from lodel.settings import Settings
54
-    # EditorialModel update/refresh
55
-    
56
-    # TODO
57
-
58
-    # Dyncode refresh
59
-    create_dyncode( Settings.editorialmodel.emfile,
60
-                    Settings.editorialmodel.emtranslator,
61
-                    Settings.editorialmodel.dyncode)
62
-
63
-
64
-def init_all_dbs():
65
-    import loader
66
-    loader.start()
67
-    import leapi_dyncode as dyncode
68
-    from lodel.plugin.datasource_plugin import DatasourcePlugin
69
-    from lodel.settings.utils import SettingsError
70
-    from lodel.leapi.leobject import LeObject
71
-    from lodel.plugin import Plugin
72
-    from lodel import logger
73
-
74
-    ds_cls = dict() # EmClass indexed by rw_datasource
75
-    for cls in dyncode.dynclasses:
76
-        ds = cls._datasource_name
77
-        if ds not in ds_cls:
78
-            ds_cls[ds] = [cls]
79
-        else:
80
-            ds_cls[ds].append(cls)
81
-    
82
-    for ds_name in ds_cls:
83
-        mh = DatasourcePlugin.init_migration_handler(ds_name)
84
-        #Retrieve plugin_name & ds_identifier for logging purpose
85
-        plugin_name, ds_identifier = DatasourcePlugin.plugin_name(
86
-            ds_name, False)
87
-        try:
88
-            mh.init_db(ds_cls[ds_name])
89
-        except Exception as e:
90
-            msg = "Migration failed for datasource %s(%s.%s) when running \
91
-init_db method: %s"
92
-            msg %= (ds_name, plugin_name, ds_identifier, e)
93
-        logger.info("Database initialisation done for %s(%s.%s)" % (
94
-            ds_name, plugin_name, ds_identifier))
95
-
96
-def list_registered_hooks():
97
-    import loader
98
-    loader.start()
99
-    from lodel.plugin.hooks import LodelHook
100
-    hlist = LodelHook.hook_list()
101
-    print("Registered hooks are : ")
102
-    for name in sorted(hlist.keys()):
103
-        print("\t- %s is registered by : " % name)
104
-        for reg_hook in hlist[name]:
105
-            hook, priority = reg_hook
106
-            msg = "\t\t- {modname}.{funname} with priority : {priority}"
107
-            msg = msg.format(
108
-                modname = hook.__module__,
109
-                funname = hook.__name__,
110
-                priority = priority)
111
-            print(msg)
112
-        print("\n")
113
-
114
-##@brief update plugin's discover cache
115
-#@note impossible to give arguments from a Makefile...
116
-#@todo write a __main__ to be able to run ./lodel_admin
117
-def update_plugin_discover_cache(path_list = None):
118
-    os.environ['LODEL2_NO_SETTINGS_LOAD'] = 'True'
119
-    import loader
120
-    from lodel.plugin.plugins import Plugin
121
-    res = Plugin.discover(path_list)
122
-    print("Plugin discover result in %s :\n" % res['path_list'])
123
-    for pname, pinfos in res['plugins'].items():
124
-        print("\t- %s %s -> %s" % (
125
-            pname, pinfos['version'], pinfos['path']))
126
-
127
-if __name__ == '__main__':
128
-    _simlink_hack()
129
-    import loader
130
-    loader.start()
131
-    from lodel.plugin.scripts import main_run
132
-    main_run()

Loading…
Cancel
Save