<commit_before>import os
import sys

from fabric.api import run, sudo, env, local
from fabric.contrib.files import append, sed, exists, contains
from fabric.context_managers import prefix
from fabric.tasks import Task

class PostgresInstall(Task):
    """
    Install postgresql on server

    install postgresql package;
    enable postgres access from localhost without password;
    enable all other user access from other machines with password;
    database server listen to all machines '*';
    create a user for database with password.
    """

    name = 'setup'
    db_version = '9.1'
    encrypt = 'md5'
    hba_txts = ('local   all    postgres                     trust\n'
               'local   all    all                          password\n'
               '# # IPv4 local connections:\n'
               'host    all    all         127.0.0.1/32     md5\n'
               '# # IPv6 local connections:\n'
               'host    all    all         ::1/128          md5\n'
               '# # IPv4 external\n'
               'host    all    all         0.0.0.0/0        %s\n')

    def run(self, db_version=None, encrypt=None):

        if not db_version:
            db_version = self.db_version
        db_version = ''.join(db_version.split('.')[:2])
        data_dir = self._get_data_dir(db_version)

        if not encrypt:
            encrypt = self.encrypt

        self._install_package(db_version=db_version)

        self._setup_hba_config(data_dir, encrypt=encrypt)
        self._setup_postgres_config(data_dir)

        self._restart_db_server(db_version)
        self._create_user()

    def _get_data_dir(self, db_version):
        return os.path.join('/var', 'pgsql', 'data%s' %db_version)

    def _install_package(self, db_version=None):
        pkg = 'postgresql%s-server' %db_version<commit_msg>align texts<commit_after>import os
import sys

from fabric.api import run, sudo, env, local
from fabric.contrib.files import append, sed, exists, contains
from fabric.context_managers import prefix
from fabric.tasks import Task

class PostgresInstall(Task):
    """
    Install postgresql on server

    install postgresql package;
    enable postgres access from localhost without password;
    enable all other user access from other machines with password;
    database server listen to all machines '*';
    create a user for database with password.
    """

    name = 'setup'
    db_version = '9.1'
    encrypt = 'md5'
    hba_txts = ('local   all    postgres                     trust\n'
                'local   all    all                          password\n'
                '# # IPv4 local connections:\n'
                'host    all    all         127.0.0.1/32     md5\n'
                '# # IPv6 local connections:\n'
                'host    all    all         ::1/128          md5\n'
                '# # IPv4 external\n'
                'host    all    all         0.0.0.0/0        %s\n')

    def run(self, db_version=None, encrypt=None):

        if not db_version:
            db_version = self.db_version
        db_version = ''.join(db_version.split('.')[:2])
        data_dir = self._get_data_dir(db_version)

        if not encrypt:
            encrypt = self.encrypt

        self._install_package(db_version=db_version)

        self._setup_hba_config(data_dir, encrypt=encrypt)
        self._setup_postgres_config(data_dir)

        self._restart_db_server(db_version)
        self._create_user()

    def _get_data_dir(self, db_version):
        return os.path.join('/var', 'pgsql', 'data%s' %db_version)

    def _install_package(self, db_version=None):
        pkg = 'postgresql%s-server' %db_version
{'fraction_non_alphanumeric': 0.09192886456908345, 'fraction_numerical': 0.014227086183310533, 'mean_word_length': 2.0090534979423866, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '3195135', 'n_tokens_mistral': 1123, 'n_tokens_neox': 1073, 'n_words': 282}