示例#1
0
def main():
    picross.pic_set_interrupt()
    picross.pic_init_time()

    parser = optparse.OptionParser(usage=sys.argv[0] + ' [options] id rpc arg')
    parser.add_option('--quiet',
                      action='store_true',
                      dest='quiet',
                      default=False,
                      help='quiet')
    parser.add_option('--timeout',
                      action='store',
                      type='int',
                      dest='timeout',
                      default=300000,
                      help='rpc timeout (300000 ms)')
    parser.add_option('--verbose',
                      action='store_true',
                      dest='verbose',
                      default=False,
                      help='verbose')

    (opts, args) = parser.parse_args(sys.argv)

    if len(args) < 3:
        parser.error('wrong number of arguments')

    id = args[1]
    name = args[2]
    arg = ' '.join(args[3:])

    def coroutine():

        inv = rpc.invoke_rpc(id, name, arg, opts.timeout)
        yield inv
        yield async .Coroutine.completion(inv.status(), inv.args()[0])

    def handler(ei):
        traceback.print_exception(file=sys.stderr, *ei)
        return async .Coroutine.failure('internal error')

    def failed(msg):
        if opts.verbose:
            print >> sys.stderr, 'rpc failed:', msg
        picross.exit(-1)

    def succeeded(msg):
        if opts.verbose:
            print >> sys.stderr, 'rpc succeeded:', msg
        print msg
        picross.exit(0)

    def startup(dummy):
        result = async .Coroutine(coroutine(), handler)
        result.setErrback(failed).setCallback(succeeded)
        return result

    session.run_session(startup, clock=False)
示例#2
0
 def __init__(self, device, ep):
     self.end_point = ep
     picross.pic_set_interrupt()
     self.interface = picross.usbdevice(device, 0)
     self.bulk_pipe = picross.bulk_out_pipe(self.end_point, 512)
     self.interface.add_bulk_out(self.bulk_pipe)
     self.interface.start_pipes()
     self.interface.control_out(0x40, 0xb1, 0, 0, '')
     time.sleep(4)
示例#3
0
def main():
    parser = optparse.OptionParser(usage=sys.argv[0]+' [options] tag=id ..')
    parser.add_option('-n','--name',action='store',dest='name',default='',help='file name')
    parser.add_option('-a','--absolute',action='store_true',dest='abs',default=False,help='absolute timestamps')
    parser.add_option('-r','--wav',action='store_true',dest='wav',default=False,help='create .wav audio file')

    (opt,args) = parser.parse_args(sys.argv)

    picross.pic_set_interrupt()

    if len(args) < 2:
        parser.error('wrong number of arguments')

    prefix=opt.name+'-' if opt.name else ''

    map = {}
    for arg in args[1:]:
        spl = arg.split('=')
        if len(spl)!=2:
            parser.error('invalid argument %s' % arg)
        map[spl[1]]=prefix+spl[0]

    def coroutine():
        r = async.Deferred()
        d = {}

        for (id,tag) in map.items():
            d[id] = Plumber(tag,id,opt.abs,opt.wav)

        yield r

    def handler(ei):
        traceback.print_exception(file=sys.stderr,*ei)
        return async.Coroutine.failure('internal error')

    def failed(msg):
        print msg
        picross.exit(-1)

    def succeeded():
        picross.exit(0)

    def startup(dummy):
        result = async.Coroutine(coroutine(),handler)
        result.setErrback(failed).setCallback(succeeded)
        return result

    session.run_session(startup,clock=False,rt=False)
