Sample STAX

   1: <?xml version="1.0" encoding="UTF-8" standalone="no"?> 
   2: <!DOCTYPE stax SYSTEM "stax.dtd"> 
   3: <stax> 
   4: <script> 
   5:     from ConfigParser import ConfigParser 
   6: </script> 
   7:  
   8: <defaultcall function="main"/> 
   9:  
  10: <function name="main"> 
  11:   <function-map-args>
  12:     <function-optional-arg name="type" default="'win03uepinstall'"/>
  13:   </function-map-args>
  14: <sequence> 
  15:  
  16: <script> 
  17:     result = 1 
  18:     filename = 'c:/STAF/services/custom/test/sample.cfg'
  19:     file=open(filename)
  20:     config = ConfigParser() 
  21:     config.read(filename) 
  22:     vmfile = config.get(type, 'VM_FILE')
  23:     vmhost = config.get(type, 'VM_HOST')
  24:     vmsnapshot = config.get(type, 'VM_SNAPSHOT')
  25:     host = config.get(type, 'HOST') 
  26:     content = file.readlines()
  27: </script> 
  28:     
  29: <process name="'revertSnapShot'"> 
  30:     <location>vmhost</location> 
  31:     <command>'vmrun revertToSnapshot "%s" "%s"' %(vmfile,vmsnapshot)</command>
  32: </process>
  33: <if expr="RC != 0">
  34:     <return>STAXResult[0][1]</return>
  35: </if>
  36:     
  37: <process name="'startSnapShot'"> 
  38:     <location>vmhost</location> 
  39:     <command>'vmrun start "%s"' %(vmfile)</command>
  40: </process>
  41: <if expr="RC != 0">
  42:     <return>STAXResult[0][1]</return>
  43: </if>
  44:  
  45: <script>pingRC = 1</script>
  46: <loop until="pingRC == 0">
  47:     <sequence>
  48:         <stafcmd>
  49:             <location>'local'</location>
  50:             <service>'delay'</service>
  51:             <request>'delay 3000'</request>
  52:         </stafcmd>    
  53:         <if expr="RC != 0">
  54:             <return>STAFResult[0][1]</return>
  55:         </if>
  56:         <stafcmd>
  57:             <location>vmhost</location>
  58:             <service>'ping'</service>
  59:             <request>'ping'</request>
  60:         </stafcmd>
  61:         <script>pingRC = RC</script>    
  62:     </sequence>
  63: </loop>
  64:     
  65: <return>'Bingo!'</return> 
  66: </sequence> 
  67: </function> 
  68:  
  69: </stax> 
<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
<!DOCTYPE stax SYSTEM "stax.dtd"> 
<stax> 
 
<defaultcall function="main"/> 
    
<script> 
    projectPath = "C:/Documents and Settings/pyin/workspace_Europa"
    tomachine = "10.42.97.208"
    todirectory = "c:/tmp"
    zipfile = "C:/Documents and Settings/pyin/workspace_Europa/project.zip"
    tozipfile = "C:/tmp/project.zip"
</script> 
 
<function name="main"> 
  <function-map-args>
    <function-optional-arg name="projectPath" default='projectPath'/>
    <function-optional-arg name="tomachine" default='tomachine'/>
    <function-optional-arg name="todirectory" default='todirectory'/>
    <function-optional-arg name="zipfile" default='zipfile'/>
  </function-map-args>
<sequence> 
 
    
    <stafcmd>
        <location>'local'</location>
        <service>'zip'</service>
        <request>'add zipfile "%s" directory "%s" recurse relativeto "%s"' %(zipfile, projectPath,projectPath)</request>
    </stafcmd>    
    <if expr="RC != 0">
        <return>STAFResult</return>
    </if>
    
    <stafcmd>
        <location>'local'</location>
        <service>'fs'</service>
        <request>'copy file "%s" tomachine "%s" tofile "%s"' %(zipfile, tomachine, tozipfile)</request>
    </stafcmd>    
    <if expr="RC != 0">
        <return>STAFResult</return>
    </if>
    
    <stafcmd>
        <location>tomachine</location>
        <service>'zip'</service>
        <request>'unzip zipfile "%s" todirectory "%s"' %(tozipfile, todirectory)</request>
    </stafcmd>    
    <if expr="RC != 0">
        <return>STAFResult</return>
    </if>
    
<return>'Bingo!'</return> 
</sequence> 
</function> 
 
</stax> 
Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s