Пример #1
0
 def action(self, word, stp, timeout, key="DSN", check_jtag=True):
     printer.cyan("%11s with %s (will time out in %4d seconds)" % (word, stp, timeout))
     lines = self.command("jtag %s %s %s" % (stp, self.target, word), timeout=timeout, only_first_line=False)
     self.check_exit_codes(lines)
     self.check_key(lines, key)
     if check_jtag:
         self.check_for_jtag_errors(lines)
Пример #2
0
 def action(self, word, stp, timeout, key="DSN", check_jtag=True):
     printer.cyan("%11s with %s (will time out in %3d seconds)" %
                  (word, stp, timeout))
     lines = ngfec.command(self.server,
                           "jtag %s %s %s" % (stp, self.target, word),
                           timeout=timeout)
     self.check_exit_codes(lines)
     self.check_key(lines, key)
     if check_jtag:
         self.check_for_jtag_errors(lines)
Пример #3
0
def command(p, cmd, timeout=5):
    fields = cmd.split()
    if not fields:
        return None

    if fields[0] == "jtag":
        if len(fields) < 4:
            print("COMMAND has to few fields: (%s)" % cmd)
            return None

        regexp = "(.*)%s %s %s# retcode=(.*)" % tuple(fields[1:])
    else:
        regexp = "{0}\s?#((\s|E)[^\r^\n]*)".format(re.escape(cmd))

    try:
        p.sendline(cmd)
        p.expect(regexp, timeout=timeout)
        return p.match.group(0).split("\r\n")
    except pexpect.TIMEOUT:
        tail = "tail -20 %s" % p.logfile.name

        msg = printer.msg('The command "', p=False)
        msg += printer.cyan(cmd, p=False)
        msg += printer.msg(
            '"\n       produced unexpected output.  Consult the log file, e.g.',
            p=False)
        msg += printer.msg('\n       "%s" gives this:' %
                           printer.gray(tail, p=False),
                           p=False)
        printer.error(msg)
        os.system(tail)
        sys.exit()
def main():
    correct_required = _get_correct_required(sys.argv[1:])
    random.seed(datetime.now())
    total_correct = 0

    while total_correct < correct_required:
        # Choosing a random game
        game = _choose_game()

        # Output the game
        starting_game = lang['starting_game'].format(game.name, total_correct,
                                                     correct_required)
        seperator = '*' * len(starting_game)
        printer.blue(seperator + os.linesep + starting_game + os.linesep +
                     seperator)

        # Get a question and validator function for the game
        question, validator = game.play_game()

        # Ask it
        printer.cyan(question)

        # Loop until an answer is correct
        is_correct = False
        total_incorrect = 0

        while is_correct == False and total_incorrect < retry_limit:
            user_input = _ask_question(lang['submit_answer'])
            is_correct = validator(user_input)

            # If that's not correct, provide a message before looping
            if is_correct == False:
                total_incorrect += 1
                remaining = retry_limit - total_incorrect
                printer.red(lang['incorrect'].format(remaining))

        if is_correct == False:
            print(lang['limit_reached'])
            return  # Must break out, probable infinite loop reached

        printer.green(lang['correct'])
        total_correct += 1
Пример #5
0
    def command(self,
                cmd,
                timeout=5,
                bail_on_timeout=False,
                only_first_line=True):
        fields = cmd.split()
        if not fields:
            return None

        if fields[0] == "jtag":
            if len(fields) < 4:
                print("COMMAND has to few fields: (%s)" % cmd)
                return None

            regexp = "(.*)%s %s %s# retcode=(.*)" % tuple(fields[1:])
        else:
            regexp = "{0}\s?#((\s|E)[^\r^\n]*)".format(re.escape(cmd))

        try:
            self.server.sendline(cmd)
            self.server.expect(regexp, timeout=timeout)
            out = self.server.match.group(0).split("\r\n")
        except pexpect.TIMEOUT:
            if not bail_on_timeout:
                out = [cmd + " # ERROR: timed out after %d seconds" % timeout]
            else:
                lines = [
                    printer.msg('The command "', p=False),
                    printer.cyan(cmd, p=False),
                    printer.msg(
                        '"\n       produced unexpected output.  Consult the log file, e.g.',
                        p=False),
                    printer.msg('\n       "%s" gives this:' %
                                printer.gray(tail, p=False),
                                p=False),
                    printer.error(msg)
                ]
                self.bail(lines, tail=True)

        if "ERROR" in out[0]:
            printer.red(out[0])
        return out[0] if only_first_line else out
