equal
deleted
inserted
replaced
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
18 """datafeed parser for xml generated by cubicweb""" |
18 """datafeed parser for xml generated by cubicweb""" |
19 |
19 |
20 import urllib2 |
20 import urllib2 |
21 import StringIO |
21 import StringIO |
|
22 import os.path as osp |
22 from cookielib import CookieJar |
23 from cookielib import CookieJar |
23 from datetime import datetime, timedelta |
24 from datetime import datetime, timedelta |
24 |
25 |
25 from lxml import etree |
26 from lxml import etree |
26 |
27 |
191 |
192 |
192 def parse(self, url): |
193 def parse(self, url): |
193 if not url.startswith('http'): |
194 if not url.startswith('http'): |
194 stream = StringIO.StringIO(url) |
195 stream = StringIO.StringIO(url) |
195 else: |
196 else: |
|
197 for mappedurl in HOST_MAPPING: |
|
198 if url.startswith(mappedurl): |
|
199 url = url.replace(mappedurl, HOST_MAPPING[mappedurl], 1) |
|
200 break |
196 self.source.info('GET %s', url) |
201 self.source.info('GET %s', url) |
197 stream = _OPENER.open(url) |
202 stream = _OPENER.open(url) |
198 return _entity_etree(etree.parse(stream).getroot()) |
203 return _entity_etree(etree.parse(stream).getroot()) |
199 |
204 |
200 def process_one(self, url): |
205 def process_one(self, url): |
332 if role == 'object': |
337 if role == 'object': |
333 rql = 'SET %s, Y eid IN (%s), NOT Y %s X' % (rql, eidstr, rtype) |
338 rql = 'SET %s, Y eid IN (%s), NOT Y %s X' % (rql, eidstr, rtype) |
334 else: |
339 else: |
335 rql = 'SET %s, Y eid IN (%s), NOT X %s Y' % (rql, eidstr, rtype) |
340 rql = 'SET %s, Y eid IN (%s), NOT X %s Y' % (rql, eidstr, rtype) |
336 self._cw.execute(rql, {'x': entity.eid}) |
341 self._cw.execute(rql, {'x': entity.eid}) |
|
342 |
|
343 def registration_callback(vreg): |
|
344 global HOST_MAPPING |
|
345 vreg.register_all(globals().values(), __name__) |
|
346 host_mapping_file = osp.join(vreg.config.apphome, 'hostmapping.py') |
|
347 if osp.exists(host_mapping_file): |
|
348 HOST_MAPPING = eval(file(host_mapping_file).read()) |
|
349 vreg.info('using host mapping %s from %s', HOST_MAPPING, host_mapping_file) |
|
350 else: |
|
351 HOST_MAPPING = {} |