def convert(input_file, output_file, options=[]): init_uniconv() from app.io import load from uniconvertor import filters import app app.init_lib() filters.load_plugin_configuration() if len(options) and options[0] == '-parse': load.parse_drawing(input_file, output_file) else: doc = load.load_drawing(input_file) extension = os.path.splitext(output_file)[1].lower() fileformat = filters.guess_export_plugin(extension) if fileformat: saver = filters.find_export_plugin(fileformat) saver(doc, output_file) else: sys.stderr.write('ERROR: unrecognized extension %s\n' % extension) sys.exit(1) doc.Destroy()
def uniconv_run(): _pkgdir = __path__[0] app_dir = os.path.join(_pkgdir, 'app') app_ver = string.strip(open(os.path.join(app_dir, 'VERSION')).read()) if len(sys.argv)<3 or sys.argv[1]=='--help': print '\nUniConvertor',app_ver print __doc__ sys.exit(0) options=[] input_file=sys.argv[-2] output_file=sys.argv[-1] if len(sys.argv)>3: options=sys.argv[1:-2] if not os.path.isfile(input_file): print '\nERROR: %s file is not found!' % input_file print '\nUniConvertor',app_ver print __doc__ sys.exit(1) sys.path.insert(1, _pkgdir) from app.io import load from sk1libs import filters import app app.init_lib() filters.load_plugin_configuration() if len(options) and options[0]=='-parse': load.parse_drawing(input_file, output_file) sys.exit(0) else: doc = load.load_drawing(input_file) extension = os.path.splitext(output_file)[1] fileformat = filters.guess_export_plugin(extension) if fileformat: saver = filters.find_export_plugin(fileformat) saver(doc, output_file) else: sys.stderr.write('ERROR: unrecognized extension %s\n' % extension) sys.exit(1) doc.Destroy() sys.exit(0)
def uniconv_run(): _pkgdir = __path__[0] app_dir = os.path.join(_pkgdir, 'app') app_ver = string.strip(open(os.path.join(app_dir, 'VERSION')).read()) if len(sys.argv) < 3 or sys.argv[1] == '--help': print '\nUniConvertor', app_ver print __doc__ sys.exit(0) options = [] input_file = sys.argv[-2] output_file = sys.argv[-1] if len(sys.argv) > 3: options = sys.argv[1:-2] if not os.path.isfile(input_file): print '\nERROR: %s file is not found!' % input_file print '\nUniConvertor', app_ver print __doc__ sys.exit(1) sys.path.insert(1, _pkgdir) from app.io import load from sk1libs import filters import app app.init_lib() filters.load_plugin_configuration() if len(options) and options[0] == '-parse': load.parse_drawing(input_file, output_file) sys.exit(0) else: doc = load.load_drawing(input_file) extension = os.path.splitext(output_file)[1] fileformat = filters.guess_export_plugin(extension) if fileformat: saver = filters.find_export_plugin(fileformat) saver(doc, output_file) else: sys.stderr.write('ERROR: unrecognized extension %s\n' % extension) sys.exit(1) doc.Destroy() sys.exit(0)