Esempio n. 1
0
def deploy_cmd(override, **tooldata):
    context = tooldata.get('context')
    conf = tooldata.get('config')
    awsclient = context.get('_awsclient')

    cloudformation = load_template()
    #call_pre_hook(awsclient, cloudformation)

    if get_parameter_diff(awsclient, conf):
        print(colored.red('Parameters have changed. Waiting 10 seconds. \n'))
        print(
            'If parameters are unexpected you might want to exit now: control-c'
        )
        # Choose a spin style.
        spin = Spinner(Default)
        # Spin it now.
        for i in range(100):
            print(u'\r{0}'.format(spin.next()), end='')
            sys.stdout.flush()
            time.sleep(0.1)
        print('\n')

    exit_code = deploy_stack(awsclient,
                             context,
                             conf,
                             cloudformation,
                             override_stack_policy=override)
    return exit_code
Esempio n. 2
0
def countdown(t, conf):
    cprint('Making the model using the following parameters\n{0}'\
            .format(json.dumps(conf, indent=4, sort_keys=True)), 'red')
    spin = Spinner(Default)
    for i in range(t, 0, -1):
        text = colored('Will start training in', 'green')
        print(u'\r {0} {1} {2}'.format(spin.next(), text, i), end=" ")
        sys.stdout.flush()
        time.sleep(0.1)
    print('\n')
Esempio n. 3
0
def countdown(t, conf):
    cprint('Making the model using the following parameters\n{0}'\
            .format(json.dumps(conf, indent=4, sort_keys=True)), 'red')
    spin = Spinner(Default)
    for i in range(t, 0, -1):
        text = colored('Will start training in', 'green')
        print(u'\r {0} {1} {2}'.format(spin.next(), text, i), end=" ")
        sys.stdout.flush()
        time.sleep(0.1)
    print('\n')
Esempio n. 4
0
def print_parameter_diff(awsclient, config):
    """print differences between local config and currently active config
    """
    client_cf = awsclient.get_client('cloudformation')
    try:
        stackname = config['cloudformation']['StackName']
        if stackname:
            response = client_cf.describe_stacks(StackName=stackname)
            if response['Stacks']:
                stack_id = response['Stacks'][0]['StackId']
                stack = response['Stacks'][0]
            else:
                return None
        else:
            print(
                'StackName is not configured, could not create parameter diff')
            return None
    except:
        # probably the stack is not existent
        return None

    changed = 0
    table = []
    table.append(['Parameter', 'Current Value', 'New Value'])

    # Check if there are parameters for the stack
    if 'Parameters' in stack:
        for param in stack['Parameters']:
            try:
                old = param['ParameterValue']
                if ',' in old:
                    old = old.split(',')
                new = config['cloudformation'][param['ParameterKey']]
                if old != new:
                    table.append([param['ParameterKey'], old, new])
                    changed += 1
            except Exception:
                print('Did not find %s in local config file' %
                      param['ParameterKey'])

    if changed > 0:
        print(tabulate(table, tablefmt='fancy_grid'))
        print(colored.red('Parameters have changed. Waiting 10 seconds. \n'))
        print(
            'If parameters are unexpected you might want to exit now: control-c'
        )
        # Choose a spin style.
        spin = Spinner(Default)
        # Spin it now.
        for i in range(100):
            print(u'\r{0}'.format(spin.next()), end='')
            sys.stdout.flush()
            time.sleep(0.1)
        print('\n')
Esempio n. 5
0
 def __init__(self,
              stream=None,
              spin_style=Default,
              spin_interval=0.1,
              format=u'{spinner} {message}',
              level=logging.NOTSET):
     super(SpinnerHandler, self).__init__(level)
     self._stream = stream
     self._message_format = format
     self._spinner = Spinner(spin_style)
     self._spin_interval = spin_interval
     self._current_record_changed = threading.Condition()
     self._thread = threading.Thread(target=self._display)
     self._current_record = None
Esempio n. 6
0
class BotLog(object):
    def __init__(self):
        self.spin = Spinner(Default)

    def log(self, message):
        if (CONFIG['VERBOSE']):
            print(message)
        else:
            print(u"\r{0}".format(self.spin.next()), end="")
            sys.stdout.flush()
Esempio n. 7
0
class LabeledSpinner(object):
    def __init__(self, style=None):
        from pyspin.spin import Default, Spinner
        if style is None:
            style = Default
        self.spinner = Spinner(style)
        self.last_len = 0
    def spin(self, text):
        self.display(u"{} {}".format(self.spinner.next(), text))
    def drop(self, text):
        self.display(u"{}\n".format(text))
    def display(self, text):
        import sys
        print(u'\r{}{}'.format(text, " " * (self.last_len - len(text))), end='')
        sys.stdout.flush()
        self.last_len = len(text)
Esempio n. 8
0
 def __init__(self):
     self.spin = Spinner(Default)
Esempio n. 9
0
class SpinnerHandler(logging.Handler):

    def __init__(self,
                 stream=None,
                 spin_style=Default,
                 spin_interval=0.1,
                 format=u'{spinner} {message}',
                 level=logging.NOTSET):
        super(SpinnerHandler, self).__init__(level)
        self._stream = stream
        self._message_format = format
        self._spinner = Spinner(spin_style)
        self._spin_interval = spin_interval
        self._current_record_changed = threading.Condition()
        self._thread = threading.Thread(target=self._display)
        self._current_record = None

    @staticmethod
    def filter(record):
        return hasattr(record, 'user_waiting')

    def get_stream(self):
        stream = sys.stdout if self._stream is None else self._stream
        if callable(getattr(stream, 'isatty')):
            atty = stream.isatty()
        else:
            atty = False
        try:
            stream.write('')
        except TypeError:
            stream = io.TextIOWrapper(stream)
        return stream, atty

    def emit(self, record):
        if not self.filter(record):
            return
        stream, atty = self.get_stream()
        if not atty:
            stream.write(record.getMessage() + '\n')
            return
        with self._current_record_changed:
            self._current_record = record
            self._current_record_changed.notify()
        if not self._thread.is_alive():
            self._thread.start()

    def _display(self):
        stream, _ = self.get_stream()
        format_message = self._message_format.format
        format_line = u'\r{0:{1}}\r'.format
        previous_line_length = 0
        while True:
            record = self._current_record
            if record is None or not record.user_waiting:
                break
            s = format_message(spinner=self._spinner.next(),
                               record=record,
                               message=record.getMessage())
            stream.write(format_line(s, previous_line_length or 1))
            previous_line_length = len(s)
            stream.flush()
            with self._current_record_changed:
                self._current_record_changed.wait(self._spin_interval)
        s = self._current_record.getMessage()
        stream.write(u'\r{0:{1}}\n'.format(s, previous_line_length or 1))
        stream.flush()
        self._thread = threading.Thread(target=self._display)
Esempio n. 10
0
 def __init__(self, style=None):
     from pyspin.spin import Default, Spinner
     if style is None:
         style = Default
     self.spinner = Spinner(style)
     self.last_len = 0