79 'help': ('Time before logs from datafeed imports are deleted.'), |
79 'help': ('Time before logs from datafeed imports are deleted.'), |
80 'group': 'datafeed-source', 'level': 2, |
80 'group': 'datafeed-source', 'level': 2, |
81 }), |
81 }), |
82 ) |
82 ) |
83 |
83 |
84 def __init__(self, repo, source_config, eid=None): |
|
85 AbstractSource.__init__(self, repo, source_config, eid) |
|
86 self.update_config(None, self.check_conf_dict(eid, source_config, |
|
87 fail_if_unknown=False)) |
|
88 |
|
89 def check_config(self, source_entity): |
84 def check_config(self, source_entity): |
90 """check configuration of source entity""" |
85 """check configuration of source entity""" |
91 typedconfig = super(DataFeedSource, self).check_config(source_entity) |
86 typed_config = super(DataFeedSource, self).check_config(source_entity) |
92 if typedconfig['synchronization-interval'] < 60: |
87 if typed_config['synchronization-interval'] < 60: |
93 _ = source_entity._cw._ |
88 _ = source_entity._cw._ |
94 msg = _('synchronization-interval must be greater than 1 minute') |
89 msg = _('synchronization-interval must be greater than 1 minute') |
95 raise ValidationError(source_entity.eid, {'config': msg}) |
90 raise ValidationError(source_entity.eid, {'config': msg}) |
96 return typedconfig |
91 return typed_config |
97 |
92 |
98 def _entity_update(self, source_entity): |
93 def _entity_update(self, source_entity): |
99 source_entity.complete() |
94 super(DataFeedSource, self)._entity_update(source_entity) |
100 self.parser_id = source_entity.parser |
95 self.parser_id = source_entity.parser |
101 self.latest_retrieval = source_entity.latest_retrieval |
96 self.latest_retrieval = source_entity.latest_retrieval |
102 if source_entity.url: |
97 |
103 self.urls = [url.strip() for url in source_entity.url.splitlines() |
98 def update_config(self, source_entity, typed_config): |
104 if url.strip()] |
99 """update configuration from source entity. `typed_config` is config |
105 else: |
|
106 self.urls = [] |
|
107 |
|
108 def update_config(self, source_entity, typedconfig): |
|
109 """update configuration from source entity. `typedconfig` is config |
|
110 properly typed with defaults set |
100 properly typed with defaults set |
111 """ |
101 """ |
112 self.synchro_interval = timedelta(seconds=typedconfig['synchronization-interval']) |
102 super(DataFeedSource, self).update_config(source_entity, typed_config) |
113 self.max_lock_lifetime = timedelta(seconds=typedconfig['max-lock-lifetime']) |
103 self.synchro_interval = timedelta(seconds=typed_config['synchronization-interval']) |
114 if source_entity is not None: |
104 self.max_lock_lifetime = timedelta(seconds=typed_config['max-lock-lifetime']) |
115 self._entity_update(source_entity) |
|
116 self.config = typedconfig |
|
117 |
105 |
118 def init(self, activated, source_entity): |
106 def init(self, activated, source_entity): |
119 if activated: |
107 super(DataFeedSource, self).init(activated, source_entity) |
120 self._entity_update(source_entity) |
|
121 self.parser_id = source_entity.parser |
108 self.parser_id = source_entity.parser |
122 self.load_mapping(source_entity._cw) |
109 self.load_mapping(source_entity._cw) |
123 |
110 |
124 def _get_parser(self, session, **kwargs): |
111 def _get_parser(self, session, **kwargs): |
125 return self.repo.vreg['parsers'].select( |
112 return self.repo.vreg['parsers'].select( |