Wiki

Version 225 (Etienne Pallier, 03/22/2016 10:53 am)

1 1 Etienne Pallier
h1. Technical Documentation for the PYROS project (FGFT-CC)
2 1 Etienne Pallier
3 1 Etienne Pallier
4 1 Etienne Pallier
HOWTO Format Redmine Wiki : http://www.redmine.org/projects/redmine/wiki/FrRedmineWikiFormatting
5 1 Etienne Pallier
6 1 Etienne Pallier
{{>toc}}
7 1 Etienne Pallier
8 1 Etienne Pallier
9 121 Etienne Pallier
---
10 1 Etienne Pallier
11 121 Etienne Pallier
h2. %{margin-left:0px; font-weight:bold; font-size:25px;  display:block; color:red;}I - TODO%
12 121 Etienne Pallier
13 126 Etienne Pallier
 * installation sur windows
14 125 Etienne Pallier
15 126 Etienne Pallier
 * gitlab
16 1 Etienne Pallier
17 126 Etienne Pallier
 * séparation des BD Django et Pyros
18 125 Etienne Pallier
19 126 Etienne Pallier
 * intégration dans Eclipse
20 126 Etienne Pallier
21 174 Etienne Pallier
 * Intégration des modules Django déjà développés
22 125 Etienne Pallier
23 121 Etienne Pallier
24 3 Etienne Pallier
---
25 1 Etienne Pallier
26 140 Etienne Pallier
h2. %{margin-left:0px; font-weight:bold; font-size:25px;  display:block; color:red;}I - DATABASE SCHEMA (v0.2.1)%
27 116 Etienne Pallier
28 116 Etienne Pallier
29 117 Etienne Pallier
{{thumbnail(PYROS_PDM_v021.png, size=300, title=Pyros data model)}}
30 121 Etienne Pallier
31 121 Etienne Pallier
32 121 Etienne Pallier
---
33 116 Etienne Pallier
34 141 Etienne Pallier
h2. %{margin-left:0px; font-weight:bold; font-size:25px;  display:block; color:red;}II - Get the project (from gitlab)%
35 141 Etienne Pallier
36 169 Etienne Pallier
h3. Get the project from the terminal
37 1 Etienne Pallier
38 1 Etienne Pallier
<pre>
39 1 Etienne Pallier
git clone https://gitlab.irap.omp.eu/epallier/pyros.git PYROS
40 169 Etienne Pallier
41 174 Etienne Pallier
(or also : git clone git@gitlab.irap.omp.eu:epallier/pyros.git)
42 1 Etienne Pallier
</pre>
43 1 Etienne Pallier
44 197 Etienne Pallier
This creates a PYROS/ folder containing the project (with a .git/ subfolder for synchronization with the git repository)
45 1 Etienne Pallier
46 225 Etienne Pallier
(
47 225 Etienne Pallier
_If you just wanted a static copy of the project (without synchronization) just remove the .git/ folder:_
48 1 Etienne Pallier
<pre>
49 1 Etienne Pallier
$ rm -r .git/
50 174 Etienne Pallier
</pre>
51 225 Etienne Pallier
)
52 174 Etienne Pallier
53 174 Etienne Pallier
h3. Get the project from Eclipse
54 169 Etienne Pallier
55 197 Etienne Pallier
<pre>
56 169 Etienne Pallier
TODO:
57 197 Etienne Pallier
</pre>
58 169 Etienne Pallier
59 141 Etienne Pallier
h2. %{margin-left:0px; font-weight:bold; font-size:25px;  display:block; color:red;}III - INSTALLATION%
60 2 Etienne Pallier
61 120 Etienne Pallier
62 120 Etienne Pallier
---
63 120 Etienne Pallier
64 184 Etienne Pallier
h3. Install MySql (only if necessary)
65 2 Etienne Pallier
66 49 Etienne Pallier
 * Linux Ubuntu
67 49 Etienne Pallier
<pre>
68 107 Paul Carensac
69 107 Paul Carensac
$ sudo apt-get install mysql-server
70 107 Paul Carensac
$ sudo apt-get install mysql-client
71 107 Paul Carensac
72 49 Etienne Pallier
</pre>
73 49 Etienne Pallier
74 49 Etienne Pallier
 * Linux CentOS
75 49 Etienne Pallier
<pre>
76 49 Etienne Pallier
TODO:
77 49 Etienne Pallier
$ sudo yum install mysql
78 49 Etienne Pallier
...
79 49 Etienne Pallier
</pre>
80 49 Etienne Pallier
81 49 Etienne Pallier
 * Mac OS X
82 1 Etienne Pallier
Install XAMPP
83 1 Etienne Pallier
(but you could also use the pre-installed Mac OS MySql)
84 177 Etienne Pallier
<pre>
85 177 Etienne Pallier
TODO:
86 49 Etienne Pallier
</pre>
87 1 Etienne Pallier
88 49 Etienne Pallier
 * Windows
89 177 Etienne Pallier
Install XAMPP
90 49 Etienne Pallier
<pre>
91 49 Etienne Pallier
TODO:
92 49 Etienne Pallier
</pre>
93 49 Etienne Pallier
94 49 Etienne Pallier
95 49 Etienne Pallier
---
96 1 Etienne Pallier
97 185 Etienne Pallier
h3. Install Python3.5 (only if necessary)
98 1 Etienne Pallier
99 11 Etienne Pallier
100 11 Etienne Pallier
 * Mac OS X :
101 1 Etienne Pallier
<pre>
102 183 Etienne Pallier
103 24 Etienne Pallier
1) Installer MacPort
104 24 Etienne Pallier
(TODO: doc)
105 24 Etienne Pallier
106 24 Etienne Pallier
2) Installer le "port" python35
107 1 Etienne Pallier
$ sudo port install python35
108 183 Etienne Pallier
109 1 Etienne Pallier
</pre>
110 1 Etienne Pallier
111 1 Etienne Pallier
 * Linux (Ubuntu) :
112 1 Etienne Pallier
<pre>
113 107 Paul Carensac
sudo add-apt-repository ppa:fkrull/deadsnakes
114 107 Paul Carensac
sudo apt-get update
115 107 Paul Carensac
sudo apt-get install python3.5
116 107 Paul Carensac
117 107 Paul Carensac
sudo pip install virtualenv
118 23 Etienne Pallier
</pre>
119 1 Etienne Pallier
120 1 Etienne Pallier
121 183 Etienne Pallier
 * Windows 10 :
