viniciuschiele / central Goto Github PK
View Code? Open in Web Editor NEWA dynamic configuration library. https://viniciuschiele.gitbooks.io/central
License: MIT License
A dynamic configuration library. https://viniciuschiele.gitbooks.io/central
License: MIT License
I'm testing Central but have stucked in an problem: After load some configuration from a json file I got error when try to use json.dumps to save the config data values to another json file:
>>> import json
>>> from central.config.file import FileConfig
>>> config = FileConfig('/opt/daspanel/data/civmw76wg000001p2dwqxpvet/db/civmw76wg000001p2dwqxpvet.json')
>>> config.load()
>>> json.dumps(config._data)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/json/__init__.py", line 244, in dumps
return _default_encoder.encode(obj)
File "/usr/lib/python2.7/json/encoder.py", line 207, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python2.7/json/encoder.py", line 270, in iterencode
return _iterencode(o, 0)
File "/usr/lib/python2.7/json/encoder.py", line 184, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: {u'engines': [{u'sitetypes': [{u'sitetype': u'generic', u'_cuid': u'', u'description': u'Generic site - PHP71'}, {u'sitetype': u'grav', u'_cuid': u'', u'description': u'Grav flat-file CMS'}, {u'sitetype': u'wordpress', u'_cuid': u'', u'description': u'Wordpress 4.X'}, {u'sitetype': u'cakephp2x', u'_cuid': u'', u'description': u'CakePHP 2.X'}, {u'sitetype': u'nextcloud12x', u'_cuid': u'', u'description': u'Nextcloud 12.X'}], u'provider': u'DOCKER', u'runtime': u'php71', u'description': u'PHP 7.1', u'_cuid': u'cj5h6dqar0000325kybi7t8up'}, {u'sitetypes': [{u'sitetype': u'generic', u'_cuid': u'', u'description': u'Generic site - PHP70'}, {u'sitetype': u'grav', u'_cuid': u'', u'description': u'Grav flat-file CMS'}, {u'sitetype': u'wordpress', u'_cuid': u'', u'description': u'Wordpress 4.X'}, {u'sitetype': u'cakephp2x', u'_cuid': u'', u'description': u'CakePHP 2.X'}, {u'sitetype': u'nextcloud12x', u'_cuid': u'', u'description': u'Nextcloud 12.X'}], u'provider': u'DOCKER', u'runtime': u'php70', u'description': u'PHP 7.0', u'_cuid': u'cj5h6e0490000325kdnaltrcy'}, {u'sitetypes': [{u'sitetype': u'generic', u'_cuid': u'', u'description': u'Generic site - PHP56'}, {u'sitetype': u'grav', u'_cuid': u'', u'description': u'Grav flat-file CMS'}, {u'sitetype': u'wordpress', u'_cuid': u'', u'description': u'Wordpress 4.X'}, {u'sitetype': u'cakephp2x', u'_cuid': u'', u'description': u'CakePHP 2.X'}, {u'sitetype': u'nextcloud12x', u'_cuid': u'', u'description': u'Nextcloud 12.X'}], u'provider': u'DOCKER', u'runtime': u'php56', u'description': u'PHP 5.6', u'_cuid': u'cj5h6e68y0000325kq5k643q4'}, {u'sitetypes': [{u'sitetype': u'generic', u'_cuid': u'', u'description': u'Generic site - Static'}], u'provider': u'DOCKER', u'runtime': u'static', u'description': u'Static', u'_cuid': u'cj5h6eczq0000325kx0i6534o'}], u's3': {u'access_key': u'civmw76wg000001p2dwq', u'browser_url': u'https://s3.svc.daspanel.site', u'region': u'us-east-1', u'endpoint': u'https://s3.svc.daspanel.site', u'secret_key': u'hlHpOfEAk45E7151'}, u'smtp': {u'password': u'civmw76wg000001p2dwqxpvet', u'type': u'mail-catcher', u'user': u'[email protected]', u'server': u'daspanel-mail-catcher:1025'}, u'redis': {u'port': 6379, u'password': u'civmw76wg000001p2dwqxpvet', u'user': u'', u'server': u'daspanel-redis', u'database': 0}, u'sys': {u'config_version': u'0.1.0', u'admin': u'[email protected]', u'hostname': u'daspanel.site', u'apiserver': u'http://daspanel-api:8080/1.0', u'debug': False, u'password': u'hlHpOfEAk45E7151', u'msghub': u'mail-catcher'}, u'mysql': {u'password': u'hlHpOfEAk45E7151', u'user': u'civmw76wg000001p2dwqxpvet', u'server': u'daspanel-mysql', u'port': 3306}} is not JSON serializable
How I can convert the contents of config._data in an python string using json.dumps ?
the content of the original json file is:
{
"engines": [
{
"sitetypes": [
{
"sitetype": "generic",
"_cuid": "",
"description": "Generic site - PHP71"
},
{
"sitetype": "grav",
"_cuid": "",
"description": "Grav flat-file CMS"
},
{
"sitetype": "wordpress",
"_cuid": "",
"description": "Wordpress 4.X"
},
{
"sitetype": "cakephp2x",
"_cuid": "",
"description": "CakePHP 2.X"
},
{
"sitetype": "nextcloud12x",
"_cuid": "",
"description": "Nextcloud 12.X"
}
],
"description": "PHP 7.1",
"runtime": "php71",
"_cuid": "cj5h6dqar0000325kybi7t8up",
"provider": "DOCKER"
},
{
"sitetypes": [
{
"sitetype": "generic",
"_cuid": "",
"description": "Generic site - PHP70"
},
{
"sitetype": "grav",
"_cuid": "",
"description": "Grav flat-file CMS"
},
{
"sitetype": "wordpress",
"_cuid": "",
"description": "Wordpress 4.X"
},
{
"sitetype": "cakephp2x",
"_cuid": "",
"description": "CakePHP 2.X"
},
{
"sitetype": "nextcloud12x",
"_cuid": "",
"description": "Nextcloud 12.X"
}
],
"description": "PHP 7.0",
"runtime": "php70",
"_cuid": "cj5h6e0490000325kdnaltrcy",
"provider": "DOCKER"
},
{
"sitetypes": [
{
"sitetype": "generic",
"_cuid": "",
"description": "Generic site - PHP56"
},
{
"sitetype": "grav",
"_cuid": "",
"description": "Grav flat-file CMS"
},
{
"sitetype": "wordpress",
"_cuid": "",
"description": "Wordpress 4.X"
},
{
"sitetype": "cakephp2x",
"_cuid": "",
"description": "CakePHP 2.X"
},
{
"sitetype": "nextcloud12x",
"_cuid": "",
"description": "Nextcloud 12.X"
}
],
"description": "PHP 5.6",
"runtime": "php56",
"_cuid": "cj5h6e68y0000325kq5k643q4",
"provider": "DOCKER"
},
{
"sitetypes": [
{
"sitetype": "generic",
"_cuid": "",
"description": "Generic site - Static"
}
],
"description": "Static",
"runtime": "static",
"_cuid": "cj5h6eczq0000325kx0i6534o",
"provider": "DOCKER"
}
],
"s3": {
"access_key": "civmw76wg000001p2dwq",
"browser_url": "https:\/\/s3.svc.daspanel.site",
"region": "us-east-1",
"endpoint": "https:\/\/s3.svc.daspanel.site",
"secret_key": "hlHpOfEAk45E7151"
},
"smtp": {
"password": "civmw76wg000001p2dwqxpvet",
"type": "mail-catcher",
"user": "[email protected]",
"server": "daspanel-mail-catcher:1025"
},
"redis": {
"password": "civmw76wg000001p2dwqxpvet",
"user": "",
"database": 0,
"port": 6379,
"server": "daspanel-redis"
},
"sys": {
"config_version": "0.1.0",
"admin": "[email protected]",
"hostname": "daspanel.site",
"apiserver": "http:\/\/daspanel-api:8080\/1.0",
"debug": false,
"password": "hlHpOfEAk45E7151",
"msghub": "mail-catcher"
},
"mysql": {
"user": "civmw76wg000001p2dwqxpvet",
"password": "hlHpOfEAk45E7151",
"port": 3306,
"server": "daspanel-mysql"
}
}
Thanks,
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.