Question

I got inspired by an article in [http://www.xmldatabases.org/WK/blog/1094?t=item Inspirational Technology] and added some configuration-option to the software as an XML-File.

In times before I just did a copy \develeopment\somefile.ini \distribuiton\somefile.ini  after runing Py2Exe.

But after combining Py2Exe with Innosetup, it was really crucial to get these files copied to the Py2Exe dist-Directory during the Py2Exe Buildrun.

Solution

It was present all times in Py2Exe. But I did not really understand how to use it :)))

   1 setup(
   2     options = options,
   3     # The lib directory contains everything except the executables and the python dll.
   4     zipfile = zipfile,
   5     windows = [wxprog],
   6     # use out build_installer class as extended py2exe build command
   7     cmdclass = {"py2exe": build_installer},
   8     packages = ["encodings"],
   9     data_files=[("prog",["kategorien.xml",])]
  10     )

The crucial line is

   1     data_files=[ ("prog",["kategorien.xml",])]

here you are supposed to supply a list of tuples. [ (,), (,), ...]

Each tuple  ("directoy",["list.txt", "of.txt", "files.txt)  consists of 2 Elements:

So in my example I have some configuration data in  kategorien.xml  and want to get this file copied to the program-directory. (Maybe that is bad style and whe should put it within \documents and settings\currentuser\application settings\my bompany\myproduct\mysettings.xml, but for distribution WITHIN one company I want to be able to support filepaths by phone :-)) )

and how do you deal with this .xml-setings

Just to be buzzword-compliant every application this days should store at least something in [http://www.xml.org/ XML]. There are many, many libraries to do XML-Stuff in Python, I found 2 of them rather pythonic:

* effbots [http://effbot.org/zone/element-index.htm ElementTree] * and gnosis.xml of David Mertz

Elementtree Documentation is easier to find (it's on the same website) and not totally up to date ("Element" is now a sub to "Elementtree" and no longer on module-level and such); gnosis-Tools are rather hidden [http://gnosis.cx/download/Gnosis_Utils-current.tar.gz GnosisDownload] within a textual link which is only available from the end of an article in IBMs developer World. Also there is no website "getting started" for Gnosis, you have to dig for the /doc directory.

The configuration file is:

<?xml version="1.0" encoding="iso-8859-1"?>
<Kategorien>
    <Kategorie>Kundentermin</Kategorie>
    <Kategorie>Kundentelefonate </Kategorie>
    <Kategorie>Auslandsbesuche </Kategorie>
</Kategorien>

and I read it with

   1 p=jpath.path(sys.argv[0])
   2 p=p.splitpath()[0]
   3 p=p.joinpath("kategorien.xml")
   4 from elementtree import ElementTree
   5 t=ElementTree.fromstring(p.bytes())
   6 kategorien=[k.text for k in t.getiterator(tag="Kategorie")]

after that kategorien contains a standard Python list of the categories defined in kategorien.xml

jpath is a renamed PathModul written by Jason Jarondorff

20040113HAM