122 183 Etienne Pallier
<pre>
123 187 Etienne Pallier
TODO:
124 183 Etienne Pallier
</pre>
125 3 Etienne Pallier
126 4 Etienne Pallier
---
127 5 Etienne Pallier
128 192 Etienne Pallier
h3. Create a Python3 virtual environment dedicated to the project (inside the project folder)
129 127 Etienne Pallier
130 131 Etienne Pallier
<pre>
131 1 Etienne Pallier
132 193 Etienne Pallier
$ mkdir private/
133 193 Etienne Pallier
134 133 Etienne Pallier
$ cd private/
135 3 Etienne Pallier
136 3 Etienne Pallier
$ which python3.5
137 3 Etienne Pallier
/opt/local/bin/python3.5
138 15 Etienne Pallier
139 127 Etienne Pallier
$ virtualenv-3.5 venv_py35_pyros -p /opt/local/bin/python3.5
140 3 Etienne Pallier
=> creates a venv_py35_pyros/ folder inside PYROS/private/
141 1 Etienne Pallier
142 131 Etienne Pallier
</pre>
143 1 Etienne Pallier
144 7 Etienne Pallier
---
145 3 Etienne Pallier
146 65 Etienne Pallier
h3. Activate the python virtual environment (from inside the project)
147 7 Etienne Pallier
148 55 Etienne Pallier
<pre>
149 1 Etienne Pallier
150 65 Etienne Pallier
$ pwd
151 134 Etienne Pallier
.../PYROS/private
152 1 Etienne Pallier
153 65 Etienne Pallier
$ source ./venv_py35_pyros/bin/activate
154 65 Etienne Pallier
155 3 Etienne Pallier
$ python -V
156 1 Etienne Pallier
Python 3.5.1
157 3 Etienne Pallier
158 3 Etienne Pallier
$ which pip
159 77 Etienne Pallier
.../PYROS/venv_py35_pyros/bin/pip
160 16 Etienne Pallier
161 194 Etienne Pallier
Upgrade pip to last version available:
162 3 Etienne Pallier
$ pip install --upgrade pip
163 3 Etienne Pallier
Collecting pip
164 3 Etienne Pallier
  Downloading pip-8.1.1-py2.py3-none-any.whl (1.2MB)
165 3 Etienne Pallier
Installing collected packages: pip
166 3 Etienne Pallier
  Found existing installation: pip 7.1.2
167 3 Etienne Pallier
    Uninstalling pip-7.1.2:
168 3 Etienne Pallier
      Successfully uninstalled pip-7.1.2
169 1 Etienne Pallier
Successfully installed pip-8.1.1
170 194 Etienne Pallier
171 194 Etienne Pallier
Upgrade wheel to last version available:
172 194 Etienne Pallier
$ pip install --upgrade wheel
173 194 Etienne Pallier
Collecting wheel
174 194 Etienne Pallier
  Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
175 194 Etienne Pallier
Installing collected packages: wheel
176 194 Etienne Pallier
  Found existing installation: wheel 0.24.0
177 194 Etienne Pallier
    Uninstalling wheel-0.24.0:
178 194 Etienne Pallier
      Successfully uninstalled wheel-0.24.0
179 194 Etienne Pallier
Successfully installed wheel-0.29.0
180 194 Etienne Pallier
181 55 Etienne Pallier
182 55 Etienne Pallier
</pre>
183 18 Etienne Pallier
184 212 Etienne Pallier
h3. Install the needed Python packages (from within the virtual environment)
185 18 Etienne Pallier
186 66 Etienne Pallier
First, be sure that the virtual environment is activated:
187 66 Etienne Pallier
<pre>
188 66 Etienne Pallier
$ python -V
189 66 Etienne Pallier
Python 3.5.1
190 66 Etienne Pallier
</pre>
191 66 Etienne Pallier
192 62 Etienne Pallier
 * *Automatic Installation of all packages*
193 62 Etienne Pallier
<pre>
194 90 Etienne Pallier
$ pip install -r REQUIREMENTS.txt
195 62 Etienne Pallier
</pre>
196 62 Etienne Pallier
197 93 Etienne Pallier
 * *Or, manual installation of each package*
198 62 Etienne Pallier
199 62 Etienne Pallier
  * *Install Django* :
200 32 Etienne Pallier
<pre>
201 3 Etienne Pallier
$ pip install django
202 3 Etienne Pallier
Collecting django
203 3 Etienne Pallier
  Downloading Django-1.9.4-py2.py3-none-any.whl (6.6MB)
204 3 Etienne Pallier
Installing collected packages: django
205 3 Etienne Pallier
Successfully installed django-1.9.4
206 3 Etienne Pallier
207 3 Etienne Pallier
$ pip install django-admin-tools
208 3 Etienne Pallier
Collecting django-admin-tools
209 3 Etienne Pallier
  Downloading django_admin_tools-0.7.2-py2.py3-none-any.whl (289kB)
210 3 Etienne Pallier
Installing collected packages: django-admin-tools
211 3 Etienne Pallier
Successfully installed django-admin-tools-0.7.2
212 3 Etienne Pallier
213 21 Etienne Pallier
$ pip install django-debug-toolbar
214 21 Etienne Pallier
Collecting django-debug-toolbar
215 21 Etienne Pallier
  Downloading django_debug_toolbar-1.4-py2.py3-none-any.whl (212kB)
216 21 Etienne Pallier
Requirement already satisfied (use --upgrade to upgrade): Django>=1.7 in ./venv_py35_pyros/lib/python3.5/site-packages (from django-debug-toolbar)
217 21 Etienne Pallier
Collecting sqlparse (from django-debug-toolbar)
218 21 Etienne Pallier
  Downloading sqlparse-0.1.19.tar.gz (58kB)
219 21 Etienne Pallier
Building wheels for collected packages: sqlparse
220 21 Etienne Pallier
  Running setup.py bdist_wheel for sqlparse ... done
221 21 Etienne Pallier
  Stored in directory: /Users/epallier/Library/Caches/pip/wheels/7b/d4/72/6011bb100dd5fc213164e4bbee13d4e03261dd54ce6a5de6b8
222 21 Etienne Pallier
Successfully built sqlparse
223 21 Etienne Pallier
Installing collected packages: sqlparse, django-debug-toolbar
224 21 Etienne Pallier
Successfully installed django-debug-toolbar-1.4 sqlparse-0.1.19
225 21 Etienne Pallier
226 21 Etienne Pallier
$ pip install django-extensions
227 21 Etienne Pallier
Collecting django-extensions
228 21 Etienne Pallier
  Downloading django_extensions-1.6.1-py2.py3-none-any.whl (202kB)
229 21 Etienne Pallier
Collecting six>=1.2 (from django-extensions)
230 21 Etienne Pallier
  Downloading six-1.10.0-py2.py3-none-any.whl
231 21 Etienne Pallier
Installing collected packages: six, django-extensions
232 21 Etienne Pallier
Successfully installed django-extensions-1.6.1 six-1.10.0
233 21 Etienne Pallier
234 21 Etienne Pallier
$ pip install django-suit
235 21 Etienne Pallier
Collecting django-suit
236 21 Etienne Pallier
  Downloading django-suit-0.2.18.tar.gz (587kB)
237 21 Etienne Pallier
Building wheels for collected packages: django-suit
238 1 Etienne Pallier
  Running setup.py bdist_wheel for django-suit ... done
239 1 Etienne Pallier
  Stored in directory: /Users/epallier/Library/Caches/pip/wheels/12/8b/9a/e02ab0ad9229881638aa040d47d77c8f562999533811927d41
240 1 Etienne Pallier
Successfully built django-suit
241 1 Etienne Pallier
Installing collected packages: django-suit
242 1 Etienne Pallier
Successfully installed django-suit-0.2.18
243 21 Etienne Pallier
244 32 Etienne Pallier
</pre>
245 32 Etienne Pallier
246 63 Etienne Pallier
  * *Install the web application server gunicorn (will be used in production instead of the dev django web server)* :
247 32 Etienne Pallier
<pre>
248 25 Etienne Pallier
$ pip install gunicorn
249 25 Etienne Pallier
Collecting gunicorn
250 25 Etienne Pallier
  Downloading gunicorn-19.4.5-py2.py3-none-any.whl (112kB)
251 21 Etienne Pallier
Installing collected packages: gunicorn
252 26 Etienne Pallier
Successfully installed gunicorn-19.4.5
253 1 Etienne Pallier
</pre>
254 1 Etienne Pallier
255 63 Etienne Pallier
  * *Install the python mysql client*:
256 32 Etienne Pallier
<pre>
257 32 Etienne Pallier
$ pip install mysqlclient
258 72 Etienne Pallier
...
259 72 Etienne Pallier
</pre>
260 33 Etienne Pallier
261 73 Etienne Pallier
   * => Issue under Mac OS X:
262 72 Etienne Pallier
<pre>
263 3 Etienne Pallier
$ pip install mysqlclient
264 3 Etienne Pallier
Collecting mysqlclient
265 1 Etienne Pallier
  Downloading mysqlclient-1.3.7.tar.gz (79kB)
266 22 Etienne Pallier
Building wheels for collected packages: mysqlclient
267 3 Etienne Pallier
  Running setup.py bdist_wheel for mysqlclient ... error
268 3 Etienne Pallier
269 1 Etienne Pallier
  ----------------------------------------
270 1 Etienne Pallier
  Failed building wheel for mysqlclient
271 1 Etienne Pallier
  Running setup.py clean for mysqlclient
272 1 Etienne Pallier
Failed to build mysqlclient
273 1 Etienne Pallier
Installing collected packages: mysqlclient
274 1 Etienne Pallier
  Running setup.py install for mysqlclient ... done
275 1 Etienne Pallier
Successfully installed mysqlclient-1.3.7
276 1 Etienne Pallier
277 1 Etienne Pallier
BOUH !!!
278 1 Etienne Pallier
279 1 Etienne Pallier
$ pip install --upgrade wheel
280 1 Etienne Pallier
Collecting wheel
281 1 Etienne Pallier
  Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
282 1 Etienne Pallier
Installing collected packages: wheel
283 1 Etienne Pallier
  Found existing installation: wheel 0.24.0
284 1 Etienne Pallier
    Uninstalling wheel-0.24.0:
285 1 Etienne Pallier
      Successfully uninstalled wheel-0.24.0
286 1 Etienne Pallier
Successfully installed wheel-0.29.0
287 1 Etienne Pallier
288 1 Etienne Pallier
$ pip uninstall mysqlclient
289 1 Etienne Pallier
290 1 Etienne Pallier
$ pip install mysqlclient
291 1 Etienne Pallier
Collecting mysqlclient
292 1 Etienne Pallier
  Using cached mysqlclient-1.3.7.tar.gz
293 1 Etienne Pallier
Building wheels for collected packages: mysqlclient
294 1 Etienne Pallier
  Running setup.py bdist_wheel for mysqlclient ... done
295 1 Etienne Pallier
  Stored in directory: /Users/epallier/Library/Caches/pip/wheels/9b/06/50/d11418c26cf8f2156b13d4363b5afde8e7e75ebb8540d0228d
296 1 Etienne Pallier
Successfully built mysqlclient
297 1 Etienne Pallier
Installing collected packages: mysqlclient
298 1 Etienne Pallier
Successfully installed mysqlclient-1.3.7
299 1 Etienne Pallier
300 1 Etienne Pallier
YES !!!
301 1 Etienne Pallier
302 1 Etienne Pallier
</pre>
303 1 Etienne Pallier
304 107 Paul Carensac
   * => Issues under Ubuntu:
305 107 Paul Carensac
<pre>
306 107 Paul Carensac
$ pip install mysqlclient
307 107 Paul Carensac
Collecting mysqlclient
308 107 Paul Carensac
  Downloading mysqlclient-1.3.7.tar.gz (79kB)
309 107 Paul Carensac
    100% |████████████████████████████████| 81kB 1.5MB/s
310 107 Paul Carensac
    Complete output from command python setup.py egg_info:
311 107 Paul Carensac
    /bin/sh: 1: mysql_config: not found
312 107 Paul Carensac
    Traceback (most recent call last):
313 107 Paul Carensac
      File "<string>", line 1, in <module>
314 107 Paul Carensac
    [...]
315 107 Paul Carensac
    ----------------------------------------
316 107 Paul Carensac
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-q6j4inuz/mysqlclient/
317 1 Etienne Pallier
318 108 Paul Carensac
BOUH !!!
319 108 Paul Carensac
320 107 Paul Carensac
$ sudo apt-get install libmysqlclient-dev
321 108 Paul Carensac
322 107 Paul Carensac
$ pip install mysqlclient
323 107 Paul Carensac
Collecting mysqlclient
324 107 Paul Carensac
  Using cached mysqlclient-1.3.7.tar.gz
325 107 Paul Carensac
Building wheels for collected packages: mysqlclient
326 107 Paul Carensac
  Running setup.py bdist_wheel for mysqlclient ... error
327 107 Paul Carensac
328 107 Paul Carensac
    _mysql.c:40:20: fatal error: Python.h: No such file or directory
329 107 Paul Carensac
     #include "Python.h"
330 107 Paul Carensac
                        ^
331 107 Paul Carensac
    compilation terminated.
332 107 Paul Carensac
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
333 107 Paul Carensac
    
334 107 Paul Carensac
    ----------------------------------------
335 107 Paul Carensac
Command "/home/carens_p/pyros/venv_py35_pyros/bin/python3.5 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-k3klv92j/mysqlclient/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-gz242xxs-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/carens_p/pyros/venv_py35_pyros/include/site/python3.5/mysqlclient" failed with error code 1 in /tmp/pip-build-k3klv92j/mysqlclient/
336 107 Paul Carensac
337 108 Paul Carensac
BOUH !!!
338 108 Paul Carensac
339 107 Paul Carensac
$ sudo apt-get install python3.5-dev
340 108 Paul Carensac
341 107 Paul Carensac
$ pip install mysqlclient
342 107 Paul Carensac
343 107 Paul Carensac
YES !!!
344 107 Paul Carensac
345 107 Paul Carensac
</pre>
346 12 Etienne Pallier
347 12 Etienne Pallier
---
348 28 Etienne Pallier
349 142 Etienne Pallier
h3. Test the project
350 142 Etienne Pallier
351 142 Etienne Pallier
<pre>
352 142 Etienne Pallier
353 150 Etienne Pallier
$ cd src/
354 150 Etienne Pallier
355 1 Etienne Pallier
$ ./manage.py runserver
356 38 Etienne Pallier
(or gunicorn pyros.wsgi)
357 3 Etienne Pallier
==> http://localhost:8000
358 87 Etienne Pallier
...
359 87 Etienne Pallier
...
360 87 Etienne Pallier
Ctrl-c
361 87 Etienne Pallier
362 1 Etienne Pallier
</pre>
363 142 Etienne Pallier
364 142 Etienne Pallier
365 142 Etienne Pallier
366 142 Etienne Pallier
---
367 142 Etienne Pallier
368 3 Etienne Pallier
h3. Replace the default pyrosapp models.py with the inspectdb generated one
369 3 Etienne Pallier
370 105 Etienne Pallier
From src/ :
371 1 Etienne Pallier
372 105 Etienne Pallier
<pre>
373 105 Etienne Pallier
$ mv models.py pyrosapp/
374 105 Etienne Pallier
</pre>
375 3 Etienne Pallier
376 139 Paul Carensac
Add pyrosapp to the project's applications :
377 7 Etienne Pallier
378 139 Paul Carensac
Edit src/pyros/settings.py
379 1 Etienne Pallier
380 139 Paul Carensac
<pre>
381 139 Paul Carensac
INSTALLED_APPS = [
382 139 Paul Carensac
    'django.contrib.admin',
383 139 Paul Carensac
    'django.contrib.auth',
384 139 Paul Carensac
    'django.contrib.contenttypes',
385 139 Paul Carensac
    'django.contrib.sessions',
386 139 Paul Carensac
    'django.contrib.messages',
387 139 Paul Carensac
    'django.contrib.staticfiles',
388 139 Paul Carensac
    'pyrosapp',
389 139 Paul Carensac
]
390 139 Paul Carensac
</pre>
391 9 Etienne Pallier
392 47 Etienne Pallier
---
393 3 Etienne Pallier
394 145 Paul Carensac
h3. Fix and improve the pyrosapp models.py file (generated by inspectdb)
395 1 Etienne Pallier
396 145 Paul Carensac
Once models.py file generated, we need to delete the database and create an empty one :
397 145 Paul Carensac
 
