# Path: core/ezdxf/pp/dxf2html.py
# def dxf2html(self):
#     """Creates a structured HTML view of the DXF tags - not a CAD drawing!
#     """
#     def get_name():
#         if self.drawing.filename is None:
#             return "unknown"
#         else:
#             filename = os.path.basename(self.drawing.filename)
#             return os.path.splitext(filename)[0]
# 
#     template = load_resource('dxf2html.html')
#     return template.format(
#         name=get_name(),
#         css=load_resource('dxf2html.css'),
#         javascript=load_resource('dxf2html.js'),
#         dxf_file=self.sections2html(),
#         section_links=self.sections_link_bar(),
#     )


import sys
import os
import io
from .dxf2html import dxf2html
from ezdxf import readfile, options
# Purpose: DXF Pretty Printer
# Created: 16.07.2015
# Copyright (C) 2015, Manfred Moitzi
# License: MIT License
from __future__ import unicode_literals
__author__ = "mozman <mozman@gmx.at>"



if __name__ == "__main__":
    options.compress_binary_data = True
    filename = sys.argv[1]
    try:
        dwg = readfile(filename)
    except IOError:
        print("Unable to read DXF file '{}', or invalid DXF file.".format(filename))
        sys.exit()
    html_filename = os.path.splitext(dwg.filename)[0] + '.html'
    try:
        with io.open(html_filename, mode='wt', encoding='utf-8') as fp:

# Path: core/ezdxf/pp/dxf2html.py
# def dxf2html(self):
#     """Creates a structured HTML view of the DXF tags - not a CAD drawing!
#     """
#     def get_name():
#         if self.drawing.filename is None:
#             return "unknown"
#         else:
#             filename = os.path.basename(self.drawing.filename)
#             return os.path.splitext(filename)[0]
# 
#     template = load_resource('dxf2html.html')
#     return template.format(
#         name=get_name(),
#         css=load_resource('dxf2html.css'),
#         javascript=load_resource('dxf2html.js'),
#         dxf_file=self.sections2html(),
#         section_links=self.sections_link_bar(),
#     )


# Path: core/ezdxf/pp/__main__.py
import sys
import os
import io
from .dxf2html import dxf2html
from ezdxf import readfile, options

# Purpose: DXF Pretty Printer
# Created: 16.07.2015
# Copyright (C) 2015, Manfred Moitzi
# License: MIT License
from __future__ import unicode_literals
__author__ = "mozman <mozman@gmx.at>"



if __name__ == "__main__":
    options.compress_binary_data = True
    filename = sys.argv[1]
    try:
        dwg = readfile(filename)
    except IOError:
        print("Unable to read DXF file '{}', or invalid DXF file.".format(filename))
        sys.exit()
    html_filename = os.path.splitext(dwg.filename)[0] + '.html'
    try:
        with io.open(html_filename, mode='wt', encoding='utf-8') as fp:

            fp.write(dxf2html(dwg))