示例#1
0
def synthesize(name=None, dir=None, mode=None):
  proc = "synthesize"
  args = srclib.arguments(name, dir, mode, proc)  # get the arguments
  if not args:
    return 1
  path = args[0]
  datain = args[1]
  dataout = args[2]
  rc = srclib.metadata(datain, path)  # get the metadata
  if rc != 0:
    return rc
  msg = None
  rc = srclib.execute("iveset", path, mode, None)  # execute iveset
  if rc != 0:
    msg = "Abnormal termination of iveset"
  else:
    if not os.path.exists(path + ".inp"):  # get the data
      msg = "Missing " + path + ".inp file"
    else:
      f = open(path + ".inp", "r")
      cmd = f.read()
      f.close()
      spss.Submit(cmd)
      if not mode:
        os.remove(path + ".inp")
      rc = srclib.execute("impute", path, mode, None)  # execute impute
      if rc != 0:
        msg = "Abnormal termination of synthesize"
      else:
        if dataout:  # output the synthesized data
          rc = srclib.execute("putdata", path, mode, None)  # execute putdata
          if rc != 0:
            msg = "Abnormal termination of putdata"
          else:
            if not os.path.exists(dataout + ".out"):  # write the synthesized data
              msg = "Missing " + dataout + ".out file"
            else:
              f = open(dataout + ".out", "r")
              cmd = f.read()
              f.close()
              spss.Submit(cmd)  # execute the command
              if not mode:
                os.remove(dataout + ".imp")
                os.remove(dataout + ".out")
  if msg:
    if os.path.exists(path + ".log"):  # copy the log
      print
      f = open(path + ".log", "r")
      print f.read()
      f.close()
    print msg  # print the error message
  else:
    if not os.path.exists(path + ".lst"):  # copy the listing
      msg = "Missing " + path + ".lst file"
    else:
      print
      f = open(path + ".lst", "r")
      print f.read()
      f.close()
示例#2
0
def bbdesign(name=None, dir=None, mode=None):
  proc = "bbdesign"
  args = srclib.arguments(name, dir, mode, proc)  # get the arguments
  if not args:
    return 1
  path = args[0]
  datain = args[1]
  dataout = args[2]
  rc = srclib.metadata(datain, path)  # get the metadata
  if rc != 0:
    return rc
  msg = None
  args = []  # execute putdata
  args.append("/setup")
  rc = srclib.execute("bbdesign", path, mode, args)  # execute bbdesign setup
  if rc != 0:
    msg = "Abnormal termination of bbdesign"
  else:
    if not os.path.exists(path + ".inp"):  # get the data
      msg = "Missing " + path + ".inp file"
    else:
      f = open(path + ".inp", "r")
      cmd = f.read()
      f.close()
      spss.Submit(cmd)
      if not mode:
        os.remove(path + ".inp")
      rc = srclib.execute("bbdesign", path, mode, None)  # execute bbdesign go
      if rc != 0:
        msg = "Abnormal termination of bbdesign"
      else:
        if os.path.exists(path + ".out"):  # write the samples
          f = open(path + ".out", "r")
          cmd = f.read()
          f.close()
          spss.Submit(cmd)  # execute the command
          if not mode:
            os.remove(path + ".out")
  if msg:
    if os.path.exists(path + ".log"):  # copy the log
      print
      f = open(path + ".log", "r")
      print f.read()
      f.close()
    print msg  # print the error message
  else:
    if not os.path.exists(path + ".lst"):  # copy the listing
      msg = "Missing " + path + ".lst file"
    else:
      print
      f = open(path + ".lst", "r")
      print f.read()
      f.close()
