Exemple #1
0
def optional_checks(data, msg, r, token_comment, awarder, awardee_comment, awardee, token_found):
	logging.debug("Optional Checks")
	if check_awardee_not_author(data["check_ana"], token_comment.submission.author, awardee):
		error_bad_recipient = messages.error_bad_recipient(data, msg, token_comment)
		reply_unique(data,token_comment,error_bad_recipient)
		logging.info("Error Bad Recipient Sent")
	elif check_awarder_to_awardee_history(data, msg, r, awardee_comment, awardee, token_comment, awarder):
		error_submission_history = messages.error_submission_history(msg, awardee_comment.author.name)
		reply_unique(data,token_comment,error_submission_history)
		logging.info("Error Submission History Sent")
	elif check_length(data, token_comment.body, token_found):
		error_length = messages.error_length(data, msg, awardee_comment.author.name)
		reply_unique(data,token_comment,error_length)
		logging.info("Error Length Sent")
	else:
		logging.debug("Token Valid - Beginning Award Process")
		flair_count = token.start_increment(data, msg, r, awardee)
		logging.debug("Token Awarded")
		token_comment.save()
		logging.debug("Comment Saved")
		confirmation = messages.confirm(data, msg, awardee_comment, awardee)
		reply_unique(data,token_comment,confirmation)
		logging.info("Confirmation Message Sent")
		wiki.start(data, r, token_comment, token_comment.author.name, awardee_comment.author.name, flair_count)
		logging.info("Wiki Updates Complete")
		wait()
Exemple #2
0
 def execute(self, cmd, tab):
     selected = [f for f in tab.sorted if f in tab.selections]
     loop = self.__check_loop(cmd, selected)
     if cmd[-1] == '&':
         mode = PowerCLI.RUN_BACKGROUND
         cmd_orig = cmd[:-1].strip()
     elif cmd[-1] == '%':
         mode = PowerCLI.RUN_NEEDCURSESWIN
         cmd_orig = cmd[:-1].strip()
     else:
         mode = PowerCLI.RUN_NORMAL
         cmd_orig = cmd
     if loop:
         for f in selected:
             try:
                 cmd = self.__replace_cli(cmd_orig, tab, selected, f)
             # except Exception as msg: # python v2.6+
             except Exception, msg:
                 messages.error('Cannot execute PowerCLI command:\n  %s\n\n%s' % \
                                    (cmd_orig, str(msg)))
                 st = -1
             else:
                 st = self.__run(cmd, tab.path, mode)
             if st == -1:
                 self.app.lpane.display()
                 self.app.rpane.display()
                 if messages.confirm('Error running PowerCLI',
                                     'Do you want to stop now?') == 1:
                     break
         tab.selections = []
Exemple #3
0
 def execute(self, cmd, tab):
     selected = [f for f in tab.sorted if f in tab.selections]
     loop = self.__check_loop(cmd, selected)
     if cmd[-1] == '&':
         mode = PowerCLI.RUN_BACKGROUND
         cmd_orig = cmd[:-1].strip()
     elif cmd[-1] == '%':
         mode = PowerCLI.RUN_NEEDCURSESWIN
         cmd_orig = cmd[:-1].strip()
     else:
         mode = PowerCLI.RUN_NORMAL
         cmd_orig = cmd
     if loop:
         for f in selected:
             try:
                 cmd = self.__replace_cli(cmd_orig, tab, selected, f)
             # except Exception as msg: # python v2.6+
             except Exception, msg:
                 messages.error('Cannot execute PowerCLI command:\n  %s\n\n%s' % \
                                    (cmd_orig, str(msg)))
                 st = -1
             else:
                 st = self.__run(cmd, tab.path, mode)
             if st == -1:
                 self.app.lpane.display()
                 self.app.rpane.display()
                 if messages.confirm('Error running PowerCLI',
                                     'Do you want to stop now?') == 1:
                     break
         tab.selections = []
