Wiki

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