Yes Sharon, This was a typo. Below is my script function. I am attaching
the CSV file used in the script with this email. Below function gives me
three lists. Which is working fine when i am running this script using
python. I am also able to get the value of Lists variable when I run this
script using python. But when I am using it in stax I am getting the error.
Please refer below script tag and the calling function.
<script>
import csv
class RecordDetails:
Token = ""
Records = []
csv_file = 'E:\\Automation_STAF\\AD.csv'
testList = list(csv.reader(open(csv_file, 'r')))
curToken = "null"
recordDetails = RecordDetails()
recordDetails=None
records = [RecordDetails]
for index, line in enumerate(testList):
token="null"
token = testList[index][4]
if token=="null":
continue
if curToken !=token:
curToken =token
recordDetails = RecordDetails()
recordDetails.Token = curToken
recordDetails.Records=[]
records.append(recordDetails)
if recordDetails!=None:
recordDetails.Records.append(line)
d={}
CountSequence=1
for i, obj in enumerate(records):
if records[i].Token=="Sequence":
d[CountSequence] =records[i].Records
CountSequence +=1
if records[i].Token=="Parallel":
d[CountSequence] =records[i].Records
CountSequence +=1
machineList = ['10.211.105.108','10.211.105.109' , '10.211.105.110' ]
Lists = len(records)
</script>
---------------------------------------
And below is my main function from where I am accessing the Lists variable.
<function name="DCP_Auto">
<sequence>
<script>print "Getting the Job ID"</script>
<call function="'WriteMachineName'"/>
<script>i=1</script>
<log message="1">'Lists'</log>
<loop from ="i" to = "Lists" >
<if expr ="d[i][0][4]='Sequence'">
<call function="'SequentialDriverFunction'"/>
<elseif expr ="d[i][0][4]='Parallel'">
<call function="'ParallelDriverFunction'"/>
</elseif>
</if>
</loop>
</sequence>
</function>
Please help me identifying the issue.
Thanks,
Sandeep
On Mon, Aug 19, 2013 at 9:06 PM, Sharon Lucas <luc...@us.ibm.com> wrote:
> In your example, you showed that you assigned a variable named "List" the
> length of a list. However, then you tried to use a variable named "Lists"
> instead of "List". Since no variable exists called "Lists", you would get
> an error that this variable is not defined. So, is this the cause of the
> problem, or did you have a typo in your note and did you really attempt to
> use a variable called "List" instead of "Lists"?
>
> If this was a typo and you really tried to access the variable using the
> same name you had assigned, then another possibility is that you assigned
> the "Lists" variable in a scope that is not accessible via the function
> from which you are trying to use the "Lists" variable. Since you did not
> provide a complete STAX job that demonstrates the problem, I can only guess
> that this is what is happening. Please provide a complete STAX job that
> demonstrates the problem. Here's more information about scope:
>
> As talked about in section "function: Define a Named Task" in the STAX
> User's Guide at
> http://staf.sourceforge.net/current/STAX/staxug.html#Header_Function"
>
> *- Scope determines how variables are to be assigned*
> By default, all variables assigned in a function are global to the job's
> current STAX-Thread. However, you can assign a *local* scope to a
> function such that all names assigned in a function are local to that
> function and exist only while the function runs. Functions defined with a
> local scope provide a nested namespace, which contains a copy of variables
> in the caller's scope and which localizes any new variables created or
> changes to existing variables.
>
> *- STAXGlobal class provides the ability to create truly global variables*
> An exception to the above scoping rules are variables that are instances
> of the STAXGlobal class. A STAXGlobal class is a Python class which STAX
> provides as a wrapper to provide for the creation of truly global
> variables, even across STAX-Threads and when used in functions declared
> with a local scope. See the *STAXGlobal
> Class*<http://staf.sourceforge.net/current/STAX/staxug.html#STAXGlobal_Class>section
> for more information on how to create and use STAXGlobal variables.
>
> So, depending on where your variable containing a list's length was
> assigned, it may not be accessible from the function where you are trying
> to access it. This can occur if the variable was created in a different
> STAX-Thread, or in a function whose scope is defined as "local", etc.
>
> Here's a STAX job that assigns a variable called myListLength in the same
> function from which it is being accessed by a <loop> element and it works
> fine.
>
> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> <!DOCTYPE stax SYSTEM "stax.dtd">
>
> <stax>
>
> <defaultcall function="Main"/>
>
> <function name="Main">
> <sequence>
>
> <script>
> myList = ['first', 'second', 'third']
> myListLength = len(myList)
> </script>
>
> <log message="1">'List length: %s records=%s' % (myListLength,
> myList)</log>
>
> <loop var="i" from="1" to="myListLength">
> <sequence>
> <log message="1">'i=%s' % (i)</log>
> </sequence>
> </loop>
>
> </sequence>
> </function>
>
> </stax>
>
> So, if instead your STAX job did something like the following where the
> myListLength variable was assigned in a function with a local scope, it
> would then not be accessible via function RunLoop:
>
> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> <!DOCTYPE stax SYSTEM "stax.dtd">
>
> <stax>
>
> <defaultcall function="Main"/>
>
> <function name="Main">
> <sequence>
> <call function="'AssignVariable'"/>
> <call function="'RunLoop'"/>
> </sequence>
> </function>
>
> <function name="AssignVariable" scope="local">
> <sequence>
> <script>
> myList = ['first', 'second', 'third']
> myListLength = len(myList)
> </script>
> </sequence>
> </function>
>
> <function name="RunLoop">
> <sequence>
>
> <log message="1">'List length: %s records=%s' % (myListLength,
> myList)</log>
>
> <loop var="i" from="1" to="myListLength">
> <sequence>
> <log message="1">'i=%s' % (i)</log>
> </sequence>
> </loop>
>
> </sequence>
> </function>
>
> </stax>
>
> If you ran this STAX job, you would get Python error "NameError: name
> 'myListLength' is not defined" as follows:
>
> C:\>STAF local STAX EXECUTE FILE "C:/stax/sandeep.xml" RETURNRESULT WAIT
> Response
> --------
> {
> Job ID : 30
> Start Date-Time: 20130819-10:30:56
> End Date-Time : 20130819-10:30:56
> Status : Terminated
> Result : None
> Job Log Errors : [
> {
> Date-Time: 20130819-10:30:56
> Level : Error
> Message : STAXPythonEvaluationError signal raised. Terminating job.
>
> ===== XML Information =====
>
> File: c:\stax\sandeep.xml, Machine: local://local
> Line 27: Error in element type "log".
>
> ===== Python Error Information =====
>
> com.ibm.staf.service.stax.STAXPythonEvaluationException:
>
> Python string evaluation failed for:
> 'List length: %s records=%s' % (myListLength, myList)
>
> Traceback (most recent call last):
> File "<pyEval string>", line 1, in <module>
> NameError: name 'myListLength' is not defined
>
> ===== Call Stack for STAX Thread 1 =====
>
> [
> function: Main (Line: 8, File: c:\stax\sandeep.xml, Machine:
> local://local)
> sequence: 2/2 (Line: 9, File: c:\stax\sandeep.xml, Machine:
> local://local)
> function: RunLoop (Line: 24, File: c:\stax\sandeep.xml, Machine:
> local://local
> )
> sequence: 1/2 (Line: 25, File: c:\stax\sandeep.xml, Machine:
> local://local)
> ]
> }
> ]
> Testcase Totals: {
> Tests : 0
> Passes: 0
> Fails : 0
> }
> }
>
> C:\>
>
> --------------------------------------------------------------
> Sharon Lucas
> IBM Austin, luc...@us.ibm.com
> (512) 286-7313 or Tieline 363-7313
>
>
>
>
> From: Sandeep <sandeep.bhos...@gmail.com>
> To: staf-users@lists.sourceforge.net,
> Date: 08/19/2013 06:20 AM
> Subject: [staf-users] Gettitng error in loop
> ------------------------------
>
>
>
> Hi
>
> I am using the STAX XML for my project. I am using script tag to run my
> python script. In the script itselef I have declared some variable which I
> am using in the loop. But I am getting error in the loop. I am not able to
> access the script variable. Below refer below for the problem statement
>
> Below code is in my STAX xml.
>
> <script>
> Python code here. I have a variable declared as List.
> List = len(records)
> I have verified the List variable by running the python script and I am
> getting its value.
>
> </script>
>
> Now when I use this variable in the loop below i am not getting the value
> to
> my variable of the script tag.
> Below is my loop
>
>
> <script>i=1</script>
> <log message="1">"Lists"</log>
> <loop from ="i" to = "Lists" >
> <if expr ="d[i][0][4]='Sequence'">
> <call function="'SequentialDriverFunction'"/>
> <elseif expr ="d[i][0][4]='Parallel'">
> <call function="'ParallelDriverFunction'"/>
> </elseif>
> </if>
> </loop>
>
>
> Here I am getting error as "Error in attribute "to" associated with
> element
> type "loop"."
>
> For this I have checked the List variable from the log message and I found
> that I am not getting the value of variable(which is defined in the above
> script tag)
>
> Can you please tell me how can I access the value of the variable from the
> script tag?
>
> Thank you
>
> Regards,
> Sandeep
>
>
>
>
>
> ------------------------------------------------------------------------------
> Get 100% visibility into Java/.NET code with AppDynamics Lite!
> It's a free troubleshooting tool designed for production.
> Get down to code-level detail for bottlenecks, with <2% overhead.
> Download for free and get started troubleshooting in minutes.
> http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
> _______________________________________________
> staf-users mailing list
> staf-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/staf-users
>
>
>
QTP,Open Thick Console,C:\Cone_Automation\RunTest.vbs,Open,Sequence
Exe,Execute After SIA Scripts,C:\Automation_STAF\SIA_Validation.exe,aftersia,Sequence
Selenium,Launch Web Portal,C:\Program Files (x86)\NUnit 2.5.2\bin\net-2.0\nunit-console.exe,C:\SPC_IA_Smoke\SPC_IA_Smoke\bin\Debug\SPC_IA_Smoke.dll /xml=C:\SPC_IA_Smoke\SPC_IA_Smoke\bin\Debug\Panels.xml /run=SPC_IA_Automation.SPC_UI.SPC_CORE.Panels.LaunchWebPortal,Parallel
Selenium,Verify Endpoint Security Panels,C:\Program Files (x86)\NUnit 2.5.2\bin\net-2.0\nunit-console.exe,C:\SPC_IA_Smoke\SPC_IA_Smoke\bin\Debug\SPC_IA_Smoke.dll /xml=C:\SPC_IA_Smoke\SPC_IA_Smoke\bin\Debug\Panels.xml /run=SPC_IA_Automation.SPC_UI.SPC_CORE.Panels.VerifyEndpointSecurityPanels,Parallel
QTP,Create SEP Job,C:\Cone_Automation\RunTest.vbs,SEP,Sequence
Exe,Run SEP Job,C:\Automation_STAF\JobManagement.exe run SEP,C:\JobNames.csv,Sequence
------------------------------------------------------------------------------
Introducing Performance Central, a new site from SourceForge and
AppDynamics. Performance Central is your source for news, insights,
analysis and resources for efficient Application Performance Management.
Visit us today!
http://pubads.g.doubleclick.net/gampad/clk?id=48897511&iu=/4140/ostg.clktrk
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users