Right, your code gives me the number of the entries in the STAFResult. But I 
also want to retrieve the list of the file names, which is a marshalled 
STAFResult, I guess.

Thanks,

Cindy


From: Sharon Lucas [mailto:luc...@us.ibm.com]
Sent: April-19-11 10:50 AM
To: Cindy Zhu
Cc: staf-users@lists.sourceforge.net
Subject: RE: [staf-users] STAXResult

Why are you trying to marshall the STAFResult?  I have do idea why you are 
doing this.  I gave you an example of how to get the number of entries in the 
STAFResult (which it is a list).

<script>dir = '%s\Silk\Apps\TestResults' % (tempfolder)

<stafcmd name="'List all .txt files'">
 <location>'local'</location>
 <service>'FS'</services>
 <request>'LIST DIRECTORY %s EXT txt TYPE F' % (dir)</request>
</stafcmd>

<if expr="RC == 0">
 <log message="1">'Directory %s contains %s files with extension .txt' % (dir, 
len(STAFResult)</log>
</if>

--------------------------------------------------------------
Sharon Lucas
IBM Austin,   luc...@us.ibm.com
(512) 286-7313 or Tieline 363-7313




From:        Cindy Zhu <c...@fekete.com>
To:        Sharon Lucas/Austin/IBM@IBMUS
Cc:        "staf-users@lists.sourceforge.net" <staf-users@lists.sourceforge.net>
Date:        04/19/2011 11:45 AM
Subject:        RE: [staf-users] STAXResult
________________________________



Thank you very much. You mentioned this:

 *   STAFResult - the result from the STAF command. It can be a string, or, if 
the result is marshalled, it is the root object of the marshalled result which 
could be a Python List or a Python Dictionary (aka Map).
No too much documentation mentioned how to marshall STAFResult. Is the 
following code correct?
<stafcmd name="'Get result files ">
            <location>'local'</location>
            <service>'FS'</service>
           <request>'LIST DIRECTORY "D:\Silk\Apps\Harmony\TestResults" EXT 
txt'</request>
</stafcmd>
<if expr="RC==0">
<script>
from PySTAF import *
import re
result=STAFResult
len=[len(STAFResult))
mr=marshall(STAFResult)
...........
</script>
</if>
Do I need to "from PySTAF import *" to import the module to marshall 
STAFResult? I also got "NameError: marshall" when I ran the code?

Can you please help?
Thanks,
Cindy


From: Sharon Lucas [mailto:luc...@us.ibm.com]
Sent: April-19-11 9:26 AM
To: Cindy Zhu
Cc: staf-users@lists.sourceforge.net
Subject: Re: [staf-users] STAXResult

The <stafcmd> element does not set a Python variable named STAXResult.   The 
section titled "stafcmd: Run a STAF Command" in the STAX User's Guide at 
http://staf.sourceforge.net/current/STAX/staxug.html#Header_Stafcmd describes 
the Python variables that are set by the <stafcmd> element.  It says:

After the STAF command has completed, the following variables are set and can 
be referenced by the job:

 *   RC - the return code from the STAF command. It is an integer.
 *   STAFResult - the result from the STAF command. It can be a string, or, if 
the result is marshalled, it is the root object of the marshalled result which 
could be a Python List or a Python Dictionary (aka Map).
 *   STAFResultContext - the STAF marshalling context object for the result 
from the STAF command. It is an object of type org.python.core.PyInstance. The 
STAFMarshallingContext class provides a container for map class definitions and 
an object that uses (or is defined in terms of) them. Its string representation 
is equivalent to the "verbose format" (the hierarchical nested format) provided 
by the STAF executable.
 *   STAFResultString - The result string from the STAF command. It is a 
string. If the result is marshalled, it is the marshalled result string. Note: 
This variable would only be used if you needed the actual result string from a 
STAF command, such as if submitting a GET FILE request to the FS service when 
the specified file contains marshalled data and you want the actual contents of 
the file.

The FS service's LIST DIRECTORY request returns a list (as described in 
sub-section "Results" in section "8.4.9 LIST DIRECTORY" in the STAF User's 
Guide at http://staf.sourceforge.net/current/STAFUG.htm#HDRFSSRV).  It says the 
result of a FS LIST DIRECTORY request (if neither the LONG nor the SUMMARY 
option is specified) "will contain a marshalled <List> of <String> representing 
the names of the matching entries in the specified directory".

So,, STAFResult will contain a Python List of strings containing the file 
names.  A Python List provides many functions such as the len() function that 
you can use to get the number of items in the list..   e.g. len(STAFResult)    
Iterating the list is not required.   Note that you can google for "Python List 
size" and find many hits for documentation such as "An Introduction to Python 
Lists" at http://effbot.org/zone/python-list.htm that describes the Python 
Lists and talks about the len(List) function that returns the number of items 
in a Python list.

<script>dir = '%s\Silk\Apps\TestResults' % (tempfolder)

<stafcmd name="'List all .txt files'">
 <location>'local'</location>
 <service>'FS'</services>
 <request>'LIST DIRECTORY %s EXT txt TYPE F' % (dir)</request>
</stafcmd>

<if expr="RC == 0">
 <log message="1">'Directory %s contains %s files with extension .txt' % (dir, 
len(STAFResult)</log>
</if>

Note that the FS service's LIST DIRECTORY request provides a SUMMARY option to 
provide only a summary of the selected contents of a directory, including its 
total size in bytes, number of files, and number of subdirectories.  The 
previously mentioned section in the STAF User's Guide says:

"If the SUMMARY option is specified, the result buffer will contain a 
marshalled <Map:STAF/Service/FS/ListSummaryInfo> representing summarized 
information about the matching entries in the directory including total size, 
number of files, and number of subdirectories."  It then defines the map with 
the field names that are provided such as numFiles and numDirectories..

So, as another option, if you didn't need a list of the file names that met 
your list criteria, just the number of files, then you could use <stafcmd> to 
submit request "LIST DIRECTORY dirName EXT TXT SUMMARY' request as folllows:

<script>dir = '%s\Silk\Apps\TestResults' % (tempfolder)

<stafcmd name="'List all .txt files'">
 <location>'local'</location>
 <service>'FS'</services>
 <request>'LIST DIRECTORY %s EXT txt SUMMARY' % (dir)</request>
</stafcmd>

<if expr="RC == 0">
 <log message="1">'Directory %s contains %s files with extension .txt' % (dir, 
STAFResult['numFiles'])</log>
</if>

I hope that helps you see how easy it is to do (and where to find 
documentation).

--------------------------------------------------------------
Sharon Lucas
IBM Austin,   luc...@us.ibm.com
(512) 286-7313 or Tieline 363-7313




From:        Cindy Zhu <c...@fekete.com>
To:        "staf-users@lists.sourceforge.net" <staf-users@lists.sourceforge.net>
Date:        04/18/2011 04:53 PM
Subject:        [staf-users] STAXResult

________________________________




Hi,

I have the following STAX job to list .txt files in a folder:

<stafcmd name="'List all .txt files">
                                               <location>'local'</location>
                                               <service>'FS'</services>
                                               <request>'LIST DIRECTORY 
%s\Silk\Apps\TestResults EXT txt' % tempfolder</request>
</stafcmd>

Is there a function in STAXResult to return the how many files are listed 
without iterate the STAX result? or where I can get the documentation about the 
available functions for STAXResult

Thanks,

Cindy

------------------------------------------------------------------------------
Benefiting from Server Virtualization: Beyond Initial Workload
Consolidation -- Increasing the use of server virtualization is a top
priority.Virtualization can reduce costs, simplify management, and improve
application availability and disaster protection. Learn more about boosting
the value of server virtualization. 
http://p.sf.net/sfu/vmware-sfdev2dev_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users
------------------------------------------------------------------------------
Benefiting from Server Virtualization: Beyond Initial Workload 
Consolidation -- Increasing the use of server virtualization is a top
priority.Virtualization can reduce costs, simplify management, and improve 
application availability and disaster protection. Learn more about boosting 
the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users

Reply via email to