398 145 Paul Carensac
<pre>
399 145 Paul Carensac
$ mysql -u root [-p (if password needed)]
400 106 Etienne Pallier
401 145 Paul Carensac
mysql> DROP DATABSE pyros
402 145 Paul Carensac
mysql> CREATE SCHEMA IF NOT EXISTS 'pyros' DEFAULT CHARACTER SET utf8;
403 1 Etienne Pallier
404 145 Paul Carensac
</pre>
405 1 Etienne Pallier
406 145 Paul Carensac
Then edit pyrosapp/models.py :
407 1 Etienne Pallier
408 145 Paul Carensac
 * Change 'managed = False' to 'managed = True' for every model
409 145 Paul Carensac
410 145 Paul Carensac
 * Change classes names to CamelCase (do not change the 'db_table = ...' lines). *Be careful* : it is needed to change all occurences :
411 145 Paul Carensac
412 145 Paul Carensac
    * NrtAlanysis
413 145 Paul Carensac
    * ScheduleHistory
414 145 Paul Carensac
    * ScientificProgram
415 145 Paul Carensac
    * SequenceType
416 145 Paul Carensac
    * SiteWatch
417 145 Paul Carensac
    * SiteWatchHistory
418 145 Paul Carensac
    * StrategyObs
419 154 Paul Carensac
    * UserLevel
420 145 Paul Carensac
    * WeatherWatch
421 145 Paul Carensac
    * WeatherWatchHistory
422 145 Paul Carensac
423 145 Paul Carensac
 * Change the deleting mode from 'models.DO_NOTHING' to 'models.CASCADE' for the following foreign keys :
424 145 Paul Carensac
425 145 Paul Carensac
    * Image.plan
426 145 Paul Carensac
    * Plan.album
427 145 Paul Carensac
    * Album.sequence
428 145 Paul Carensac
    * Sequence.request
429 145 Paul Carensac
430 145 Paul Carensac
 * Change the 'ForeignKey' liaisons to 'OneToOneField' liaisons (just replace ForeignKey by OneToOneField), and change deleting mode to 'models.CASCADE' for the following foreign keys :
431 145 Paul Carensac
432 145 Paul Carensac
    * Alert.request
433 145 Paul Carensac
    * Detector.device
434 145 Paul Carensac
    * Filter.device
435 145 Paul Carensac
    * Telescope.device
436 145 Paul Carensac
437 145 Paul Carensac
 * We need to redefine many to many relationships for the following classes :
438 145 Paul Carensac
439 145 Paul Carensac
    * User - ScientificProgram :
440 145 Paul Carensac
441 145 Paul Carensac
        * add 'users = models.ManyToManyField('User')' in ScientificProgram class
442 145 Paul Carensac
        * delete UserHasScientificProgram class
443 145 Paul Carensac
444 145 Paul Carensac
    * Sequence - ScheduleHistory
445 145 Paul Carensac
446 145 Paul Carensac
        * add 'sequences = models.ManyToManyField('Sequence')' in ScheduleHistory class
447 145 Paul Carensac
        * delete ScheduleHasSequences class
448 145 Paul Carensac
449 199 Paul Carensac
450 199 Paul Carensac
 * For each ForeignKey and ManyToManyField creation in models.py, add the 'related_name=[...]' named parameter, as in the following examples :
451 199 Paul Carensac
452 199 Paul Carensac
<pre>
453 199 Paul Carensac
class Sequence(models.Model):
454 199 Paul Carensac
    request = models.ForeignKey(Request, models.CASCADE, related_name="sequences")
455 199 Paul Carensac
    sequencetype = models.ForeignKey('SequenceType', models.DO_NOTHING, related_name="sequences")
456 199 Paul Carensac
    schedule = models.ForeignKey(Schedule, models.DO_NOTHING, related_name="sequences")
457 199 Paul Carensac
    name = models.CharField(max_length=45, blank=True, null=True)
458 199 Paul Carensac
    desc = models.TextField(blank=True, null=True)
459 199 Paul Carensac
    ...
460 199 Paul Carensac
461 199 Paul Carensac
class ScheduleHistory(models.Model):
462 199 Paul Carensac
    sequences = models.ManyToManyField('Sequence', related_name='schedulehistorys')
463 199 Paul Carensac
    created = models.DateTimeField(blank=True, null=True)
464 199 Paul Carensac
    ...
465 199 Paul Carensac
466 199 Paul Carensac
</pre>
467 199 Paul Carensac
468 145 Paul Carensac
 * Finally apply modifications to the database :
469 145 Paul Carensac
470 145 Paul Carensac
<pre>
471 145 Paul Carensac
$ pwd
472 145 Paul Carensac
.../PYROS/src
473 145 Paul Carensac
$ python manage.py makemigrations pyrosapp
474 145 Paul Carensac
$ python manage.py migrate
475 145 Paul Carensac
</pre>
476 109 Etienne Pallier
477 109 Etienne Pallier
---
478 111 Etienne Pallier
479 156 Paul Carensac
h2. %{margin-left:0px; font-weight:bold; font-size:25px;  display:block; color:red;}IV - CONFIGURATION of the Django Back Office (administration interface)%
480 155 Paul Carensac
481 155 Paul Carensac
---
482 155 Paul Carensac
483 155 Paul Carensac
h3. Back Office setup
484 155 Paul Carensac
485 155 Paul Carensac
 * Prerequisites in src/pyros/settings.py :
486 155 Paul Carensac
487 155 Paul Carensac
    * INSTALLED_APPS must (at least) contain :
488 155 Paul Carensac
489 155 Paul Carensac
        * django.contrib.admin
490 155 Paul Carensac
        * django.contrib.auth
491 155 Paul Carensac
        * django.contrib.contenttypes
492 155 Paul Carensac
        * django.contrib.sessions
493 155 Paul Carensac
494 155 Paul Carensac
    * MIDDLEWARES must (at least) contain :
495 155 Paul Carensac
496 155 Paul Carensac
        * django.contrib.sessions.middleware.SessionMiddleware
497 155 Paul Carensac
        * django.middleware.common.CommonMiddleware
498 155 Paul Carensac
        * django.contrib.auth.middleware.AuthenticationMiddleware
499 155 Paul Carensac
500 155 Paul Carensac
 * At least one 'python manage.py migrate' must have been executed
501 155 Paul Carensac
502 155 Paul Carensac
 * Create a superuser for the administration :
