<commit_before>#!/usr/bin/env php
<?php

$config_keys =  array(
	'FILE' => '',
	'URL' => 'example.com',
	'SSL' => 'false',
	'ADMIN' => '<EMAIL>',
	'TIMEZONE'=> 'UTC',
	'SESSION_NAME' => '__ses',
	'SESSION_EXPIRY'=> '3600',
	'SESSION_IDLE'=> '3600',
	'SESSION_AUTO_RENEW' => 'true',
	'LOGIN_PATH' => '/login',
	'TOKEN_SECRET' => '',
	'TOKEN_EXPIRY' => '300',
	'DB_TYPE' =>'mysql',
	'DB_HOST' =>'localhost',
	'DB_USER' => '',
	'DB_PASS' =>'',
	'DB_NAME' => ''
);


function logger($str) {
	if (is_array($str)) {
		print_r($str);
	} else {
		echo $str;
	}
	echo "\n";
}

function extract_config_from_cmdline($arguments) {
	global $config_keys;
	$config = array();
	$re = "/^--([a-z]+)\\=(.*)$/m";
	foreach ($arguments as $key => $value) {
		if (preg_match_all($re, $value, $matches)) {
			if (!isset($matches[1])) continue;
			if (!isset($matches[2])) continue;
			$config[strtoupper($matches[1][0])] = $matches[2][0];
		}
	}
	return $config;
}

function get_sample_config($config) {
	global $config_keys;
	$template  = "<?php
/*
 * Generated by Flubber setup
 */
define('SITEURL', '__URL__');

define('HAS_SSL', __SSL__);

define('SITEADMIN', '__ADMIN__');

define('TIMEZONE', '__TIMEZONE__');

define('SESSION_NAME', '__SESSION_NAME__');

define('SESSION_EXPIRY', __SESSION_EXPIRY__);

define('SESSION_IDLE', __SESSION_IDLE__);

define('SESSION_AUTO_RENEW', __SESSION_AUTO_RENEW__);

define('LOGIN_URI', '__LOGIN_PATH__');

// CSRF token secret, make sure to put a long random string.
define('TOKEN_SECRET', '__TOKEN_SECRET__');

// CSRF tokens expiry time (in seconds)
define('TOKEN_EXPIRY', __TOKEN_EXPIRY__);

// DB configuration
define('DBTYPE', '__DB_TYPE__');

define('DBHOST', '__DB_HOST__');

define('DBUSER', '__DB_USER__');

define('DBPASS', '__DB_PASS__');

define('DBNAME', '__DB_NAME__');

?>";

	foreach($config_keys as $key => $default) {
		$re = "~__".$key."__~m";
		$subst = "";
		if (array_key_exists($key, $config)) {
			$subst = $config[$key];
		} else {
			$subst = $default;
		}
		$template = preg_replace($re, $subst, $template);
	}
	return $template;
}

function prepare_dirs() {
	global $config;

	if (!array_key_exists('PATH', $config)) {
		echo "Unable to find --path in config.";
		exit;
	}
	$path = $config['PATH'];
	if (file_exists($path)) {
		echo $path . " already exists.";
		exit;
	}
	if (!mkdir($path)) {
		echo "Unable to create `".$path."`.  Make sure you have permission to the directory.";
		exit;
	}

	if (!chmod($path, 0777)) {
		echo "Unable to give full permission to directory. Give the directory write permission before running the setup.";
		exit;
	}

	mkdir($path."/config", 0777);
	mkdir($path."/config/locale", 0777);
	mkdir($path."/handlers", 0777);<commit_msg>clear message<commit_after>#!/usr/bin/env php
<?php

$config_keys =  array(
	'FILE' => '',
	'URL' => 'example.com',
	'SSL' => 'false',
	'ADMIN' => '<EMAIL>',
	'TIMEZONE'=> 'UTC',
	'SESSION_NAME' => '__ses',
	'SESSION_EXPIRY'=> '3600',
	'SESSION_IDLE'=> '3600',
	'SESSION_AUTO_RENEW' => 'true',
	'LOGIN_PATH' => '/login',
	'TOKEN_SECRET' => '',
	'TOKEN_EXPIRY' => '300',
	'DB_TYPE' =>'mysql',
	'DB_HOST' =>'localhost',
	'DB_USER' => '',
	'DB_PASS' =>'',
	'DB_NAME' => ''
);


function logger($str) {
	if (is_array($str)) {
		print_r($str);
	} else {
		echo $str;
	}
	echo "\n";
}

function extract_config_from_cmdline($arguments) {
	global $config_keys;
	$config = array();
	$re = "/^--([a-z]+)\\=(.*)$/m";
	foreach ($arguments as $key => $value) {
		if (preg_match_all($re, $value, $matches)) {
			if (!isset($matches[1])) continue;
			if (!isset($matches[2])) continue;
			$config[strtoupper($matches[1][0])] = $matches[2][0];
		}
	}
	return $config;
}

function get_sample_config($config) {
	global $config_keys;
	$template  = "<?php
/*
 * Generated by Flubber setup
 */
define('SITEURL', '__URL__');

define('HAS_SSL', __SSL__);

define('SITEADMIN', '__ADMIN__');

define('TIMEZONE', '__TIMEZONE__');

define('SESSION_NAME', '__SESSION_NAME__');

define('SESSION_EXPIRY', __SESSION_EXPIRY__);

define('SESSION_IDLE', __SESSION_IDLE__);

define('SESSION_AUTO_RENEW', __SESSION_AUTO_RENEW__);

define('LOGIN_URI', '__LOGIN_PATH__');

// CSRF token secret, make sure to put a long random string.
define('TOKEN_SECRET', '__TOKEN_SECRET__');

// CSRF tokens expiry time (in seconds)
define('TOKEN_EXPIRY', __TOKEN_EXPIRY__);

// DB configuration
define('DBTYPE', '__DB_TYPE__');

define('DBHOST', '__DB_HOST__');

define('DBUSER', '__DB_USER__');

define('DBPASS', '__DB_PASS__');

define('DBNAME', '__DB_NAME__');

?>";

	foreach($config_keys as $key => $default) {
		$re = "~__".$key."__~m";
		$subst = "";
		if (array_key_exists($key, $config)) {
			$subst = $config[$key];
		} else {
			$subst = $default;
		}
		$template = preg_replace($re, $subst, $template);
	}
	return $template;
}

function prepare_dirs() {
	global $config;

	if (!array_key_exists('PATH', $config)) {
		echo "Please send `--path=/path/to/your/project` \n\tFor example --path=/var/www/example.com";
		exit;
	}
	$path = $config['PATH'];
	if (file_exists($path)) {
		echo $path . " already exists.";
		exit;
	}
	if (!mkdir($path)) {
		echo "Unable to create `".$path."`.  Make sure you have permission to the directory.";
		exit;
	}

	if (!chmod($path, 0777)) {
		echo "Unable to give full permission to directory. Give the directory write permission before running the setup.";
		exit;
	}

	mkdir($path."/config", 0777);
	mkdir($path."/config/locale", 0777);
	mkdir($path."/handlers", 0777);
{'fraction_non_alphanumeric': 0.21172816952868104, 'fraction_numerical': 0.01205699671172817, 'mean_word_length': 4.893433799784715, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, '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': '6296816', 'n_tokens_mistral': 2259, 'n_tokens_neox': 2160, 'n_words': 440}