forked from 0x2620/pandora
add manage.py update_config_documentation
This commit is contained in:
parent
c7bb3c3d0e
commit
4c35340f38
2 changed files with 65 additions and 0 deletions
41
pandora/app/documentation.py
Normal file
41
pandora/app/documentation.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
from __future__ import print_function
|
||||
|
||||
import re
|
||||
import ox.jsonc
|
||||
|
||||
|
||||
def get(config_jsonc='config.pandora.jsonc'):
|
||||
with open(config_jsonc, 'rb') as fd:
|
||||
data = fd.read().decode('utf-8')
|
||||
config = ox.jsonc.loads(data)
|
||||
docs = {}
|
||||
for m in re.compile('( \/\*.*?\*\/)\W+"([^\W]+?)":', re.DOTALL).findall(data):
|
||||
docs[m[1]] = m[0].strip()
|
||||
'''
|
||||
for key in config:
|
||||
if key not in docs:
|
||||
print(config_jsonc, 'missing', key)
|
||||
'''
|
||||
for key in docs.keys():
|
||||
if key not in config:
|
||||
print('parse error, invalid config key:', key)
|
||||
del docs[key]
|
||||
return docs
|
||||
|
||||
def update(config_jsonc='config.jsonc', base='config.pandora.jsonc'):
|
||||
with open(config_jsonc, 'rb') as fd:
|
||||
config = data = fd.read().decode('utf-8')
|
||||
docs = get(base)
|
||||
current_docs = get(config_jsonc)
|
||||
for key in docs:
|
||||
if key in current_docs:
|
||||
match = re.escape(' '+docs[key]) + '\W+"' + re.escape(key) + '":'
|
||||
else:
|
||||
match = ' "' + re.escape(key) + '":'
|
||||
data = re.sub(match, ' %s\n "%s":' % (docs[key], key), data)
|
||||
if data != config:
|
||||
print('updating config documentation', config_jsonc)
|
||||
with open('%s' % config_jsonc, 'wb') as fd:
|
||||
fd.write(data.encode('utf-8'))
|
|
@ -0,0 +1,24 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
from __future__ import print_function
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.conf import settings
|
||||
from ... import documentation
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
"""
|
||||
"""
|
||||
help = 'update config.jsonc documentation'
|
||||
args = '[config.jsonc] [baseconfig.jsonc]'
|
||||
|
||||
def handle(self, *args, **options):
|
||||
target = settings.SITE_CONFIG
|
||||
base = settings.DEFAULT_CONFIG
|
||||
if len(args) == 1:
|
||||
target = args[0]
|
||||
elif len(args) == 2:
|
||||
target = args[0]
|
||||
base = args[1]
|
||||
print('update docs', target, 'base', base)
|
||||
documentation.update(target, base)
|
Loading…
Reference in a new issue