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)
def cli(): parser = optparse.OptionParser() parser.add_option('--stdout', action='store_true', dest='stdout', default=False, help='log to stdout') x = [a for a in sys.argv if not a.startswith('-psn')] (opts, args) = parser.parse_args(x) name = 'eigencommander1' lock = resource.LockFile(name) if not lock.lock(): print 'cannot get lock: aborting' sys.exit(-1) if opts.stdout: logfile = sys.__stdout__ else: logfile = resource.open_logfile(name) def logger(msg): if logfile: print >> logfile, name, msg logfile.flush() app = commanderApp(name, logfunc=logger) app.MainLoop() picross.exit(0)
def __init__(self, name): self.name = name self.logfile = resource.open_logfile(name)
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