Problems including pyconfig

Asked by Jonathan Kossick

Hello, I have a problem I can't fix...
Since I added the pyconfig module to my application I get an error while packaging:

running build_i18n
error: voc2brain/configurations/pyconfig: Ist ein Verzeichnis
make: *** [debian/python-module-stampdir/voc2brain] Fehler 1
dpkg-buildpackage: Fehler: Fehler-Exitstatus von debian/rules build war 2

Translation for "Ist ein Verzeichnis": is a directory
Link to the pyconfig module: http://code.google.com/p/python-code-snippets/wiki/PyConfig

I already added the pyconfig directory to "data_files" but the error occurs anyway...

Question information

Language:
English Edit question
Status:
Solved
For:
Quickly Edit question
Assignee:
No assignee Edit question
Solved by:
Jonathan Kossick
Solved:
Last query:
Last reply:
Revision history for this message
Tony Byrne (tony-badwolf) said :
#1

Hi Jonathan
 I had a look at PyConfig and it made me sad. It's 3 year old code and there are better "included batteries" now. The actual fault is probably related to statements in PyConfig importing data_eval, the outer directory also being called PyConfig and the presence of __init__.py.

 I suppose everyone sooner or later everyone writes a pickle replacement, here is another one, includes a test.

# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-

"""
PyConfig
~~~~~~~~

Alternative for ConfigParser/shelve/pickle. Stores a dict as json object into a file.

:license: GNU GPL v3 or above.
"""

import os
import json

class PyConfig(dict):
    def __init__(self, filename, verbose=1, *args, **kwds):
        self.filename = filename
        self.verbose = verbose

        dict.__init__(self, *args, **kwds)

        if os.path.isfile(self.filename):
            self._read()
        else:
            if self.verbose:
                print "PyConfig info: file '%s' doesn't exist, yet." % (
                    self.filename
                )

    def _read(self):
        if self.verbose:
            print "Reading %r ..." % self.filename

        f = file(self.filename, "r")
        data = json.load(f)
        f.close()

        dict.update(self, data)

    def save(self):
        if self.verbose:
            print "Save into %r ..." % self.filename,

        f = file(self.filename, "w")
        json.dump(self, f, sort_keys=True, indent=4)
        f.close()
        if self.verbose:
            print "OK, data saved."

if __name__ == '__main__':
    py = PyConfig(filename="FooBar.txt")
    py["foo"] = "bar"
    py[1] = "FooBar"
    py.save()

    py = PyConfig(filename="FooBar.txt")
    print py # should look like: {"foo": "bar, 1: "FooBar"}

    # however json silently coerces keys to strings :(
    assert py == {"foo": "bar", '1': "FooBar"}

Revision history for this message
Jonathan Kossick (j-kossick) said :
#2

Thanks a lot! It worked for me but I had to integrate your code in my main and delete the pyconfig folder. Thanks a lot