<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 cfg
from devstack import date
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 utils

from devstack.packaging import apt
from devstack.packaging import yum

from devstack.components import keystone

from devstack.progs import common

LOG = logging.getLogger("devstack.progs.actions")

#this map controls which distro has
#which package management class
_PKGR_MAP = {
    settings.UBUNTU11: apt.AptPackager,
    settings.RHEL6: yum.YumPackager,
}

# This is used to map an action to a useful string for
# the welcome display
_WELCOME_MAP = {
    settings.INSTALL: "INSTALLER",
    settings.UNINSTALL: "UNINSTALLER",
    settings.START: "STARTER",
    settings.STOP: "STOPPER",
}

# For actions in this list we will reverse the component order
_REVERSE_ACTIONS = [settings.UNINSTALL, settings.STOP]

# These will not automatically stop when uninstalled since it seems to break there password reset.
_NO_AUTO_STOP = [settings.DB, settings.RABBIT]


def _clean_action(action):
    if action is None:
        return None
    action = action.strip().lower()
    if not (action in settings.ACTIONS):
        return None
    return action


def _get_pkg_manager(distro, keep_packages):
    cls = _PKGR_MAP.get(distro)
    return cls(distro, keep_packages)


def _check_roots(action, rootdir, components):
    #TODO the check is really pretty basic so should not be depended on...
    to_skip = list()
    if action == settings.INSTALL:
        if sh.isdir(rootdir):
            to_skip = list()
            for c in components:
                check_pth = sh.joinpths(rootdir, c)
                if sh.isdir(check_pth) and len(sh.listdir(check_pth)) != 0:
                    LOG.warn("Component directory [%s] already exists and its not empty (skipping installing that component)!" % check_pth)
                    LOG.warn("If this is undesired please remove it or uninstall %s!" % (c))
                    to_skip.append(c)
    return to_skip


def _pre_run(action_name, **kargs):
    if action_name == settings.INSTALL:
        root_dir = kargs.get("root_dir")
        if root_dir:
            sh.mkdir(root_dir)


def _post_run(action_name, **kargs):
    secs_taken = kargs.get("time_taken")
    if secs_taken not is None:
        print("It took %s seconds to complete action %s." % (action_name, secs_taken))
    if action_name == settings.UNINSTALL:
        root_dir = kargs.get("root_dir")
        if root_dir:
            sh.rmdir(root_dir)
    cfg = kargs.get("config")
    actives = kargs.get("actives")<commit_msg>Fixed none.<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 cfg
from devstack import date
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 utils

from devstack.packaging import apt
from devstack.packaging import yum

from devstack.components import keystone

from devstack.progs import common

LOG = logging.getLogger("devstack.progs.actions")

#this map controls which distro has
#which package management class
_PKGR_MAP = {
    settings.UBUNTU11: apt.AptPackager,
    settings.RHEL6: yum.YumPackager,
}

# This is used to map an action to a useful string for
# the welcome display
_WELCOME_MAP = {
    settings.INSTALL: "INSTALLER",
    settings.UNINSTALL: "UNINSTALLER",
    settings.START: "STARTER",
    settings.STOP: "STOPPER",
}

# For actions in this list we will reverse the component order
_REVERSE_ACTIONS = [settings.UNINSTALL, settings.STOP]

# These will not automatically stop when uninstalled since it seems to break there password reset.
_NO_AUTO_STOP = [settings.DB, settings.RABBIT]


def _clean_action(action):
    if action is None:
        return None
    action = action.strip().lower()
    if not (action in settings.ACTIONS):
        return None
    return action


def _get_pkg_manager(distro, keep_packages):
    cls = _PKGR_MAP.get(distro)
    return cls(distro, keep_packages)


def _check_roots(action, rootdir, components):
    #TODO the check is really pretty basic so should not be depended on...
    to_skip = list()
    if action == settings.INSTALL:
        if sh.isdir(rootdir):
            to_skip = list()
            for c in components:
                check_pth = sh.joinpths(rootdir, c)
                if sh.isdir(check_pth) and len(sh.listdir(check_pth)) != 0:
                    LOG.warn("Component directory [%s] already exists and its not empty (skipping installing that component)!" % check_pth)
                    LOG.warn("If this is undesired please remove it or uninstall %s!" % (c))
                    to_skip.append(c)
    return to_skip


def _pre_run(action_name, **kargs):
    if action_name == settings.INSTALL:
        root_dir = kargs.get("root_dir")
        if root_dir:
            sh.mkdir(root_dir)


def _post_run(action_name, **kargs):
    secs_taken = kargs.get("time_taken")
    if secs_taken != None:
        print("It took %s seconds to complete action %s." % (action_name, secs_taken))
    if action_name == settings.UNINSTALL:
        root_dir = kargs.get("root_dir")
        if root_dir:
            sh.rmdir(root_dir)
    cfg = kargs.get("config")
    actives = kargs.get("actives")
{'fraction_non_alphanumeric': 0.08305994631673129, 'fraction_numerical': 0.0044736057262153295, 'mean_word_length': 3.176214196762142, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '5868022', 'n_tokens_mistral': 2045, 'n_tokens_neox': 1978, 'n_words': 702}