コード例 #1
0
 def setUp(self):
     slacker_obj = mocks.mocked_slacker_object(
         channels_list=fixtures.channels, users_list=fixtures.users)
     self.slackbot = mocks.mocked_slackbot_object()
     with mock.patch.dict(os.environ, {'DESTALINATOR_ACTIVATED': 'true'}):
         self.announcer = announcer.Announcer(
             slacker_injected=slacker_obj, slackbot_injected=self.slackbot)
コード例 #2
0
ファイル: scheduler.py プロジェクト: rossrader/destalinator
def destalinate_job():
    print("Destalinating")
    if "SB_TOKEN" not in os.environ or "API_TOKEN" not in os.environ:
        print("ERR: Missing at least one Slack environment variable.")
    else:
        scheduled_warner = warner.Warner()
        scheduled_archiver = archiver.Archiver()
        scheduled_announcer = announcer.Announcer()
        scheduled_flagger = flagger.Flagger()
        print("Warning")
        scheduled_warner.warn()
        print("Archiving")
        scheduled_archiver.archive()
        print("Announcing")
        scheduled_announcer.announce()
        print("Flagging")
        scheduled_flagger.flag()
        print("OK: destalinated")
    print("END: destalinate_job")
コード例 #3
0
def destalinate_job():
    logging.info("Destalinating")
    if not _config.sb_token or not _config.api_token:
        logging.error(
            "Missing at least one required Slack environment variable.\n"
            "Make sure to set DESTALINATOR_SB_TOKEN and DESTALINATOR_API_TOKEN."
        )
    else:
        try:
            archiver.Archiver().archive()
            warner.Warner().warn()
            announcer.Announcer().announce()
            flagger.Flagger().flag()
            logging.info("OK: destalinated")
        except Exception as e:  # pylint: disable=W0703
            raven_client.captureException()
            if not _config.sentry_dsn:
                raise e
    logging.info("END: destalinate_job")
コード例 #4
0
def destalinate_job():
    print("Destalinating")
    if "SB_TOKEN" not in os.environ or "API_TOKEN" not in os.environ:
        print("ERR: Missing at least one Slack environment variable.")
    else:
        try:
            scheduled_warner = warner.Warner()
            scheduled_archiver = archiver.Archiver()
            scheduled_announcer = announcer.Announcer()
            scheduled_flagger = flagger.Flagger()
            print("Warning")
            scheduled_warner.warn()
            print("Archiving")
            scheduled_archiver.archive()
            print("Announcing")
            scheduled_announcer.announce()
            print("Flagging")
            scheduled_flagger.flag()
            print("OK: destalinated")
        except Exception as e:  # pylint: disable=W0703
            raven_client.captureException()
            if not os.getenv('SENTRY_DSN'):
                raise e
    print("END: destalinate_job")
コード例 #5
0
ファイル: main.py プロジェクト: ivopascal/Epistemic_Kwartet
        f = open("output.txt", "a")
        print("This is game " + str(i + 1), file=f)
        f.close()

        #create the deck and shuffle the cards accross players
        d = deck.Deck(ncards=52)
        d.shuffle()
        cuts = d.cut(4)
        players = list()
        #create the player, the player gets a set of shuffled cards an id number and a strategy number
        for i in range(4):
            players.append(
                player.Player(cuts[i], nkinds=d.nkinds, id=i, strategy=i))

        #create the announcer and set the opponents
        a = announcer.Announcer(players)
        for i in range(4):
            players[i].intro_opponents(players[:i] + players[i + 1:])
            players[i].set_announcer(a)

#start at turn_number 0 and counter for the current player
        turn = 0
        player_counter = 0

        #print turn 0 and print the starting cards of each player.
        f = open("output.txt", "a")
        print("turn " + str(turn), file=f)
        for p in players:
            print(p.cards, file=f)
        f.close()
コード例 #6
0
    def loadConfig(self):
        config = ConfigParser.SafeConfigParser(allow_no_value=True)
        config.read('main.ini')

        self.mods["base"] = self.loadMod("base")

        self.Weapons = Weapons()

        self.announcer = announcer.Announcer(self.actionHandler)
        self.announcer.start()

        requiredImports = []
        moduleImports = {}

        for mod in config.options("mods"):
            mod = str(mod).strip()
            if not mod in self.mods and mod != "base" and mod[0] != "#":
                logging.debug("Attempting to load module %s" % mod)
                curmod = self.loadMod(mod)
                if curmod:
                    self.mods[mod] = curmod
                    if hasattr(curmod, "requiredImports"):
                        requiredImports.extend(curmod.requiredImports)
                        moduleImports[
                            mod] = curmod.requiredImports  #this is used to check whether all dependencies are met before initializing the module
                    else:
                        moduleImports[mod] = []

        failedImports = []
        while len(requiredImports) > 0:
            impModule = requiredImports.pop()
            if not impModule in dir() or not impModule in self.mods:
                logging.info(
                    "Trying to import additional required module %s :" %
                    impModule)

                try:
                    file, pathname, descr = imp.find_module(impModule)
                except ImportError:
                    iM = self.loadMod(impModule)
                    if iM:
                        if hasattr(iM, "requiredImports"):
                            requiredImports.extend(iM.requiredImports)
                        self.mods[impModule] = iM
                        logging.info("Successfully imported module %s!" %
                                     impModule)
                    else:
                        logging.info(
                            "Could not import %s! (does the module exist?)" %
                            impModule)
                        failedImports.append(str(os.path.basename(impModule)))
                else:
                    imp.load_module(impModule, file, pathname, descr)
                    logging.info("Successfully imported module %s !" %
                                 impModule)

        for n, m in self.mods.items():  #name, module instance
            logging.info("Trying to initalize mod %s" % n)
            unmet = set(moduleImports.setdefault(n, [])) & set(failedImports)
            if len(unmet) > 0:
                logging.info("Unmet dependencies for module %s :" % n)
                logging.info(unmet)
                logging.info("Unloading module!")
                del (self.mods[n])
            else:
                logging.info("Loaded %s ( %s ) by %s" % (m.name, n, m.author))
                modConfig = ConfigParser.SafeConfigParser(allow_no_value=True)
                modConfig.read('configs/%s.cfg' % os.path.basename(n))
                self.mods[n] = m.Bf3Mod(self, self.actionHandler, modConfig)

        for n, m in self.mods.items():
            self.mods[n].modInit()