示例#4
0
def main():
    picross.pic_set_interrupt()

    parser = optparse.OptionParser(usage=sys.argv[0] + ' [options] id')
    parser.add_option('-i',
                      '--id',
                      action='store_const',
                      dest='id',
                      const=0x0020,
                      default=0,
                      help='fast id')
    parser.add_option('-D',
                      '--fdata',
                      action='store_const',
                      dest='fdata',
                      const=0x0040,
                      default=0,
                      help='fast data')
    parser.add_option('-S',
                      '--fscalar',
                      action='store_const',
                      dest='fscalar',
                      const=0x0080,
                      default=0,
                      help='fast scalar')
    parser.add_option('-V',
                      '--fvector',
                      action='store_const',
                      dest='fvector',
                      const=0x0100,
                      default=0,
                      help='fast vector')
    parser.add_option('-T',
                      '--ftime',
                      action='store_const',
                      dest='ftime',
                      const=0x0200,
                      default=0,
                      help='fast time')
    parser.add_option('-d',
                      '--sdata',
                      action='store_const',
                      dest='sdata',
                      const=0x0001,
                      default=0,
                      help='slow data')
    parser.add_option('-s',
                      '--sscalar',
                      action='store_const',
                      dest='sscalar',
                      const=0x0002,
                      default=0,
                      help='slow scalar')
    parser.add_option('-v',
                      '--svector',
                      action='store_const',
                      dest='svector',
                      const=0x0004,
                      default=0,
                      help='slow vector')
    parser.add_option('-t',
                      '--stime',
                      action='store_const',
                      dest='stime',
                      const=0x0008,
                      default=0,
                      help='slow time')
    parser.add_option('-x',
                      '--flags',
                      action='store_const',
                      dest='flags',
                      const=0x0800,
                      default=0,
                      help='flags')
    parser.add_option('-a',
                      '--address',
                      action='store_const',
                      dest='flags',
                      const=0x1000,
                      default=0,
                      help='full address')
    parser.add_option('-M',
                      '--monitor',
                      action='store_true',
                      dest='monitor',
                      default=False,
                      help='monitor mode')

    (opt, args) = parser.parse_args(sys.argv)

    if len(args) != 2:
        parser.error('wrong number of arguments')

    id = args[1]
    flags = opt.id | opt.fdata | opt.fscalar | opt.fvector | opt.ftime | opt.sdata | opt.sscalar | opt.svector | opt.stime | opt.flags

    if flags == 0:
        flags = 0x0001

    fast = False
    if (flags & (0x20 | 0x40 | 0x80 | 0x100)) != 0:
        fast = True

    def coroutine():
        (a, p) = paths.breakid_list(id)
        p = ''.join(chr(c) for c in p)
        r = async .Deferred()
        c = Opener(a, p, flags, r if not opt.monitor else None, fast)
        yield r

    def handler(ei):
        traceback.print_exception(file=sys.stderr, *ei)
        return async .Coroutine.failure('internal error')

    def failed(msg):
        print msg
        picross.exit(-1)

    def succeeded():
        picross.exit(0)

    def startup(dummy):
        result = async .Coroutine(coroutine(), handler)
        result.setErrback(failed).setCallback(succeeded)
        return result

    session.run_session(startup, clock=False, rt=False)
示例#5
0
def main():
    parser = optparse.OptionParser(usage=sys.argv[0] +
                                   ' [options] agent script')
    parser.add_option('--quiet',
                      action='store_true',
                      dest='quiet',
                      default=False,
                      help='quiet')
    parser.add_option('--ctimeout',
                      action='store',
                      type='int',
                      dest='ctimeout',
                      default=5000,
                      help='con timeout (5000 ms)')
    parser.add_option('--rtimeout',
                      action='store',
                      type='int',
                      dest='rtimeout',
                      default=300000,
                      help='rpc timeout (300000 ms)')
    parser.add_option('--verbose',
                      action='store_true',
                      dest='verbose',
                      default=False,
                      help='verbose')

    (opts, args) = parser.parse_args(sys.argv)

    if len(args) != 3:
        parser.error('wrong number of arguments')

    lang = args[1]
    script = args[2]

    fp = open_script(script)

    if fp is None:
        parser.error('cant open %s' % script)

    def handler(ei):
        traceback.print_exception(*ei)
        return async .Coroutine.failure('internal error')

    def failed(msg):
        if opts.verbose:
            print 'script failed:', msg
        picross.exit(-1)

    def succeeded():
        if opts.verbose:
            print 'script finished'
        picross.exit(0)

    def startup(dummy):
        result = async .Coroutine(
            coroutine(lang, fp, opts.ctimeout, opts.rtimeout, opts.verbose),
            handler)
        result.setErrback(failed).setCallback(succeeded)
        return result

    picross.pic_set_interrupt()
    session.run_session(startup, clock=False)
