Beispiel #1
0
def onBaseAppReady(isBootstrap):
    """
    KBEngine method.
    baseapp已经准备好了
    @param isBootstrap: 是否为第一个启动的baseapp
    @type isBootstrap: BOOL
    """
    INFO_MSG('onBaseAppReady: isBootstrap=%s' % isBootstrap)

    # 安装监视器
    Watcher.setup()

    if isBootstrap:
        # 创建spacemanager
        # KBEngine.createBaseLocally( "Spaces", {} )
        # 创建邮箱系统
        KBEngine.createBaseLocally("PlayerMgr", {})
        # 创建邮箱系统
        KBEngine.createBaseLocally("Mails", {})

        KBEngine.globalData["Onlines"] = set()

        KBEngine.createBaseLocally("GlobalTimerMgr", {})

        KBEngine.createBaseLocally("RoomMgr", {})
        KBEngine.createBaseLocally("AutoRoomMgr", {})

        if isWorldBossMgrLoad is False:
            worldBossMgr = KBEngine.createBaseLocally("WorldBossMgr", {})
            worldBossMgr.writeToDB(None, True)

        if isGuildMgrLoad is False:
            guildMgr = KBEngine.createBaseLocally("GuildMgr", {})
            guildMgr.iniNPCGuild()
            guildMgr.writeToDB(None, True)

        if isRankMgrLoad is False:
            rankMgr = KBEngine.createBaseLocally("RankMgr", {})
            rankMgr.writeToDB(None, True)

        if isArenaMgrLoad is False:
            arenaMgr = KBEngine.createBaseLocally("ArenaMgr", {})
            arenaMgr.loadFakeData()
            arenaMgr.writeToDB(None, True)

        if isAdviserMgrLoad is False:
            adviserMgr = KBEngine.createBaseLocally("AdviserMgr", {})
            adviserMgr.writeToDB(None, True)
            adviserMgr.initAdviserData()

        if isOfficialMgrLoad is False:
            officialMgr = KBEngine.createBaseLocally("OfficialMgr", {})
            officialMgr.writeToDB(None, True)

        if isLeagueMgrLoad is False:
            leagueMgr = KBEngine.createBaseLocally("LeagueMgr", {})
            leagueMgr.writeToDB(None, True)
Beispiel #2
0
def onBaseAppReady(isBootstrap):
    """
	KBEngine method.
	baseapp已经准备好了
	@param isBootstrap: 是否为第一个启动的baseapp
	@type isBootstrap: BOOL
	"""
    INFO_MSG('onBaseAppReady: isBootstrap=%s, appID=%s, bootstrapGroupIndex=%s, bootstrapGlobalIndex=%s' % \
     (isBootstrap, os.getenv("KBE_COMPONENTID"), os.getenv("KBE_BOOTIDX_GROUP"), os.getenv("KBE_BOOTIDX_GLOBAL")))

    Watcher.setup()

    if isBootstrap:
        KBEngine.createEntityLocally("Halls", {})
def onBaseAppReady(isBootstrap):
	"""
	KBEngine method.
	baseapp已经准备好了
	@param isBootstrap: 是否为第一个启动的baseapp
	@type isBootstrap: BOOL
	"""
	INFO_MSG('onBaseAppReady: isBootstrap=%s' % isBootstrap)
	
	# 安装监视器
	Watcher.setup()
	
	if isBootstrap:
		# 创建spacemanager
		KBEngine.createBaseLocally( "Spaces", {} )
Beispiel #4
0
def onBaseAppReady(isBootstrap):
    """
	KBEngine method.
	baseapp已经准备好了
	@param isBootstrap: 是否为第一个启动的baseapp
	@type isBootstrap: BOOL
	"""
    INFO_MSG('onBaseAppReady: isBootstrap=%s' % isBootstrap)

    # 安装监视器
    Watcher.setup()

    if isBootstrap:
        # 创建spacemanager
        KBEngine.createEntityLocally("Spaces", {})
