示例#1
0
def db_create(specfile, filepath, dbfile, force):
    """Create the database (create tables and insert datasets into it).
    """
    logging.info("creating db '%s'" % dbfile)
    if force:
        U.rename_if_exists(dbfile)
    for dataset in load_datasets(specfile, filepath):
        db_process_dataset(dbfile, dataset)
示例#2
0
def csv_process_dataset(outdir, dataset, force):
    """Create db tables and insert datasets into it.
    """
    outfile = dataset['table_name']
    keynames = dataset['keynames']
    values = dataset['values']

    outfile = os.path.sep.join((outdir, outfile + '.csv'))
    logging.info("creating csv file '%s'" % outfile)
    if force:
        U.rename_if_exists(outfile)

    writer = XC.UnicodeWriter(open(outfile, 'wb'))
    writer.writerow(keynames)

    for xs in values:
        writer.writerow([(x.value and x.value or "") for x in xs])