503 155 Paul Carensac
504 155 Paul Carensac
<pre>
505 155 Paul Carensac
$ python manage.py createsuperuser
506 155 Paul Carensac
</pre>
507 155 Paul Carensac
508 156 Paul Carensac
* For each app of the project, fill the admin.py file :
509 155 Paul Carensac
510 155 Paul Carensac
<pre>
511 155 Paul Carensac
from django.contrib import admin
512 155 Paul Carensac
from app.models import Model1, Model2
513 155 Paul Carensac
514 155 Paul Carensac
admin.site.register(Model1)
515 155 Paul Carensac
admin.site.register(Model2)
516 155 Paul Carensac
</pre>
517 155 Paul Carensac
518 155 Paul Carensac
*Reminder* : each application must be registered in the settings.py INSTALLED_APPS variable.
519 157 Paul Carensac
520 168 Paul Carensac
* For each model in models.py, add a '__str__()' method in order to identify the object on the back office. Example :
521 157 Paul Carensac
522 157 Paul Carensac
<pre>
523 157 Paul Carensac
class UserLevel(models.Model):
524 157 Paul Carensac
    name = models.CharField(max_length=45, blank=True, null=True)
525 157 Paul Carensac
    desc = models.TextField(blank=True, null=True)
526 157 Paul Carensac
    priority = models.IntegerField(blank=True, null=True)
527 157 Paul Carensac
    quota = models.FloatField(blank=True, null=True)
528 157 Paul Carensac
529 157 Paul Carensac
    class Meta:
530 157 Paul Carensac
        managed = True
531 157 Paul Carensac
        db_table = 'userlevel'
532 157 Paul Carensac
533 157 Paul Carensac
    def __str__(self):
534 163 Paul Carensac
        return (str(self.name))
535 157 Paul Carensac
</pre>
536 157 Paul Carensac
537 159 Paul Carensac
*Naming convention* : Use self.name when possible, the creation time/date otherwise. Example :
538 159 Paul Carensac
539 159 Paul Carensac
<pre>
540 159 Paul Carensac
class SiteWatch(models.Model):
541 159 Paul Carensac
    updated = models.DateTimeField(blank=True, null=True)
542 159 Paul Carensac
    lights = models.CharField(max_length=45, blank=True, null=True)
543 159 Paul Carensac
    dome = models.CharField(max_length=45, blank=True, null=True)
544 159 Paul Carensac
    doors = models.CharField(max_length=45, blank=True, null=True)
545 159 Paul Carensac
    temperature = models.FloatField(blank=True, null=True)
546 159 Paul Carensac
547 159 Paul Carensac
    class Meta:
548 159 Paul Carensac
        managed = True
549 159 Paul Carensac
        db_table = 'sitewatch'
550 159 Paul Carensac
551 159 Paul Carensac
    def __str__(self):
552 160 Paul Carensac
        return (str(self.updated))
553 159 Paul Carensac
</pre>
554 173 Etienne Pallier
555 211 Paul Carensac
---
556 211 Paul Carensac
557 211 Paul Carensac
h3. Adaptation of the one-to-many and many-to-many display
558 211 Paul Carensac
559 211 Paul Carensac
* The one-to-many relationships are the following (One.many format) :
560 211 Paul Carensac
561 211 Paul Carensac
    * Schedule.sequences
562 211 Paul Carensac
    * Request.sequences
563 211 Paul Carensac
    * Sequence.albums
564 211 Paul Carensac
    * Album.plans
565 211 Paul Carensac
    * Plan.images
566 211 Paul Carensac
    * Telescope.detectors
567 211 Paul Carensac
    * Detector.filters
568 211 Paul Carensac
    * NrtAnalysis.images
569 211 Paul Carensac
    * Filter.plans
570 211 Paul Carensac
    * Detector.albums
571 211 Paul Carensac
    * UserLevel.users
572 211 Paul Carensac
    * Country.users
573 211 Paul Carensac
    * ScientificProgram.requests
574 211 Paul Carensac
    * User.requests
575 211 Paul Carensac
    * StrategyObs.alerts
576 211 Paul Carensac
    * SequenceType.sequences
577 211 Paul Carensac
578 211 Paul Carensac
* For each "many", create a new class in admin.py just after the imports, following these examples :
579 211 Paul Carensac
580 211 Paul Carensac
<pre>
581 211 Paul Carensac
582 211 Paul Carensac
For Schedule.sequences, Request.sequences and Sequentype.sequences, we will need :
583 211 Paul Carensac
584 211 Paul Carensac
class SequenceInline(admin.TabularInline):
585 211 Paul Carensac
    model = Sequence
586 211 Paul Carensac
    fields = ("name",)
587 211 Paul Carensac
    show_change_link = True
588 211 Paul Carensac
589 211 Paul Carensac
590 211 Paul Carensac
For Sequence.albums and Detector.albums, we will need :
591 211 Paul Carensac
592 211 Paul Carensac
class AlbumInline(admin.TabularInline):
593 211 Paul Carensac
    model = Album
594 211 Paul Carensac
    fields = ("name",)
595 211 Paul Carensac
    show_change_link = True
596 211 Paul Carensac
597 211 Paul Carensac
598 211 Paul Carensac
For StrategyObs.alerts, we will need :
599 211 Paul Carensac
600 211 Paul Carensac
class AlertInline(admin.TabularInline):
601 211 Paul Carensac
    model = Alert
602 211 Paul Carensac
    fields = ("request.name",) # there is no 'name' attribute in the Alert model
603 211 Paul Carensac
    show_change_link = True
604 211 Paul Carensac
605 211 Paul Carensac
</pre>
606 211 Paul Carensac
607 222 Paul Carensac
* For each "One", declare a new class in admin.py, just after the "Inlines" class declaration, as done in the following examples :
608 211 Paul Carensac
609 222 Paul Carensac
<pre>
610 222 Paul Carensac
For Request.sequences :
611 222 Paul Carensac
612 222 Paul Carensac
class RequestAdmin(admin.ModelAdmin):
613 222 Paul Carensac
    inlines = [
614 222 Paul Carensac
	SequenceInline,
615 222 Paul Carensac
    ]
616 222 Paul Carensac
617 222 Paul Carensac
For Detector.filters and Detector.albums :
618 222 Paul Carensac
619 222 Paul Carensac
class DetectorAdmin(admin.ModelAdmin):
620 222 Paul Carensac
    inlines = [
621 222 Paul Carensac
	FilterInline,
622 222 Paul Carensac
        AlbumInline,
623 222 Paul Carensac
    ]
624 222 Paul Carensac
625 222 Paul Carensac
</pre>
626 222 Paul Carensac
627 222 Paul Carensac
* The many-to-many relationships are the following :
628 222 Paul Carensac
    * ScientificProgram - User
629 222 Paul Carensac
    * ScheduleHistory - Sequence
630 222 Paul Carensac
631 222 Paul Carensac
* For each many-to-many relationship, declare a new "Inline" class in admin.py just after the imports, like this :
632 222 Paul Carensac
633 222 Paul Carensac
<pre>
634 222 Paul Carensac
For ScientificProgram - User :
635 222 Paul Carensac
636 222 Paul Carensac
class UserAndSPInline(admin.TabularInline):
637 222 Paul Carensac
    model = ScientificProgram.users.through
638 222 Paul Carensac
639 222 Paul Carensac
640 222 Paul Carensac
For ScheduleHistory - Sequence
641 222 Paul Carensac
642 222 Paul Carensac
class SequenceAndSHInline(admin.TabularInline):
643 222 Paul Carensac
    model = ScheduleHistory.sequences.through
