예제 #1
0
        'ucanid': ucanids[station_index],
    }

    is_missing = last_reports[station_index] < 0
    if missing_only and not is_missing: continue

    print 'updating last report date for :\n', station
    last_report = latestReportDate(station, newa_base_time, icao_base_time,
                                   debug)

    # set last_reports to latest date found
    if last_report != last_reports[station_index]:
        last_reports[station_index] = last_report
        num_changed += 1
        station['last'] = last_report
        print message % station
        sys.stdout.flush()

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

if num_changed > 0 and not test_run:
    backup_filepath = factory.backupIndexFile()
    print 'Index file backed up to', backup_filepath

    print 'Last report date will be updated for %d stations.' % num_changed
    manager = factory.getFileManager('index', mode='a')
    manager.replaceDataset('last_report', last_reports, last_report_attrs)
    manager.closeFile()
    print 'Station index file has been updated.'
    print factory.getFilepath('index')
        where = 'historicalExtremes for station %d' % ucanid
        exception_type, formatted, details = captureLastException()
        if debug:
            print where
            print exception_type
            if details is not None: print details
            print ''.join(formatted)
            os._exit(99)
        else:
            exceptions_encountered.append(
                (where, exception_type, formatted, details))

    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

    if not debug:  # open sequence log file
        log_filepath = factory.getFilepath((ucanid, 'sequences'))
        log_file = open(log_filepath, 'wt')
        log_file.write(announce)
    else:
        log_file = None
        print 'sequence history for %d' % ucanid

    try:
        historicalSequences(factory, ucanid, datasets, options.report_missing,
                            log_file, options.min_run_length, debug)
    except:
        where = 'historicalSequences for station %d' % ucanid
        exception_type, formatted, details = captureLastException()
        if debug:
            print where
            print exception_type
        errmsg = 'Value of input option -s is invalid : %s' % states
        raise ValueError, errmsg
last_state = states[-1]

# creat a factory instance and get directory/file paths
factory = ObsnetDataFactory(options)

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

date_str = download_date.strftime('%Y%m%d')
time_str = datetime.now().strftime('%y%m%d.%H%M')

debug = options.debug

# get path to station index file
index_filepath = factory.getFilepath('index')
if not os.path.exists(index_filepath):
    raise IOError, 'Station index file not accessable : %s' % index_filepath

# make a backup copy of index file
if create_backup: factory.backupIndexFile()

# get log directory path
log_dirpath = os.path.join(factory.getDirectoryPath('working'), 'updates')
if not os.path.exists(log_dirpath):
    os.makedirs(log_dirpath)

# get file path for change log
change_log_name = '%s_changes.log' % time_str
change_log_path = os.path.join(log_dirpath, change_log_name)