<commit_before>import random
import re
import os
import traceback
import urllib.parse

def print_notice(s):
    print('\033[92m'+s+'\033[0m\n')

def path_exists(path):
    if not os.path.exists(path):
        answer = input("That path doesn't exist. Create it? [y/n]").strip().lower()
        if answer=='y':
            os.makedirs(path)
            return True
        else:
            return False
    else:
        return True

class Question(object):
    def __init__(self, key, question, default, validation=None):
        self.key = key
        self.question = question
        self.default = default
        self.validation = validation

    def validate(self, value):
        return self.validation is None or self.validation(value)

class Command(object):

    questions = [
        Question('DEBUG', 'Is this installation for development?', False),
        Question('NUMBAS_PATH', 'Path of the Numbas compiler:','/srv/numbas/compiler/', validation=path_exists),
        Question('DB_ENGINE', 'Which database engine are you using?', 'mysql'),
        Question('STATIC_ROOT', 'Where are static files stored?','/srv/numbas/static/', validation=path_exists),
        Question('MEDIA_ROOT', 'Where are uploaded files stored?','/srv/numbas/media/', validation=path_exists),
        Question('PREVIEW_PATH', 'Where are preview exams stored?','/srv/numbas/previews/', validation=path_exists),
        Question('PREVIEW_URL', 'Base URL of previews:','/previews/'),
        Question('PYTHON_EXEC', 'Python command:','python3'),
        Question('SITE_TITLE', 'Title of the site:','Numbas'),
        Question('ALLOW_REGISTRATION', 'Allow new users to register themselves?', True),
        Question('DEFAULT_FROM_EMAIL', 'Address to send emails from:', ''),
    ]
    db_questions = [
        Question('DB_NAME', 'Name of the database:','numbas_editor'),
        Question('DB_USER', 'Database user:', 'numbas_editor'),<commit_msg>fix default value for PREVIEW_URL in first_setup.py<commit_after>import random
import re
import os
import traceback
import urllib.parse

def print_notice(s):
    print('\033[92m'+s+'\033[0m\n')

def path_exists(path):
    if not os.path.exists(path):
        answer = input("That path doesn't exist. Create it? [y/n]").strip().lower()
        if answer=='y':
            os.makedirs(path)
            return True
        else:
            return False
    else:
        return True

class Question(object):
    def __init__(self, key, question, default, validation=None):
        self.key = key
        self.question = question
        self.default = default
        self.validation = validation

    def validate(self, value):
        return self.validation is None or self.validation(value)

class Command(object):

    questions = [
        Question('DEBUG', 'Is this installation for development?', False),
        Question('NUMBAS_PATH', 'Path of the Numbas compiler:','/srv/numbas/compiler/', validation=path_exists),
        Question('DB_ENGINE', 'Which database engine are you using?', 'mysql'),
        Question('STATIC_ROOT', 'Where are static files stored?','/srv/numbas/static/', validation=path_exists),
        Question('MEDIA_ROOT', 'Where are uploaded files stored?','/srv/numbas/media/', validation=path_exists),
        Question('PREVIEW_PATH', 'Where are preview exams stored?','/srv/numbas/previews/', validation=path_exists),
        Question('PREVIEW_URL', 'Base URL of previews:','/numbas-previews/'),
        Question('PYTHON_EXEC', 'Python command:','python3'),
        Question('SITE_TITLE', 'Title of the site:','Numbas'),
        Question('ALLOW_REGISTRATION', 'Allow new users to register themselves?', True),
        Question('DEFAULT_FROM_EMAIL', 'Address to send emails from:', ''),
    ]
    db_questions = [
        Question('DB_NAME', 'Name of the database:','numbas_editor'),
        Question('DB_USER', 'Database user:', 'numbas_editor'),
{'fraction_non_alphanumeric': 0.1377720870678617, 'fraction_numerical': 0.005121638924455826, 'mean_word_length': 3.393700787401575, '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': '55118', 'n_tokens_mistral': 1156, 'n_tokens_neox': 1135, 'n_words': 295}