def publish_doc(self, docname, output): conf = self.config title = ConfluenceState.title(docname) parent_id = None if self.config.master_doc and self.config.confluence_page_hierarchy: if self.config.master_doc != docname: parent = ConfluenceState.parentDocname(docname) parent_id = ConfluenceState.uploadId(parent) if not parent_id: parent_id = self.parent_id data = { 'content': output, 'labels': [], } if self.config.confluence_global_labels: data['labels'].extend(self.config.confluence_global_labels) metadata = self.metadata[docname] if 'labels' in metadata: data['labels'].extend([v for v in metadata['labels']]) uploaded_id = self.publisher.storePage(title, data, parent_id) ConfluenceState.registerUploadId(docname, uploaded_id) if self.config.master_doc == docname: self.master_doc_page_id = uploaded_id if conf.confluence_purge and self.legacy_pages is None: if conf.confluence_purge_from_master and self.master_doc_page_id: baseid = self.master_doc_page_id else: baseid = self.parent_id # if no base identifier and dry running, ignore legeacy page # searching as there is no initial master document to reference # against if (conf.confluence_purge_from_master and conf.confluence_publish_dryrun and not baseid): self.legacy_pages = [] elif self.config.confluence_adv_aggressive_search is True: self.legacy_pages = self.publisher.getDescendantsCompat(baseid) else: self.legacy_pages = self.publisher.getDescendants(baseid) # only populate a list of possible legacy assets when a user is # configured to check or push assets to the target space asset_override = conf.confluence_asset_override if asset_override is None or asset_override: for legacy_page in self.legacy_pages: attachments = self.publisher.getAttachments(legacy_page) self.legacy_assets[legacy_page] = attachments if conf.confluence_purge: if uploaded_id in self.legacy_pages: self.legacy_pages.remove(uploaded_id)
def publish_asset(self, key, docname, output, type, hash): conf = self.config publisher = self.publisher title = ConfluenceState.title(docname) page_id = ConfluenceState.uploadId(docname) if not page_id: # A page identifier may not be tracked in cases where only a subset # of documents are published and the target page an asset will be # published to was not part of the request. In this case, ask the # Confluence instance what the target page's identifier is. page_id, _ = publisher.getPage(title) if page_id: ConfluenceState.registerUploadId(docname, page_id) else: ConfluenceLogger.warn('cannot publish asset since publishing ' 'point cannot be found ({}): {}'.format( key, docname)) return if conf.confluence_asset_override is None: # "automatic" management -- check if already published; if not, push attachment_id = publisher.storeAttachment(page_id, key, output, type, hash) elif conf.confluence_asset_override: # forced publishing of the asset attachment_id = publisher.storeAttachment(page_id, key, output, type, hash, force=True) if attachment_id and conf.confluence_purge: if page_id in self.legacy_assets: legacy_asset_info = self.legacy_assets[page_id] if attachment_id in legacy_asset_info: legacy_asset_info.pop(attachment_id, None)