<commit_before># -*- encoding: utf-8 -*-

"""
Provides a class and script. See bin/roger.py for a reference of how the script
is called.

Promote moves containers between dev, stage, prod environments


:Classes:

RogerPromote: Provides application promotion between environments for the
supported Mesos frameworks.

:Exceptions:

RogerPromoteError: Generic exception for errors in RogerPromote
"""

# ~
# stdlib
import argparse
import tempfile
import os
import os.path
import shutil
import sys
import subprocess

# ~
# core
from cli.settings import Settings
from cli.appconfig import AppConfig
from cli.frameworkUtils import FrameworkUtils
from cli.marathon import Marathon
from cli.chronos import Chronos


def describe():
    return 'Enables application promotion between environments'


class RogerPromoteError(Exception):
    pass


class RogerPromote(object):
    """
    Enable application promotion between environments

    :Params:
    :app_config [cli.appconfig.AppConfig]: Default: cli.appconfig.AppConfig
    :settings [cli.settings.Settings]: Default: cli.settings.Settings
    :framework_utils [cli.framework_utils.FrameworkUtils]:
        Default: cli.framework_utils.FrameworkUtils
    :framework [cli.framework.Framework]: Subclass of Framework
        Default: cli.marathon.Marathon
    """

    def __init__(
        self,
        app_config=AppConfig(),
        settings=Settings(),
        framework_utils=FrameworkUtils(),
        framework=Marathon()
    ):
        self._app_config = app_config
        self._settings = settings
        self._framework_utils = framework_utils
        self._framework = framework
        self._config_dir = None
        self._roger_env = None
        self._temp_dir = None

    @classmethod
    def promote(cls, instance=None):
        """
        :Params:
        :instance [cli.roger_promote.RogerPromote]: Avalailable for test

        :Raises:
        :cli.roger_utils.RogerPromoteError:

        :Return [bool]: True if successful, False if otherwise
        """
        # Get instance
        if instance:  # if the instance is not None,
            rp = instance  # re will equal that instance
        else:
            rp = cls()  # if instance is none then rp with be the class

        # Get Namespace obj
        args = rp.arg_parse().parse_args()

        # Set framework based on app config
        rp._set_framework(args.config, args.app_name)

        # Get deployed version in source environment (should be the image name)
        # image = rp._image_name(args.from_env, args.app_name)

        # Get repo name
        repo = rp._config_resolver('repo', args.app_name, args.config)
        if not repo:
            raise RogerPromoteError('Repo not found')

        # Clone the repo
        rp._clone_repo(repo)

        # Locate roger_push.py
        roger_push = rp._roger_push_script()

        app_data = app_config(self.config_dir, args.config, args.app_name)
        image_refs = app_data['containers']
        failed_images = []
        for image_ref in image_refs:
            template_path = self._get_template_path(
                image_ref,
                self.config_dir,
                args,
                args.app_name
            )

            image_name = rp._image_name(
                args.from_env,
                args.config,
                template_path
            )

            # Execute the script
            cmd = [
                roger_push,
                '--env', args.to_env,
                args.app_name, rp._temp_dir, image_name, args.config<commit_msg> needed refrence to instance<commit_after># -*- encoding: utf-8 -*-

"""
Provides a class and script. See bin/roger.py for a reference of how the script
is called.

Promote moves containers between dev, stage, prod environments


:Classes:

RogerPromote: Provides application promotion between environments for the
supported Mesos frameworks.

:Exceptions:

RogerPromoteError: Generic exception for errors in RogerPromote
"""

# ~
# stdlib
import argparse
import tempfile
import os
import os.path
import shutil
import sys
import subprocess

# ~
# core
from cli.settings import Settings
from cli.appconfig import AppConfig
from cli.frameworkUtils import FrameworkUtils
from cli.marathon import Marathon
from cli.chronos import Chronos


def describe():
    return 'Enables application promotion between environments'


class RogerPromoteError(Exception):
    pass


class RogerPromote(object):
    """
    Enable application promotion between environments

    :Params:
    :app_config [cli.appconfig.AppConfig]: Default: cli.appconfig.AppConfig
    :settings [cli.settings.Settings]: Default: cli.settings.Settings
    :framework_utils [cli.framework_utils.FrameworkUtils]:
        Default: cli.framework_utils.FrameworkUtils
    :framework [cli.framework.Framework]: Subclass of Framework
        Default: cli.marathon.Marathon
    """

    def __init__(
        self,
        app_config=AppConfig(),
        settings=Settings(),
        framework_utils=FrameworkUtils(),
        framework=Marathon()
    ):
        self._app_config = app_config
        self._settings = settings
        self._framework_utils = framework_utils
        self._framework = framework
        self._config_dir = None
        self._roger_env = None
        self._temp_dir = None

    @classmethod
    def promote(cls, instance=None):
        """
        :Params:
        :instance [cli.roger_promote.RogerPromote]: Avalailable for test

        :Raises:
        :cli.roger_utils.RogerPromoteError:

        :Return [bool]: True if successful, False if otherwise
        """
        # Get instance
        if instance:  # if the instance is not None,
            rp = instance  # re will equal that instance
        else:
            rp = cls()  # if instance is none then rp with be the class

        # Get Namespace obj
        args = rp.arg_parse().parse_args()

        # Set framework based on app config
        rp._set_framework(args.config, args.app_name)

        # Get deployed version in source environment (should be the image name)
        # image = rp._image_name(args.from_env, args.app_name)

        # Get repo name
        repo = rp._config_resolver('repo', args.app_name, args.config)
        if not repo:
            raise RogerPromoteError('Repo not found')

        # Clone the repo
        rp._clone_repo(repo)

        # Locate roger_push.py
        roger_push = rp._roger_push_script()

        app_data = rp.app_config(self.config_dir, args.config, args.app_name)
        image_refs = app_data['containers']
        failed_images = []
        for image_ref in image_refs:
            template_path = self._get_template_path(
                image_ref,
                self.config_dir,
                args,
                args.app_name
            )

            image_name = rp._image_name(
                args.from_env,
                args.config,
                template_path
            )

            # Execute the script
            cmd = [
                roger_push,
                '--env', args.to_env,
                args.app_name, rp._temp_dir, image_name, args.config
{'fraction_non_alphanumeric': 0.07721306897514661, 'fraction_numerical': 0.00027925160569673273, 'mean_word_length': 2.31007393715342, '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': '1029113', 'n_tokens_mistral': 2032, 'n_tokens_neox': 1943, 'n_words': 551}