def search(name=None, dir=None, mode=None):
    proc = "search"
    args = srclib.arguments(name, dir, mode, proc)  # get the arguments
    if not args:
        return 1
    path = args[0]
    datain = args[1]
    dataout = args[2]
    rc = srclib.metadata(datain, path)  # get the metadata
    if rc != 0:
        return rc
    msg = None
    rc = srclib.execute("srchset", path, mode, None)  # execute srchset
    if rc != 0:
        msg = "Abnormal termination of srchset"
    else:
        if not os.path.exists(path + ".inp"):  # get the data
            msg = "Missing " + path + ".inp file"
        else:
            f = open(path + ".inp", "r")
            cmd = f.read()
            f.close()
            spss.Submit(cmd)
            if not mode:
                os.remove(path + ".inp")
            rc = srclib.execute("search", path, mode, None)  # execute search
            if rc != 0:
                msg = "Abnormal termination of search"
            else:
                if dataout:
                    srclib.residuals(datain, dataout, path,
                                     mode)  # output the residuals
    if msg:
        if os.path.exists(path + ".log"):  # copy the log
            print
            f = open(path + ".log", "r")
            print f.read()
            f.close()
        print msg  # print the error message
    else:
        if not os.path.exists(path + ".lst"):  # copy the listing
            msg = "Missing " + path + ".lst file"
        else:
            print
            f = open(path + ".lst", "r")
            print f.read()
            f.close()
示例#4
0
def putdata(name=None,
            dir=None,
            mode=None,
            dataout=None,
            impl=None,
            mult=None):
    msg = None
    if not name:  # name
        msg = "Missing run name."
    else:
        m = re.match(r"^\s*(\w[\w\-]*)\s*$", name)
        if m:
            name = m.group(1)
        else:
            msg = "Run name error."
    if not msg:
        cwd = spssaux.getShow("DIRECTORY")  # spss current working directory
        if not dir:
            path = os.path.join(cwd, name)  # spss current working directory
        else:  # specified directory
            m = re.match(r'^\s*"([~\.\\/:\w\- ]*)"\s*$', dir)  # double quotes
            if m:
                dir = m.group(1).strip()
            else:
                m = re.match(r"^\s*'([~\.\\/:\w\- ]*)'\s*$",
                             dir)  # single quotes
                if m:
                    dir = m.group(1).strip()
                else:
                    m = re.match(r"^\s*([~\.\\/:\w\-]*)\s*", dir)  # no quotes
                    if m:
                        dir = m.group(1)
                    else:
                        msg = "Invalid directory."
            if not msg:
                path = os.path.join(os.path.normpath(dir), name)
    if not msg:  # mode
        if mode:
            m = re.match(r"^\s*(debug|test)\s*$", mode, flags=re.IGNORECASE)
            if m:
                mode = m.group(1).lower()
            else:
                msg = "Mode error."
    if not msg:  # dataout
        if not dataout:
            msg = "Missing dataout."
        else:
            m = re.match(r'^\s*"([~\.\\/:\w\- ]*)"\s*$',
                         dataout)  # double quotes
            if m:
                dataout = m.group(1).strip()
            else:
                m = re.match(r"^\s*'([~\.\\/:\w\- ]*)'\s*$",
                             dataout)  # single quotes
                if m:
                    dataout = m.group(1).strip()
                else:
                    m = re.match(r"^\s*([~\.\\/:\w\-]*)\s*",
                                 dataout)  # no quotes
                    if m:
                        dataout = m.group(1)
                    else:
                        msg = "Invalid dataout."
            if not msg:
                if sys.platform.startswith("win"):  # windows
                    m = re.match(r"^([a-zA-Z]:|[\\/])", dataout)
                else:  # linux
                    m = re.match("^(~|/)", dataout)
                if not m:  # not full path
                    dataout = os.path.join(
                        cwd, dataout)  # prefix the current working directory
                dataout = os.path.normpath(dataout)  # normalize the path
    if not msg:  # impl
        if impl:
            m = re.match(r"^\s*(all|\d+)\s*$", impl, flags=re.IGNORECASE)
            if m:
                impl = m.group(1).lower()
            else:
                msg = "Invalid implicate."
    if not msg:  # mult
        if mult:
            m = re.match(r"^\s*(all|\d+)\s*$", mult, flags=re.IGNORECASE)
            if m:
                mult = m.group(1).lower()
            else:
                msg = "Invalid multiple."
    if not msg:
        args = []  # execute putdata
        args.append("/dataout={0}".format(dataout))
        if impl:
            args.append("/impl={0}".format(impl))
        if mult:
            args.append("/mult={0}".format(mult))
        rc = srclib.execute("putdata", path, mode, args)
        if rc != 0:
            msg = "Abnormal termination of putdata"
        else:
            if not os.path.exists(dataout + ".out"):  # write the imputed data
                msg = "Missing " + dataout + ".out file"
            else:
                f = open(dataout + ".out", "r")
                cmd = f.read()
                f.close()
                spss.Submit(cmd)  # execute the command
                if not mode:
                    os.remove(dataout + ".imp")
                    os.remove(dataout + ".out")
    if msg:
        print msg  # print the error message
