Created
April 15, 2020 08:23
-
-
Save Mitmischer/2d1ce097a5d8d68cbe25f79ffac71536 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| # input : a Xournal file as XML (uncompressed) | |
| import humanize | |
| import xml.etree.ElementTree as ET | |
| import sys | |
| def width_count_to_size(widths_count): | |
| # double is 64-bit | |
| return widths_count*8 | |
| def stroke_count_to_size(stroke_count): | |
| # sizes are for identifier, tool, ts(?!), fn(?!), color | |
| return stroke_count*(1+ 1 + 4 + 1+ 3*(1) ) | |
| def main(): | |
| if len(sys.argv) != 2: | |
| print("please provide exactly one argument") | |
| exit() | |
| tree = ET.parse(sys.argv[1]) | |
| root = tree.getroot() | |
| stroke_count = 0 | |
| widths_count = 0 | |
| # a.k.a the text of a stroke element | |
| stroke_coordinates = 0 | |
| for page in root: | |
| print("Analyzing page...") | |
| # analyse pages only, the rest adds little overhead | |
| if page.tag == "page": | |
| for layer in page: | |
| # analyse layer only, background adds little overhead | |
| if layer.tag == "layer": | |
| for stroke in layer: | |
| if stroke.tag == "stroke": | |
| stroke_count = stroke_count + 1 | |
| coordinates = len(stroke.text.split(" ")) | |
| widths = len(stroke.attrib["width"].split(" ")) | |
| stroke_coordinates = stroke_coordinates + coordinates | |
| widths_count = widths_count + widths | |
| print("--- total: ---") | |
| stroke_size = stroke_count_to_size(stroke_count) | |
| width_size = width_count_to_size(widths_count) | |
| coordinates_size = width_count_to_size(stroke_coordinates) | |
| total_size = stroke_size + width_size + coordinates_size | |
| print("{0} strokes, totalling {1}".format(stroke_count, humanize.naturalsize(stroke_size, True))) | |
| print("{0} elements in width attributes, totalling {1}".format(widths_count, humanize.naturalsize(width_size, True))) | |
| print("{0} coordinates, totalling {1}".format(stroke_coordinates, humanize.naturalsize(coordinates_size, True))) | |
| print("total size: {0} ({1} bytes)".format(humanize.naturalsize(total_size, True), total_size)) | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment