2018-10-13 17:34:17 +02:00
|
|
|
#! /usr/bin/env python
|
2021-05-27 09:05:49 +02:00
|
|
|
#%# family=auto
|
|
|
|
#%# capabilities=autoconf
|
2018-10-13 17:34:17 +02:00
|
|
|
|
|
|
|
import cPickle
|
|
|
|
import os
|
|
|
|
import psycopg2
|
2021-05-27 09:05:49 +02:00
|
|
|
import itertools
|
2018-10-13 17:34:17 +02:00
|
|
|
import sys
|
|
|
|
|
2019-02-10 16:13:56 +01:00
|
|
|
base_dir = None
|
|
|
|
for dirname in os.listdir('/var/lib/machines/'):
|
|
|
|
if os.path.exists(os.path.join('/var/lib/machines/', dirname, 'var/lib/wcs')):
|
|
|
|
base_dir = os.path.join('/var/lib/machines/', dirname, 'var/lib/wcs')
|
|
|
|
break
|
|
|
|
|
2018-10-13 17:34:17 +02:00
|
|
|
if len(sys.argv) == 2 and sys.argv[1] == 'autoconf':
|
2019-02-10 16:13:56 +01:00
|
|
|
if base_dir:
|
|
|
|
print 'yes'
|
|
|
|
else:
|
|
|
|
print 'no'
|
2018-10-13 17:34:17 +02:00
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
if len(sys.argv) == 2 and sys.argv[1] == 'config':
|
|
|
|
print '''graph_title Count of submitted forms
|
|
|
|
graph_category entrouvert
|
|
|
|
count.label Count
|
|
|
|
'''
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
total = 0
|
2019-02-10 16:13:56 +01:00
|
|
|
|
2021-05-27 09:05:49 +02:00
|
|
|
for tenant in itertools.chain(os.listdir(base_dir), os.listdir(os.path.join(base_dir, 'tenants')):
|
|
|
|
if tenant in ('collectstatic', 'scripts', 'skeletons', 'spooler', 'tenants'):
|
2018-10-13 17:34:17 +02:00
|
|
|
continue
|
|
|
|
if tenant.endswith('.invalid'):
|
|
|
|
continue
|
|
|
|
if not os.path.isdir(os.path.join(base_dir, tenant)):
|
|
|
|
continue
|
|
|
|
cfg = cPickle.load(open(os.path.join(base_dir, tenant, 'config.pck')))
|
|
|
|
if not 'postgresql' in cfg:
|
|
|
|
continue
|
|
|
|
psql_cfg = {}
|
|
|
|
for k, v in cfg['postgresql'].items():
|
|
|
|
if v and isinstance(v, basestring):
|
|
|
|
psql_cfg[k] = v
|
|
|
|
pgconn = psycopg2.connect(**psql_cfg)
|
|
|
|
cur = pgconn.cursor()
|
|
|
|
try:
|
|
|
|
cur.execute('''SELECT COUNT(*) from wcs_all_forms WHERE status != 'draft' ''')
|
|
|
|
except psycopg2.ProgrammingError:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
total += cur.fetchone()[0]
|
|
|
|
pgconn.close()
|
|
|
|
|
|
|
|
print 'count.value', total
|