I need a script that will take a directory containing a number of XML files, modify certain values in the XML files, and save the resulting modified XML files. A config file will specify which values in the XML file to modify.
Ideally the script could run on a Mac (OS 10.4 or 10.5), since the XML files reference directories on a MacOS system. However, if this isn't convenient, I could also run the script on a different *nix account that I have shell access to.
## Deliverables
The spec is below - I have sample directory structure and config files that I can send separately.
PURPOSE OF THE SCRIPT
Apple Motion is a 3D graphics application. When you create a 3D project in Motion, Motion saves the project as an XML file.
We need to be able to take a set of these Apple Motion XML files and convert each one into 32 different formats. We create these different conversions by modifying certain values in the XML files.
For any given Apple Motion XML file, it's a fairly straightforward process: Take the XML file, change a handful of values, and save it as a new file. Repeat 32 times. Then move on to the next Apple Motion XML file and start again on another set of 32.
In order to do this, we are using 1) A template Apple Motion XML file, and 2) Some values specified in a config file. We take the values in the config file, plug them into the XML template file, and save the result. We repeat this 32 times for each XML file (since we are converting each XML template to 32 different formats).
We have included samples of the two config files used by this script: [login to view URL], and theme.config.
We also included samples of what our XML templates look like, located in the templates/ directory.
HOW THE SCRIPT WORKS: STEP BY STEP
1) Look in templates/
The first template is called [login to view URL]
Open it
Now that we have the first template, let's create the first of the 32 conversions.
2) Look in the [login to view URL] file.
The first line looks like this:
dvcprohd_720p24,960,720,24,1440,1,1.333333015,0,/Applications/[login to view URL] HD [login to view URL],1.4,1.4,1.4
This line contains everything we need to know to perform our first conversion. Let's do it!
3) In our template, [login to view URL], make the following replacements:
Plug "960" into <scene><sceneSettings><width>
Plug "720" into <scene><sceneSettings><height>
Plug "24" into <scene><sceneSettings><framerate>
Plug "1440" into <scene><sceneSettings><duration>
Plug "1" into <scene><sceneSettings><NTSC>
Plug "1.333333015" into <scene><sceneSettings><pixelAspectRatio>
Plug "0" into <scene><sceneSettings><fieldRenderingMode>
Plug
"/Applications/[login to view URL] HD [login to view URL]"
into
<scene><sceneSettings><presetPath>
Next up, a tricky bit. Our last three values are all "1.4". We need to take "1.4", and plug it in so that we get this:
<parameter name="Scale" id="105" flags="4176">
<foldFlags>15</foldFlags>
<parameter name="X" id="1" flags="16777296" value="1.4"/>
<parameter name="Y" id="2" flags="16777296" value="1.4"/>
<parameter name="Z" id="3" flags="16777296" value="1.4"/>
</parameter>
This is found inside of <scenenode><parameter><parameter><parameter>.
Note that we are only modifying the value="1.4" part here. All of the other stuff around it should be left as we found it.
4) Now name the new file [login to view URL]
Where did we get this name from?
"crumplepop_reflector_left_full" comes from the filename of our template, with the ".[login to view URL]" extensions removed.
"dvcprohd_720p24" comes from the first value in the first line of formats.config.
Finally, ".[login to view URL]" comes from the last value specified in theme.config.
We concatenate all of these to create the file name.
5) We're almost done. The last step is to save our brand new file into this directory:
/output/crumplepop_reflector_dvcprohd_720p24/
If this directory doesn't exist already, we need to create it.
Here's how we came up with that directory name:
/output/ is specified in [login to view URL]
"crumplepop_reflector" is specified in [login to view URL]
"dvcprohd_720p24" was the first value in the first line of formats.config.
We concatenate all of these to create the directory name.
The purpose of creating this directory (and others like it) is so that all of the files of the theme "crumplepop_reflector" in the format "dvcprohd_720p24" will be stored in the same place.
Success! We've created our first conversion.
6) Now we go to line 2 of [login to view URL], and start again to create our second conversion. When we are done, we will have created 32 different conversions of the template file crumplepop_reflector_left_full.HD.motn.
7) When those 32 are complete, we take another looks in the templates/ directory. Is there another template file for us to convert? If there is, we begin all over again, creating another 32 conversions of that one. And so on, until we have performed conversions on all of the templates in the templates/directory.
Put another way, If we have 10 templates in the templates/ directory, this will generate 320 files in the output/directory, since we are creating 32 formats of each template (10 * 32 = 320).