def make(args): from hwp5.plat import get_xslt from hwp5.importhelper import pkg_resources_filename from tempfile import mkstemp from hwp5.xmlmodel import Hwp5File hwp5_filename = args['<hwp5file>'] rootname = os.path.basename(hwp5_filename) if rootname.lower().endswith('.hwp'): rootname = rootname[0:-4] txt_path = rootname + '.txt' xslt = get_xslt() plaintext_xsl = pkg_resources_filename('hwp5', 'xsl/plaintext.xsl') hwp5file = Hwp5File(hwp5_filename) try: xhwp5_fd, xhwp5_path = mkstemp() try: xhwp5_file = os.fdopen(xhwp5_fd, 'w') try: hwp5file.xmlevents().dump(xhwp5_file) finally: xhwp5_file.close() xslt(plaintext_xsl, xhwp5_path, txt_path) finally: os.unlink(xhwp5_path) finally: hwp5file.close()
def hwp5_resources_path(res_path): try: path = pkg_resources_filename('hwp5', res_path) except Exception: logger.info('%s: pkg_resources_filename failed; using resource_stream', res_path) with mkstemp_open() as (path, g): import pkg_resources f = pkg_resources.resource_stream('hwp5', res_path) try: shutil.copyfileobj(f, g) g.close() yield path finally: f.close() else: yield path
def hwp5_resources_path(path): yield pkg_resources_filename('hwp5', path)
def hwp5_resources_filename(path): ''' get paths of 'hwp5' package resources ''' return pkg_resources_filename('hwp5', path)
def get_fixture_path(filename): from hwp5.importhelper import pkg_resources_filename return pkg_resources_filename(__name__, filename)
def hwp5_resources_path(path): yield pkg_resources_filename("hwp5", path)
def hwp5_resources_filename(path): """ get paths of 'hwp5' package resources """ return pkg_resources_filename("hwp5", path)