Mercurial > libervia-backend
comparison src/plugins/plugin_import.py @ 2390:f57a8eaec8ed
plugins import, tickets import, bugzilla import: comments handling:
- comments are put in "comments" key in import data, it's a list of microblog data
- in resulting item, the comments uri is put in comments_uri field
- (plugin import) root_service and root_node are kept in session
- (plugin ticket) reporter name is now in "reporter" key instead of "reporter_name"
- (plugin bugizlla): if not reporter name is found, first part of email address is used
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 20 Oct 2017 08:48:41 +0200 |
parents | 2c2b826b0bb3 |
children | 66baa687c682 |
comparison
equal
deleted
inserted
replaced
2389:5675af905725 | 2390:f57a8eaec8ed |
---|---|
51 """Initialize a specialized import handler | 51 """Initialize a specialized import handler |
52 | 52 |
53 @param import_handler(object): specialized import handler instance | 53 @param import_handler(object): specialized import handler instance |
54 must have the following methods: | 54 must have the following methods: |
55 - importItem: import a single main item (i.e. prepare data for publishing) | 55 - importItem: import a single main item (i.e. prepare data for publishing) |
56 - importSubitems: import sub items (i.e. items linked to main item, e.g. comments). Must return a dict with kwargs for recursiveImport if items are to be imported. At east "items_import_data", "service" and "node" keys must be provided. | 56 - importSubitems: import sub items (i.e. items linked to main item, e.g. comments). |
57 if None is returned, no subitems will be imported | 57 Must return a dict with kwargs for recursiveImport if items are to be imported recursively. |
58 At least "items_import_data", "service" and "node" keys must be provided. | |
59 if None is returned, no recursion will be done to import subitems, but import can still be done directly by the method. | |
58 - publishItem: actualy publish an item | 60 - publishItem: actualy publish an item |
59 - itemFilters: modify item according to options | 61 - itemFilters: modify item according to options |
60 @param name(unicode): import handler name | 62 @param name(unicode): import handler name |
61 """ | 63 """ |
62 assert name == name.lower().strip() | 64 assert name == name.lower().strip() |
137 if opt_default: | 139 if opt_default: |
138 options[opt_name] = opt_default | 140 options[opt_name] = opt_default |
139 else: | 141 else: |
140 if not value: | 142 if not value: |
141 del options[opt_name] | 143 del options[opt_name] |
144 | |
142 try: | 145 try: |
143 importer = import_handler.importers[name] | 146 importer = import_handler.importers[name] |
144 except KeyError: | 147 except KeyError: |
145 raise exceptions.NotFound(u"Importer [{}] not found".format(name)) | 148 raise exceptions.NotFound(u"Importer [{}] not found".format(name)) |
146 items_import_data, items_count = yield importer.callback(client, location, options) | 149 items_import_data, items_count = yield importer.callback(client, location, options) |
157 'direction': 'out', | 160 'direction': 'out', |
158 'type': import_handler.name.upper() + '_IMPORT' | 161 'type': import_handler.name.upper() + '_IMPORT' |
159 } | 162 } |
160 self.host.registerProgressCb(progress_id, partial(self.getProgress, import_handler), metadata, profile=client.profile) | 163 self.host.registerProgressCb(progress_id, partial(self.getProgress, import_handler), metadata, profile=client.profile) |
161 self.host.bridge.progressStarted(progress_id, metadata, client.profile) | 164 self.host.bridge.progressStarted(progress_id, metadata, client.profile) |
162 session = {} # session data, can be use by importers | 165 session = { # session data, can be used by importers |
166 u'root_service': pubsub_service, | |
167 u'root_node': pubsub_node | |
168 } | |
163 self.recursiveImport(client, import_handler, items_import_data, progress_id, session, options, None, pubsub_service, pubsub_node) | 169 self.recursiveImport(client, import_handler, items_import_data, progress_id, session, options, None, pubsub_service, pubsub_node) |
164 defer.returnValue(progress_id) | 170 defer.returnValue(progress_id) |
165 | 171 |
166 @defer.inlineCallbacks | 172 @defer.inlineCallbacks |
167 def recursiveImport(self, client, import_handler, items_import_data, progress_id, session, options, return_data=None, service=None, node=None, depth=0): | 173 def recursiveImport(self, client, import_handler, items_import_data, progress_id, session, options, return_data=None, service=None, node=None, depth=0): |
170 @param import_handler(object): instance of the import handler | 176 @param import_handler(object): instance of the import handler |
171 @param items_import_data(iterable): iterable of data as specified in [register] | 177 @param items_import_data(iterable): iterable of data as specified in [register] |
172 @param progress_id(unicode): id of progression | 178 @param progress_id(unicode): id of progression |
173 @param session(dict): data for this import session | 179 @param session(dict): data for this import session |
174 can be used by importer so store any useful data | 180 can be used by importer so store any useful data |
181 "root_service" and "root_node" are set to the main pubsub service and node of the import | |
175 @param options(dict): import options | 182 @param options(dict): import options |
176 @param return_data(dict): data to return on progressFinished | 183 @param return_data(dict): data to return on progressFinished |
177 @param service(jid.JID, None): PubSub service to use | 184 @param service(jid.JID, None): PubSub service to use |
178 @param node(unicode, None): PubSub node to use | 185 @param node(unicode, None): PubSub node to use |
179 @param depth(int): level of recursion | 186 @param depth(int): level of recursion |