| author | ymh <ymh.work@gmail.com> |
| Wed, 11 Apr 2018 12:19:47 +0200 | |
| branch | documentation |
| changeset 693 | 09e00f38d177 |
| parent 686 | 385e3a12ee27 |
| permissions | -rw-r--r-- |
| 135 | 1 |
# -*- coding: utf-8 -*- |
2 |
''' |
|
| 693 | 3 |
Cette commande transforme une base de donnée hdabo en base de donnée hdalab. |
4 |
En particulier cette command est utilisée dans l'import de l'extraction rdf des données HDA. |
|
5 |
||
6 |
Cette commande enchaine en fait les commandes Django suivantes: |
|
| 135 | 7 |
|
| 693 | 8 |
- `migrate <https://docs.djangoproject.com/en/1.8/ref/django-admin/#django-admin-migrate>`_ |
9 |
- :mod:`query_wikipedia_category \-f \-\-all <hdalab.management.commands.query_wikipedia_category>` (si l'option est passée) |
|
10 |
- :mod:`query_dbpedia \-f \-\-all <hdalab.management.commands.query_dbpedia>` |
|
11 |
- :mod:`fill_tag_years <hdalab.management.commands.fill_tag_years>` |
|
12 |
- :mod:`geojson_transform \<chemin répertoire data\>/countries.geo.json <hdalab.management.commands.geojson_transform>` |
|
13 |
- :mod:`query_geo_inclusion <hdalab.management.commands.query_geo_inclusion>` |
|
14 |
- :mod:`import_insee_csv \<chemin répertoire data\>/villes.csv <hdalab.management.commands.import_insee_csv>` |
|
15 |
- :mod:`import_insee_csv \<chemin répertoire data\>/additional_cities.csv <hdalab.management.commands.import_insee_csv>` |
|
16 |
- :mod:`import_hda_insee_csv \<chemin répertoire data\>/HDA_Insee.csv <hdalab.management.commands.import_hda_insee_csv>` |
|
17 |
- :mod:`query_category_inclusion \-f \-\-all <hdalab.management.commands.query_category_inclusion>` |
|
18 |
||
19 |
**Usage**: ``django-admin import_hdabo_db [options] [<chemin répertoire data>]`` |
|
20 |
||
21 |
**Options spécifiques:** |
|
22 |
||
23 |
- *\-c,\-\-categories*: ajoute la commande :mod:`query_wikipedia_category \-f \-\-all <hdalab.management.commands.query_wikipedia_category>` à la chaîne de traitements. |
|
24 |
||
| 135 | 25 |
''' |
26 |
from django.core.management.base import BaseCommand |
|
27 |
from django.core.management import call_command |
|
28 |
from optparse import make_option |
|
29 |
import os.path |
|
30 |
||
31 |
||
32 |
class Command(BaseCommand): |
|
33 |
||
34 |
args = "[<path to the data folder>]" |
|
35 |
option_list = BaseCommand.option_list + ( |
|
36 |
make_option('-c', '--categories', |
|
37 |
action='store_true', |
|
38 |
dest='categories', |
|
39 |
default=False, |
|
40 |
help='load categories in db'), |
|
41 |
) |
|
42 |
||
43 |
||
|
686
385e3a12ee27
Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
571
diff
changeset
|
44 |
def handle(self, *args, **options): |
|
385e3a12ee27
Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
571
diff
changeset
|
45 |
|
| 135 | 46 |
if len(args) == 0: |
| 284 | 47 |
data_path = os.path.abspath(os.path.join(os.path.abspath(__file__),'../../../../../data')) |
| 135 | 48 |
else: |
49 |
data_path = args[0] |
|
|
686
385e3a12ee27
Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
571
diff
changeset
|
50 |
|
| 228 | 51 |
print("=========== MIGRATE ===========") |
|
571
d9642be7c937
replace commit_on_success with atomic
ymh <ymh.work@gmail.com>
parents:
443
diff
changeset
|
52 |
call_command('migrate') |
| 135 | 53 |
if options.get('categories', False): |
| 228 | 54 |
print("=========== QUERY WIKIPEDIA CATEGORY ===========") |
| 443 | 55 |
call_command('query_wikipedia_category', interactive=False, force=True, all=True) |
| 228 | 56 |
|
|
686
385e3a12ee27
Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
571
diff
changeset
|
57 |
print("=========== QUERY DBPEDIA ===========") |
| 443 | 58 |
call_command('query_dbpedia', interactive=False, force=True, all=True) |
| 228 | 59 |
print("=========== FILL TAG YEAR ===========") |
| 135 | 60 |
call_command('fill_tag_years') |
| 228 | 61 |
print("=========== GEOJSON TRANSFORM ===========") |
|
227
b0cd3e6e31c7
Update readmin on hdabo -> hdalab migration and update import_hdabo_db management commend
ymh <ymh.work@gmail.com>
parents:
152
diff
changeset
|
62 |
call_command('geojson_transform', os.path.join(data_path,'countries.geo.json')) |
| 228 | 63 |
print("=========== QUERY GEO INCLUSION ===========") |
| 152 | 64 |
call_command('query_geo_inclusion') |
| 228 | 65 |
print("=========== IMPORT INSEE CSV PASS 1 ===========") |
| 135 | 66 |
call_command('import_insee_csv', os.path.join(data_path,'villes.csv')) |
| 228 | 67 |
print("=========== IMPORT INSEE CSV PASS 2 ===========") |
| 135 | 68 |
call_command('import_insee_csv', os.path.join(data_path,'additional_cities.csv')) |
| 228 | 69 |
print("=========== IMPORT HDA INSEE CSV ===========") |
| 152 | 70 |
call_command('import_hda_insee_csv', os.path.join(data_path,'HDA_Insee.csv')) |
| 228 | 71 |
print("=========== QUERY CATEGORY INCLUSION ===========") |
| 230 | 72 |
call_command('query_category_inclusion', all=True, force=True, interactive=False) |
|
686
385e3a12ee27
Containerization and various corrections to make it work
ymh <ymh.work@gmail.com>
parents:
571
diff
changeset
|
73 |