Example #1
0
 def as_mozilla_line(self):
     domain_specified = IF(self.domain.startswith("."), "TRUE", "FALSE")
     secure = IF(self.secure, "TRUE", "FALSE")
     return "\t".join(
         map(str, [
             self.domain, domain_specified, self.path, secure, self.expires,
             self.name, self.value
         ]))
Example #2
0
    def post(self, request, tcid):
        dbrow = get_testcase(tcid)
        data = request.POST
        if data.get("completed") == "0": # yes
            if data.get("passfail") == "0": # yes
                result = webhelpers.PASSED
            else:
                result = webhelpers.FAILED
        else:
            result = webhelpers.INCOMPLETE

        username = request.session["username"]
        tester = models.User.get_by_username(webhelpers.dbsession, username)
        build=webhelpers.resolve_build(data.get("build"))

        rr = models.create(models.TestResult,
                objecttype=webhelpers.RUNNER,
                testcase=None,
                environment=webhelpers.resolve_environment(data.get("environment")),
                build=build,
                tester=tester,
                testversion=None,
                parent=None,
                starttime=data.get("starttime"),
                endtime=str(models.tables.time_now()),
                arguments=None,
                result=result,
                diagnostic=None,
                note=None,
                valid=True,
            )
        webhelpers.dbsession.add(rr)
        tr = models.create(models.TestResult,
                objecttype=webhelpers.TEST,
                testcase=dbrow,
                environment=None,
                build=build,
                tester=tester,
                testversion=None,
                parent=rr,
                starttime=data.get("starttime"),
                endtime=str(models.tables.time_now()),
                arguments=None,
                result=result,
                diagnostic=IF(result != webhelpers.PASSED, data.get("note")),
                note=IF(result == webhelpers.PASSED, data.get("note")),
                valid=True,
            )
        webhelpers.dbsession.add(tr)
        try:
            webhelpers.dbsession.commit()
        except (DataError, IntegrityError), err:
            webhelpers.dbsession.rollback()
            title = "Test runner error"
            resp = framework.ResponseDocument(request, testcase_run_constructor, title=title)
            resp.doc.new_para(err, class_="error")
            resp.doc.new_para("There was an error recording this test. Please try again.")
            return resp.finalize()
Example #3
0
def nt2cygwin(winpath):
    if winpath.find(":") > 0:
        [drive, path] = winpath.split(":", 1)
        return "/cygdrive/%s%s%s" % (drive.lower(),
                                     IF(path.startswith("\\"), "",
                                        "/"), path.replace("\\", "/"))
    else:
        return "/cygdrive/c%s%s" % (IF(winpath.startswith("\\"), "",
                                       "/"), winpath.replace("\\", "/")
                                    )  # assume C: drive if not given
Example #4
0
def location(host=None, user=None, path=None, forssh=False):
    """Construct an appropriate ssh/scp path spec based on the combination of
    parameters. Supply host, user, and path."""
    sep = IF(forssh, "", ":")
    if host is None:
        if user is None:
            if path is None:
                raise ValueError, "must supply at least one of host, or user."
            else:
                return path
        else:
            if path is None:
                raise ValueError, "user without host?"
            else:
                return path  # ignore user in this case
    else:
        if user is None:
            if path is None:
                return "%s%s" % (host, sep)
            else:
                return "%s:%s" % (host, path)
        else:
            if path is None:
                return "%s@%s%s" % (user, host, sep)
            else:
                return "%s@%s:%s" % (user, host, path)
Example #5
0
 def __str__(self):
     s = []
     for address, disp in self._store.items():
         s.append("%s is %s\n" %
                  (address.cidr(), IF(disp, "used.", "free.")))
     s.sort()
     return "".join(s)
