コード例 #1
0
def convert_xls_to_xml(xls_conf, xls_conf_keys, xls_schema, xslt_filename,
                       xls_filename, xml_filename):
    xls_reader = XLSReader(xls_filename, xls_conf)
    xls_readers = [(key, xls_reader) for key in xls_conf_keys]
    try:
        output_xml = utils.multiple_objects_to_xml(xls_readers, xls_schema,
                                                   xslt_filename)
    except Exception as e:
        print(e.message, file=sys.stderr)
        quit(1)
    with open(xml_filename, 'w') as xml_file:
        utils.save_xml(output_xml, xml_file)
    print('Conversion complete!', file=sys.stdout)
コード例 #2
0
ファイル: views.py プロジェクト: kongxiuzhi/bookms
    def _export(request):
        if not os.path.exists('tmp/'):
            os.mkdir('tmp')
        for item in os.listdir('tmp/'):
            os.remove('tmp/' + item)
        filename = 'tmp/bills_export_%s.xml' % (
            date.today().strftime('%Y%m%d'))

        bill_ids = request.GET.get('id', '').strip().split(',')
        bill_ids = map(unicode.strip, filter(None, bill_ids))

        lines = utils.bills_export(bill_ids)
        lines.extend(utils.bills_export_other())
        utils.save_xml(lines, filename)
        wrapper = FileWrapper(file(filename))
        response = HttpResponse(wrapper,
                                content_type='application/octet-stream')
        # response['Content-Length'] = os.path.getsize(filename)
        response['Content-Disposition'] = 'attachment; filename=%s' % filename
        return response
コード例 #3
0
                        help='Schema definition for data field')
arg_parser.add_argument(
    '--xslt',
    required=True,
    dest='xslt',
    help='Definition for transformation from tsv to xml document')

args = arg_parser.parse_args()
tsv_filenames = args.tsv.split(',')
xml_filename = args.xml
tsv_conf = args.conf
tsv_conf_keys = args.confKey.split(',')
tsv_schema = args.schema
xslt_filename = args.xslt

key_files = dict(zip(tsv_conf_keys, tsv_filenames))
tsv_readers = [(key, TSVReader(key_files[key], tsv_conf, key))
               for key in key_files]

try:
    output_xml = utils.multiple_objects_to_xml(tsv_readers, tsv_schema,
                                               xslt_filename)
except Exception as e:
    print(e.message, file=sys.stderr)
    quit(1)

with open(xml_filename, 'w') as xml_file:
    utils.save_xml(output_xml, xml_file)

print('Conversion complete!', file=sys.stdout)