Ejemplo n.º 1
0
 def refresh(self):
     # execute command: 'git annex metadata' in shell.
     p = subprocess.Popen(
         'git annex metadata',
         stdout=subprocess.PIPE,
         shell=True
     )
     (output, err) = p.communicate()
     # wait for date to terminate..
     p_status = p.wait()
     # verify return code 'p_status'.
     if p_status == 0:
         # success.
         parser = utils.Parser()
         self.collection = parser.read_annex_data(output)
         self.collection_unique = parser.get_candidate_and_timepoint_collection(
             self.collection
         )
         print self.collection_unique
         print '- Annex: success collecting data.'
     else:
         # error.
         print '- Annex: error! unable to read from git-annex.'
         self.collection = []
         self.collection_unique = []
Ejemplo n.º 2
0
def _init_mnist_model():
    print('init_mnist_model')
    global mnist_model
    config_path = os.path.join(root_path, 'config/gan.cfg')
    config = utils.Parser(config_path)
    mnist_model = Mnist(config, exp_name='mnist_classification')
    checkpoint_dir = os.path.join(config.model_dir, 'mnist_classification')
    mnist_model.load_model(checkpoint_dir)
Ejemplo n.º 3
0
def main():
    print("Welcome to edge tool!")
    edge_ip_address, edge_command = arg_parser()
    try:
        edge_instance = utils.Ssh(edge_ip_address, 'agent', 'EdgeDevice200%')
        edge_instance.cleaner(edge_ip_address)
        edge_command_output = edge_instance.execute(edge_command)
    finally:
        edge_instance.terminate_connection()
    parsing = utils.Parser(edge_command_output)
    parsing.parse_output()
Ejemplo n.º 4
0
        # NOTE: set env.current_state to None because testing process
        # interrupts the training process
        env.current_state = None

        return total_reward_aver



if __name__ == '__main__':
    argv = sys.argv
    # ----Parsing config file.----
    logger.info(socket.gethostname())
    config_file = 'gridworld_tdppo.cfg'
    config_path = os.path.join(root_path, 'config/' + config_file)
    config = utils.Parser(config_path)
    config.print_config()

    # ----Instantiate a trainer object.----
    trainer = Trainer(config, exp_name=argv[1])

    if argv[2] == 'train':
        # ----Training----
        logger.info('TRAIN')
        load_model = '/datasets/BigLearning/haowen/AutoLossApps/saved_models/'\
            'tdppo2/controller'
        #trainer.train(save_model=True, load_model=load_model)
        trainer.train(save_model=True)
    elif argv[2] == 'test':
        ## ----Testing----
        logger.info('TEST')
Ejemplo n.º 5
0
async def on_command(msg):
    content_type, chat_type, chat_id, msg_date, msg_id = telepot.glance(
        msg, long=True)
    try:
        botcom = msg['entities'][0]['type']
        if not botcom == 'bot_command':
            return
    except KeyError:
        return
    if content_type == 'text':
        raw_message, command, command_argument, msg_reply, command_from = utils.Parser(
            msg)
        try:
            reply_id = msg_reply['message_id']
        except TypeError:
            reply_id = 'None'
        if regex.search(r'\/store(\@raku_bot)?\Z', command) is not None:
            if msg_reply is not None:
                await bot.sendChatAction(chat_id, 'typing')
                if not await utils.Exists(command_argument):
                    s = commands.Handler(msg_reply)
                    if await s.store(command_argument, command_from):
                        await bot.sendMessage(
                            chat_id,
                            'Meme stored, meme with `/meme ' +
                            command_argument + '`',
                            parse_mode='Markdown',
                            reply_to_message_id=msg_id)
                    else:
                        await bot.sendMessage(chat_id,
                                              'Something went wrong :\'(',
                                              reply_to_message_id=msg_id)
                else:
                    await bot.sendMessage(chat_id,
                                          'Mem already exist :V',
                                          reply_to_message_id=msg_id)
        if regex.search(r'\/meme(\@raku_bot)?\Z', command) is not None:
            if command_argument is not None:
                await bot.sendChatAction(chat_id, 'typing')
                if await utils.Exists(command_argument):
                    s = commands.Handler(msg)
                    sendwith, gotmeme, memekw = await s.send(command_argument)
                    await getattr(bot, sendwith)(chat_id,
                                                 *gotmeme,
                                                 **memekw,
                                                 reply_to_message_id=reply_id)
                else:
                    await bot.sendMessage(chat_id,
                                          'Meme not found',
                                          reply_to_message_id=msg_id)
        elif regex.search(
                r'\/list(\@raku_bot)?\Z', command) is not None or regex.search(
                    r'\/start(\@raku_bot)?\Z',
                    command) is not None and command_argument == 'list':
            await bot.sendChatAction(chat_id, 'typing')
            if utils.isPrivate(msg):
                await bot.sendMessage(chat_id,
                                      await commands.lister.getList(),
                                      parse_mode='html')
            else:
                await bot.sendMessage(
                    chat_id,
                    '<a href="http://telegram.me/raku_bot?start=list">Ask in PM pls</a>',
                    reply_to_message_id=msg_id,
                    parse_mode='html',
                    disable_web_page_preview=True)
        elif regex.search(r'\/sauce(\@raku_bot)?\Z', command) is not None:
            if msg_reply is not None or command_argument is not None:
                await bot.sendChatAction(chat_id, 'typing')
            if msg_reply is None:
                if command_argument is not None:
                    if await utils.Exists(command_argument):
                        s = commands.Handler(msg)
                        author = await s.sauce(command_argument)
                    else:
                        await bot.sendMessage(chat_id,
                                              'Meme not found',
                                              reply_to_message_id=msg_id)
                else:
                    return
            elif msg_reply is not None:
                s = commands.Handler(msg_reply)
                author = await s.sauce()
            try:
                if author:
                    await bot.sendMessage(chat_id,
                                          'this was @' + author +
                                          ' tbh.......',
                                          reply_to_message_id=msg_id)
                else:
                    await bot.sendMessage(chat_id,
                                          'Meme not found',
                                          reply_to_message_id=msg_id)
            except UnboundLocalError:
                return
        elif regex.search(r'\/lucc(\@raku_bot)?\Z', command) is not None:
            await bot.sendChatAction(chat_id, 'typing')
            luckymeme = await commands.lucc.getLucc()
            s = commands.Handler(msg)
            sendwith, gotmeme, memekw = await s.send(luckymeme)
            await getattr(bot, sendwith)(chat_id,
                                         *gotmeme,
                                         **memekw,
                                         reply_to_message_id=reply_id)
        elif regex.search(r'\/pray(\@raku_bot)?\Z', command) is not None:
            await bot.sendChatAction(chat_id, 'typing')
            await bot.sendMessage(
                chat_id, 'In light of recent events, we\'d like to #prayfor' +
                command_argument)
        elif regex.search(r'\/delet(\@raku_bot)?\Z', command) is not None:
            from_id = msg['from']['id']
            if from_id == 105301944:
                if command_argument is not None:
                    await bot.sendChatAction(chat_id, 'typing')
                    if await utils.Exists(command_argument):
                        if await commands.deleter.deleteMeme(command_argument):
                            await bot.sendMessage(chat_id,
                                                  'Meme baleet >:U',
                                                  reply_to_message_id=msg_id)
                    else:
                        await bot.sendMessage(chat_id,
                                              'Meme not found',
                                              reply_to_message_id=msg_id)
            else:
                return
    else:
        return