<commit_before>"""
Creates a database for Molly, and appropriate users, once given login
information as super user, or by running as root.
"""

from molly.installer.utils import quiet_exec, CommandFailed

def create(dba_user, dba_pass, username, password, database):
    
    creds = []
    if dba_user:
        creds += ['-U', dba_user]
    if dba_pass:
        os.environ['PGPASSWORD'] = dba_pass
    
    try:
        quiet_exec(['psql'] + creds + ['-c',"CREATE USER %s WITH PASSWORD '%s';" % (username, password)], 'dbcreate')
    except CommandFailed:
        pass
    
    quiet_exec(['psql'] + creds + ['-c',"ALTER ROLE %s WITH PASSWORD '%s';" % (username, password)], 'dbcreate')
    try:
        quiet_exec(['createdb'] + creds + ['-T','template_postgis',database], 'dbcreate')
    except CommandFailed:
        quiet_exec(['dropdb'] + creds + [database], 'dbcreate')
        quiet_exec(['createdb'] + creds + ['-T','template_postgis',database], 'dbcreate')
    quiet_exec(['psql'] + creds + ['-c',"GRANT ALL ON DATABASE %s TO %s;" % (database, username)], 'dbcreate')

    if dba_pass:
        del os.environ['PGPASSWORD']
    <commit_msg>Fix broken setting of postgres password<commit_after>"""
Creates a database for Molly, and appropriate users, once given login
information as super user, or by running as root.
"""

import os

from molly.installer.utils import quiet_exec, CommandFailed

def create(dba_user, dba_pass, username, password, database):
    
    creds = []
    if dba_user:
        creds += ['-U', dba_user]
    if dba_pass:
        os.environ['PGPASSWORD'] = dba_pass
    
    try:
        quiet_exec(['psql'] + creds + ['-c',"CREATE USER %s WITH PASSWORD '%s';" % (username, password)], 'dbcreate')
    except CommandFailed:
        pass
    
    quiet_exec(['psql'] + creds + ['-c',"ALTER ROLE %s WITH PASSWORD '%s';" % (username, password)], 'dbcreate')
    try:
        quiet_exec(['createdb'] + creds + ['-T','template_postgis',database], 'dbcreate')
    except CommandFailed:
        quiet_exec(['dropdb'] + creds + [database], 'dbcreate')
        quiet_exec(['createdb'] + creds + ['-T','template_postgis',database], 'dbcreate')
    quiet_exec(['psql'] + creds + ['-c',"GRANT ALL ON DATABASE %s TO %s;" % (database, username)], 'dbcreate')

    if dba_pass:
        del os.environ['PGPASSWORD']
    
{'fraction_non_alphanumeric': 0.1601713062098501, 'fraction_numerical': 0.0, 'mean_word_length': 3.4836852207293667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5257482', 'n_tokens_mistral': 781, 'n_tokens_neox': 772, 'n_words': 205}