Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
mat2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Simon Magnin
mat2
Commits
30e567de
Commit
30e567de
authored
6 years ago
by
Julien (jvoisin) Voisin
Browse files
Options
Downloads
Patches
Plain Diff
tmp
parent
9826de35
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
libmat2/office.py
+19
-1
19 additions, 1 deletion
libmat2/office.py
with
19 additions
and
1 deletion
libmat2/office.py
+
19
−
1
View file @
30e567de
...
...
@@ -12,7 +12,7 @@ assert Set
assert
Pattern
def
_parse_xml
(
full_path
:
str
):
"""
This function parse XML, with namespace support.
"""
"""
This function parse
s
XML, with namespace support.
"""
namespace_map
=
dict
()
for
_
,
(
key
,
value
)
in
ET
.
iterparse
(
full_path
,
(
"
start-ns
"
,
)):
...
...
@@ -22,6 +22,21 @@ def _parse_xml(full_path: str):
return
ET
.
parse
(
full_path
),
namespace_map
def
_sort_xml_attributes
(
full_path
:
str
)
->
bool
:
tree
=
ET
.
parse
(
full_path
)
root
=
tree
.
getroot
()
for
c
in
root
:
c
[:]
=
sorted
(
c
,
key
=
lambda
child
:
(
child
.
tag
,
child
.
get
(
'
desc
'
)))
print
(
'
CLENAING %s
'
%
full_path
)
xmlstr
=
ET
.
tostring
(
root
,
encoding
=
"
utf-8
"
,
method
=
"
xml
"
)
print
(
xmlstr
.
decode
(
"
utf-8
"
))
tree
.
write
(
full_path
,
xml_declaration
=
True
)
return
True
class
MSOfficeParser
(
ArchiveBasedAbstractParser
):
mimetypes
=
{
'
application/vnd.openxmlformats-officedocument.wordprocessingml.document
'
,
...
...
@@ -154,6 +169,9 @@ class LibreOfficeParser(ArchiveBasedAbstractParser):
return
True
def
_specific_cleanup
(
self
,
full_path
:
str
)
->
bool
:
if
os
.
path
.
basename
(
full_path
).
endswith
(
'
.xml
'
):
_sort_xml_attributes
(
full_path
)
if
os
.
path
.
basename
(
full_path
)
==
'
content.xml
'
:
return
self
.
__remove_revisions
(
full_path
)
return
True
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment