| author | ymh <ymh.work@gmail.com> |
| Sat, 31 Aug 2013 19:20:46 +0200 | |
| changeset 14 | 52fa6990e0bb |
| parent 13 | 6296aa12fd71 |
| child 22 | 48ff361f96c8 |
| permissions | -rw-r--r-- |
| 0 | 1 |
# -*- coding: utf-8 -*- |
2 |
||
| 6 | 3 |
from django.core.management import BaseCommand |
4 |
from django.db import reset_queries, transaction |
|
5 |
from optparse import make_option |
|
6 |
from p4l.models import Record, Language |
|
|
13
6296aa12fd71
model simplification, correct import on language. We do not try to impose a language when none is found. add forgotten abstract field on import.
ymh <ymh.work@gmail.com>
parents:
7
diff
changeset
|
7 |
from p4l.utils import show_progress |
| 0 | 8 |
from rdflib import Graph, Namespace, BNode, URIRef |
9 |
from rdflib.plugins.sparql import prepareQuery |
|
| 6 | 10 |
import logging |
| 0 | 11 |
import xml.etree.cElementTree as ET |
12 |
||
13 |
logger = logging.getLogger(__name__) |
|
14 |
||
15 |
||
16 |
RDF = Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#") |
|
17 |
RDFS = Namespace("http://www.w3.org/2000/01/rdf-schema#") |
|
18 |
DCT = Namespace("http://purl.org/dc/terms/") |
|
19 |
IIEP = Namespace("http://www.iiep.unesco.org/plan4learning/model.owl#") |
|
20 |
UNESCO = Namespace("http://www.iiep.unesco.org/Ontology/") |
|
21 |
||
22 |
DEFAULT_LANGUAGE_URI = "http://psi.oasis-open.org/iso/639/#eng" |
|
23 |
||
24 |
DEFAULT_LANGUAGE_QUERY = """SELECT ( COALESCE(?lang, ?other_lang) as ?main_lang) WHERE { |
|
25 |
OPTIONAL { ?s dct:language ?lang }. |
|
26 |
OPTIONAL { ?s iiep:otherLanguage ?other_lang }. |
|
27 |
}""" |
|
28 |
||
29 |
||
30 |
class Command(BaseCommand): |
|
31 |
||
32 |
args = "record_url ..." |
|
33 |
||
34 |
help = "Import p4l record rdf format" |
|
35 |
||
36 |
option_list = BaseCommand.option_list + ( |
|
37 |
make_option('-b', '--batch-size', |
|
38 |
dest= 'batch_size', |
|
39 |
type='int', |
|
40 |
default= 50, |
|
41 |
help= 'number of object to import in bulk operations' |
|
42 |
), |
|
43 |
) |
|
44 |
||
45 |
def __init__(self, *args, **kwargs): |
|
46 |
super(Command, self).__init__(*args, **kwargs) |
|
47 |
self.__query_cache = {} |
|
48 |
||
49 |
||
50 |
def __get_sparql_query(self, query, namespaces): |
|
51 |
||
52 |
return self.__query_cache[query] \ |
|
53 |
if query in self.__query_cache \ |
|
54 |
else self.__query_cache.setdefault(query, prepareQuery(query, initNs=namespaces)) |
|
55 |
||
56 |
def get_empty_graph(self): |
|
57 |
record_graph = Graph() |
|
58 |
record_graph.bind('iiep',"http://www.iiep.unesco.org/plan4learning/model.owl#") |
|
59 |
record_graph.bind('dct',"http://purl.org/dc/terms/") |
|
60 |
return record_graph |
|
61 |
||
62 |
def extract_single_value_form_graph(self, graph, q, bindings={}, index=0, convert=lambda v:unicode(v) if v is not None else None): |
|
63 |
return next(self.extract_multiple_values_from_graph(graph, q, bindings, index, convert), None) |
|
64 |
||
65 |
def extract_multiple_values_from_graph(self, graph, q, bindings={}, index=0, convert=lambda v:unicode(v) if v is not None else None): |
|
66 |
||
67 |
index_list = index |
|
68 |
if isinstance(index, int): |
|
69 |
index_list = range(index+1) |
|
70 |
||
71 |
if hasattr(convert, '__call__'): |
|
72 |
convert_dict = dict((k, convert) for k in index_list) |
|
73 |
else: |
|
74 |
convert_dict = convert |
|
75 |
||
76 |
convert_dict = dict((k, f if hasattr(f,'__call__') else lambda v:unicode(v) if v is not None else None) for k,f in convert_dict.iteritems()) |
|
77 |
||
78 |
for row in graph.query(self.__get_sparql_query(q, dict(graph.namespaces())), initBindings=bindings): |
|
79 |
if len(row) < len(index_list): |
|
80 |
break |
|
81 |
else: |
|
82 |
res = dict([ (k, convert_dict.get(k, lambda v:unicode(v) if v is not None else None)(v)) for k, v in zip(index_list, row)]) |
|
83 |
if isinstance(index, int): |
|
84 |
yield res[index] |
|
85 |
else: |
|
86 |
yield res |
|
87 |
||
88 |
||
89 |
def convert_bool(self, val): |
|
90 |
if val == True or val == False: |
|
91 |
return val |
|
92 |
if val is None: |
|
93 |
return False |
|
94 |
if isinstance(val, basestring): |
|
95 |
if len(val) == 0: |
|
96 |
return False |
|
97 |
if val[0].lower() in ['t','y','1','o']: |
|
98 |
return True |
|
99 |
else: |
|
100 |
return False |
|
101 |
return bool(val) |
|
102 |
||
103 |
||
104 |
def add_to_related_collection(self, coll, graph, fields, q, bindings={}, convert=lambda v: unicode(v) if v is not None else None, through_fields=None): |
|
105 |
||
106 |
for val in self.extract_multiple_values_from_graph(graph, q, bindings=bindings, index=fields, convert=convert): |
|
107 |
||
108 |
if through_fields: |
|
109 |
new_obj_val = dict([(k,v) for k,v in val.iteritems() if k not in through_fields]) |
|
110 |
else: |
|
111 |
new_obj_val = val |
|
112 |
||
113 |
if hasattr(coll, 'through'): |
|
114 |
new_obj_rel, _ = coll.model.objects.get_or_create(**new_obj_val) |
|
115 |
if through_fields: |
|
116 |
through_vals = {coll.source_field_name: coll.instance, coll.target_field_name: new_obj_rel} |
|
117 |
through_vals.update(dict([(k,v) for k,v in val.iteritems() if k in through_fields])) |
|
118 |
coll.through.objects.create(**through_vals) |
|
119 |
new_obj = None |
|
120 |
else: |
|
121 |
new_obj = new_obj_rel |
|
122 |
||
123 |
else: |
|
124 |
new_obj = coll.create(**new_obj_val) |
|
125 |
||
126 |
if new_obj: |
|
127 |
coll.add(new_obj) |
|
128 |
||
129 |
||
130 |
||
131 |
||
132 |
def build_record(self, graph): |
|
133 |
||
134 |
record_uri = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?s WHERE { ?s rdf:type iiep:Record .}") |
|
135 |
||
136 |
record = Record() |
|
137 |
record.uri = record_uri |
|
138 |
record.identifier = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s dct:identifier ?o .}", bindings={'s':URIRef(record.uri)}) |
|
139 |
record.notes = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s iiep:notes ?o .}", bindings={'s':URIRef(record.uri)}) |
|
140 |
record.recordType = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s dct:type ?o .}", bindings={'s':URIRef(record.uri)}) |
|
141 |
record.isDocumentPart = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s iiep:isDocumentPart ?o .}", bindings={'s':URIRef(record.uri)}, convert=self.convert_bool) |
|
|
14
52fa6990e0bb
adapt model to new rdf serialization
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
142 |
record.isMultilingual = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s iiep:isMultilingual ?o .}", bindings={'s':URIRef(record.uri)}, convert=self.convert_bool) |
| 0 | 143 |
record.editionStatement = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s iiep:editionStatement ?o .}", bindings={'s':URIRef(record.uri)}) |
144 |
||
145 |
language = self.extract_single_value_form_graph(graph,"SELECT DISTINCT ?o WHERE { ?s dct:language ?o .}", bindings={'s':URIRef(record.uri)}) |
|
146 |
if language: |
|
|
14
52fa6990e0bb
adapt model to new rdf serialization
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
147 |
record.language, _ = Language.objects.get_or_create(uri=language) |
| 0 | 148 |
|
149 |
record.save() |
|
150 |
||
|
14
52fa6990e0bb
adapt model to new rdf serialization
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
151 |
self.add_to_related_collection(record.otherLanguages, graph, ['uri'], "SELECT ?o WHERE { ?s iiep:otherLanguage ?o .}", bindings={'s':URIRef(record.uri)}) |
|
52fa6990e0bb
adapt model to new rdf serialization
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
152 |
self.add_to_related_collection(record.subjects, graph, ['uri'], "SELECT ?o WHERE { ?s dct:subject ?o .}", bindings={'s':URIRef(record.uri)}) |
|
52fa6990e0bb
adapt model to new rdf serialization
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
153 |
self.add_to_related_collection(record.themes, graph, ['uri'], "SELECT ?o WHERE { ?s iiep:theme ?o .}", bindings={'s':URIRef(record.uri)}) |
|
52fa6990e0bb
adapt model to new rdf serialization
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
154 |
self.add_to_related_collection(record.countries, graph, ['uri'], "SELECT ?o WHERE { ?s iiep:country ?o .}", bindings={'s':URIRef(record.uri)}) |
| 0 | 155 |
self.add_to_related_collection(record.authors, graph, ['name'], "SELECT ?o WHERE { ?s iiep:author ?o .}", bindings={'s':URIRef(record.uri)}) |
156 |
self.add_to_related_collection(record.subjectPersons, graph, ['name'], "SELECT ?o WHERE { ?s iiep:subjectPerson ?o .}", bindings={'s':URIRef(record.uri)}) |
|
|
14
52fa6990e0bb
adapt model to new rdf serialization
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
157 |
self.add_to_related_collection(record.projectNames, graph, ['uri'], "SELECT ?o WHERE { ?s iiep:projectName ?o . }") |
| 0 | 158 |
|
159 |
self.add_to_related_collection( |
|
160 |
record.periodicals, |
|
161 |
graph, |
|
162 |
['label','lang'], |
|
163 |
"SELECT DISTINCT ?o ( lang(?o) as ?l) WHERE { ?s iiep:periodical ?o .}", |
|
164 |
bindings={'s':URIRef(record.uri)}, |
|
165 |
through_fields = ['lang'] |
|
166 |
) |
|
167 |
||
168 |
self.add_to_related_collection( |
|
169 |
record.meetings, |
|
170 |
graph, |
|
171 |
['label', 'meetingNumber', 'meetingPlace', 'meetingDate', 'meetingYear', 'lang'], |
|
172 |
"SELECT ?l ?mn ?mp ?md ?my (lang(COALESCE(?l,?nm, ?mp,?md,?my)) as ?lang) WHERE { [iiep:meeting ?bnode]. OPTIONAL { ?bnode rdfs:label ?l }. OPTIONAL { ?bnode iiep:meetingNumber ?mn }. OPTIONAL { ?bnode iiep:meetingPlace ?mp }. OPTIONAL { ?bnode iiep:meetingDate ?md }. OPTIONAL { ?bnode iiep:meetingYear ?my }}", |
|
|
13
6296aa12fd71
model simplification, correct import on language. We do not try to impose a language when none is found. add forgotten abstract field on import.
ymh <ymh.work@gmail.com>
parents:
7
diff
changeset
|
173 |
convert={'meetingYear' : lambda y: int(y) if y is not None else None}, |
| 0 | 174 |
through_fields = ['lang'] |
175 |
) |
|
176 |
||
177 |
self.add_to_related_collection( |
|
178 |
record.series, |
|
179 |
graph, |
|
180 |
['title', 'volume', 'lang'], |
|
181 |
"SELECT ?t ?vol (lang(COALESCE(?t,?vol)) as ?lang) WHERE { [iiep:serie ?bnode]. OPTIONAL { ?bnode dct:title ?t }. OPTIONAL { ?bnode iiep:volume ?vol } }", |
|
182 |
through_fields = ['lang'] |
|
183 |
) |
|
184 |
||
185 |
self.add_to_related_collection( |
|
186 |
record.subjectCorporateBodies, |
|
187 |
graph, |
|
|
14
52fa6990e0bb
adapt model to new rdf serialization
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
188 |
['uri'], |
|
52fa6990e0bb
adapt model to new rdf serialization
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
189 |
"SELECT ?o WHERE { ?s iiep:subjectCorporateBody ?o. }", |
|
52fa6990e0bb
adapt model to new rdf serialization
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
190 |
bindings={'s':URIRef(record.uri)} |
| 0 | 191 |
) |
192 |
||
193 |
self.add_to_related_collection( |
|
194 |
record.subjectMeetings, |
|
195 |
graph, |
|
196 |
['label', 'meetingNumber', 'meetingPlace', 'meetingDate', 'meetingYear'], |
|
| 7 | 197 |
"SELECT ?l ?mn ?mp ?md ?my WHERE { [iiep:subjectMeeting ?bnode]. OPTIONAL { ?bnode rdfs:label ?l }. OPTIONAL { ?bnode iiep:meetingNumber ?mn }. OPTIONAL { ?bnode iiep:meetingPlace ?mp }. OPTIONAL { ?bnode iiep:meetingDate ?md }. OPTIONAL { ?bnode iiep:meetingYear ?my }}", |
| 0 | 198 |
convert={'meetingYear' : lambda y: int(y) if y is not None else None} |
199 |
) |
|
200 |
||
201 |
self.add_to_related_collection( |
|
202 |
record.corporateAuthors, |
|
203 |
graph, |
|
|
14
52fa6990e0bb
adapt model to new rdf serialization
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
204 |
['uri'], |
|
52fa6990e0bb
adapt model to new rdf serialization
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
205 |
"SELECT ?o WHERE { ?s iiep:corporateAuthor ?o.}", |
|
52fa6990e0bb
adapt model to new rdf serialization
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
206 |
bindings={'s':URIRef(record.uri)} |
| 0 | 207 |
) |
208 |
||
209 |
self.add_to_related_collection( |
|
210 |
record.issns, |
|
211 |
graph, |
|
212 |
['issn', 'lang'], |
|
213 |
"SELECT ?issn (lang(COALESCE(?issn)) as ?lang) WHERE { ?s iiep:issn ?issn . }", |
|
214 |
bindings={'s':URIRef(record.uri)}, |
|
215 |
) |
|
216 |
||
217 |
self.add_to_related_collection( |
|
218 |
record.isbns, |
|
219 |
graph, |
|
220 |
['isbn', 'lang'], |
|
221 |
"SELECT ?isbn (lang(COALESCE(?isbn)) as ?lang) WHERE { ?s iiep:isbn ?isbn . }", |
|
222 |
bindings={'s':URIRef(record.uri)}, |
|
223 |
) |
|
224 |
||
225 |
self.add_to_related_collection( |
|
226 |
record.documentCodes, |
|
227 |
graph, |
|
228 |
['documentCode', 'lang'], |
|
229 |
"SELECT ?c (lang(COALESCE(?c)) as ?lang) WHERE { ?s iiep:documentCode ?c . }", |
|
230 |
bindings={'s':URIRef(record.uri)}, |
|
231 |
) |
|
232 |
||
233 |
self.add_to_related_collection( |
|
234 |
record.titles, |
|
235 |
graph, |
|
236 |
['title', 'lang'], |
|
237 |
"SELECT ?t (lang(COALESCE(?t)) as ?lang) WHERE { ?s dct:title ?t . }", |
|
238 |
bindings={'s':URIRef(record.uri)}, |
|
|
13
6296aa12fd71
model simplification, correct import on language. We do not try to impose a language when none is found. add forgotten abstract field on import.
ymh <ymh.work@gmail.com>
parents:
7
diff
changeset
|
239 |
) |
|
6296aa12fd71
model simplification, correct import on language. We do not try to impose a language when none is found. add forgotten abstract field on import.
ymh <ymh.work@gmail.com>
parents:
7
diff
changeset
|
240 |
|
|
6296aa12fd71
model simplification, correct import on language. We do not try to impose a language when none is found. add forgotten abstract field on import.
ymh <ymh.work@gmail.com>
parents:
7
diff
changeset
|
241 |
self.add_to_related_collection( |
|
6296aa12fd71
model simplification, correct import on language. We do not try to impose a language when none is found. add forgotten abstract field on import.
ymh <ymh.work@gmail.com>
parents:
7
diff
changeset
|
242 |
record.abstracts, |
|
6296aa12fd71
model simplification, correct import on language. We do not try to impose a language when none is found. add forgotten abstract field on import.
ymh <ymh.work@gmail.com>
parents:
7
diff
changeset
|
243 |
graph, |
|
6296aa12fd71
model simplification, correct import on language. We do not try to impose a language when none is found. add forgotten abstract field on import.
ymh <ymh.work@gmail.com>
parents:
7
diff
changeset
|
244 |
['abstract', 'lang'], |
|
6296aa12fd71
model simplification, correct import on language. We do not try to impose a language when none is found. add forgotten abstract field on import.
ymh <ymh.work@gmail.com>
parents:
7
diff
changeset
|
245 |
"SELECT ?t (lang(COALESCE(?t)) as ?lang) WHERE { ?s dct:abstract ?t . }", |
|
6296aa12fd71
model simplification, correct import on language. We do not try to impose a language when none is found. add forgotten abstract field on import.
ymh <ymh.work@gmail.com>
parents:
7
diff
changeset
|
246 |
bindings={'s':URIRef(record.uri)}, |
| 0 | 247 |
) |
248 |
||
249 |
self.add_to_related_collection( |
|
250 |
record.addedTitles, |
|
251 |
graph, |
|
252 |
['title', 'lang'], |
|
253 |
"SELECT ?t (lang(COALESCE(?t)) as ?lang) WHERE { ?s iiep:addedTitle ?t . }", |
|
254 |
bindings={'s':URIRef(record.uri)}, |
|
255 |
) |
|
256 |
||
257 |
self.add_to_related_collection( |
|
258 |
record.titlesMainDocument, |
|
259 |
graph, |
|
260 |
['title', 'lang'], |
|
261 |
"SELECT ?t (lang(COALESCE(?t)) as ?lang) WHERE { ?s iiep:titleMainDocument ?t . }", |
|
262 |
bindings={'s':URIRef(record.uri)}, |
|
263 |
) |
|
264 |
||
265 |
self.add_to_related_collection( |
|
266 |
record.imprints, |
|
267 |
graph, |
|
268 |
['imprintCity', 'publisher', 'imprintDate', 'lang'], |
|
269 |
"SELECT ?c ?p ?d (lang(COALESCE(?c, ?p, ?d)) as ?lang) WHERE { [ iiep:imprint ?bnode ]. OPTIONAL { ?bnode iiep:imprintCity ?c }. OPTIONAL { ?bnode dct:publisher ?p }. OPTIONAL { ?bnode iiep:imprintDate ?d }}", |
|
270 |
) |
|
271 |
||
272 |
self.add_to_related_collection( |
|
273 |
record.collations, |
|
274 |
graph, |
|
275 |
['collation', 'lang'], |
|
276 |
"SELECT ?c (lang(COALESCE(?c)) as ?lang) WHERE { ?s iiep:collation ?c . }", |
|
277 |
bindings={'s':URIRef(record.uri)}, |
|
278 |
) |
|
279 |
||
280 |
self.add_to_related_collection( |
|
281 |
record.volumeIssues, |
|
282 |
graph, |
|
283 |
['volume', 'number', 'lang'], |
|
| 6 | 284 |
"SELECT ?v ?n (lang(COALESCE(?v, ?n)) as ?lang) WHERE { [ iiep:volumeIssue ?bnode ]. OPTIONAL { ?bnode iiep:volume ?v }. OPTIONAL { ?bnode iiep:number ?n }}", |
| 0 | 285 |
) |
286 |
||
287 |
self.add_to_related_collection( |
|
288 |
record.urls, |
|
289 |
graph, |
|
290 |
['address', 'display', 'accessLevel'], |
|
291 |
"SELECT ?a ?d ?al WHERE { [ iiep:url ?bnode ]. OPTIONAL { ?bnode iiep:address ?a }. OPTIONAL { ?bnode iiep:display ?d }. OPTIONAL { ?bnode iiep:accessLevel ?al }.}", |
|
292 |
) |
|
293 |
||
294 |
return record |
|
295 |
||
296 |
||
297 |
def filter_node(self, node, graph, res_graph): |
|
298 |
for p,o in graph[node]: |
|
299 |
res_graph.add((node,p,o)) |
|
300 |
if isinstance(o, BNode): |
|
301 |
self.filter_node(o, graph, res_graph) |
|
302 |
||
303 |
||
304 |
||
305 |
def calculate_records_nb(self, records_url): |
|
306 |
context = ET.iterparse(records_url, events=("end",)) |
|
307 |
i = 0 |
|
308 |
for _,elem in context: |
|
309 |
if elem.tag == "{%s}Record" % IIEP: |
|
310 |
i += 1 |
|
311 |
return i |
|
312 |
||
313 |
def process_url(self, records_url, options): |
|
314 |
||
315 |
total_records = self.calculate_records_nb(records_url) |
|
316 |
writer = None |
|
317 |
errors=[] |
|
318 |
||
319 |
context = ET.iterparse(records_url, events=("end",)) |
|
320 |
i = 0 |
|
| 6 | 321 |
for _,elem in context: |
| 0 | 322 |
if elem.tag == "{%s}Record" % IIEP: |
323 |
i += 1 |
|
324 |
writer = show_progress(i, total_records, "Processing record nb %d " % i, 50, writer=writer) |
|
325 |
try: |
|
326 |
record_graph = self.get_empty_graph() |
|
327 |
record_graph.parse(data=ET.tostring(elem, encoding='utf-8'), format='xml') |
|
328 |
# add transaction management |
|
329 |
self.build_record(record_graph) |
|
330 |
except Exception as e: |
|
331 |
transaction.rollback() |
|
332 |
msg = "Error processing resource %d in %s : %s" % (i, records_url, repr(e)) |
|
333 |
logger.exception(msg) |
|
334 |
errors.append((i, records_url, msg)) |
|
335 |
else: |
|
336 |
transaction.commit() |
|
337 |
||
338 |
if i%self.batch_size == 0: |
|
339 |
reset_queries() |
|
340 |
||
341 |
return errors |
|
342 |
||
343 |
||
344 |
# def process_url(self, records_url, options): |
|
345 |
# #open graph with rdflib |
|
|
13
6296aa12fd71
model simplification, correct import on language. We do not try to impose a language when none is found. add forgotten abstract field on import.
ymh <ymh.work@gmail.com>
parents:
7
diff
changeset
|
346 |
# |
| 0 | 347 |
# g = Graph() |
348 |
# print("Loading %s" % records_url) |
|
349 |
# g.parse(records_url) |
|
350 |
# print("Parsing %s done" % records_url) |
|
351 |
# for i,record_uri in enumerate(g[:RDF.type:IIEP.Record]): |
|
352 |
# print(i, repr(record_uri)) |
|
353 |
# record_graph = self.get_empty_graph() |
|
354 |
# self.filter_node(record_uri, g, record_graph) |
|
355 |
# self.build_record(record_graph) |
|
356 |
# if i > 3: |
|
357 |
# break |
|
358 |
||
359 |
||
360 |
||
361 |
||
362 |
def handle(self, *args, **options): |
|
363 |
||
364 |
self.batch_size = options.get('batch_size', 50) |
|
365 |
transaction.enter_transaction_management() |
|
366 |
transaction.managed(True) |
|
367 |
||
368 |
for records_url in args: |
|
369 |
print("Processing %s" % records_url) |
|
370 |
errors = self.process_url(records_url, options) |
|
371 |
print("Processing %s Done" % records_url) |
|
372 |
if errors: |
|
373 |
print("%d error(s) when processing %s, check your log file." % (len(errors), records_url)) |
|
374 |
||
375 |
transaction.leave_transaction_management() |
|
376 |