Example #1
0
def Run(args):
    """Execute the TEXT command"""


    args = args[args.keys()[0]]
    ###print args


    # define the TEXT subcommand syntax
    oobj = Syntax([
        Template("", subc="", var="strings", ktype="literal", islist=True),
        
        Template("HEADING", subc="OUTLINE", var="heading", ktype="literal"),
        Template("TITLE", subc="OUTLINE", var="otitle", ktype="literal"),
        Template("PAGEBREAK", subc="OUTLINE", var="pagebreak", ktype="bool"),
        
        Template("WRAP", subc="WRAP", var="wrap", ktype="int", vallist=[1]),
    ])
    
    # ensure localization function is defined
    global _
    try:
        _("---")
    except:
        def _(msg):
            return msg

    if args.has_key("HELP"):
        #print helptext
        helper()
    else:
        oobj.parsecmd(args)
        createText(**oobj.parsedparams)
def Run(args):
    """Execute the SCRIPTEX command"""

    args = args[args.keys()[0]]
   ###print args   #debug

    oobj = Syntax([
        Template("SCRIPT", subc="",  ktype="literal", var="scriptname"),
        Template("", subc="PARAMETERS",  ktype="literal", var="params", islist=True),
        Template("HELP", subc="", ktype="bool")])
    
    # A HELP subcommand overrides all else
    if args.has_key("HELP"):
        #print helptext
        helper()
    else:
        oobj.parsecmd(args)
        try:
            # check for missing required parameters
            args, junk, junk, deflts = inspect.getargspec(scriptwparams.runscript)
            args = set(args[: len(args) - len(deflts)])    # the required arguments
            omitted = [item for item in args if not item in oobj.parsedparams]
            if omitted:
                raise ValueError, "The following required parameters were not supplied:\n" + ", ".join(omitted)
            oobj.parsedparams["params"] = dictFromTokenList(oobj.parsedparams.get("params", {}))
            scriptwparams.runscript(**oobj.parsedparams)
        except:
            # Exception messages are printed here, but the exception is not propagated, and tracebacks are suppressed,
            # because as an Extension command, the Python handling should be suppressed.
            print "Error:", sys.exc_info()[1]
            sys.exc_clear()
Example #3
0
def Run(args):
    """Execute the PROPOR command"""
    
    debug = False
    if debug:
        print args   #debug
    args = args[args.keys()[0]]
    # Note that the keys of args are the names of the subcommands that were given.
    if debug:
        print args
    
    # define the syntax
    oobj = Syntax([
        Template("NUM", subc="",  ktype="str", islist=True),
        Template("DENOM", subc="",  ktype="str", islist=True),
        Template("ID", subc="", ktype="existingvarlist", islist=False),
        Template("HELP", subc="", ktype="bool"),
        
        Template("NAME", subc="DATASET", var="dsname", ktype="varname"),
        Template("ALPHA", subc="LEVEL",  ktype="float", vallist=(.0000000001, .99999999999)),
    ])
    

   # A HELP subcommand overrides all else
    if args.has_key("HELP"):
        print helptext
    else:
        try:
            # parse and execute the command
            oobj.parsecmd(args, vardict = spssaux.VariableDict())
            ###print oobj.parsedparams
            dopropor(**oobj.parsedparams)
        except:
            # Exception messages are printed here, but the exception is not propagated, and tracebacks are suppressed,
            # because as an Extension command, the Python handling should be suppressed (unless debug mode)
            if debug:
                raise
            else:
                print sys.exc_info()[1]
                sys.exc_clear()
