<commit_before>#!/usr/bin/env python

import tempfile
import os.path as op
import os
import re
import sys
from random import choice

# Import everything from the configuration file
from configuration import *

def exit_err(msg):
    print(msg)
    sys.exit(1)

# Make sure trailing and leading slashes are where they are expected.
if abs_catmaid_path[-1] == '/':
    exit_err("abs_catmaid_path should not have a trailing slash! Aborting.")
if catmaid_servername[-1] == '/':
    exit_err("catmaid_servername should not have a trailing slash! Aborting.")
if catmaid_servername.startswith('http://'):
    exit_err("catmaid_servername should not start with 'http://'! Aborting.")
if len(catmaid_subdirectory) > 0:
    if catmaid_subdirectory[-1] == '/':
        exit_err("catmaid_subdirectory should not have a trailing slash! Aborting.")
    if catmaid_subdirectory[0] == '/':
        exit_err("catmaid_subdirectory should not have a leading slash! Aborting.")

in_configfile = op.join('projects/mysite/django.wsgi.example')
out_configfile = op.join('projects/mysite/django.wsgi')

o = open( out_configfile ,'w')
data = open( in_configfile, 'r' ).read()
data = re.sub('CATMAIDPATH', abs_catmaid_path, data)
data = re.sub('PYTHONLIBPATH', abs_virtualenv_python_library_path, data)
o.write( data )
o.close()

# Create a secret key for Django
alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
catmaid_secret_key = ''.join([choice(alphabet) for i in range(50)])

for f in ['', '_production']:
    in_configfile = op.join('projects/mysite/settings{0}.py.example'.format(f))
    out_configfile = op.join('projects/mysite/settings{0}.py'.format(f))
    o = open( out_configfile ,'w')
    data = open( in_configfile, 'r' ).read()
    data = re.sub('CATMAIDPATH', abs_catmaid_path, data)
    data = re.sub('CATMAID_DATABASE_NAME', catmaid_database_name, data)
    data = re.sub('CATMAID_DATABASE_USERNAME', catmaid_database_username, data)
    data = re.sub('CATMAID_DATABASE_PASSWORD', catmaid_database_password, data)
    data = re.sub('CATMAID_SECRET_KEY', catmaid_secret_key, data)
    data = re.sub('CATMAID_TIMEZONE', catmaid_timezone, data)
    data = re.sub('CATMAID_WRITABLE_PATH', catmaid_writable_path, data)
    data = re.sub('CATMAID_HDF5_SUBDIR', catmaid_hdf5_subdir, data)
    data = re.sub('CATMAID_CROP_SUBDIR', catmaid_crop_subdir, data)
    data = re.sub('CATMAID_SERVERNAME', catmaid_servername, data)
    data = re.sub('CATMAID_SUBDIR', catmaid_subdirectory, data)
    # If CATMAID doesn't live in a sub-directery, double-slashes can occur
    # in the generated configurations. Remove those:
    data = re.sub('//', '/', data)
    # Write out the configuration<commit_msg>Fix bug in config creation that caused some invalid URLs<commit_after>#!/usr/bin/env python

import tempfile
import os.path as op
import os
import re
import sys
from random import choice

# Import everything from the configuration file
from configuration import *

def exit_err(msg):
    print(msg)
    sys.exit(1)

# Make sure trailing and leading slashes are where they are expected.
if abs_catmaid_path[-1] == '/':
    exit_err("abs_catmaid_path should not have a trailing slash! Aborting.")
if catmaid_servername[-1] == '/':
    exit_err("catmaid_servername should not have a trailing slash! Aborting.")
if catmaid_servername.startswith('http://'):
    exit_err("catmaid_servername should not start with 'http://'! Aborting.")
if len(catmaid_subdirectory) > 0:
    if catmaid_subdirectory[-1] == '/':
        exit_err("catmaid_subdirectory should not have a trailing slash! Aborting.")
    if catmaid_subdirectory[0] == '/':
        exit_err("catmaid_subdirectory should not have a leading slash! Aborting.")

in_configfile = op.join('projects/mysite/django.wsgi.example')
out_configfile = op.join('projects/mysite/django.wsgi')

o = open( out_configfile ,'w')
data = open( in_configfile, 'r' ).read()
data = re.sub('CATMAIDPATH', abs_catmaid_path, data)
data = re.sub('PYTHONLIBPATH', abs_virtualenv_python_library_path, data)
o.write( data )
o.close()

# Create a secret key for Django
alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
catmaid_secret_key = ''.join([choice(alphabet) for i in range(50)])

for f in ['', '_production']:
    in_configfile = op.join('projects/mysite/settings{0}.py.example'.format(f))
    out_configfile = op.join('projects/mysite/settings{0}.py'.format(f))
    o = open( out_configfile ,'w')
    data = open( in_configfile, 'r' ).read()
    data = re.sub('CATMAIDPATH', abs_catmaid_path, data)
    data = re.sub('CATMAID_DATABASE_NAME', catmaid_database_name, data)
    data = re.sub('CATMAID_DATABASE_USERNAME', catmaid_database_username, data)
    data = re.sub('CATMAID_DATABASE_PASSWORD', catmaid_database_password, data)
    data = re.sub('CATMAID_SECRET_KEY', catmaid_secret_key, data)
    data = re.sub('CATMAID_TIMEZONE', catmaid_timezone, data)
    data = re.sub('CATMAID_WRITABLE_PATH', catmaid_writable_path, data)
    data = re.sub('CATMAID_HDF5_SUBDIR', catmaid_hdf5_subdir, data)
    data = re.sub('CATMAID_CROP_SUBDIR', catmaid_crop_subdir, data)
    data = re.sub('CATMAID_SERVERNAME', catmaid_servername, data)
    data = re.sub('CATMAID_SUBDIR', catmaid_subdirectory, data)
    # If CATMAID doesn't live in a sub-directery, double-slashes can occur
    # in the generated configurations. Remove those, if they are not part
    # of a recognized protocol specification:
    known_protocols = ["http", "https", "ftp", "ssh", "nfs", "smb"]
    known_protocols = ["(?<!%s:)" % p for p in known_protocols]
    known_protocols = ''.join(known_protocols)
    data = re.sub('%s//' % known_protocols, '/', data)
    # Write out the configuration
{'fraction_non_alphanumeric': 0.1306788282757411, 'fraction_numerical': 0.007717944220312226, 'mean_word_length': 4.878350515463918, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, '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': '6176257', 'n_tokens_mistral': 2083, 'n_tokens_neox': 1954, 'n_words': 467}