Beispiel #5
0
    def main(self, args=None):
        args = self.parse_args(args)

        self.update_config(args)

        # Reporter only really needs to check the verbosity level
        self._reporter = Core.Reporter(self.config, self.config_path)

        if "subparser" in args:

            if args.subparser == "create":
                generate.NewProject(args.path, self._reporter)
                exit()

            if args.subparser == "serve":
                port = None
                if args.port:
                    port = args.port
                serve.BasicServer(args.path, self._reporter, port)

            if args.subparser == "build":
                self._reporter.log(
                    "Wrangling %s" % (self.config['wrangler']['input_dir']),
                    "green")
                self.render()

            if args.subparser == "watch":

                watch_init = signal('watch_init')
                watch_change = signal('watch_change')

                watch_init.connect(self.on_watch_ready)
                watch_change.connect(self.on_watch_change)
                watcher = watch.Watcher(
                    self.config["wrangler"]["input_dir"],
                    self.config["wrangler"]["templates_dir"])

            if args.subparser == "clean":
                # self.update_config(args)
                files = [
                    self.config["wrangler"]["compiled_templates_file"],
                    self.config["wrangler"]["build_cache_file"]
                ]

                for f in files:
                    if os.path.exists(f):
                        try:
                            os.remove(f)
                            self._reporter.log("Cleaning up: %s" % (f), "blue")
                        except:
                            self._reporter.log("Couldn't access: %s" % (f),
                                               "red")
                self._reporter.log("Done", "green")
                exit()

        else:
            return None
Beispiel #6
0
    def run(self):
        self.init_src()
        watcher = Watcher.Watcher(self, self.workq, self.src, self.dst)

        try:
            watcher.loop()
            Sync.Start(self, self.worker, self.db)
        except KeyboardInterrupt:
            watcher.stop()
            Sync.Stop()
Beispiel #7
0
def onBaseAppReady(isBootstrap):
    """
	KBEngine method.
	baseapp已经准备好了
	@param isBootstrap: 是否为第一个启动的baseapp
	@type isBootstrap: BOOL
	"""
    # 安装监视器
    Watcher.setup()

    h1global.initBaseApp()

    if isBootstrap:
        # 创建spacemanager
        h1global.createSingletonFromDB("GameWorld", "GameWorld", 1, {})

    pay_poller.start("localhost", 30060)
    draw_poller.start("localhost", 30070)
    INFO_MSG('onBaseAppReady: isBootstrap=%s, appID=%s, bootstrapGroupIndex=%s, bootstrapGlobalIndex=%s' % \
     (isBootstrap, os.getenv("KBE_COMPONENTID"), os.getenv("KBE_BOOTIDX_GROUP"), os.getenv("KBE_BOOTIDX_GLOBAL")))
Beispiel #8
0
class TestSomeMethods(unittest.TestCase):
    '''
    Note, only testing single memento serial/deserial (however multiple mementos are supported and serialized/deserialized correctly)
    '''
    file_path = "../sample_db_test.json"
    webpage_to_test = "http://www.pja.edu.pl/"
    w = Watcher.Watcher()
    o = ObserverDP.ConcreteObserver(webpage=webpage_to_test, subject=w)
    c = Caretaker.Caretaker(save_path=file_path, watcher=w)

    def test_serialize(self):
        self.c.add_memento(self.w.generate_memento())
        self.c.serialize()
        serialized = open(file=self.file_path)
        json_content = json.load(serialized)[0]
        self.assertEqual(
            json_content.get("webpages")[self.webpage_to_test],
            self.w.urls_to_watch.get(self.webpage_to_test),
        )  # serialized correctly if both match
        self.assertEqual(
            len(self.w.observers), len(json_content.get("observers"))
        )  # number of observers matches
        serialized.close()

    def test_deserialize(self):
        '''
        Note, only tests single memento, but can pass specific index into get_memento if you want to try others
        :return:
        '''
        new_watcher = Watcher.Watcher()
        new_caretaker = Caretaker.Caretaker.deserialize(save_path=self.file_path)
        new_caretaker.set_watcher(
            new_watcher
        )  # can't deserialize specific watcher, rather have to create new one then restore from memento
        new_watcher.restore(
            new_caretaker.get_memento()
        )  # Restoring from most recent state
        self.assertEqual(self.w.observers[0].webpage, new_watcher.observers[0].webpage)

    def test_update(self):
        util.get_last_modified = MagicMock(
            return_value="Fri, 11 Dec 2020 23:08:20 GMT"
        )  # mock dif response
        sample_watcher = Watcher.Watcher()
        sample_observer = ObserverDP.ConcreteObserver(
            webpage=self.webpage_to_test, subject=sample_watcher
        )
        self.assertEqual("", sample_watcher.urls_to_watch.get(self.webpage_to_test))
        sample_watcher.check_pages()
        self.assertEqual(
            sample_watcher.urls_to_watch.get(self.webpage_to_test),
            "Fri, 11 Dec 2020 23:08:20 GMT",
        )
