Ejemplo n.º 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)
Ejemplo n.º 2
0
def cli():
    parser = optparse.OptionParser()
    parser.add_option('--stdout',
                      action='store_true',
                      dest='stdout',
                      default=False,
                      help='log to stdout')
    picross.pic_init_time()

    x = [a for a in sys.argv if not a.startswith('-psn')]
    (opts, args) = parser.parse_args(x)

    name = '<eigenbrowser1>'

    if sys.platform == 'win32':
        lock = resource.LockFile('eigenbrowser')
    else:
        lock = resource.LockFile(name)

    if not lock.lock():
        print 'cannot get lock: aborting'
        sys.exit(-1)

    if opts.stdout:
        logfile = sys.__stdout__
    else:
        if sys.platform == 'win32':
            logfile = resource.open_logfile('eigenbrowser')
        else:
            logfile = resource.open_logfile(name)

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

    try:
        app = browserApp(name, logfunc=logger)
    except:
        import traceback
        print "exception raised"
        print "start traceback:"
        exeinfo = traceback.format_exc(limit=None)
        print exeinfo
        picross.exit(0)

    print "running application MainLoop"
    app.MainLoop()
    picross.exit(0)
Ejemplo n.º 3
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