Example #6
0
def smtpcli(argv):
    """smtpcli [-h] [-l <logfilename>] [-s <portname>] [host] [port]

Provides an interactive session at a protocol level to an SMTP server. 
    """
    bindto = None
    port = 25
    sourcefile = None
    paged = False
    logname = None
    try:
        optlist, longopts, args = getopt.getopt(argv[1:], "b:hp:s:l:g")
    except getopt.GetoptError:
        print(smtpcli.__doc__)
        return
    for opt, val in optlist:
        if opt == "-b":
            bindto = val
        if opt == "-l":
            logname = val
        elif opt == "-s":
            sourcefile = val
        elif opt == "-g":
            paged = True
        elif opt == "-h":
            print(smtpcli.__doc__)
            return
        elif opt == "-p":
            try:
                port = int(val)
            except ValueError:
                print(smtpcli.__doc__)
                return

    theme = UI.DefaultTheme(PROMPT)
    parser = CLI.get_cli(EmailClientCLI, paged=paged, theme=theme)
    if len(args) > 0:
        if len(args) > 1:
            port = int(args[1])
        else:
            port = 25
        host = args[0]
    else:
        host = ""
    if logname:
        parser.commands.logfile(["logfile", logname])
    if host:
        parser.commands.connect(["connect"] + IF(bindto, ["-s", bindto], []) +
                                [host, port])
    else:
        parser.commands._print(
            "Be sure to run 'connect' before anything else.\n")

    if sourcefile:
        try:
            parser.parse(sourcefile)
        except CLI.CommandQuit:
            pass
    else:
        parser.interact()
Example #7
0
def render_testcase(doc, dbrow):
    doc.add_header(2, dbrow.name)
    NM = doc.nodemaker
    sect = doc.add_section("testcasebody", id="rowid_%s" % dbrow.id)
    if dbrow.functionalarea:
        sect.add_header(3, "Area Tested")
        dl = sect.add_definition_list()
        dl.add_definition("Testing area:",
                          " ".join(map(str, dbrow.functionalarea)))

    sect.add_header(3, "Implementation")
    if dbrow.automated:
        if dbrow.testimplementation:
            sect.new_para(
                "Implemented in: '%s'%s." %
                (dbrow.testimplementation,
                 IF(dbrow.interactive, " (user interactive test)", "")))
        else:
            sect.new_para("Test is automated but has no implementation!",
                          class_="error")
    else:
        if dbrow.testimplementation:
            sect.new_para("Manual test implemented in: '%s'." %
                          (dbrow.testimplementation, ))
        else:
            sect.new_para(
                "This is a manual test that may be run by the this web interface."
            )

    for colname in ('purpose', 'passcriteria', 'startcondition',
                    'endcondition', 'procedure'):
        sect.add_header(3, colname.capitalize())
        sect.append(NM("ASIS", None, getattr(
            dbrow, colname)))  # these entries stored as XHTML markup already.
Example #8
0
def md5sum(filename, mode=Binary):
    m = md5()
    f = open(filename, IF(mode, "rb", "r"))
    b = f.read(4096)
    while b:
        m.update(b)
        b = f.read(4096)
    return m.hexdigest()
Example #9
0
def sudo(command, user=None, password=None, extraopts=None, logfile=None):
    opts = "-S %s" % (IF(user, "-u %s" % (user, ), ""), )
    cmd = "%s %s %s %s" % (SUDO, opts, extraopts or "", command)
    proc = proctools.spawnpipe(cmd, logfile=logfile, merge=0)
    if password:
        proc.readerr(9)  # discard password prompt
        proc.write("%s\r" % (password, ))
        proc.readerr(1)  # discard newline
    return proc
Example #10
0
def build_framing(request, doc, title):
    nav = doc.add_section("navigation")
    NM = doc.nodemaker
    nav.append(NM("P", None,
         NM("A", {"href":"/"}, "Home"), NM("_", None),
         IF(request.path.count("/") > 2, NM("A", {"href":".."}, "Up")), NM("_", None),
    ))
    nav.append(NM("P", {"class_": "title"}, title))
    nav.append(NM("P", None,
            NM("A", {"href": "/auth/logout"}, "logout")))
    doc.add_section("messages", id="messages")
Example #11
0
 def __str__(self):
     scr = [
         "%s  attr: %d  fg: %d  bg: %d wrap: %s" %
         (self.cursor, self.attr, self.fg, self.bg,
          IF(self._wrap, "ON", "OFF"))
     ]
     scr.append("+%s+" % ("-" * self.cols, ))
     for r in self.buf:
         chars = map(lambda t: t[0], map(decode, r))
         scr.append("|%s|" % ("".join(chars), ))
     scr.append("+%s+\n" % ("-" * self.cols, ))
     return "\n".join(scr)
Example #12
0
 def _print_source(self, filename, first, last):
     breaklist = self._dbg.get_file_breaks(filename)
     try:
         for lineno in range(first, last+1):
             line = linecache.getline(filename, lineno)
             if not line:
                 self._ui.printf('%Y[EOF]%N')
                 break
             else:
                 s = []
                 s.append("%5.5s%s" % (lineno, IF(lineno in breaklist, self._ui.format(" %RB%N"), "  ")))
                 if lineno == self._dbg.curframe.f_lineno:
                     s.append(self._ui.format("%I->%N "))
                 else:
                     s.append("   ")
                 self._print("".join(s), line.rstrip())
                 self._dbg.lineno = lineno
     except KeyboardInterrupt:
         pass