Beispiel #9
0
 def test_deserialize(self):
     '''
     Note, only tests single memento, but can pass specific index into get_memento if you want to try others
     :return:
     '''
     new_watcher = Watcher.Watcher()
     new_caretaker = Caretaker.Caretaker.deserialize(save_path=self.file_path)
     new_caretaker.set_watcher(
         new_watcher
     )  # can't deserialize specific watcher, rather have to create new one then restore from memento
     new_watcher.restore(
         new_caretaker.get_memento()
     )  # Restoring from most recent state
     self.assertEqual(self.w.observers[0].webpage, new_watcher.observers[0].webpage)
def onBaseAppReady(isBootstrap):
    """
	Ouroboros method.
	baseapp is ready.
	@param isBootstrap: Whether the first start of the baseapp
	@type isBootstrap: BOOL
	"""
    #INFO_MSG("ya")
    #EntityCreator.CreateBaseEntities()
    props = {"name": "MyFirstEntity"}
    # Create FirstEntity
    #Ouroboros.createEntityLocally("FirstEntity", props)
    # Create a Scene entity when the baseapp is ready
    #Ouroboros.createEntityLocally("Scene", {})

    INFO_MSG('onBaseAppReady: isBootstrap=%s' % isBootstrap)

    # Installation monitor
    Watcher.setup()

    if isBootstrap:
        # Create spacemanager
        Ouroboros.createEntityLocally("Spaces", {})
Beispiel #11
0
 def test_update(self):
     util.get_last_modified = MagicMock(
         return_value="Fri, 11 Dec 2020 23:08:20 GMT"
     )  # mock dif response
     sample_watcher = Watcher.Watcher()
     sample_observer = ObserverDP.ConcreteObserver(
         webpage=self.webpage_to_test, subject=sample_watcher
     )
     self.assertEqual("", sample_watcher.urls_to_watch.get(self.webpage_to_test))
     sample_watcher.check_pages()
     self.assertEqual(
         sample_watcher.urls_to_watch.get(self.webpage_to_test),
         "Fri, 11 Dec 2020 23:08:20 GMT",
     )
Beispiel #12
0
def onBaseAppReady(isBootstrap):
    """
    KBEngine method.
    baseapp已经准备好了
    @param isBootstrap: 是否为第一个启动的baseapp
    @type isBootstrap: BOOL
    """
    INFO_MSG('onBaseAppReady: isBootstrap=%s' % isBootstrap)

    # 安装监视器
    Watcher.setup()

    if isBootstrap:
        # 创建spacemanager
        # KBEngine.createBaseLocally( "Spaces", {} )
        # 创建邮箱系统
        KBEngine.createBaseLocally("PlayerMgr", {})
        # 创建邮箱系统
        KBEngine.createBaseLocally("Mails", {})

        KBEngine.globalData["Onlines"] = set()

        KBEngine.createBaseLocally("CloneMgr", {})
        pass
