File: info.py

package info (click to toggle)
netplan.io 1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 4,268 kB
  • sloc: python: 34,640; ansic: 14,096; xml: 4,989; javascript: 2,165; sh: 513; makefile: 118
file content (68 lines) | stat: -rw-r--r-- 2,462 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/python3
#
# Copyright (C) 2019 Canonical, Ltd.
# Author: Mathieu Trudel-Lapierre <mathieu.trudel-lapierre@canonical.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

'''netplan info command line'''

from .. import utils
from ... import _features


class NetplanInfo(utils.NetplanCommand):

    def __init__(self):
        super().__init__(command_id='info',
                         description='Show available features',
                         leaf=True)

    def run(self):  # pragma: nocover (covered in autopkgtest)
        format_group = self.parser.add_mutually_exclusive_group(required=False)
        format_group.add_argument('--json', dest='version_format', action='store_const',
                                  const='json',
                                  help='Output version and features in JSON format')
        format_group.add_argument('--yaml', dest='version_format', action='store_const',
                                  const='yaml',
                                  help='Output version and features in YAML format')

        self.func = self.command_info
        self.parse_args()
        self.run_command()

    def command_info(self):

        netplan_version = {
            'netplan.io': {
                'website': 'https://netplan.io/',
            }
        }

        flags = _features.NETPLAN_FEATURE_FLAGS
        netplan_version['netplan.io'].update({'features': flags})

        # Default to output in YAML format.
        if self.version_format is None:
            self.version_format = 'yaml'

        if self.version_format == 'json':
            import json
            print(json.dumps(netplan_version, indent=2))

        elif self.version_format == 'yaml':
            print('''netplan.io:
  website: "{}"
  features:'''.format(netplan_version['netplan.io']['website']))
            for feature in _features.NETPLAN_FEATURE_FLAGS:
                print('  - ' + feature)