This commit is contained in:
Daniel Langbein 2021-09-26 11:44:54 +02:00
parent 8bbd1579bc
commit f204428a55

View File

@ -25,7 +25,8 @@ try:
except ImportError as e:
print(f'Optional dependency "notify2" is not available. {MSG_FALLBACK_STR}')
except Exception as e:
print(f'Error during import or initialization of notify2. Is the dependency "dbus-python" missing? {MSG_FALLBACK_STR}')
print(f'Error during import or initialization of notify2. '
f'Is the dependency "dbus-python" missing? {MSG_FALLBACK_STR}')
def main():
@ -103,19 +104,21 @@ def save_relative_paths(xopp_file: Path) -> int:
if not root.tag == 'xournal':
raise Exception(f'Unexpected root element: {root.tag}')
child1: Element
for child1 in root:
if child1.tag == 'page':
child2: Element
for child2 in child1:
if child2.tag == 'background' \
and 'type' in child2.attrib \
and child2.attrib['type'] == 'pdf' \
and 'domain' in child2.attrib \
and child2.attrib['domain'] == 'absolute' \
and 'filename' in child2.attrib:
print(f'type: {child2.tag}, attrib: {child2.attrib}')
abs_pdf: Path = Path(child2.attrib['filename'])
page: Element
for page in root:
if page.tag == 'page':
background: Element
for background in page:
if background.tag == 'background' \
and 'type' in background.attrib \
and background.attrib['type'] == 'pdf' \
and 'domain' in background.attrib \
and background.attrib['domain'] == 'absolute' \
and 'filename' in background.attrib:
print(f'type: {background.tag}, attrib: {background.attrib}')
abs_pdf: Path = Path(background.attrib['filename'])
if not abs_pdf.is_absolute():
continue # No action required as the path is already relative
@ -127,7 +130,7 @@ def save_relative_paths(xopp_file: Path) -> int:
rel_pdf: Path = xopp_file.parent.joinpath(abs_pdf.name)
if rel_pdf.exists():
# Replace absolute with relative path
child2.attrib['filename'] = abs_pdf.name
background.attrib['filename'] = abs_pdf.name
xml_modified = True
else:
print("The PDF file was neither found at it's absolute path"