def regress(name=None, dir=None, mode=None):
    proc = "regress"
    args = srclib.arguments(name, dir, mode, proc)  # get the arguments
    if not args:
        return 1
    path = args[0]
    datain = args[1]
    dataout = args[2]
    rc = srclib.metadata(datain, path)  # get the metadata
    if rc != 0:
        return rc
    msg = None
    rc = srclib.execute("iveset", path, mode, None)  # execute iveset
    if rc != 0:
        msg = "Abnormal termination of iveset"
    else:
        if not os.path.exists(path + ".ctl"):  # get the method
            msg = "Missing " + path + ".ctl file"
        else:
            f = open(path + ".ctl", "rb")
            method = struct.unpack('i', f.read(4))[0]
            f.close()
            if not os.path.exists(path + ".inp"):  # get the data
                msg = "Missing " + path + ".inp file"
            else:
                f = open(path + ".inp", "r")
                cmd = f.read()
                f.close()
                spss.Submit(cmd)
                if not mode:
                    os.remove(path + ".inp")
                if method & 1:  # imputation
                    rc = srclib.execute("impute", path, mode,
                                        None)  # execute impute
                    if rc != 0:
                        msg = "Abnormal termination of impute"
                    else:
                        if dataout:  # output the imputed data
                            rc = srclib.execute("putdata", path, mode,
                                                None)  # execute putdata
                            if rc != 0:
                                msg = "Abnormal termination of putdata"
                            else:
                                if not os.path.exists(
                                        dataout +
                                        ".out"):  # write the imputed data
                                    msg = "Missing " + dataout + ".out file"
                                else:
                                    f = open(dataout + ".out", "r")
                                    cmd = f.read()
                                    f.close()
                                    spss.Submit(cmd)  # execute the command
                                    if not mode:
                                        os.remove(dataout + ".imp")
                                        os.remove(dataout + ".out")
                        if not msg:
                            rc = srclib.execute("setdata", path, mode,
                                                None)  # execute setdata
                            if rc != 0:
                                msg = "Abnormal termination of setdata"
                else:  # no imputation
                    if os.path.exists(path + ".agg"):  # remove the .agg file
                        os.remove(path + ".agg")
                if not msg:
                    rc = srclib.execute("regress", path, mode,
                                        None)  # execute regress
                    if rc != 0:
                        msg = "Abnormal termination of regress"
                    else:
                        if os.path.exists(path +
                                          ".out"):  # write the estimates, etc.
                            f = open(path + ".out", "r")
                            cmd = f.read()
                            f.close()
                            spss.Submit(cmd)  # execute the command
                            if not mode:
                                os.remove(path + ".out")
    if msg:
        if os.path.exists(path + ".log"):  # copy the log
            print
            f = open(path + ".log", "r")
            print f.read()
            f.close()
        print msg  # print the error message
    else:
        if not os.path.exists(path + ".lst"):  # copy the listing
            msg = "Missing " + path + ".lst file"
        else:
            print
            f = open(path + ".lst", "r")
            print f.read()
            f.close()