644 222 Paul Carensac
645 222 Paul Carensac
</pre>
646 222 Paul Carensac
647 222 Paul Carensac
+Note :+ The order in the line "model = ScientificProgram.users.through" is very important : the first model (ScientificProgram) is the one in which is declared the ManyToManyField relationship.
648 211 Paul Carensac
649 1 Etienne Pallier
h2. %{margin-left:0px; font-weight:bold; font-size:25px;  display:block; color:red;}V - INSTALLATION FROM THE BEGINNING (for dev only)%
650 204 Etienne Pallier
651 205 Etienne Pallier
h3. Install MySql (only if necessary)
652 205 Etienne Pallier
653 205 Etienne Pallier
See above in III-Installation
654 1 Etienne Pallier
https://projects.irap.omp.eu/projects/pyros/wiki/Wiki#III-INSTALLATION
655 207 Etienne Pallier
656 207 Etienne Pallier
657 207 Etienne Pallier
---
658 207 Etienne Pallier
659 208 Etienne Pallier
h3. Create the database (from sql script generated with Mysql Workbench)
660 207 Etienne Pallier
661 207 Etienne Pallier
 * Linux and Mac OS X:
662 207 Etienne Pallier
<pre>
663 207 Etienne Pallier
One liner:
664 207 Etienne Pallier
$ mysql -u root < pyros_create.sql
665 207 Etienne Pallier
666 207 Etienne Pallier
Or :
667 207 Etienne Pallier
$ mysql -u root
668 207 Etienne Pallier
mysql> create database pyros;
669 207 Etienne Pallier
mysql> use pyros;
670 207 Etienne Pallier
mysql> source pyros_create.sql;
671 207 Etienne Pallier
672 207 Etienne Pallier
(
673 207 Etienne Pallier
TODO:
674 207 Etienne Pallier
mysql> grant all on pyros.* to pyros@localhost identified by ‘pyros’;)
675 207 Etienne Pallier
mysql> flush privileges;
676 207 Etienne Pallier
)
677 207 Etienne Pallier
</pre>
678 207 Etienne Pallier
679 207 Etienne Pallier
680 207 Etienne Pallier
 * Windows:
681 207 Etienne Pallier
<pre>
682 207 Etienne Pallier
TODO: Use phpmyadmin ?
683 207 Etienne Pallier
</pre>
684 205 Etienne Pallier
685 205 Etienne Pallier
h3. Install Python3.5 (only if necessary)
686 205 Etienne Pallier
687 205 Etienne Pallier
See above in III-Installation
688 205 Etienne Pallier
https://projects.irap.omp.eu/projects/pyros/wiki/Wiki#III-INSTALLATION
689 205 Etienne Pallier
690 210 Etienne Pallier
691 210 Etienne Pallier
h3. Create the project structure
692 210 Etienne Pallier
693 210 Etienne Pallier
<pre>
694 210 Etienne Pallier
$ mkdir PYROS
695 210 Etienne Pallier
</pre>
696 210 Etienne Pallier
697 210 Etienne Pallier
Example of a good organization :
698 210 Etienne Pallier
699 210 Etienne Pallier
1 project = N applis
700 210 Etienne Pallier
1 appli = N models
701 210 Etienne Pallier
A! L’appli est à côté du projet, PAS DEDANS,
702 210 Etienne Pallier
cela facilite la REUTILISATION
703 210 Etienne Pallier
(an appli can be part of many projects => reuse)
704 210 Etienne Pallier
1 appli = 1 Python module, organized for Django, by default = appli web (but not mandatory)
705 210 Etienne Pallier
706 210 Etienne Pallier
<pre>
707 210 Etienne Pallier
708 210 Etienne Pallier
MYPROJECT/
709 210 Etienne Pallier
	REQUIREMENTS.txt
710 210 Etienne Pallier
	src/
711 210 Etienne Pallier
		myproject/
712 210 Etienne Pallier
		appli1/
713 210 Etienne Pallier
		appli2/
714 210 Etienne Pallier
715 210 Etienne Pallier
		appliN/
716 210 Etienne Pallier
717 210 Etienne Pallier
	public/
718 210 Etienne Pallier
		static/
719 210 Etienne Pallier
720 210 Etienne Pallier
	private/
721 210 Etienne Pallier
		venv_py35_pyros/
722 210 Etienne Pallier
723 210 Etienne Pallier
</pre>
724 210 Etienne Pallier
725 210 Etienne Pallier
726 210 Etienne Pallier
Set needed folders:
727 210 Etienne Pallier
<pre>
728 210 Etienne Pallier
$ cd PYROS/
729 210 Etienne Pallier
$ mkdir private public
730 210 Etienne Pallier
$ mkdir public/static
731 210 Etienne Pallier
</pre>
732 210 Etienne Pallier
733 210 Etienne Pallier
734 210 Etienne Pallier
735 210 Etienne Pallier
---
736 210 Etienne Pallier
737 205 Etienne Pallier
h3. Create a Python3 virtual environment dedicated to the project (inside the project folder)
738 205 Etienne Pallier
739 205 Etienne Pallier
See above in III-Installation
740 205 Etienne Pallier
https://projects.irap.omp.eu/projects/pyros/wiki/Wiki#III-INSTALLATION
741 205 Etienne Pallier
742 205 Etienne Pallier
h3. Activate the Python virtual environment (from inside the project)
743 205 Etienne Pallier
744 205 Etienne Pallier
See above in III-Installation
745 205 Etienne Pallier
https://projects.irap.omp.eu/projects/pyros/wiki/Wiki#III-INSTALLATION
746 205 Etienne Pallier
747 213 Etienne Pallier
h3. Install the needed Python packages (from within the virtual environment)
748 205 Etienne Pallier
749 1 Etienne Pallier
See above in III-Installation
750 213 Etienne Pallier
https://projects.irap.omp.eu/projects/pyros/wiki/Wiki#Install-the-needed-Python-packages-from-within-the-virtual-environment
751 213 Etienne Pallier
(cf manual installation)
752 213 Etienne Pallier
753 215 Etienne Pallier
h3. Create a Django project named PYROS
754 1 Etienne Pallier
755 215 Etienne Pallier
<pre>
756 215 Etienne Pallier
757 215 Etienne Pallier
From inside the project:
758 215 Etienne Pallier
$ pwd
759 215 Etienne Pallier
.../PYROS/
760 215 Etienne Pallier
761 215 Etienne Pallier
$ django-admin startproject pyros
762 215 Etienne Pallier
763 215 Etienne Pallier
Rename the project folder "pyros/" as "src/"
764 215 Etienne Pallier
765 215 Etienne Pallier
$ mv pyros src
766 215 Etienne Pallier
767 215 Etienne Pallier
We have then this architecture:
768 215 Etienne Pallier
769 215 Etienne Pallier
PYROS
770 215 Etienne Pallier
├── REQUIREMENTS.txt
771 215 Etienne Pallier
├── private
772 215 Etienne Pallier
│   └── venv_py35_pyros
773 215 Etienne Pallier
├── public
774 215 Etienne Pallier
│   └── static
775 215 Etienne Pallier
├── src
776 215 Etienne Pallier
│   ├── manage.py
777 215 Etienne Pallier
│   ├── pyros
778 215 Etienne Pallier
│   │   ├── __init__.py
779 215 Etienne Pallier
│   │   ├── settings.py
780 215 Etienne Pallier
│   │   ├── urls.py
781 215 Etienne Pallier
│   │   └── wsgi.py
782 215 Etienne Pallier
783 215 Etienne Pallier
</pre>
784 215 Etienne Pallier
785 215 Etienne Pallier
786 215 Etienne Pallier
787 215 Etienne Pallier
788 215 Etienne Pallier
---
789 205 Etienne Pallier
790 205 Etienne Pallier
h3. Test the project
791 205 Etienne Pallier
792 205 Etienne Pallier
See above in III-Installation
793 205 Etienne Pallier
https://projects.irap.omp.eu/projects/pyros/wiki/Wiki#III-INSTALLATION
794 205 Etienne Pallier
795 205 Etienne Pallier
h3. The Web server
796 205 Etienne Pallier
797 217 Etienne Pallier
798 217 Etienne Pallier
Apache : gère tous les fichiers statiques (images, html…), et délègue les fichiers python au serveur django (par défaut)
799 217 Etienne Pallier
800 217 Etienne Pallier
Le fichier pyros/urls.py prend le relai pour tout ce qui est django
801 217 Etienne Pallier
802 217 Etienne Pallier
Le moteur web django sera soit du wsgi soit du unicorn
803 217 Etienne Pallier
804 217 Etienne Pallier
Par défaut, 1 seul worker, mais on peut en configurer plusieurs, l’idéal étant de faire "nb coeurs + 1" 
805 217 Etienne Pallier
(le worker maître qui fait le dispatching aux autres)
806 217 Etienne Pallier
807 217 Etienne Pallier
Frontend : Apache ou Ngininx
808 217 Etienne Pallier
809 217 Etienne Pallier
Backend : gunicorn (gère facilement des workers) ou uwsgi
810 217 Etienne Pallier
811 217 Etienne Pallier
<pre>
812 217 Etienne Pallier
$ gunicorn pyros.wsgi
813 217 Etienne Pallier
(à la place de manage runserver => A EVITER EN PROD)
814 217 Etienne Pallier
815 217 Etienne Pallier
Ou encore:
816 217 Etienne Pallier
817 217 Etienne Pallier
$ gunicorn --workers 5 library.wsgi
818 217 Etienne Pallier
</pre>
819 217 Etienne Pallier
820 217 Etienne Pallier
---
821 217 Etienne Pallier
822 219 Etienne Pallier
h3. Set the database engine as MySql
823 219 Etienne Pallier
824 219 Etienne Pallier
Edit src/pyros/settings.py
825 219 Etienne Pallier
826 219 Etienne Pallier
<pre>
827 219 Etienne Pallier
DATABASES = {
828 219 Etienne Pallier
    'default': {
829 219 Etienne Pallier
        'ENGINE': 'django.db.backends.mysql',
830 219 Etienne Pallier
        'NAME': 'pyros',
831 219 Etienne Pallier
        'USER': 'root',
832 219 Etienne Pallier
        'PASSWORD': ''
833 219 Etienne Pallier
    }
834 219 Etienne Pallier
}
835 219 Etienne Pallier
</pre>
836 219 Etienne Pallier
837 219 Etienne Pallier
---
838 205 Etienne Pallier
839 221 Etienne Pallier
h3. Import the database into Django (with inspectdb)
840 221 Etienne Pallier
841 221 Etienne Pallier
From src/ :
842 221 Etienne Pallier
843 221 Etienne Pallier
<pre>
844 221 Etienne Pallier
$ ./manage.py inspectdb > models.py
845 221 Etienne Pallier
</pre>
846 221 Etienne Pallier
847 221 Etienne Pallier
Issue on Mac OS X:
848 221 Etienne Pallier
<pre>
849 221 Etienne Pallier
Traceback (most recent call last):
850 221 Etienne Pallier
  File "/Users/epallier/Documents/_W_more/PROJECTS/GFT/SOFT/PYROS/pyros/venv_py35_pyros/lib/python3.5/site-packages/django/db/backends/mysql/base.py", line 25, in <module>