Exemple #4
0
 def __run(self, cmd, path, mode):
     if mode == PowerCLI.RUN_NEEDCURSESWIN:
         curses.endwin()
         try:
             msg = utils.get_shell_output3('cd "%s" && %s' % (path, cmd))
         except KeyboardInterrupt:
             os.system('reset')
             msg = 'Stopped by user'
         st = -1 if msg else 0
     elif mode == PowerCLI.RUN_BACKGROUND:
         utils.run_in_background(cmd, path)
         st, msg = 0, ''
     else: # PowerCLI.RUN_NORMAL
         st, msg = utils.ProcessFunc('Executing PowerCLI', cmd,
                                     utils.run_shell, cmd, path, True).run()
     if st == -1:
         messages.error('Cannot execute PowerCLI command:\n  %s\n\n%s' % \
                            (cmd, str(msg)))
     elif st != -100 and msg is not None and msg != '':
         if self.app.prefs.options['show_output_after_exec']:
             curses.curs_set(0)
             if messages.confirm('Executing PowerCLI', 'Show output', 1):
                 lst = [(l, 2) for l in msg.split('\n')]
                 pyview.InternalView('Output of "%s"' % utils.encode(cmd),
                                     lst, center=0).run()
     return st
Exemple #5
0
 def __run(self, cmd, path, mode):
     if mode == PowerCLI.RUN_NEEDCURSESWIN:
         curses.endwin()
         try:
             msg = utils.get_shell_output3('cd "%s" && %s' % (path, cmd))
         except KeyboardInterrupt:
             os.system('reset')
             msg = 'Stopped by user'
         st = -1 if msg else 0
     elif mode == PowerCLI.RUN_BACKGROUND:
         utils.run_in_background(cmd, path)
         st, msg = 0, ''
     else:  # PowerCLI.RUN_NORMAL
         st, msg = utils.ProcessFunc('Executing PowerCLI', cmd,
                                     utils.run_shell, cmd, path,
                                     True).run()
     if st == -1:
         messages.error('Cannot execute PowerCLI command:\n  %s\n\n%s' % \
                            (cmd, str(msg)))
     elif st != -100 and msg is not None and msg != '':
         if self.app.prefs.options['show_output_after_exec']:
             curses.curs_set(0)
             if messages.confirm('Executing PowerCLI', 'Show output', 1):
                 lst = [(l, 2) for l in msg.split('\n')]
                 pyview.InternalView('Output of "%s"' % utils.encode(cmd),
                                     lst,
                                     center=0).run()
     return st
Exemple #6
0
def exit(tab):
    """exit from vfs, clean all"""

    ans = 0
    rebuild = app.prefs.options['rebuild_vfs']
    if app.prefs.confirmations['ask_rebuild_vfs']:
        ans = messages.confirm('Rebuild vfs file', 'Rebuild vfs file', rebuild)
        app.display()
    if ans:
        if tab.vfs == 'pan':
            return pan_regenerate(tab)
        else:
            regenerate_file(tab)
    files.delete_bulk(tab.base, ignore_errors=True)
    app.regenerate()
Exemple #7
0
def exit(tab):
    """exit from vfs, clean all"""

    ans = 0
    rebuild = app.prefs.options['rebuild_vfs']
    if app.prefs.confirmations['ask_rebuild_vfs']:
        ans = messages.confirm('Rebuild vfs file', 'Rebuild vfs file', rebuild)
        app.display()
    if ans:
        if tab.vfs == 'pan':
            return pan_regenerate(tab)
        else:
            regenerate_file(tab)
    files.delete_bulk(tab.base, ignore_errors=True)
    app.regenerate()
