trivial: apply black

This commit is contained in:
Frédéric Péters 2021-01-13 17:45:56 +01:00
parent 8029a2e7fb
commit 414001bd1e
5 changed files with 51 additions and 30 deletions

View File

@ -5,8 +5,18 @@ from jinja2 import Environment, FileSystemLoader, __version__, StrictUndefined
assert version.parse(__version__) < version.parse('2.11')
TEMPLATE = 'publik-application.conf.j2'
MODULES = ('authentic2-multitenant', 'bijoe', 'chrono', 'combo', 'corbo',
'fargo', 'hobo', 'mandayejs', 'passerelle', 'welco')
MODULES = (
'authentic2-multitenant',
'bijoe',
'chrono',
'combo',
'corbo',
'fargo',
'hobo',
'mandayejs',
'passerelle',
'welco',
)
for module in MODULES:
loader = FileSystemLoader('.')

View File

@ -6,17 +6,19 @@ import shutil
import os
briques = ['authentic2-multitenant',
'bijoe',
'chrono',
'combo',
'corbo',
'fargo',
'hobo',
'mandayejs',
'passerelle',
'wcs',
'welco']
briques = [
'authentic2-multitenant',
'bijoe',
'chrono',
'combo',
'corbo',
'fargo',
'hobo',
'mandayejs',
'passerelle',
'wcs',
'welco',
]
def link(application, basepath):
@ -65,7 +67,7 @@ if __name__ == '__main__':
basepath = args.basepath
if not os.path.isdir(basepath):
raise(Exception('path not found: %s' % basepath))
raise (Exception('path not found: %s' % basepath))
if application == 'all':
for app in briques:
@ -74,4 +76,4 @@ if __name__ == '__main__':
if application in briques:
link(application, basepath)
else:
raise(Exception('application unknown: %s' % application))
raise (Exception('application unknown: %s' % application))

View File

@ -41,9 +41,11 @@ def write_setting(brique, host, port, password):
if not os.path.isdir(settings_d):
os.system('mkdir -p %s' % settings_d)
with open(settings, "w") as fh:
fh.write("DATABASES['default']['HOST'] = '{host}'\n"
"DATABASES['default']['PORT'] = {port}\n"
"DATABASES['default']['PASSWORD'] = '{password}'".format(host=host, port=port, password=password))
fh.write(
"DATABASES['default']['HOST'] = '{host}'\n"
"DATABASES['default']['PORT'] = {port}\n"
"DATABASES['default']['PASSWORD'] = '{password}'".format(host=host, port=port, password=password)
)
def main(args):
@ -57,8 +59,11 @@ def main(args):
if args.password:
password = "".join(random.choice(string.ascii_letters + string.digits) for _ in range(16))
run("ALTER USER \"%s\" with password '%s';" % (user, password), fake=args.fake)
run("CREATE DATABASE {} WITH OWNER = \"{}\" TEMPLATE = template0 "
"LC_COLLATE = 'fr_FR.UTF-8' LC_CTYPE = 'fr_FR.UTF-8';".format(database, user), fake=args.fake)
run(
"CREATE DATABASE {} WITH OWNER = \"{}\" TEMPLATE = template0 "
"LC_COLLATE = 'fr_FR.UTF-8' LC_CTYPE = 'fr_FR.UTF-8';".format(database, user),
fake=args.fake,
)
if extensions:
for e in extensions:
run("CREATE EXTENSION %s;" % e, database=database, fake=args.fake)

View File

@ -6,8 +6,7 @@ import subprocess
userlist = {
'hobo': {'uid': '2100'},
'authentic-multitenant': {'uid': '2101',
'home': '/var/lib/authentic2-multitenant'},
'authentic-multitenant': {'uid': '2101', 'home': '/var/lib/authentic2-multitenant'},
'wcs': {'uid': '2102'},
'passerelle': {'uid': '2104'},
'combo': {'uid': '2105'},
@ -16,8 +15,9 @@ userlist = {
'chrono': {'uid': '2108'},
'corbo': {'uid': '2109'},
'bijoe': {'uid': '2110'},
'mandayejs': {'uid': '2111'}
}
'mandayejs': {'uid': '2111'},
}
def run(cmd, check=True):
# when dropping jessie and python3.4 support better use:
@ -28,10 +28,11 @@ def run(cmd, check=True):
return (0, output)
except subprocess.CalledProcessError:
if check:
raise(Exception('Command failed: "{}"'.format(cmd)))
raise (Exception('Command failed: "{}"'.format(cmd)))
else:
return (1, None)
for user, data in userlist.items():
uid = data.get('uid')
home = data.get('home', '/var/lib/%s' % user)
@ -39,15 +40,18 @@ for user, data in userlist.items():
if rc == 0:
current_uid = ou.decode().split(':')[2]
if current_uid != uid:
raise(Exception('{} uid does not match'.format(user)))
raise (Exception('{} uid does not match'.format(user)))
else:
run('addgroup --system --gid {} {}'.format(uid, user))
rc, ou = run('getent passwd {}'.format(user), check=False)
if rc == 0:
uid = ou.decode().split(':')[2]
if uid != uid:
raise(Exception('{} uid does not match'.format(user)))
raise (Exception('{} uid does not match'.format(user)))
else:
run('adduser --disabled-password --system --uid {uid} --gecos "{user} daemon" --ingroup {user} --no-create-home --home {home} {user}'.format(user=user, uid=uid, home=home))
run(
'adduser --disabled-password --system --uid {uid} --gecos "{user} daemon" --ingroup {user} --no-create-home --home {home} {user}'.format(
user=user, uid=uid, home=home
)
)

View File

@ -25,7 +25,7 @@ for brique in briques:
if not os.path.isdir('/etc/%s' % brique):
continue
settings_d ='/etc/%s/settings.d' % brique
settings_d = '/etc/%s/settings.d' % brique
if not os.path.isdir(settings_d):
os.mkdir(settings_d)