10000 more code clean up · homeylab/bookstack-file-exporter@39214aa · GitHub
[go: up one dir, main page]

Skip to content

Commit 39214aa

Browse files
committed
more code clean up
1 parent f3cbf8b commit 39214aa

File tree

2 files changed

+6
-24
lines changed

2 files changed

+6
-24
lines changed

bookstack_file_exporter/archiver/page_archiver.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
# pylint: disable=import-error
44
from requests import Response
55

6-
76
from bookstack_file_exporter.exporter.node import Node
87
from bookstack_file_exporter.archiver import util as archiver_util
98
from bookstack_file_exporter.config_helper.config_helper import ConfigNode
109
from bookstack_file_exporter.common import util as common_util
1110

12-
1311
_META_FILE_SUFFIX = "_meta.json"
1412
_TAR_SUFFIX = ".tar"
1513
_TAR_GZ_SUFFIX = ".tgz"
@@ -26,9 +24,7 @@
2624
"tgz": _TAR_GZ_SUFFIX
2725
}
2826

29-
3027
_IMAGE_DIR_NAME = "images"
31-
# _MARKDOWN_IMAGE_REGEX= re.compile(r"\[\!\[^$|.*\].*\]")
3228
_MARKDOWN_STR_CHECK = "markdown"
3329

3430
class ImageNode:
@@ -54,13 +50,16 @@ def _get_image_name(self) -> str:
5450

5551
@property
5652
def image_relative_path(self):
53+
"""return image path local to page directory"""
5754
return self._image_relative_path
5855

5956
@property
6057
def markdown_str(self):
58+
"""return markdown url str to replace"""
6159
return self._markdown_str
62-
60+
6361
def set_markdown_content(self, img_details: Dict[str, Union[int, str]]):
62+
"""provide image metadata to set markdown properties"""
6463
self._markdown_str = self._get_md_url_str(img_details)
6564

6665
@staticmethod
@@ -121,7 +120,6 @@ def _archive_page(self, page: Node, export_format: str, data: bytes,
121120
image_nodes: List[ImageNode] = None):
122121
page_file_name = f"{self.archive_base_path}/" \
123122
f"{page.file_path}/{page.name}{_FILE_EXTENSION_MAP[export_format]}"
124-
# not yet implemented
125123
if self.modify_md and export_format == _MARKDOWN_STR_CHECK and image_nodes:
126124
data = self._update_image_links(data, image_nodes)
127125
self.write_data(page_file_name, data)
@@ -176,12 +174,12 @@ def _update_image_links(self, page_data: bytes, image_nodes: List[ImageNode]) ->
176174
img_meta_url = f"{self.api_urls['images']}/{img_node.id}"
177175
img_details = common_util.http_get_request(img_meta_url,
178176
self._headers, self.verify_ssl)
179-
180177
img_node.set_markdown_content(img_details.json())
181178
if not img_node.markdown_str:
182179
continue
183180
# 1 - what to replace, 2 - replace with, 3 is the data to replace
184-
page_data = re.sub(img_node.markdown_str.encode(), img_node.image_relative_path().encode(), page_data)
181+
page_data = re.sub(img_node.markdown_str.encode(),
182+
img_node.image_relative_path.encode(), page_data)
185183
return page_data
186184

187185
@property

bookstack_file_exporter/archiver/util.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@ def write_tar(base_tar_dir: str, file_path: str, data: bytes):
2727
log.debug("Adding file: %s with size: %d bytes to tar file", tar_info.name, tar_info.size)
2828
tar.addfile(tar_info, fileobj=data_obj)
2929

30-
# create files first for manipulation/changes and tar later
31-
# def write_file(file_path: str, data: bytes):
32-
# """write byte data to a local file"""
33-
# os.makedirs(os.path.dirname(file_path), exist_ok=True)
34-
# with open(file_path, 'wb') as file_obj:
35-
# file_obj.write(data)
36-
3730
def get_json_bytes(data: Dict[str, Union[str, int]]) -> bytes:
3831
"""dump dict to json file"""
3932
return json.dumps(data, indent=4).encode('utf-8')
@@ -55,12 +48,3 @@ def scan_archives(base_dir: str, extension: str) -> str:
5548
"""scan export directory for archives"""
5649
file_pattern = f"{base_dir}_*{extension}"
5750
return glob.glob(file_pattern)
58-
59-
# def find_file_matches(file_path: str, regex_expr: re.Pattern) -> List[str]:
60-
# """find all matching lines for regex pattern"""
61-
# matches=[]
62-
# with open(file_path, encoding="utf-8") as open_file:
63-
# for line in open_file:
64-
# for match in re.finditer(regex_expr, line):
65-
# matches.append(match.group)
66-
# return matches

0 commit comments

Comments
 (0)
0