示例#6
0
文件: rexec.py 项目: tylerwood/EigenD
def main():
    picross.pic_set_interrupt()
    user_default = session.get_username()
    parser = optparse.OptionParser(usage=sys.argv[0] + ' [options] command')
    parser.add_option('--user',
                      action='store',
                      dest='user',
                      default=user_default,
                      help='user (%s)' % user_default)
    parser.add_option('--quiet',
                      action='store_true',
                      dest='quiet',
                      default=False,
                      help='quiet')
    parser.add_option('--ctimeout',
                      action='store',
                      type='int',
                      dest='ctimeout',
                      default=20000,
                      help='con timeout (20000 ms)')
    parser.add_option('--rtimeout',
                      action='store',
                      type='int',
                      dest='rtimeout',
                      default=60000,
                      help='rpc timeout (60000 ms)')

    (opts, args) = parser.parse_args(sys.argv)

    cmdline = ' '.join(args[1:])

    finder = [None]
    language = [None]
    rpc = [None]
    agent = [None]

    def rpc_ok(*a, **kw):
        if not opts.quiet: print 'rpc completed'
        language[0].original().cancel()
        picross.exit(0)

    def rpc_failed(msg):
        if not opts.quiet: print 'rpc failed: ', msg
        language[0].original().cancel()
        picross.exit(-1)

    def lang_connected():
        if not opts.quiet: print 'connected to', agent[0]
        rpc[0] = language[0].original().invoke_rpc('exec',
                                                   cmdline,
                                                   time=opts.rtimeout)
        rpc[0].setCallback(rpc_ok).setErrback(rpc_failed)

    def lang_discon():
        if not opts.quiet: print 'language agent not connected'
        language[0].original().cancel()

    def lang_found(name):
        agent[0] = name
        language[0] = timeout.Timeout(Connector(name), opts.ctimeout, False)
        language[0].setCallback(lang_connected).setErrback(lang_discon)
        finder[0].original().close_index()

    def lang_notfound():
        if not opts.quiet: print 'language agent not found'
        finder[0].original().close_index()

    def doexec(manager):
        finder[0] = timeout.Timeout(Finder(), opts.ctimeout, False)
        finder[0].setCallback(lang_found).setErrback(lang_notfound)
        return finder[0]

    if cmdline:
        session.run_session(doexec, user=opts.user, clock=False)
示例#7
0
def main():
    """
    bad main function
    """

    #sys.setdlopenflags(dl.RTLD_NOW|dl.RTLD_LOCAL)

    picross.pic_set_interrupt()
    picross.pic_mlock_code()
    picross.pic_init_time()

    parser = optparse.OptionParser(usage=sys.argv[0] +
                                   ' [options] [address=agent ...]')
    parser.add_option('--stdout',
                      action='store_true',
                      dest='stdout',
                      default=False,
                      help='log to stdout')
    parser.add_option('--path',
                      action='append',
                      dest='path',
                      default=[],
                      help='add to search path')
    parser.add_option('--mt',
                      action='store',
                      type='int',
                      dest='mt',
                      default=1,
                      help='number of threads (1)')
    parser.add_option('--target',
                      action='store',
                      dest='target',
                      default=None,
                      help='state to load')
    parser.add_option('--name',
                      action='store',
                      type='int',
                      dest='name',
                      default=1,
                      help='address')

    (opts, args) = parser.parse_args(sys.argv)

    lock = resource.LockFile('eigend-%d' % opts.name)
    if not lock.lock():
        print 'cannot run more than one eigend at a time'
        sys.exit(-1)

    preload = {}

    logfilename = 'eigend'

    for a in args[1:]:
        sa = a.split('=')
        if len(sa) != 2:
            parser.error('invalid preload %s' % a)
        preload[bracketify(sa[0])] = sa[1]

    if not opts.path:
        zd = os.path.join(picross.release_root_dir(), 'plugins')
        opts.path.append(zd)

    if opts.stdout:
        logfile = sys.__stdout__
    else:
        logfile = resource.open_logfile(logfilename)

    result = [None]

    def load_ok(errs):
        print 'load ok', errs

    def load_failed(errs):
        print 'load failed', errs

    def hostlogger(msg):
        if logfile:
            print >> logfile, msg
            logfile.flush()

    def startup(mgr):
        a = Agent(mgr,
                  opts.name,
                  opts.path,
                  logger=hostlogger,
                  icon='app_cmdline/agentd.png')

        try:
            if opts.target:
                x = a.load_file(opts.target)
                path, result[0] = x
                result[0].setCallback(load_ok).setErrback(load_failed)
            else:
                for (name, plugin) in preload.iteritems():
                    a.add_agent(name, plugin)

        except Exception, e:
            utils.log_exception()

        return a