Wiki

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