Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coverage/enhance #46

Merged
merged 4 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Removed
- `extract_namespaces` function in `util.py`
### Added
- `DMetaBaseError` added to `dmeta/__init__.py`
### Changed
Expand Down
3 changes: 1 addition & 2 deletions dmeta/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def clear(microsoft_file_name, in_place=False):
xml_element.text = ""
e_app.write(app_xml_path)


modified = microsoft_file_name
if not in_place:
modified = microsoft_file_name[:microsoft_file_name.rfind('.')] + "_cleared" + "." + microsoft_format
Expand All @@ -58,7 +57,7 @@ def clear(microsoft_file_name, in_place=False):
def clear_all(in_place=False):
"""
Clear all the editable metadata in any microsoft file in the current directory.

:param in_place: the `in_place` flag applies the changes directly to the original file
:type in_place: bool
:return: None
Expand Down
22 changes: 0 additions & 22 deletions dmeta/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,11 @@
import json
from shutil import rmtree
from zipfile import ZipFile
import defusedxml.ElementTree as ET
from .params import SUPPORTED_MICROSOFT_FORMATS, NOT_IMPLEMENTED_ERROR, \
FILE_FORMAT_DOES_NOT_EXIST_ERROR, INVALID_CONFIG_FILE_NAME_ERROR, CONFIG_FILE_DOES_NOT_EXIST_ERROR
from .errors import DMetaBaseError


def extract_namespaces(xml_file_path):
"""
Return used namespaces in the associated xml file.

:param xml_file_path: path to the xml file
:type xml_file_path: str
:return: dict of namespaces[name: value]
"""
namespaces = {}
tree = ET.parse(xml_file_path)
root = tree.getroot()
# Extract namespaces from the root element
for key, value in root.attrib.items():
if key.startswith('xmlns:'):
_, _, cropped_name = key.partition(':')
namespaces[cropped_name] = value
elif key == 'xmlns':
namespaces['xmlns'] = value
return namespaces


def get_microsoft_format(file_name):
"""
Extract format from the end of the given microsoft file name.
Expand Down