851 221 Etienne Pallier
    import MySQLdb as Database
852 221 Etienne Pallier
  File "/Users/epallier/Documents/_W_more/PROJECTS/GFT/SOFT/PYROS/pyros/venv_py35_pyros/lib/python3.5/site-packages/MySQLdb/__init__.py", line 19, in <module>
853 221 Etienne Pallier
    import _mysql
854 221 Etienne Pallier
ImportError: dlopen(/Users/epallier/Documents/_W_more/PROJECTS/GFT/SOFT/PYROS/pyros/venv_py35_pyros/lib/python3.5/site-packages/_mysql.cpython-35m-darwin.so, 2): Library not loaded: libmysqlclient.18.dylib
855 221 Etienne Pallier
  Referenced from: /Users/epallier/Documents/_W_more/PROJECTS/GFT/SOFT/PYROS/pyros/venv_py35_pyros/lib/python3.5/site-packages/_mysql.cpython-35m-darwin.so
856 221 Etienne Pallier
  Reason: image not found
857 221 Etienne Pallier
858 221 Etienne Pallier
=> BOUH !!!
859 221 Etienne Pallier
860 221 Etienne Pallier
LA SOLUTION EST ICI : http://stackoverflow.com/questions/6383310/python-mysqldb-library-not-loaded-libmysqlclient-18-dylib
861 221 Etienne Pallier
862 221 Etienne Pallier
Il suffit de faire ceci:
863 221 Etienne Pallier
864 221 Etienne Pallier
$ sudo mkdir -p /usr/local/lib   
865 221 Etienne Pallier
$ sudo ln -s /Applications/XAMPP/xamppfiles/lib/libmysql* /usr/local/lib/
866 221 Etienne Pallier
867 221 Etienne Pallier
Mais on peut aussi faire ceci:
868 221 Etienne Pallier
869 221 Etienne Pallier
Okay, so the offending file is /Users/epallier/Documents/_W_more/PROJECTS/GFT/SOFT/PYROS/pyros/venv_py35_pyros/lib/python3.5/site-packages/_mysql.cpython-35m-darwin.so
870 221 Etienne Pallier
871 221 Etienne Pallier
Next, figure out where _mysql.so thinks it should find libmysqlclient.18.dylib:
872 221 Etienne Pallier
873 221 Etienne Pallier
$ otool -L /Users/epallier/Documents/_W_more/PROJECTS/GFT/SOFT/PYROS/pyros/venv_py35_pyros/lib/python3.5/site-packages/_mysql.cpython-35m-darwin.so
874 221 Etienne Pallier
/Users/epallier/Documents/_W_more/PROJECTS/GFT/SOFT/PYROS/pyros/venv_py35_pyros/lib/python3.5/site-packages/_mysql.cpython-35m-darwin.so:
875 221 Etienne Pallier
	libmysqlclient.18.dylib (compatibility version 18.0.0, current version 18.0.0)
876 221 Etienne Pallier
...
877 221 Etienne Pallier
878 221 Etienne Pallier
So, it's looking for libmysqlclient.18.dylib with no path information, let's fix that:
879 221 Etienne Pallier
880 221 Etienne Pallier
$ locate libmysqlclient.18.dylib
881 221 Etienne Pallier
/Applications/XAMPP/xamppfiles/lib/libmysqlclient.18.dylib
882 221 Etienne Pallier
/Library/SystemMigration/History/Migration-68137DFB-CB6A-4FBB-81E2-11BDB5D01E48/QuarantineRoot/usr/lib/libmysqlclient.18.dylib
883 221 Etienne Pallier
884 221 Etienne Pallier
$ sudo install_name_tool -change libmysqlclient.18.dylib /Applications/XAMPP/xamppfiles/lib/libmysqlclient.18.dylib /Users/epallier/Documents/_W_more/PROJECTS/GFT/SOFT/PYROS/pyros/venv_py35_pyros/lib/python3.5/site-packages/_mysql.cpython-35m-darwin.so
885 221 Etienne Pallier
886 221 Etienne Pallier
Now _mysql.so knows the full path to the library and everything works, regardless of environment variables.
887 221 Etienne Pallier
888 221 Etienne Pallier
$ otool -L /Users/epallier/Documents/_W_more/PROJECTS/GFT/SOFT/PYROS/pyros/venv_py35_pyros/lib/python3.5/site-packages/_mysql.cpython-35m-darwin.so
889 221 Etienne Pallier
/Users/epallier/Documents/_W_more/PROJECTS/GFT/SOFT/PYROS/pyros/venv_py35_pyros/lib/python3.5/site-packages/_mysql.cpython-35m-darwin.so:
890 221 Etienne Pallier
	/Applications/XAMPP/xamppfiles/lib/libmysqlclient.18.dylib (compatibility version 18.0.0, current version 18.0.0)