Exemple #8
0
def optional_checks(data,msg,r,token_comment,awarder,awardee_comment,awardee,token_found):
	logging.debug("Optional Checks")
	if check_awardee_not_author(data["check_ana"],token_comment.submission.author,awardee):
		error_bad_recipient = messages.error_bad_recipient(data,msg,token_comment)
		token_comment.reply(error_bad_recipient).distinguish()
		logging.info("Error Bad Recipient Sent")
	elif check_awarder_to_awardee_history(data,msg,r,awardee_comment,awardee,token_comment,awarder):
		error_submission_history = messages.error_submission_history(msg,awardee_comment.author.name)
		token_comment.reply(error_submission_history).distinguish()
		logging.info("Error Submission History Sent")
	elif check_length(data,token_comment.body,token_found):
		error_length = messages.error_length(data,msg,awardee_comment.author.name)
		token_comment.reply(error_length).distinguish()
		logging.info("Error Length Sent")
	else:
		logging.debug("Token Valid - Beginning Award Process")
		flair_count = token.start_increment(data,msg,r,awardee)
		logging.debug("Token Awarded")
		token_comment.save()
		logging.debug("Comment Saved")
		edited_reply = False
		for reply in token_comment.replies:
			if reply.author:
				logging.debug("Editing existing comment")
				if str(reply.author.name).lower() == data["running_username"].lower():
					confirmation = messages.confirm(data,msg,awardee_comment,awardee)
					reply.edit(confirmation).distinguish()
					edited_reply = True
		if edited_reply == False:
			logging.debug("Leaving new comment")
			confirmation = messages.confirm(data,msg,awardee_comment,awardee)
			token_comment.reply(confirmation).distinguish()
		logging.info("Confirmation Message Sent")
		wiki.start(data,r,token_comment,token_comment.author.name,awardee_comment.author.name,flair_count)
		logging.info("Wiki Updates Complete")
		wait()
Exemple #9
0
 def check_keys(self):
     ch = self.dlg.getch()
     if ch == 0x03:
         os.kill(self.pid_child, signal.SIGSTOP)
         self.show_parent()
         ans = messages.confirm('Stop process',
                                'Stop \"%s\"' % self.action.lower(), 1)
         if ans:
             os.kill(self.pid_child, signal.SIGKILL)
             os.wait()
             return -100
         else:
             os.kill(self.pid_child, signal.SIGCONT)
             return 1
     return 0
Exemple #10
0
 def check_keys(self):
     ch = app.statusbar.win.getch()
     if ch == 0x03:
         os.kill(self.pid_child, signal.SIGSTOP)
         self.show_parent()
         ans = messages.confirm('Stop process',
                                '%s %s' % (self.title, self.subtitle),
                                1)
         if ans:
             os.kill(self.pid_child, signal.SIGKILL)
             os.wait()
             return -100
         else:
             self.show_win()
             os.kill(self.pid_child, signal.SIGCONT)
     return 0
Exemple #11
0
def ask_convert_invalid_encoding_filename(filename):
    auto = app.prefs.options['automatic_file_encoding_conversion']
    if auto == -1:
        return False
    elif auto == 1:
        return True
    elif auto == 0:
        ret = messages.confirm('Detected invalid encoding',
                               'In file <%s>, convert' % filename)
        try:
            app.display()
        except:
            pass
        return (ret == 1)
    else:
        raise ValueError
Exemple #12
0
 def process_response(self, result):
     if isinstance(result, unicode) or isinstance(result, str): # overwrite?
         self.show_parent()
         ans = messages.confirm(self.action,
                                'Overwrite \'%s\'' % result, 1)
         if ans == -1:
             return -1
         elif ans == 0:
             return 0
         elif ans == 1:
             args = (self.filename, ) + self.args + (False, )
             self.dlg.show()
             return self.exec_file(args)
     elif isinstance(result, tuple): # error from child
         self.show_parent()
         messages.error('Cannot %s\n' % self.action.lower() +
                        self.filename + ': %s (%s)' % result)
         return 0
     else:
         return 0
Exemple #13
0
        iteration += FLAGS.batch
        #with tf.device('/device:GPU:0'):

        batch_x, batch_y, _, cls_batch = data.train.next_batch(FLAGS.batch)

        feed_dict = {x: batch_x, y: batch_y}

        sess.run(cnn['optimizer'], feed_dict=feed_dict)

        #with tf.device('/cpu:0'):

        tr_loss = sess.run(cnn['cost'], feed_dict=feed_dict)
        tr_acc = sess.run(cnn['accuracy'], feed_dict=feed_dict)

except KeyboardInterrupt:
    exit_flag = 0
    m.newline(2)
    m.alert("Training stoped")

    histograms.save_graphs()

    if m.confirm("Do you want to save model checkpoint?"):
        m.info("Saving model checkpoint")
        saver.save(sess, model_checkpoint)
        m.info("Checkpoint saved on: %s" % (model_checkpoint))

    else:
        m.alert("Model checkpoint won't be saved!")

    m.normal("bye bye! :)")