def run_system_test(): """ NEW ONE 08/09/2015 replacing old version from 31/08/2015 """ from breeze.middlewares import is_on global SKIP_SYSTEM_CHECK if not SKIP_SYSTEM_CHECK and is_on(): print Bcolors.ok_blue('Running Breeze system integrity checks ......') for pre_check in PRE_BOOT_CHECK_LIST: pre_check.inline_check() checking_list = CheckerList(CHECK_LIST) checking_list.check_list() checking_list.rendezvous() else: print Bcolors.ok_blue('Skipping Breeze system integrity checks ......')
def rendezvous(self, wait_for_all=not ONLY_WAIT_FOR_CRITICAL): # Rendez-vous for processes """ wait for all process in the list to complette New version, replaces the 08/09/2015 one, better use of OOP :type wait_for_all: bool """ offset = len(PRE_BOOT_CHECK_LIST) for each in self[:]: assert isinstance(each, SysCheckUnit) and each.has_proc # Only wait for mandatory checks if wait_for_all or each.mandatory: each.block() self._results[each.url] = each.exitcode == 0 if self.FAIL_ON_CRITICAL_MISSING and each.exitcode != 0 and each.mandatory: print Bcolors.fail('BREEZE INIT FAILED ( %s )' % repr(each.ex())) # raise each.ex() import sys sys.exit(2) each.terminate() self.remove(each) # print self._results for each in self: self._results[each.url] = each.exitcode == 0 success_text = 'successful : %s/%s' % (len(self.succeeded) + offset, len(self.boot_tests) + offset) if not self.any_running: print Bcolors.ok_green('System is up and running, All checks done ! (%s)' % success_text) else: print Bcolors.ok_green('System is up and running, %s, ') % success_text + \ Bcolors.warning('but %s (non critical) check%s %s still running %s') % \ (self.running_count, 's' if self.running_count > 1 else '', self.article, self.still_running)
def __init__(self, funct, url, legend, msg, type, t_out=0, arg=None, supl=None, ex=SystemCheckFailed, mandatory=False, long_poll=False, ui_text=('Online', 'Offline')): """ init Arguments : funct: the function to run to asses test result url: id of test, and url part to access it legend: title to display on WebUI msg: title to display on Console type: type of this test t_out: timeout to set test as failed arg: arguments to funct supl: a function to run after this test ex: an exception to eventually raise on check failure mandatory: is this test success is required to system consistent boot :param funct: the function to run to asses test result :type funct: callable :param url: id of test, and url part to access it :type url: str :param legend: title to display on WebUI :type legend: str :param msg: title to display on Console :type msg: str :param type: type of this test :type type: RunType.property :param t_out: timeout to set test as failed :type t_out: int :param arg: arguments to funct :type arg: :param supl: a function to run after this test :type supl: callable :param ex: an exception to eventually raise on check failure :type ex: Exception :param mandatory: is this test success is required to system consistent boot :type mandatory: bool :param ui_text: optional text to be shown in UI, default is ('Online', 'Offline') :type ui_text: (str, str) """ if type is RunType.runtime or callable(funct): self.checker_function = funct self.url = url self.legend = legend self._msg = msg self.t_out = int(t_out) self.arg = arg self.type = type self.supl = supl self.mandatory = mandatory self.ex = ex self.lp = long_poll self.ui_text = ui_text # self._process = Process else: raise InvalidArgument(Bcolors.fail('Argument function must be a callable object'))
def split_runner(self, from_ui=False): """ Checker function runner. Call the function, display console message and exception if appropriate :type from_ui: bool """ res = False if callable(self.checker_function): try: if self.arg is not None: res = self.checker_function(self.arg) else: res = self.checker_function() except Exception as e: self.ex = e pass else: raise InvalidArgument(Bcolors.fail('Argument function must be a callable object')) sup = '' sup2 = '' if not res: if self.mandatory: sup2 = Bcolors.warning('required and critical !') else: sup2 = Bcolors.warning('NOT critical') if not from_ui: print self.msg, if self.supl is not None and callable(self.supl): sup = self.supl() print OK if res else BAD if self.mandatory else WARN, sup, sup2 if not res: import sys if self.RAISE_EXCEPTION and not from_ui: raise self.ex if from_ui or self.mandatory: sys.exit(1) sys.exit(2)
prediction_data[ld.lower()].append({ "sentence": roberta.bpe.decode(sd1), "prediction": pld.lower(), "prediction_prob": ppd, "correct": ld.lower() == pld.lower() }) overall_accuracy = "<b>{: <31}</> = <b><green>{:6.2f}</> ({:3d} / {:3d})\n\n".format("overall accuracy", float(ncorrect) * 100 / float(nsamples), ncorrect, nsamples) print("") output = "" # First compute a qualitative summary author_str = {} for label in roberta.task.label_dictionary.symbols: if label.lower() not in prediction_data: continue ncorrect = sum([x["correct"] for x in prediction_data[label.lower()]]) ntotal = max(len(prediction_data[label.lower()]), 1) author_str[label.lower()] = "author <b>{: <24}</> = <b><green>{:6.2f}</> ({:3d} / {:3d})\n".format(label, float(ncorrect) * 100 / ntotal, ncorrect, ntotal) output += author_str[label.lower()] output += "{}\n".format("".join("─" for _ in range(60))) output += overall_accuracy output += "{}\n\n".format("".join("=" for _ in range(60))) print(Bcolors.postprocess(output)) with open(args.input_file + ".acceptability_labels", "w") as f: f.write("\n".join(argmax_results) + "\n")
def msg(self): return Bcolors.ok_blue(self._msg)
# import breeze.auxiliary as aux DEBUG = True SKIP_SYSTEM_CHECK = False # FAIL_ON_CRITICAL_MISSING = True # RAISE_EXCEPTION = False # ONLY_WAIT_FOR_CRITICAL = True # if checker should also wait for non-critical if DEBUG: # quick fix to solve PyCharm Django console environment issue from breeze.process import MyProcess as Process else: from multiprocessing import Process OK = '[' + Bcolors.ok_green('OK') + ']' BAD = '[' + Bcolors.fail('NO') + ']' WARN = '[' + Bcolors.warning('NO') + ']' # clem 25/09/2015 class CheckerList(list): """ list of SysCheckUnit with filtering properties """ FAIL_ON_CRITICAL_MISSING = True ONLY_WAIT_FOR_CRITICAL = True # if checker should also wait for non-critical def __init__(self, check_list): self._list_to_check = check_list self._results = dict() super(CheckerList, self).__init__()