Esempio n. 1
0
def main(args):
    if not len(args):
        print >> sys.stderr, (
            'ERROR: Must provide code generator with a filename!')
        sys.exit(1)

    output = sys.stdout

    debug = False
    for arg in args[:]:
        if arg == '-d':
            debug = True
        if arg.startswith('-'):
            args.remove(arg)

    if len(args) > 1:
        global TARGET_PROGRAM_NAME
        TARGET_PROGRAM_NAME = args[1]
        output = open(TARGET_PROGRAM_NAME + ".java", 'w')

    ast, _ = analyzer.analyze_file(args[0], debug=debug)
    CodeGenerator(ast, output)

    if output != sys.stdout:
        output.close()
Esempio n. 2
0
def process_file(output_directory, i, filename):

    print '%6d:\t%s' % (i, filename)
    data = analyzer.analyze_file(filename)
    output = output_directory + os.path.sep + ('%06d.json' % i)
    with open(output, 'w') as f_output:
        json.dump(data, f_output)

    return (i, {'data': output, 'meta': data['metadata'], 'audio': os.path.basename(filename)})
Esempio n. 3
0
def process_file(output_directory, i, filename):

    print '%6d:\t%s' % (i, filename)
    data = analyzer.analyze_file(filename)
    output = output_directory + os.path.sep + ('%06d.json' % i)
    with open(output, 'w') as f_output:
        json.dump(data, f_output)

    return (i, {
        'data': output,
        'meta': data['metadata'],
        'audio': os.path.basename(filename)
    })
Esempio n. 4
0
def download_and_analyze(fiscal_year, agency, spending_type):
    """The is a worker function, run on a separate thread."""
    dbconn = Connection()
    db = dbconn[settings.DB_NAME]
    monthly_analyses = db['monthly_analyses']

    analyses = monthly_analyses.find({'fiscal_year': fiscal_year, 'agency': agency, 'spending_type': spending_type})
    needed = analyses_needed(analyses)
    if needed:
        (filename, url, destpath) = usaspending.file_info(fiscal_year, agency, spending_type)
        dl_result = download_file(filename, url, destpath)
        if isinstance(dl_result, DownloadFileFailure):
            return (False, dl_result)
        print >>sys.stdout, "Got file %s" % filename
       
        try:
            analyses = analyze_file(destpath, fiscal_year, 
                                    settings.ANALYSIS_DATEFIELDS[spending_type],
                                    settings.ANALYSIS_FIELDS[spending_type])
            save_analyses(db, fiscal_year, agency, spending_type, analyses)
            return (True, analyses)
        except _csv.Error, e:
            return (False, e)