mirror of
https://codeberg.org/privacy1st/xournalpp-relative-background
synced 2024-12-04 22:25:02 +01:00
refactor
This commit is contained in:
parent
8bbd1579bc
commit
f204428a55
@ -25,11 +25,12 @@ try:
|
|||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
print(f'Optional dependency "notify2" is not available. {MSG_FALLBACK_STR}')
|
print(f'Optional dependency "notify2" is not available. {MSG_FALLBACK_STR}')
|
||||||
except Exception as e:
|
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():
|
def main():
|
||||||
modified_files=0
|
modified_files = 0
|
||||||
xopp_files: List[Path] = []
|
xopp_files: List[Path] = []
|
||||||
try:
|
try:
|
||||||
xopp_files = parse_args()
|
xopp_files = parse_args()
|
||||||
@ -103,19 +104,21 @@ def save_relative_paths(xopp_file: Path) -> int:
|
|||||||
if not root.tag == 'xournal':
|
if not root.tag == 'xournal':
|
||||||
raise Exception(f'Unexpected root element: {root.tag}')
|
raise Exception(f'Unexpected root element: {root.tag}')
|
||||||
|
|
||||||
child1: Element
|
page: Element
|
||||||
for child1 in root:
|
for page in root:
|
||||||
if child1.tag == 'page':
|
if page.tag == 'page':
|
||||||
child2: Element
|
|
||||||
for child2 in child1:
|
background: Element
|
||||||
if child2.tag == 'background' \
|
for background in page:
|
||||||
and 'type' in child2.attrib \
|
if background.tag == 'background' \
|
||||||
and child2.attrib['type'] == 'pdf' \
|
and 'type' in background.attrib \
|
||||||
and 'domain' in child2.attrib \
|
and background.attrib['type'] == 'pdf' \
|
||||||
and child2.attrib['domain'] == 'absolute' \
|
and 'domain' in background.attrib \
|
||||||
and 'filename' in child2.attrib:
|
and background.attrib['domain'] == 'absolute' \
|
||||||
print(f'type: {child2.tag}, attrib: {child2.attrib}')
|
and 'filename' in background.attrib:
|
||||||
abs_pdf: Path = Path(child2.attrib['filename'])
|
|
||||||
|
print(f'type: {background.tag}, attrib: {background.attrib}')
|
||||||
|
abs_pdf: Path = Path(background.attrib['filename'])
|
||||||
|
|
||||||
if not abs_pdf.is_absolute():
|
if not abs_pdf.is_absolute():
|
||||||
continue # No action required as the path is already relative
|
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)
|
rel_pdf: Path = xopp_file.parent.joinpath(abs_pdf.name)
|
||||||
if rel_pdf.exists():
|
if rel_pdf.exists():
|
||||||
# Replace absolute with relative path
|
# Replace absolute with relative path
|
||||||
child2.attrib['filename'] = abs_pdf.name
|
background.attrib['filename'] = abs_pdf.name
|
||||||
xml_modified = True
|
xml_modified = True
|
||||||
else:
|
else:
|
||||||
print("The PDF file was neither found at it's absolute path"
|
print("The PDF file was neither found at it's absolute path"
|
||||||
|
Loading…
Reference in New Issue
Block a user