Example #1
0
 def test_execute(self):
     for cmd, input, output, error in (
         ("cat", "testje", "testje", ""),
         ("cat", None, "", ""),
         ("echo bla", None, "bla\n", ""),
             #("echo bla", "test", IOError, ""), # broken pipe, does not always raise...?
         ("cat 1>&2", "testje", "", "testje"),
     ):
         if inspect.isclass(output) and issubclass(output, Exception):
             self.assertRaises(output, toolkit.execute, cmd, input)
         else:
             out, err = toolkit.execute(cmd, input)
             self.assertEqual(out, output)
             self.assertEqual(err, error)
             if not error:
                 out = toolkit.execute(cmd, input, outonly=True)
                 self.assertEqual(out, output)
Example #2
0
 def _parse(self, input):
     self._check_home()
     cmd = CMD.format(**self.__dict__)
     log.debug("Parsing %r" % input)
     out, err = execute(cmd, input.encode("utf-8"))
     if "*******" in err:
         raise ParserError("Exception from Stanford parser: %r" % err)
     log.debug("OUT: %r\nERR:%r\n" % (out, err))
     return out.decode("utf-8"), err.decode("utf-8")
Example #3
0
 def _parse(self, tokens):
     self._check_alpino()
     cmd = CMD.format(**self.__dict__)
     log.debug("Parsing %s" % tokens)
     out, err = execute(cmd, tokens.encode("latin-1"))
     log.debug(out)
     # it seems that alpino reports errors by starting a line with an exclamation mark
     if "\n! " in err:
         raise AlpinoError("Error on parsing %r: %s" % (tokens, err))
     return out.decode("latin-1")
Example #4
0
def _convert_docx(file):
    text, err = toolkit.execute("docx2txt", file.bytes)
    if not text.strip():
        raise Exception("No text from docx2txt. Error: {err}".format(**locals()))
    return text.decode("utf-8")
Example #5
0
    repo = hg.clone(repolocation, repodir)

    for branch in repo.listbranches():
        row = dict(repo=reponame, branch=branch)
        doc.rows.append(row)

        # prepare variables, update to selected branch
        docdest = DOCDEST.format(**locals())
        logfile = LOGFILE.format(**locals())
        log.info("Documenting {reponame}::{branch}".format(**locals()))
        repo.update(revision=branch)

        # run epydoc
        if not os.path.exists(docdest):
            os.makedirs(docdest)  # make sure target exists
        out, err = toolkit.execute(EPYDOCCMD.format(**locals()))
        open(LOGFILE.format(**locals()),
             'w').write("{0}\n----\n{1}".format(out, err))

        # add entries for table
        wwwdocdest = WWWDOCDEST.format(**locals())
        row["frames"] = '{wwwdocdest}index.html'.format(**locals())
        row["noframes"] = '{wwwdocdest}{reponame}-module.html'.format(
            **locals())
        row["log"] = WWWLOGDEST.format(**locals())
        reponame2 = "default" if reponame == "amcat" else reponame.replace(
            "amcat.", "")
        row["source"] = SOURCE.format(**locals())

        if reponame == 'amcat':
            # create model graph (only for repo amcat, hard hack atm..)
Example #6
0
def sendmail(sender, recipient, subject, html, plain):
    """Send an email from sender to recipient using the unix sendmail command"""
    mail = _create_message(sender, recipient, subject, html, plain)
    cmd = "%s -t" % SENDMAIL
    out = toolkit.execute(cmd, mail, outonly=True)
    if out.strip(): raise Exception(out)
Example #7
0
 def _tokenize(self, input):
     self._check_alpino()
     cmd = TOKENIZE.format(**self.__dict__)
     return execute(cmd, input.encode("utf-8"),
                    outonly=True).decode("utf-8")