1. Nekmo
  2. python-jsoncfg

Commits

Nekmo  committed 6c7526d

Init version

  • Participants
  • Branches default

Comments (0)

Files changed (6)

File .hgignore

View file
+# use glob syntax.
+syntax: glob
+
+*.pyc
+*~
+*kate-swp
+build/

File jsoncfg.py

View file
+# -*- coding: utf-8 -*-
+
+__version__ = str(1.0)
+
+import sys
+if sys.version_info < (3,0):
+    reload(sys)
+    sys.setdefaultencoding('utf8')
+    from UserDict import UserDict
+else:
+    from collections import UserDict
+
+import json
+
+from os import F_OK, W_OK, access 
+
+class JsonCfg(UserDict):
+    def __init__(self, filename, default={}):
+        self.filename = filename
+        if not access(self.filename, F_OK):
+            f = open(self.filename, 'w')
+            f.write(json.dumps(default))
+            f.close()
+        elif not access(self.filename, W_OK):
+            raise Warning('Archivo sin permisos de escritura.')
+        self.read()
+    def read(self):
+        self.data = json.load(open(self.filename, 'r'))
+    def write(self):
+        with open(self.filename, 'w') as datafile:
+            json.dump(self.data, datafile)
+
+if __name__ == "__main__":
+    import time
+    d = JsonCfg('test.json')
+    print("Contenido actual de la configuración:")
+    print(d)
+    d['string'] = 'hello world!'
+    d['unicode'] = 'niñerías.'
+    d['bool'] = True
+    d['none'] = None
+    d['number'] = 12
+    d['float'] = 0.34
+    d['time'] = time.time()
+    d['list'] = list(range(3))
+    d['dict'] = {'foo': 'bar'}
+    print("Tras los cambios (ver time):")
+    print(d)
+    print("Se respetan los tipos:")
+    print(repr(d['float']))
+    d.write()
+    print("Contenido del archivo:")
+    with open('test.json', 'r') as datafile:
+        print(datafile.read())
+    

File jsoncfg.pyc

Binary file added.

File jsoncfg.py~

View file
+# -*- coding: utf-8 -*-
+
+__version__ = 1.0
+
+import sys
+if sys.version_info < (3,0):
+    reload(sys)
+    sys.setdefaultencoding('utf8')
+    from UserDict import UserDict
+else:
+    from collections import UserDict
+
+import json
+
+from os import F_OK, W_OK, access 
+
+class JsonCfg(UserDict):
+    def __init__(self, filename, default={}):
+        self.filename = filename
+        if not access(self.filename, F_OK):
+            f = open(self.filename, 'w')
+            f.write(json.dumps(default))
+            f.close()
+        elif not access(self.filename, W_OK):
+            raise Warning('Archivo sin permisos de escritura.')
+        self.read()
+    def read(self):
+        self.data = json.load(open(self.filename, 'r'))
+    def write(self):
+        with open(self.filename, 'w') as datafile:
+            json.dump(self.data, datafile)
+
+if __name__ == "__main__":
+    import time
+    d = JsonCfg('test.json')
+    print("Contenido actual de la configuración:")
+    print(d)
+    d['string'] = 'hello world!'
+    d['unicode'] = 'niñerías.'
+    d['bool'] = True
+    d['none'] = None
+    d['number'] = 12
+    d['float'] = 0.34
+    d['time'] = time.time()
+    d['list'] = list(range(3))
+    d['dict'] = {'foo': 'bar'}
+    print("Tras los cambios (ver time):")
+    print(d)
+    print("Se respetan los tipos:")
+    print(repr(d['float']))
+    d.write()
+    print("Contenido del archivo:")
+    with open('test.json', 'r') as datafile:
+        print(datafile.read())
+    

File setup.py

View file
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2007-2008 Nathanael C. Fritz
+# All Rights Reserved
+#
+# This software is licensed as described in the README file,
+# which you should have received as part of this distribution.
+#
+
+# from ez_setup import use_setuptools
+from distutils.core import setup
+import sys
+
+import jsoncfg
+
+# if 'cygwin' in sys.platform.lower():
+#     min_version = '0.6c6'
+# else:
+#     min_version = '0.6a9'
+#
+# try:
+#     use_setuptools(min_version=min_version)
+# except TypeError:
+#     # locally installed ez_setup won't have min_version
+#     use_setuptools()
+#
+# from setuptools import setup, find_packages, Extension, Feature
+
+VERSION          = jsoncfg.__version__
+DESCRIPTION      = 'Un sencillo sistema de escritura/lectura de configuración.'
+LONG_DESCRIPTION = """
+Una manera sencilla de guardar y leer configuraciones para tus programas, usando
+tipos de Python (soportados int, float, long, str, unicode, dict, tuple, list,
+bool, None) tanto al escribir como al leer. Los datos son guardados en un
+archivo JSON.
+"""
+
+CLASSIFIERS      = [ 'Intended Audience :: Developers',
+                     'Programming Language :: Python',
+                   ]
+
+packages     = [ '.',
+                 ]
+
+setup(
+    name             = "jsoncfg",
+    version          = VERSION,
+    description      = DESCRIPTION,
+    long_description = LONG_DESCRIPTION,
+    author       = 'Nekmo',
+    author_email = 'contacto [at] nekmo.com',
+    url          = 'http://nekmo.com',
+    license      = 'GPLv3',
+    platforms    = ['any',],
+    packages     = packages,
+    requires     = [],
+    )
+

File setup.py~

View file
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2007-2008 Nathanael C. Fritz
+# All Rights Reserved
+#
+# This software is licensed as described in the README file,
+# which you should have received as part of this distribution.
+#
+
+# from ez_setup import use_setuptools
+from distutils.core import setup
+import sys
+
+import jsoncfg
+
+# if 'cygwin' in sys.platform.lower():
+#     min_version = '0.6c6'
+# else:
+#     min_version = '0.6a9'
+#
+# try:
+#     use_setuptools(min_version=min_version)
+# except TypeError:
+#     # locally installed ez_setup won't have min_version
+#     use_setuptools()
+#
+# from setuptools import setup, find_packages, Extension, Feature
+
+VERSION          = jsoncfg.__version__
+DESCRIPTION      = 'Un sencillo sistema de escritura/lectura de configuración.'
+LONG_DESCRIPTION = """
+Una manera sencilla de guardar y leer configuraciones para tus programas, usando
+tipos de Python (soportados int, float, long, str, unicode, dict, tuple, list,
+bool, None) tanto al escribir como al leer. Los datos son guardados en un
+archivo JSON.
+"""
+
+CLASSIFIERS      = [ 'Intended Audience :: Developers',
+                     'Programming Language :: Python',
+                   ]
+
+packages     = [ '.',
+                 ]
+
+setup(
+    name             = "jsoncfg",
+    version          = VERSION,
+    description      = DESCRIPTION,
+    long_description = LONG_DESCRIPTION,
+    author       = 'Nekmo',
+    author_email = 'contacto [at] nekmo.com',
+    url          = 'http://nekmo.com',
+    license      = 'GPLv3',
+    platforms    = ['any',],
+    packages     = packages,
+    py_modules   = py_modules,
+    requires     = [],
+    )
+