Exemplo n.º 1
0
def table2sav(t, filename=None):
    if filename is None:
        filename = toolkit.tempfilename(suffix=".sav", prefix="table-")

    log.debug("Creating SPSS syntax")
    # import StringIO
    # writer = StringIO.StringIO()
    # table2spss(t, writer=writer, saveas=filename, monitor=monitor.submonitor(80))
    # sps = writer.getvalue()
    # log.debug("Wrote syntax:\n%s\n" % (sps))

    log.debug("Executing PSPP")
    pspp = toolkit.executepipe("pspp -b")
    writer = pspp.next()
    writer = EchoWriter(writer)
    log.debug("Creating SPS script and sending to PSPP")
    table2spss(t, writer=writer, saveas=filename)
    log.debug("Closing PSPP")
    out, err = pspp.next()
    log.debug("PSPPP err: %s" % err)
    log.debug("PSPPP out: %s" % out)
    err = err.replace('pspp: error creating "pspp.jnl": Permission denied', "")
    err = err.replace('pspp: ascii: opening output file "pspp.list": Permission denied', "")
    if err.strip():
        raise Exception(err)
    if "error:" in out.lower():
        raise Exception("PSPP Exited with error: \n\n%s" % out)
    if not os.path.exists(filename):
        raise Exception("PSPP Exited without errors, but file was not saved.\n\nOut=%r\n\nErr=%r" % (out, err))
    return filename
Exemplo n.º 2
0
def table2sav(t, filename=None):
    if filename is None:
        filename = toolkit.tempfilename(suffix=".sav", prefix="table-")

    log.debug("Creating SPSS syntax")
    #import StringIO
    #writer = StringIO.StringIO()
    #table2spss(t, writer=writer, saveas=filename, monitor=monitor.submonitor(80))
    #sps = writer.getvalue()
    #log.debug("Wrote syntax:\n%s\n" % (sps))

    log.debug("Executing PSPP")
    pspp = toolkit.executepipe("pspp -p")
    writer = pspp.next()
    writer = EchoWriter(writer)
    log.debug("Creating SPS script and sending to PSPP")
    table2spss(t, writer=writer, saveas=filename)
    log.debug("Closing PSPP")
    out, err = pspp.next()
    log.debug("PSPPP err: %s" % err)
    log.debug("PSPPP out: %s" % out)
    err = err.replace('pspp: error creating "pspp.jnl": Permission denied', '')
    err = err.replace(
        'pspp: ascii: opening output file "pspp.list": Permission denied', '')
    if err.strip():
        raise Exception(err)
    if "error:" in out.lower():
        raise Exception("PSPP Exited with error: \n\n%s" % out)
    if not os.path.exists(filename):
        raise Exception(
            "PSPP Exited without errors, but file was not saved.\n\nOut=%r\n\nErr=%r"
            % (out, err))
    return filename
Exemplo n.º 3
0
 def __init__(self, writer):
     self.writer = writer
     fn = toolkit.tempfilename(".sps", "data")
     self.log = open(fn, "w")
     log.warn("Writing spss commands to %s" % fn)
Exemplo n.º 4
0
 def __init__(self, writer):
     self.writer = writer
     fn = toolkit.tempfilename(".sps", "data")
     self.log = open(fn, "w")
     log.warn("Writing spss commands to %s" % fn)