summaryrefslogtreecommitdiff
path: root/doc-dump.py
blob: 9ddeb79d7a21977228d2d1dce47ddbec7e10c0e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python3
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

from msodumper import globals, docstream
import sys

if not globals.PY3:
    sys = reload(sys)
    sys.setdefaultencoding("utf-8")


class DOCDumper:
    def __init__(self, filepath, params):
        self.filepath = filepath
        self.params = params

    def dump(self):
        file = open(self.filepath, 'rb')
        strm = docstream.createDOCFile(file.read(), self.params)
        file.close()
        dirnames = strm.getDirectoryNames()
        print('<?xml version="1.0"?>\n<streams ole-type="%s">' % strm.getName())
        if strm.error:
            print('<error what="%s"/>' % strm.error)
        for dirname in dirnames:
            if len(dirname) == 0 or dirname in [b'Root Entry']:
                continue
            strm.getDirectoryStreamByName(dirname).dump()
        print('</streams>')


def main(args):
    params = globals.Params()
    dumper = DOCDumper(args[1], params)
    dumper.dump()


if __name__ == '__main__':
    main(sys.argv)

# vim:set filetype=python shiftwidth=4 softtabstop=4 expandtab: