<commit_before>
import os
import signal
import shutil
import tempfile
import logging
import subprocess
import time
import unittest

import paasmaker
from ..common.testhelpers import TestHelpers
from manageddaemon import ManagedDaemon, ManagedDaemonError

import tornado.testing
import tornadoredis

class RedisDaemonError(ManagedDaemonError):
	pass

class RedisDaemon(ManagedDaemon):
	"""
	Start up a managed Redis daemon, for use by other service
	plugins, or in unit tests.

	As Redis doesn't really allow for multiple databases in the
	same instance, this class is an easy way to simulate that by
	starting a seperate instance per required database.

	Currently, it chooses some persistence options that match
	the default Ubuntu/Debian configuration. In future it will
	offer other canned persistence options to better suit
	what the server is being used for.
	"""

	REDIS_SERVER_CONFIG = """
daemonize yes
pidfile %(working_dir)s/redis.pid
dir %(working_dir)s
port %(port)d
bind %(host)s

databases 16

# Default set of save entries from Ubuntu/Debian.
save 900 1
save 300 10
save 60 10000

dbfilename dump.rdb

# Optional password line.
%(auth_line)s

timeout 300
loglevel notice
logfile %(working_dir)s/redis.log
appendonly no
"""

	def configure(self, working_dir, port, bind_host, password=None):
		"""
		Configure this Redis instance.

		:arg str working_dir: The working directory to store files.
		:arg int port: The TCP port to listen on.
		:arg str bind_host: The IP address to bind to.
		:arg str|None password: If supplied, clients will require
			this password to connect to the daemon.
		"""
		# TODO: Allow a memory limit.
		# TODO: Allow custom configuration entries.
		self.parameters['working_dir'] = working_dir
		self.parameters['port'] = port
		self.parameters['host'] = bind_host
		self.parameters['password'] = password

		# Create the working dir. If this fails, let it bubble up.
		if not os.path.exists(working_dir):
			os.makedirs(working_dir)
<commit_msg>Updated the redis daemon to use an absolute path for storing the database file.<commit_after>
import os
import signal
import shutil
import tempfile
import logging
import subprocess
import time
import unittest

import paasmaker
from ..common.testhelpers import TestHelpers
from manageddaemon import ManagedDaemon, ManagedDaemonError

import tornado.testing
import tornadoredis

class RedisDaemonError(ManagedDaemonError):
	pass

class RedisDaemon(ManagedDaemon):
	"""
	Start up a managed Redis daemon, for use by other service
	plugins, or in unit tests.

	As Redis doesn't really allow for multiple databases in the
	same instance, this class is an easy way to simulate that by
	starting a seperate instance per required database.

	Currently, it chooses some persistence options that match
	the default Ubuntu/Debian configuration. In future it will
	offer other canned persistence options to better suit
	what the server is being used for.
	"""

	REDIS_SERVER_CONFIG = """
daemonize yes
pidfile %(working_dir)s/redis.pid
dir %(working_dir)s
port %(port)d
bind %(host)s

databases 16

# Default set of save entries from Ubuntu/Debian.
save 900 1
save 300 10
save 60 10000

dbfilename %(working_dir)s/dump.rdb

# Optional password line.
%(auth_line)s

timeout 300
loglevel notice
logfile %(working_dir)s/redis.log
appendonly no
"""

	def configure(self, working_dir, port, bind_host, password=None):
		"""
		Configure this Redis instance.

		:arg str working_dir: The working directory to store files.
		:arg int port: The TCP port to listen on.
		:arg str bind_host: The IP address to bind to.
		:arg str|None password: If supplied, clients will require
			this password to connect to the daemon.
		"""
		# TODO: Allow a memory limit.
		# TODO: Allow custom configuration entries.
		self.parameters['working_dir'] = working_dir
		self.parameters['port'] = port
		self.parameters['host'] = bind_host
		self.parameters['password'] = password

		# Create the working dir. If this fails, let it bubble up.
		if not os.path.exists(working_dir):
			os.makedirs(working_dir)

{'fraction_non_alphanumeric': 0.06829388560157791, 'fraction_numerical': 0.010355029585798817, 'mean_word_length': 4.588154269972452, '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': '5298661', 'n_tokens_mistral': 1319, 'n_tokens_neox': 1187, 'n_words': 495}