2 # -*- coding: utf-8 -*-
5 # Author: Progfou <jean-christophe.andre@auf.org>
7 # Debian-Depends: python (>= 2.6)
11 from xml.dom import minidom
16 for filename in sys.argv[1:]:
17 if not zipfile.is_zipfile(filename):
20 odf = zipfile.ZipFile(filename, 'r')
22 continue # u"WARNING: skipping '%s': not a ZIP file" % filename
23 if not odf.namelist():
25 continue # u"WARNING: skipping '%s': not a ZIP file" % filename
26 if 'content.xml' not in odf.namelist() or \
27 'styles.xml' not in odf.namelist() or \
28 'settings.xml' not in odf.namelist():
30 continue # u"WARNING: skipping '%s': not an ODF file" % filename
33 filename_base, filename_ext = os.path.splitext(filename)
34 copyname = filename_base + '-déverrouillé' + filename_ext
35 new_odf = zipfile.ZipFile(copyname, 'w', zipfile.ZIP_DEFLATED)
37 for info in odf.infolist():
38 data = odf.read(info.filename)
39 if info.filename == 'content.xml':
42 content = minidom.parseString(data)
43 # unlock section protection
44 #for node in content.getElementsByTagName("text:section"):
45 # if node.getAttribute("text:protected") == 'true':
46 # node.setAttribute("text:protected", "false")
48 # save content changes, only if necessary
50 data = content.toxml().encode('utf-8')
51 elif info.filename == 'settings.xml':
54 settings = minidom.parseString(data)
55 for node in settings.getElementsByTagName("config:config-item"):
56 name = node.getAttribute("config:name")
57 if not node.firstChild:
59 value = node.firstChild.wholeText
60 # unlock form protection
61 if name == 'ProtectForm' and value == 'true':
62 node.firstChild.replaceWholeText('false')
64 # unlock document editing
65 elif name == 'LoadReadonly' and value == 'true':
66 node.firstChild.replaceWholeText('false')
68 # save settings changes, only if necessary
70 data = settings.toxml().encode('utf-8')
71 new_odf.writestr(info, data)