<commit_before># vim: tabstop=4 shiftwidth=4 softtabstop=4

#    Copyright (C) 2012 Yahoo! Inc. All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

import time

from devstack import component as comp
from devstack import exceptions as excp
from devstack import log as logging
from devstack import settings
from devstack import shell as sh
from devstack import trace as tr
from devstack import utils

#id
TYPE = settings.DB
LOG = logging.getLogger("devstack.components.db")

#used for special setups
MYSQL = 'mysql'
START_WAIT_TIME = settings.WAIT_ALIVE_SECS

#TODO maybe we should handle this differently in the future, blah
#ie in a special set of classes (make this class abstract)...
DB_ACTIONS = {
    MYSQL: {
        # Of course these aren't distro independent...
        'runtime': {
            settings.UBUNTU11: {
                'start': ["service", "mysql", 'start'],
                'stop': ["service", 'mysql', "stop"],
                'status': ["service", 'mysql', "status"],
                'restart': ["service", 'mysql', "restart"],
            },
            settings.RHEL6: {
                'start': ["service", "mysqld", 'start'],
                'stop': ["service", 'mysqld', "stop"],
                'status': ["service", 'mysqld', "status"],
                'restart': ["service", 'mysqld', "restart"],
            },
            settings.FEDORA16: {
                'start': ["service", "mysqld", 'start'],
                'stop': ["service", 'mysqld', "stop"],
                'status': ["service", 'mysqld', "status"],
                'restart': ["service", 'mysqld', "restart"],
            },
        },
        #modification commands
        'set_pwd': ['mysql', '-u', '%USER%', '--password=%OLD_PASSWORD%', '-e', ("\"USE mysql; UPDATE user SET "
                    " password=PASSWORD('%<PASSWORD>%') WHERE User='%USER%'; FLUSH privileges;\"")],
        'create_db': ['mysql', '--user=%USER%', '--password=%PASSWORD%',
                      '-e', 'CREATE DATABASE %DB%;'],
        'drop_db': ['mysql', '--user=%USER%', '--password=%PASSWORD%',
                    '-e', 'DROP DATABASE IF EXISTS %DB%;'],
        'grant_all': ["mysql", "--user=%USER%", "--password=%PASSWORD%",
                    ("-e \"GRANT ALL PRIVILEGES ON *.* TO '%USER%'@'%' "
                    "identified by '%PASSWORD%'; flush privileges;\"")],
    },
}

#need to reset pw to blank since this distributions don't seem to always reset it when u uninstall the db
RESET_BASE_PW = ''

#links about how to reset if it fails
SQL_RESET_PW_LINKS = ['https://help.ubuntu.com/community/MysqlPasswordReset',
            'http://crashmag.net/resetting-the-root-password-for-mysql-running-on-rhel-or-centos']

#used as a generic error message
BASE_ERROR = 'Currently we do not know how to %s for database type [%s]'

#the pkg json files db requires for installation
REQ_PKGS = ['db.json']


class DBUninstaller(comp.PkgUninstallComponent):
    def __init__(self, *args, **kargs):
        comp.PkgUninstallComponent.__init__(self, TYPE, *args, **kargs)
        self.runtime = DBRuntime(*args, **kargs)
<commit_msg>Some sql cleanups.<commit_after># vim: tabstop=4 shiftwidth=4 softtabstop=4

#    Copyright (C) 2012 Yahoo! Inc. All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

import time

from devstack import component as comp
from devstack import exceptions as excp
from devstack import log as logging
from devstack import settings
from devstack import shell as sh
from devstack import trace as tr
from devstack import utils

#id
TYPE = settings.DB
LOG = logging.getLogger("devstack.components.db")

#used for special setups
MYSQL = 'mysql'
START_WAIT_TIME = settings.WAIT_ALIVE_SECS

#TODO maybe we should handle this differently in the future, blah
#ie in a special set of classes (make this class abstract)...
DB_ACTIONS = {
    MYSQL: {
        # Of course these aren't distro independent...
        'runtime': {
            settings.UBUNTU11: {
                'start': ["service", "mysql", 'start'],
                'stop': ["service", 'mysql', "stop"],
                'status': ["service", 'mysql', "status"],
                'restart': ["service", 'mysql', "restart"],
            },
            settings.RHEL6: {
                'start': ["service", "mysqld", 'start'],
                'stop': ["service", 'mysqld', "stop"],
                'status': ["service", 'mysqld', "status"],
                'restart': ["service", 'mysqld', "restart"],
            },
            settings.FEDORA16: {
                'start': ["service", "mysqld", 'start'],
                'stop': ["service", 'mysqld', "stop"],
                'status': ["service", 'mysqld', "status"],
                'restart': ["service", 'mysqld', "restart"],
            },
        },
        #modification commands
        #NOTE: we aren't stopping any sql injection...
        'set_pwd': ['mysql', '--user=%USER%', '--password=%OLD_PASSWORD%', '-e', 
                    ("\"USE mysql; UPDATE user SET "
                    " password=PASSWORD('%<PASSWORD>%') WHERE User='%USER%'; FLUSH PRIVILEGES;\"")],
        'create_db': ['mysql', '--user=%USER%', '--password=%PASSWORD%',
                      '-e', 'CREATE DATABASE %DB%;'],
        'drop_db': ['mysql', '--user=%USER%', '--password=%PASSWORD%',
                    '-e', 'DROP DATABASE IF EXISTS %DB%;'],
        'grant_all': ["mysql", "--user=%USER%", "--password=%PASSWORD%", '-e',
                    ("\"GRANT ALL PRIVILEGES ON *.* TO '%USER%'@'%' "
                    " IDENTIFIED BY '%PASSWORD%'; FLUSH PRIVILEGES;\"")],
    },
}

#need to reset pw to blank since this distributions don't seem to always reset it when u uninstall the db
RESET_BASE_PW = ''

#links about how to reset if it fails
SQL_RESET_PW_LINKS = ['https://help.ubuntu.com/community/MysqlPasswordReset',
                      'http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html']

#used as a generic error message
BASE_ERROR = 'Currently we do not know how to %s for database type [%s]'

#the pkg json files db requires for installation
REQ_PKGS = ['db.json']


class DBUninstaller(comp.PkgUninstallComponent):
    def __init__(self, *args, **kargs):
        comp.PkgUninstallComponent.__init__(self, TYPE, *args, **kargs)
        self.runtime = DBRuntime(*args, **kargs)

{'fraction_non_alphanumeric': 0.14600811907983763, 'fraction_numerical': 0.004600811907983762, 'mean_word_length': 2.6480750246791707, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '2067616', 'n_tokens_mistral': 2220, 'n_tokens_neox': 2141, 'n_words': 712}