Пример #6
0
def htrOverview(d={}):
    abbr = "HTR" if "HTR0" in d else "uHTR"
    hyphens = "   " + ("-" * (67 if (abbr == "uHTR") else 82))
    printer.cyan(hyphens)

    htr = ["  ", "   %4s" % abbr]
    epcv = ["  ", "   EPCV"]
    lms = ["  ", "    LMS"]
    nWord16 = ["  ", "nWord16"]
    for iHtr in range(15):
        key = "%s%d" % (abbr, iHtr)
        if key not in d:
            continue
        h = d[key]
        htr.append("%4d" % iHtr)
        epcv.append("%d%d%d%d" % (h["E"], h["P"], h["C"], h["V"]))
        if "L" in h:
            lms.append(" %d%d%d" % (h["L"], h["M"], h["S"]))
        nWord16.append("%4d" % (h["nWord16"]))

    lines = [htr] + ([lms] if 3 <= len(lms) else []) + [epcv, nWord16]
    for line in lines:
        printer.cyan(" ".join(line))
    printer.cyan(hyphens)
Пример #7
0
def htrOverview(d={}):
    abbr = "HTR" if "HTR0" in d else "uHTR"
    hyphens = "   "+("-"*(67 if (abbr == "uHTR") else 82))
    printer.cyan(hyphens)

    htr = ["  ", "   %4s" % abbr]
    epcv = ["  ", "   EPCV"]
    lms = ["  ", "    LMS"]
    nWord16 = ["  ", "nWord16"]
    for iHtr in range(15):
        key = "%s%d" % (abbr, iHtr)
        if key not in d:
            continue
        h = d[key]
        htr.append("%4d" % iHtr)
        epcv.append("%d%d%d%d" % (h["E"], h["P"], h["C"], h["V"]))
        if "L" in h:
            lms.append(" %d%d%d" % (h["L"], h["M"], h["S"]))
        nWord16.append("%4d" % (h["nWord16"]))

    lines = [htr] + ([lms] if 3 <= len(lms) else []) + [epcv, nWord16]
    for line in lines:
        printer.cyan(" ".join(line))
    printer.cyan(hyphens)
Пример #8
0
def histogram_fit_results(lst,
                          mins,
                          factors,
                          options,
                          target,
                          h_npoints,
                          h_mins,
                          h_factors,
                          h_pvalues,
                          h_pvalues2,
                          h_delta_chi2,
                          h_delta_chi2_cut_vs_ch,
                          h_offsets,
                          h_offsets_unc,
                          h_slopes,
                          h_slopes_unc_rel,
                          h_curvatures,
                          h_curvatures_unc,
                          warn=True,
                          offset2=False,
                          slope2=False):

    for iRes, (res, res2) in enumerate(lst):
        ch = 1 + iRes
        s = "WARNING: %s MB ch %2d" % (target, ch)

        npoints = res[-3]
        h_npoints.Fill(npoints)
        if warn and npoints < options.threshold_npoints_warn:
            printer.red("%s has %d points" % (s, npoints))

        h_mins.Fill(mins[iRes])
        h_factors.Fill(factors[iRes])

        pvalue = res[-1]
        h_pvalues.Fill(pvalue)

        pvalue2 = res2[-1]
        h_pvalues2.Fill(pvalue2)

        delta_chi2 = res[-2] - res2[-2]
        h_delta_chi2.Fill(delta_chi2)
        if options.threshold_delta_chi2_warn < delta_chi2:
            h_delta_chi2_cut_vs_ch.Fill(ch)
            if warn:
                printer.dark_blue("%s has delta chi2 %e" % (s, delta_chi2))

        offset = (res2 if offset2 else res)[0][0]
        h_offsets.Fill(offset)
        h_offsets_unc.Fill((res2 if offset2 else res)[0][1])

        slope = (res2 if slope2 else res)[1][0]
        h_slopes.Fill(slope)

        h_curvatures.Fill(res2[2][0])
        h_curvatures_unc.Fill(res2[2][1])

        if options.print_fit_results and slope < 0.80:  # requirement on slope hackily filters V fits
            print("%s %2d %6.3f %6.3f" %
                  (target.split("/")[-1], ch, offset, slope))

        if warn and not (options.threshold_slope_lo_warn < slope <
                         options.threshold_slope_hi_warn):
            printer.purple("%s has fit slope  %g" % (s, slope))

        if slope:
            rel_unc = res[1][1] / slope
            h_slopes_unc_rel.Fill(rel_unc)
            if warn and options.threshold_slope_rel_unc_warn < rel_unc:
                printer.cyan("%s has fit rel unc %g" % (s, rel_unc))