def Run(args):
    """Execute the SPSSINC COMPARE DATASETS command"""


    ###print args   #debug
    args = args[args.keys()[0]]

    # Note that the keys of args are the names of the subcommands that were given.

    # define the syntax
    oobj = Syntax([
        Template("DS1", subc="",  ktype="varname"),
        Template("DS2", subc="",  ktype="varname"),
        Template("VARIABLES", subc="", ktype="existingvarlist", islist=True),
        Template("HELP", subc="", ktype="bool"),

        Template("ID", subc="DATA", var="idvar", ktype="existingvarlist"),
        Template("DIFFCOUNT", subc="DATA",  ktype="varname"),
        Template("ROOTNAME", subc="DATA",  var="reportroot", ktype="varname"),
        Template("LOGFILE", subc="DATA", var="logfile", ktype="literal"),

        Template("NONE", subc="DICTIONARY", ktype="bool"),
        Template("TYPE", subc="DICTIONARY", ktype="bool"),
        Template("MEASLEVEL", subc="DICTIONARY", ktype="bool"),
        Template("ATTRIBUTES",  subc="DICTIONARY", ktype="bool"),
        Template("FORMAT",  subc="DICTIONARY", ktype="bool"),
        Template("MISSINGVALUES", subc="DICTIONARY",  ktype="bool"),
        Template("VARLABEL",  subc="DICTIONARY", ktype="bool"),
        Template("VALUELABELS",  subc="DICTIONARY", ktype="bool"),
        Template("INDEX",  subc="DICTIONARY", ktype="bool"),
        Template("ALIGNMENT",  subc="DICTIONARY", ktype="bool"),
        Template("COLUMNWIDTH",  subc="DICTIONARY", ktype="bool")])

    # The choices set is used to set explicit negative/False values if any are specified
    choices = set(['type','measlevel','attributes','format','missingvalues','varlabel','valuelabels','index','alignment','columnwidth'])

    # ensure localization function is defined
    global _
    try:
        _("---")
    except:
        def _(msg):
            return msg

    # A HELP subcommand overrides all else
    if args.has_key("HELP"):
        print helptext
    else:
        # parse and execute the command
        try:
            # exceptions raised by code further down are added to the Warnings table at this level
            # The table has to be created here, because the comparedatasets constructor can fail
            # - sometimes with an SpssError, making this all a bit messy.
            # The blank at the end of the title string is intentional, because otherwise the table is treated differently
            # The output must be constructed indirectly, because there cannot be a Dataset and a Procedure active at
            # the same time, and only procedures can construct pivot tables and TextBlocks.

            warnings = NonProcPivotTable("Warnings",tabletitle=_("Warnings "))
            oobj.parsecmd(args, vardict = spssaux.VariableDict())
            if spss.PyInvokeSpss.IsUTF8mode():
                unistr = unicode
            else:
                unistr = str


            # check for missing required parameters
            checkrequiredparams(CompareDatasets.__init__, oobj.parsedparams, exclude=['self', 'warnings'])
            args, junk, junk, deflts = inspect.getargspec(CompareDatasets.__init__)
            args.remove("self")
            args.remove("warnings")
            args = set(args[: len(args)  - len(deflts)])    # the required arguments
            omitted = [item for item in args if not item in oobj.parsedparams]
            if omitted:
                raise ValueError(_("The following required parameters were not supplied:\n") + ", ".join(omitted))

            c = CompareDatasets(warnings, **oobj.parsedparams)
            if oobj.parsedparams.get("idvar"):
                c.cases()
            if not oobj.parsedparams.get("none", False):
                setnegativedefaults(choices, oobj.parsedparams)
                c.dictionaries(**oobj.parsedparams)
            c.close()

        except:
            # Exception messages are added to the Warnings table here, but the exception is not propagated, and tracebacks are suppressed,
            # because as an Extension command, the Python handling should be suppressed.

            if isinstance(sys.exc_info()[1], spss.errMsg.SpssError):
                warnings.addrow(_("SPSS error, possibly invalid dataset name (case matters)"))
            else:
                warnings.addrow(sys.exc_value.args[0])
            sys.exc_clear()

        if 'c' in locals():
            printresults(c)
        else:
            printresults(warnings)