Beispiel #13
0
    def watch():
        '''Create list of miners, validate them, plot them live.'''
        #  Get miners
        miners = []
        #  First check args
        if args.miner:
            #  Look for given miner in config
            if config[args.miner]:
                #  Miner exists in config file, create instance
                new_miner = Miner.Miner(
                    args.miner,  #  Name
                    config[args.miner]['host'],
                    config[args.miner]['port'],
                    Stats.Stats('Claymore json'))
                miners.append(new_miner)
                print('{}: Miner set {}'.format(__name__, str(new_miner)))
            else:
                sys.exit('Miner not in config.')
        #  Second check config
        elif int(config['GENERAL']['miners']) > 0:
            #  Get miners from config
            num_miners = int(config['GENERAL']['miners'])
            miners = []
            for each_section in config.sections():
                if each_section == 'GENERAL':
                    #  General is not a miner name, skip this section.
                    pass
                else:
                    #  For each miner section...
                    new_miner = Miner.Miner(
                        each_section,  #  Name
                        config.get(each_section, 'host'),
                        config.get(each_section, 'port'),
                        Stats.Stats('Claymore json'))
                    miners.append(new_miner)
        else:
            #  No miners in config
            print('{}: Miner not set. Add one to config.'.format(__name__))

        # TODO: Validate miners, if theyre inactive remove them from the list

        watcher = Watcher.Watcher(miners)
        names = [miner.name for miner in miners]
        print('Plotting {} stats every {}s.'.format(', '.join(names), inter))
        plotter.plot_live(watcher)
Beispiel #14
0
def main():
	cfg=ConfigParser()
	cfg.read('Config.cfg',encoding='utf-8')
	card=str(cfg.get('global','card'))
	sendto=str(cfg.get('global','sendto'))
	logintype=cfg.getint('global','logintype')
	user=str(cfg.get('global','user'))
	min_balance=cfg.get('global','min_Balance')
	
	bot=Wechat.Wechat(user,logintype)
	last_time=time.time()
	while(True):
		bot.keep_login()
		if (time.time()-last_time)<(60*60*24) :
			time.sleep(60*5)
			continue
		mny=Watcher.work(card)
		if float(mny)<min_balance:
			bot.send('[自动监控]校园卡卡号%s的余额为%s元,请及时充值' %(card,mny),sendto)
		last_time=time.time()
    global sockr
    try:
        print('start service ...')
        while True:
            message, from_ = sockr.recvfrom(bufsize)
            #print 'message:'+ str(message)
            if (message == ''):
                print('pipe broken')
                sockr.close()
                return
            else:
                print(str(message))
                start = int(time.time() * 1000.0)
                jdata = json.loads(str(message))
                jdata['rsu_timestamp'] = start
                end = jdata['timestamp']

                print('time dif :  ', (start - end), ' ms')
                #pass
                broadcast_to_nuk(json.dumps(jdata))

#pass
#print ('message from :'+ str(address[0]) , message)
    except Exception as err:
        print 'exception in comm::receiver()', err

if __name__ == "__main__":
    watch.Watcher()
    threading.Thread(target=dsrc_transmiter).start()
    dsrc_receiver()
Beispiel #16
0
        return Caretaker(save_path=save_path,
                         watcher=None,
                         saved_mementos=memento_list)

    def add_memento(self, memento_to_add: Memento):
        self.saved_mementos.append(memento_to_add)

    def get_memento(self, index=-1):
        if (index == -1):
            index = len(self.saved_mementos) - 1
        return self.saved_mementos[index]


if __name__ == "__main__":

    s = Watcher.Watcher()
    o = ObserverDP.ConcreteObserver(webpage="http://www.pja.edu.pl/",
                                    subject=s)
    o1 = ObserverDP.ConcreteObserver(webpage="http://www.pja.edu.pl/",
                                     subject=s)
    o2 = ObserverDP.ConcreteObserver(webpage="https://www.olx.pl/", subject=s)
    s.check_pages()
    c = Caretaker("./sample_db.json")
    m = s.generate_memento()
    c.add_memento(m)
    print(c.saved_mementos)
    print(c.serialize())

    w = Watcher.Watcher()
    c = Caretaker.deserialize(save_path="./sample_db.json")
    c.set_watcher(
Beispiel #17
0
def main_test(): 
	if len(sys.argv)>1 :
		card=str(sys.argv[1])
		mny=Watcher.work(card)
		print('卡号%s的余额为%s元' %(card,mny))
		exit()