891 221 Etienne Pallier
...
892 221 Etienne Pallier
893 221 Etienne Pallier
$ ./manage.py inspectdb > models.py
894 221 Etienne Pallier
895 221 Etienne Pallier
=> YES !!!
896 221 Etienne Pallier
</pre>
897 221 Etienne Pallier
898 221 Etienne Pallier
899 221 Etienne Pallier
---
900 205 Etienne Pallier
901 224 Etienne Pallier
h3. Create a Django application named "pyrosapp"
902 224 Etienne Pallier
903 224 Etienne Pallier
From src/ :
904 224 Etienne Pallier
905 224 Etienne Pallier
<pre>
906 224 Etienne Pallier
$ ./manage.py startapp pyrosapp
907 224 Etienne Pallier
</pre>
908 224 Etienne Pallier
909 224 Etienne Pallier
We obtain this structure:
910 224 Etienne Pallier
911 224 Etienne Pallier
<pre>
912 224 Etienne Pallier
913 224 Etienne Pallier
PYROS/
914 224 Etienne Pallier
├── REQUIREMENTS.txt
915 224 Etienne Pallier
├── private/
916 224 Etienne Pallier
│   └── venv_py35_pyros/
917 224 Etienne Pallier
├── public/
918 224 Etienne Pallier
│   └── static/
919 224 Etienne Pallier
├── src/
920 224 Etienne Pallier
│   ├── manage.py
921 224 Etienne Pallier
│   ├── pyros/
922 224 Etienne Pallier
│   │   ├── __init__.py
923 224 Etienne Pallier
│   │   ├── __pycache__
924 224 Etienne Pallier
│   │   ├── settings.py
925 224 Etienne Pallier
│   │   ├── urls.py
926 224 Etienne Pallier
│   │   └── wsgi.py
927 224 Etienne Pallier
│   └── pyrosapp/
928 224 Etienne Pallier
│       ├── __init__.py
929 224 Etienne Pallier
│       ├── admin.py
930 224 Etienne Pallier
│       ├── apps.py
931 224 Etienne Pallier
│       ├── migrations
932 224 Etienne Pallier
│       ├── models.py
933 224 Etienne Pallier
│       ├── tests.py
934 224 Etienne Pallier
│       └── views.py
935 224 Etienne Pallier
936 224 Etienne Pallier
937 224 Etienne Pallier
</pre>
938 224 Etienne Pallier
939 224 Etienne Pallier
---
940 205 Etienne Pallier
941 205 Etienne Pallier
h3. Replace the default pyrosapp models.py with the inspectdb generated one
942 205 Etienne Pallier
943 205 Etienne Pallier
h3. Fix and improve the pyrosapp models.py file (generated by inspectdb)
944 205 Etienne Pallier
945 201 Etienne Pallier
h3. Set Requirements
946 201 Etienne Pallier
947 201 Etienne Pallier
<pre>
948 201 Etienne Pallier
$ pip freeze > REQUIREMENTS.txt
949 201 Etienne Pallier
</pre>
950 182 Etienne Pallier
951 182 Etienne Pallier
952 1 Etienne Pallier
---
953 203 Etienne Pallier
954 203 Etienne Pallier
h3. Initialize the git repository
955 203 Etienne Pallier
956 203 Etienne Pallier
*Git global setup:*
957 203 Etienne Pallier
958 203 Etienne Pallier
<pre>
959 203 Etienne Pallier
$ git config --global user.name "Etienne Pallier"
960 203 Etienne Pallier
$ git config --global user.email "etienne.pallier@irap.omp.eu"
961 203 Etienne Pallier
962 203 Etienne Pallier
$ cat ~/.gitconfig 
963 203 Etienne Pallier
[user]
964 203 Etienne Pallier
	name = Etienne Pallier
965 203 Etienne Pallier
	email = epallier@irap.omp.eu
966 203 Etienne Pallier
[http]
967 203 Etienne Pallier
	sslVerify = false
968 203 Etienne Pallier
</pre>
969 203 Etienne Pallier
970 203 Etienne Pallier
971 203 Etienne Pallier
*Create a new repository:*
972 203 Etienne Pallier
973 203 Etienne Pallier
<pre>
974 203 Etienne Pallier
$ cd PYROS/
975 203 Etienne Pallier
976 203 Etienne Pallier
Define files and folders to be ignored:
977 203 Etienne Pallier
$ vi .gitignore
978 203 Etienne Pallier
.DS_Store
979 203 Etienne Pallier
private
980 203 Etienne Pallier
__pycache__
981 203 Etienne Pallier
982 203 Etienne Pallier
$ touch README.md
983 203 Etienne Pallier
984 203 Etienne Pallier
$ git add README.md
985 203 Etienne Pallier
986 203 Etienne Pallier
$ git commit -m "first commit"
987 203 Etienne Pallier
988 203 Etienne Pallier
$ git remote add origin https://gitlab.irap.omp.eu/epallier/pyros.git
989 203 Etienne Pallier
990 203 Etienne Pallier
$ git push -u origin master
991 203 Etienne Pallier
992 203 Etienne Pallier
$ git add .
993 203 Etienne Pallier
994 203 Etienne Pallier
( if you want to be sure to add ALL files: 
995 203 Etienne Pallier
$ git add -A
996 203 Etienne Pallier
)
997 203 Etienne Pallier
998 203 Etienne Pallier
( if you wanted to remove added files, just type:
999 203 Etienne Pallier
$ git reset HEAD
1000 203 Etienne Pallier
)
1001 203 Etienne Pallier
1002 203 Etienne Pallier
$ git commit -m "first full project commit"
1003 203 Etienne Pallier
1004 203 Etienne Pallier
$ git push -u origin master
1005 203 Etienne Pallier
Counting objects: 43, done.
1006 203 Etienne Pallier
Delta compression using up to 4 threads.
1007 203 Etienne Pallier
Compressing objects: 100% (41/41), done.
1008 203 Etienne Pallier
Writing objects: 100% (43/43), 575.13 KiB ö 0 bytes/s, done.
1009 203 Etienne Pallier
Total 43 (delta 2), reused 0 (delta 0)
1010 203 Etienne Pallier
To https://gitlab.irap.omp.eu/epallier/pyros.git
1011 203 Etienne Pallier
   9c7128c..64501c9  master -> master
1012 203 Etienne Pallier
Branch master set up to track remote branch master from origin.
1013 203 Etienne Pallier
1014 203 Etienne Pallier
$ git status
1015 203 Etienne Pallier
On branch master
1016 203 Etienne Pallier
Your branch is up-to-date with 'origin/master'.
1017 203 Etienne Pallier
nothing to commit, working directory clean
1018 203 Etienne Pallier
1019 203 Etienne Pallier
</pre>