Example #13
0
def pyterm(filename="", interactive=1):
    cmd = "%s %s %s " % (PYTHON, IF(interactive, "-i", ""), filename)
    if os.environ.has_key("DISPLAY"):
        return run_config(os.environ.get("XTERM"), cmd)
    else:
        return os.system(cmd)
Example #14
0
 def write_record(self, digest, binary, fname):
     if "\\" in fname or "\n" in fname:
         self.write("\\")
     self.write("%s %s%s\n" %
                (digest, IF(binary, "*", " "), repr(fname)[1:-1]))
Example #15
0
 def __repr__(self):
     return "%s.%s(%s)" % (self.__class__.__module__, self.__class__.__name__, IF(self, "True", "False"))
Example #16
0
def yes_no(io, prompt, default=True):
    yesno = get_input(io, prompt, IF(default, "Y", "N"))
    return yesno.upper().startswith("Y")
Example #17
0
def repr_test(name, args, kwargs):
    args_s = IF(args,
                IF(kwargs, "%s, ", "%s") % ", ".join(map(repr, args)), "")
    kws = ", ".join(map(lambda it: "%s=%r" % (it[0], it[1]), kwargs.items()))
    return "%s()(%s%s)" % (name, args_s, kws)
Example #18
0
 def yes_no(self, prompt, default=True):
     yesno = cliutils.get_input(self.format(prompt), IF(default, "Y", "N"),
                                self._io.raw_input)
     return yesno.upper().startswith("Y")
Example #19
0
 def yes_no(self, prompt, default=True):
     if self.INTERACTIVE:
         yesno = cliutils.get_input(prompt, IF(default, "Y", "N"))
         return yesno.upper().startswith("Y")
     else:
         raise TestIncompleteError, "user input in non-interactive test."
Example #20
0
 def __str__(self):
     return "%s%s" % (IF(self.weak, "W/", ""), self.data)
Example #21
0
def _verbose_progress(name, disp):
    print name, IF(disp, "OK", "ERROR")
Example #22
0
 def __str__(self):
     return "%s: %s" % (self.NAME, IF(self.data, self.value, "<>"))
Example #23
0
def yes_no(prompt, default=True, input=raw_input):
    yesno = get_input(prompt, IF(default, "Y", "N"), input)
    return yesno.upper().startswith("Y")
Example #24
0
 def __str__(self):
     return "%s%s" % (self.vendor,
                      IF(self.version, "/%s" % (self.version), ""))
Example #25
0
            user=None,
            password=None,
            prompt=None,
            callback=None,
            logfile=None,
            extraoptions="",
            cmd=None,
            async=False):
    """get_ssh(host, [user], [password], [prompt], [callback], [logfile])
Uses ssh to get a shell on the given host, and automatically authenticate by
password if a password is given.  Returns an SSHExpect object.

The logfile parameter should be a file-like object (has a 'write' method).
"""
    pm = proctools.get_procmanager()
    hostuser = IF(user, "%s@%s" % (user, host), host)
    command = "%s %s %s %s %s" % (SSH, SSH_OPTIONS, extraoptions, hostuser, cmd
                                  or "")
    sshproc = pm.spawnpty(command, logfile=logfile, async=async)
    ssh = SSHExpect(sshproc)
    sshproc.set_callback(callback or ssh.death_callback)
    ssh.set_prompt(prompt or "$")
    if password is not None:
        ssh.login(password)
    return ssh


def get_ssh_unsafe(host, *args, **kwargs):
    """get_ssh_unsafe(host, ...)
Like get_ssh(), but automatically removes any stale known_hosts entry, if
required."""
Example #26
0
    def __str__(self):
        return """                                     |
                            +=================+
                            | o o %7.7s o o |
                            +-----------------+
""" % (IF(self._locked, "locked ", "o o o o"),)
Example #27
0
 def autostop(self, on=True):
     """With AUTOSTOP on, the voicelib will automatically abort a play in
     progress and return READY. This is useful for faster reaction times for
     voice menus."""
     self.chat(["", "AUTOSTOP %s" % (IF(on, "ON", "OFF"), ), "READY"])
     self._autostop = bool(on)