示例#1
0
def main():
    opt, args = get_options()
    cmd_set_args = [Ska.ParseCM._coerce_type(x) for x in args]

    # Configure logging to emit msgs to stdout
    logging.basicConfig(level=opt.loglevel,
                        format='%(message)s',
                        stream=sys.stdout)

    logging.info('Connecting to db: dbi=%s server=%s' % (opt.dbi, opt.server))
    db = Ska.DBI.DBI(dbi=opt.dbi, server=opt.server,
                     user=opt.user, database=opt.database, verbose=False)

    # Print information about recent non-load commands
    nl_cmds = db.fetchall("SELECT * FROM cmds "
                          "WHERE timeline_id IS NULL ORDER BY date DESC")
    # Convert from np.recarray to list of dict (with params included)
    nl_cmds = _tl_to_bs_cmds(nl_cmds, None, db)
    logging.info('Most recent non-load commands')
    log_cmds(nl_cmds[:10])
    logging.info('')

    # Jump out if only doing a check
    if opt.check:
        sys.exit(0)

    # Generate commands for the specified command set
    date = DateTime(opt.date).date
    cmd_set_states = cmd_states.cmd_set(opt.cmd_set, *cmd_set_args)
    cmds = cmd_states.generate_cmds(date, cmd_set_states)

    logging.info('Add following cmds to database')
    log_cmds(cmds)
    logging.info('')

    # Add commands to database if not doing a dry run
    if not opt.dry_run:
        logging.info('Adding cmds to database')
        cmd_states.insert_cmds_db(cmds, None, db)

    # Generate python that will add the same commands to the database
    f = (sys.stdout if opt.dry_run else open(opt.archive_file, 'a'))
    logging.info('Appending cmd_set info to %s' % opt.archive_file)
    # String representation of cmd_set and args
    str_args = [repr(arg) for arg in [opt.cmd_set] + cmd_set_args]
    print('', file=f)
    print('# Autogenerated by add_nonload_cmds.py at %s' % time.ctime(), file=f)
    print('# date=%s cmd_set=%s args=%s' % (date, opt.cmd_set, ' '.join(args)), file=f)
    print("cmds = generate_cmds('%s', cmd_set(%s))" % (date, ', '.join(str_args)), file=f)
    print("cmd_states.insert_cmds_db(cmds, None, db)", file=f)

    if opt.interrupt:
        if not opt.dry_run:
            cmd_states.interrupt_loads(date, db,
                                       observing_only=opt.observing_only)
        print(("cmd_states.interrupt_loads('%s', db, "
                    "observing_only=%s, current_only=True)" %
                    (date, opt.observing_only)), file=f)
示例#2
0
2006:344:08:59:38
2006:340:16:16:00
2006:080:01:32:00

2008:292:21:24:00
2008:225:10:00:00
"""
for date in dates.split('\n'):
    date = date.strip()
    if date:
        print date
        cmds += generate_cmds(date, cmd_set('scs107'))
        cmd_states.interrupt_loads(date, db, current_only=True)


cmd_states.insert_cmds_db(cmds, None, db)

# 2010:150 NSM commands 
# date=2010:150:04:00:00.000 cmd_set=nsm args=
cmds = generate_cmds('2010:150:04:00:00.000', cmd_set('nsm'))
cmd_states.insert_cmds_db(cmds, None, db)
cmd_states.interrupt_loads('2010:150:04:00:00.000', db, current_only=True)

# date=2010:150:04:00:00.000 cmd_set=scs107 args=
cmds = generate_cmds('2010:150:04:00:00.000', cmd_set('scs107'))
cmd_states.insert_cmds_db(cmds, None, db)
cmd_states.interrupt_loads('2010:150:04:00:00.000', db, current_only=True)

# Autogenerated by add_nonload_cmds.py at Wed Jun  8 10:57:43 2011
# date=2011:158:15:23:10.000 cmd_set=scs107 args=
cmds = generate_cmds('2011:158:15:23:10.000', cmd_set('scs107'))