コード例 #1
0
    def run(self):
        """Runs the Grab n Go manager.

    Returns:
      An integer representing the exit code. Zero is success and any other
          number is a failure.
    """
        exit_code = 0
        try:
            while True:
                utils.clear_screen()
                utils.write(
                    'Which of the following actions would you like to take?\n')
                for opt, desc in six.iteritems(_OPTIONS):
                    utils.write('Action: {!r}\nDescription: {!r}'.format(
                        opt, desc))
                action = utils.prompt_enum(
                    '', accepted_values=_OPTIONS.keys(),
                    case_sensitive=False).strip().lower()
                if action == _QUIT:
                    break
                elif action == _CHANGE_PROJECT:
                    self = self._change_project()
                elif action == _CONFIGURE:
                    self._configure()
        finally:
            utils.write(
                'Done managing Grab n Go for Cloud Project {!r}.'.format(
                    self._config.project))
        return exit_code
コード例 #2
0
def main(argv):
    del argv  # Unused.
    utils.clear_screen()
    utils.write('Welcome to the Grab n Go management script!\n')

    try:
        manager = _Manager.new(FLAGS.config_file_path, FLAGS.project)
        exit_code = manager.run()
    except KeyboardInterrupt as err:
        logging.error('Manager received CTRL-C, exiting: %s', err)
        exit_code = 1

    sys.exit(exit_code)
コード例 #3
0
def main(argv):
    del argv  # Unused.
    utils.clear_screen()
    utils.write('Welcome to the Grab n Go management script!\n')

    try:
        _Manager.new(
            FLAGS.config_file_path,
            FLAGS.prefer_gcs,
            project_key=FLAGS.project,
            version=FLAGS.app_version,
        ).run()
    except KeyboardInterrupt as err:
        logging.error('Manager received CTRL-C, exiting: %s', err)
        exit_code = 1
    else:
        exit_code = 0

    sys.exit(exit_code)
コード例 #4
0
    def _configure(self):
        """Prompts the user for project wide constants.

    Returns:
      An updated instance of _Manager.
    """
        opts = sorted(self._constants.keys())
        opts.append(_QUIT)
        try:
            while True:
                utils.clear_screen()
                utils.write(
                    'Here are the project wide constants for {!r}:\n'.format(
                        self._config.project))
                configured, unconfigured = [], []
                for name in sorted(self._constants.keys()):
                    if self._constants[name].valid:
                        configured.append(name)
                    else:
                        unconfigured.append(name)
                    utils.write(
                        'Constant: {!r}\nDescription: {}\nCurrent Value: {}\n'.
                        format(name, self._constants[name].message,
                               self._constants[name].value))
                choice = utils.prompt_enum(
                    'Which constant would you like to configure?\n'
                    'Currently configured constants include: {}\n'
                    'Currently unconfigured constants include: {}\n'.format(
                        ', '.join(configured) or 'None',
                        ', '.join(unconfigured) or 'None'),
                    accepted_values=opts,
                    case_sensitive=False).strip().lower()
                if choice == _QUIT:
                    break
                else:
                    self._constants[choice].prompt()
                    self._save_constants()
        finally:
            utils.write(
                'Exiting configuration menu, to return enter {!r} in the main menu.\n'
                'Returning to the main menu.'.format(_CONFIGURE))
        return self
コード例 #5
0
 def run(self):
     """Runs the Grab n Go manager."""
     try:
         while True:
             utils.clear_screen()
             utils.write(
                 'Which of the following actions would you like to take?\n')
             for opt in self._options.values():
                 utils.write('Action: {!r}\nDescription: {}\n'.format(
                     opt.name, opt.description))
             action = utils.prompt_enum(
                 '',
                 accepted_values=list(self._options.keys()),
                 case_sensitive=False).strip().lower()
             callback = self._options[action].callback
             if callback is None:
                 break
             self = callback()
     finally:
         utils.write(
             'Done managing Grab n Go for Cloud Project {!r}.'.format(
                 self._config.project))
コード例 #6
0
 def test_clear_screen(self, test_system):
     with mock.patch.object(platform, 'system', return_value=test_system):
         with mock.patch.object(utils, 'write') as mock_write:
             utils.clear_screen()
             mock_write.assert_called_once_with('\033[H\033[J')