Exemple #1
0
    def convert(self, value, param, ctx):
        """ Try to find correct disk image regarding version. """
        if not self.choices:
            gandi = GandiContextHelper()
            gandi.echo("No configuration found, please use 'gandi setup' "
                       "command")
            sys.exit(1)

        # Exact match
        if value in self.choices:
            return value

        # Try to find 64 bits version
        new_value = '%s 64 bits' % value
        if new_value in self.choices:
            return new_value

        # Try to find without specific bits version
        p = re.compile(' (64|32) bits')
        new_value = p.sub('', value)
        if new_value in self.choices:
            return new_value

        self.fail('invalid choice: %s. (choose from %s)' %
                  (value, ', '.join(self.choices)), param, ctx)
Exemple #2
0
    def convert(self, value, param, ctx):
        """ Try to find correct disk image regarding version. """
        if not self.choices:
            gandi = GandiContextHelper()
            gandi.echo("No configuration found, please use 'gandi setup' "
                       "command")
            sys.exit(1)

        # Exact match
        if value in self.choices:
            return value

        # Try to find 64 bits version
        new_value = '%s 64 bits' % value
        if new_value in self.choices:
            return new_value

        # Try to find without specific bits version
        p = re.compile(' (64|32) bits')
        new_value = p.sub('', value)
        if new_value in self.choices:
            return new_value

        self.fail(
            'invalid choice: %s. (choose from %s)' %
            (value, ', '.join(self.choices)), param, ctx)
Exemple #3
0
    def convert(self, value, param, ctx):
        """ Return converted value. """
        if not self.choices:
            gandi = GandiContextHelper()
            gandi.echo("No configuration found, please use 'gandi setup' " "command")
            sys.exit(1)

        return click.Choice.convert(self, value, param, ctx)
Exemple #4
0
    def convert(self, value, param, ctx):
        """ Return converted value. """
        if not self.choices:
            gandi = GandiContextHelper()
            gandi.echo("No configuration found, please use 'gandi setup' "
                       "command")
            sys.exit(1)

        return click.Choice.convert(self, value, param, ctx)
Exemple #5
0
    def choices(self):
        """ Retrieve choices from API if possible"""
        if not self._choices:
            gandi = GandiContextHelper()
            self._choices = self._get_choices(gandi)
            if not self._choices:
                gandi = GandiContextHelper()
                gandi.echo("No configuration found, please use 'gandi setup' "
                           "command")
                sys.exit(1)

        return self._choices
Exemple #6
0
    def convert(self, value, param, ctx):
        """ Try to find correct kernel regarding version. """
        if not self.choices:
            gandi = GandiContextHelper()
            gandi.echo("No configuration found, please use 'gandi setup' "
                       "command")
            sys.exit(1)

        # Exact match first
        if value in self.choices:
            return value

        # Also try with x86-64 suffix
        new_value = '%s-x86_64' % value
        if new_value in self.choices:
            return new_value

        self.fail('invalid choice: %s. (choose from %s)' %
                  (value, ', '.join(self.choices)), param, ctx)