Sublime Forum

Modifiy xml and output zip when build project

#1

Hello,

I use ST2 since years to develop joomla extensions.

Usualy I:

  • save the file
  • edit the xml file of my extension to increment the version
  • send a batch file .bat to generate the zip
  • manualy upload the file on the server

My question, it’s possible to use the built command (CTRL+B) to:

  • save all file -> OK
  • edit the XML file to:
    • retrieve the current version 1.16.0226.07
    • and change to 1.16.mmdd.xx where xx is xx +1 (or 01 for new ddmm)
  • create a zip file based on the ST2 project folder

?

Thanks you and sorry if is a naive question.
Cédric

0 Likes

#2

Yes, it is.

Build systems are normal commands under the hood and pluginnable using Python, which can do all you want with ST’s API and its standard library.

reference

0 Likes

#3

Is there some samples of code?

Like how to edit a xml node?

And how to build a zip?

Cédric

0 Likes

#4

I don’t have exact example code to hand, but can at least suggest some standard python modules that might be useful for you. Just look at the documentation for these, and you may have look with web searches for “python modulename example” or something like that.

I’ve used the xml.etree module to modify an XML document:

from xml.etree import ElementTree as ET

dist = ET.parse(distributionFile)
root = dist.getroot()
for el in root.findall('element-name'):
    # Do something with the element

Look in the python documentation for the zipfile module. It’s pretty easy.

0 Likes