x
login Signup

How to find and replace strings of text in ElectricFlow projects?

Im trying to go through an entire ElectricFlow project, including the procedures and job steps, to replace variable names with new variables names. For example any occurrence of "ABAB" should become "AAAA". I am using a Perl script and the findObjects API call to gather all the strings I want to replace, but I don't know where to go from there. I was thinking of using the "modifySteps" API do the string replacement. Can someone point me in the right direction on how to find and replace strings of texts in ElectricFlow projects? Code I have so far

 use strict;
 use warnings;
 use ElectricCommander;
 $| = 1;
  
 my $ec = new ElectricCommander();
  
 # Get a list of the job steps, but no info on them yet
 my $ec_steps = $ec->findObjects("step", {
     filter => [{propertyName => "projectName",
                 operator     => "equals",
                 operand1 => "ProjectsThatContainWhatIwantToReplace"},
                 {propertyName => "command",
                 operator => "contains",
                 operand1 => "StringIWanttoReplace"},
             
     maxIds => 20000,
     
 });
 my @steps = $ec_steps->findnodes('//object/step');
 foreach my $s (@steps)
 {
 
    //modifyStep and do work to change the strings in here?
    //How so?
    
 }
 
 print "\nFinished outputting report to log file.\n";
 
avatar image By majditashman 15 asked Jan 28 at 11:38 PM
more ▼
(comments are locked)
10|750 characters needed characters left

1 answer: sort voted first

I would use DSL. Say your project looked like this:

 project "Replacement Project", {
     procedure "A Procedure",{
         property "ABAB"
         
         step "A step",{
             property "ABAB"
         }
     }
 }

If you run the API command generateDsl (ectool generateDsl --path "/projects/Replacement Project") you get something like this:

 project 'Replacement Project', {
     //[snip]
   procedure 'A Procedure', {
         //[snip]
     step 'A step', {
         //[snip]
 
       // Custom properties
       ABAB = ''
     }
 
     // Custom properties
     ABAB = ''
   }
 }


Run the following DSL to change the ABABs to AAAAs:

 project "Replacement Project", {
     getProcedures(projectName).each { proc ->
         getProperties(projectName: proc.projectName, procedureName: proc.procedureName).property.each { prop ->
               if (prop.propertyName == "ABAB") modifyProperty(propertyName: "ABAB", projectName: proc.projectName, procedureName: proc.procedureName, newName: "AAAA")
         }
         //property "ABAB", projectName: projectName, procedureName: proc.procedureName, newName: "AAAA"
         getSteps(projectName, proc.procedureName).each { st ->
             getProperties(projectName: st.projectName, procedureName: st.procedureName, stepName: st.stepName).property.each { prop ->
                 if (prop.propertyName == "ABAB") modifyProperty(propertyName: "ABAB", projectName: st.projectName, procedureName: st.procedureName, stepName: st.stepName, newName: "AAAA")
             }
         }
     }
 }
 

The result is:

 project 'Replacement Project', {
     //[snip]
   procedure 'A Procedure', {
         //[snip]
     step 'A step', {
         //[snip]
 
       // Custom properties
       AAAA = ''
     }
 
     // Custom properties
     AAAA = ''
   }
 }
 
avatar image By gregm 2k answered Apr 27 at 08:37 PM
more ▼
(comments are locked)
10|750 characters needed characters left
Your answer
toggle preview:

Up to 8 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question


Topics:

x166
x28
x17
x12

asked: Jan 28 at 11:38 PM

Seen: 59 times

Last Updated: Apr 27 at 08:37 PM

Related Questions