misc: apply double-quote-string-fixer (#79788)

This commit is contained in:
Valentin Deniaud 2023-08-16 11:53:24 +02:00
parent 1118551c85
commit af691f64f7
1 changed files with 31 additions and 31 deletions

View File

@ -8,23 +8,23 @@ import sys
publik = {
"authentic2-multitenant": {
"database": "authentic2_multitenant",
"user": "authentic-multitenant",
"extensions": ["unaccent", "pg_trgm"],
'authentic2-multitenant': {
'database': 'authentic2_multitenant',
'user': 'authentic-multitenant',
'extensions': ['unaccent', 'pg_trgm'],
},
"bijoe": {},
"chrono": {},
"combo": {"extensions": ["unaccent"]},
"fargo": {},
"hobo": {},
"passerelle": {},
"wcs": {},
"welco": {},
'bijoe': {},
'chrono': {},
'combo': {'extensions': ['unaccent']},
'fargo': {},
'hobo': {},
'passerelle': {},
'wcs': {},
'welco': {},
}
def run(command, database="postgres", fake=False):
def run(command, database='postgres', fake=False):
cmd = 'sudo -u postgres psql -c "%s" %s' % (command.replace('"', '\\"'), database)
if fake:
print(cmd)
@ -33,14 +33,14 @@ def run(command, database="postgres", fake=False):
def write_setting(brique, host, port, password):
if brique == "wcs":
print("warning: setting w.c.s. connection password is not implemented")
if brique == 'wcs':
print('warning: setting w.c.s. connection password is not implemented')
return
settings_d = "/etc/%s/settings.d" % brique
settings = "%s/database.py" % settings_d
settings_d = '/etc/%s/settings.d' % brique
settings = '%s/database.py' % settings_d
if not os.path.isdir(settings_d):
os.system('mkdir -p %s' % settings_d)
with open(settings, "w") as fh:
with open(settings, 'w') as fh:
fh.write(
"DATABASES['default']['HOST'] = '{host}'\n"
"DATABASES['default']['PORT'] = {port}\n"
@ -50,14 +50,14 @@ def write_setting(brique, host, port, password):
def main(args):
for brique, data in publik.items():
database = data.get("database", brique)
user = data.get("user", brique)
extensions = data.get("extensions")
database = data.get('database', brique)
user = data.get('user', brique)
extensions = data.get('extensions')
run('CREATE USER "%s";' % user, fake=args.fake)
if user == "wcs":
run("ALTER USER wcs CREATEDB;", fake=args.fake)
if user == 'wcs':
run('ALTER USER wcs CREATEDB;', fake=args.fake)
if args.password:
password = "".join(random.choice(string.ascii_letters + string.digits) for _ in range(16))
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 "
@ -66,20 +66,20 @@ def main(args):
)
if extensions:
for e in extensions:
run("CREATE EXTENSION %s;" % e, database=database, fake=args.fake)
run('CREATE EXTENSION %s;' % e, database=database, fake=args.fake)
if not args.fake and args.password:
write_setting(brique, args.host, args.port, password)
if __name__ == "__main__":
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("--password", action="store_true", help="generate password")
parser.add_argument("--fake", action="store_true", help="dry-run")
parser.add_argument("--host", default="localhost")
parser.add_argument("--port", default="5432")
parser.add_argument('--password', action='store_true', help='generate password')
parser.add_argument('--fake', action='store_true', help='dry-run')
parser.add_argument('--host', default='localhost')
parser.add_argument('--port', default='5432')
args = parser.parse_args()
if not args.fake and os.geteuid() != 0:
sys.exit("You need to have privileges to run this script, please try again with sudo.")
sys.exit('You need to have privileges to run this script, please try again with sudo.')
main(args)