possibility to export settings to xml
This commit is contained in:
parent
01d982f9f4
commit
74c9f6496a
|
@ -0,0 +1,32 @@
|
|||
import sys
|
||||
import os
|
||||
|
||||
import publisher
|
||||
|
||||
def clean_vhost_sessions():
|
||||
manager = sessions.StorageSessionManager()
|
||||
one_week_ago = time.time() - 2*86400
|
||||
one_month_ago = time.time() - 30*86400
|
||||
for session_key in manager.keys():
|
||||
try:
|
||||
session = manager.get(session_key)
|
||||
except AttributeError:
|
||||
del manager[session_key]
|
||||
continue
|
||||
if session._access_time < one_week_ago or session._creation_time < one_month_ago:
|
||||
del manager[session.id]
|
||||
|
||||
def export_settings(args):
|
||||
stdout = sys.stdout
|
||||
pub = publisher.WcsPublisher.create_publisher()
|
||||
|
||||
i = 0
|
||||
while i < len(args):
|
||||
if args[i] == '--vhost':
|
||||
pub.app_dir = os.path.join(pub.app_dir, args[i+1])
|
||||
i += 1
|
||||
i += 1
|
||||
|
||||
pub.reload_cfg()
|
||||
print >> stdout, pub.export_cfg()
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
import time
|
||||
import sys
|
||||
import os
|
||||
|
||||
import publisher
|
||||
|
||||
from wcs.formdef import FormDef
|
||||
|
||||
def rebuild_vhost_indexes():
|
||||
FormDef.rebuild_indexes()
|
||||
|
||||
def rebuild_indexes(args):
|
||||
pub = publisher.WcsPublisher.create_publisher()
|
||||
|
||||
if '--single_host' in args:
|
||||
rebuild_vhost_indexes()
|
||||
else:
|
||||
app_dir = pub.app_dir
|
||||
hostnames = os.listdir(app_dir)
|
||||
for hostname in hostnames:
|
||||
pub.app_dir = os.path.join(app_dir, hostname)
|
||||
rebuild_vhost_indexes()
|
||||
|
|
@ -119,6 +119,7 @@ class QommonPublisher(Publisher):
|
|||
def get_site_language(self):
|
||||
lang = self.cfg.get('language', {}).get('language', None)
|
||||
if lang == 'HTTP':
|
||||
request = get_request()
|
||||
lang = None
|
||||
accepted_languages = request.get_header('Accept-Language')
|
||||
if accepted_languages:
|
||||
|
@ -251,6 +252,42 @@ class QommonPublisher(Publisher):
|
|||
except:
|
||||
self.cfg = {}
|
||||
|
||||
def export_cfg(self):
|
||||
try:
|
||||
import elementtree.ElementTree as ET
|
||||
except ImportError:
|
||||
ET = None
|
||||
|
||||
root = ET.Element('settings')
|
||||
for k in self.cfg:
|
||||
part = ET.SubElement(root, k)
|
||||
for k2 in self.cfg[k]:
|
||||
elem = ET.SubElement(part, k2)
|
||||
val = self.cfg[k][k2]
|
||||
if val is None:
|
||||
pass
|
||||
|
||||
elif type(val) is dict:
|
||||
for k3, v3 in val.items():
|
||||
ET.SubElement(elem, k3).text = v3
|
||||
|
||||
elif type(val) is list:
|
||||
if k2[-1] == 's':
|
||||
atname = k2[:-1]
|
||||
else:
|
||||
atname = 'item'
|
||||
for v in val:
|
||||
ET.SubElement(elem, atname).text = v
|
||||
|
||||
elif type(val) in (str, unicode):
|
||||
elem.text = val
|
||||
|
||||
else:
|
||||
elem.text = str(val)
|
||||
|
||||
return ET.tostring(root)
|
||||
|
||||
|
||||
|
||||
def get_cfg(key, default = None):
|
||||
r = get_publisher().cfg.get(key, default)
|
||||
|
|
|
@ -9,6 +9,7 @@ def print_usage():
|
|||
print ' start start server'
|
||||
print ' clean_sessions clean old sessions'
|
||||
print ' rebuild_indexes rebuild database indexes'
|
||||
print ' export_settings export settings'
|
||||
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
|
@ -29,6 +30,9 @@ else:
|
|||
elif command == 'process_bounce':
|
||||
from wcs.ctl.process_bounce import process_bounce
|
||||
process_bounce(sys.argv[2:])
|
||||
elif command == 'export_settings':
|
||||
from wcs.ctl.export_settings import export_settings
|
||||
export_settings(sys.argv[2:])
|
||||
else:
|
||||
print_usage()
|
||||
|
||||
|
|
Loading…
Reference in New Issue