|
1 | 1 | from typing import Union, List, Dict
|
2 | 2 | import logging
|
| 3 | +# pylint: disable=import-error |
| 4 | +from requests.exceptions import HTTPError |
3 | 5 | from bookstack_file_exporter.exporter.node import Node
|
4 | 6 | from bookstack_file_exporter.archiver import util as archiver_util
|
5 | 7 | from bookstack_file_exporter.archiver.asset_archiver import AssetArchiver, ImageNode, AttachmentNode
|
@@ -76,12 +78,15 @@ def archive_pages(self, page_nodes: Dict[int, Node]):
|
76 | 78 | page.name, page_images)
|
77 | 79 | failed_attach = self.archive_page_assets("attachments", page.parent.file_path,
|
78 | 80 | page.name, page_attachments)
|
| 81 | + # exclude from page_images |
| 82 | + # so it doesn't attempt to get modified in markdown file |
79 | 83 | if failed_images:
|
80 |
| - # exclude from page_images so it doesn't attempt to get modified in markdown file |
81 | 84 | page_images = [img for img in page_images if img.id_ not in failed_images]
|
| 85 | + # exclude from page_attachments |
| 86 | + # so it doesn't attempt to get modified in markdown file |
82 | 87 | if failed_attach:
|
83 |
| - # exclude from page_attachments so it doesn't attempt to get modified in markdown file |
84 |
| - page_attachments = [attach for attach in page_attachments if attach.id_ not in failed_attach] |
| 88 | + page_attachments = [attach for attach in page_attachments |
| 89 | + if attach.id_ not in failed_attach] |
85 | 90 | for export_format in self.export_formats:
|
86 | 91 | page_data = self._get_page_data(page.id_, export_format)
|
87 | 92 | if page_images and export_format == 'markdown':
|
@@ -141,12 +146,14 @@ def archive_page_assets(self, asset_type: str, parent_path: str, page_name: str,
|
141 | 146 | for asset_node in asset_nodes:
|
142 | 147 | try:
|
143 | 148 | asset_data = self.asset_archiver.get_asset_bytes(asset_type, asset_node.url)
|
144 |
| - except: |
| 149 | + except HTTPError: |
145 | 150 | # probably unnecessary, but just in case
|
146 | 151 | if asset_node.id_ not in failed_assets:
|
147 | 152 | failed_assets[asset_node.id_] = 0
|
148 |
| - # a 404 or other error occurred, skip this asset, already logged in http request exception |
149 |
| - log.error(f"Failed to get image or attachment data for asset located at: {asset_node.url} - skipping") |
| 153 | + # a 404 or other error occurred |
| 154 | + # skip this asset |
| 155 | + log.error("Failed to get image or attachment data " \ |
| 156 | + "for asset located at: %s - skipping", asset_node.url) |
150 | 157 | continue
|
151 | 158 | asset_path = f"{node_base_path}/{asset_node.get_relative_path(page_name)}"
|
152 | 159 | self.write_data(asset_path, asset_data)
|
|
0 commit comments