File: framework.py

package info (click to toggle)
click 0.5.2-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,372 kB
  • sloc: python: 7,135; ansic: 857; makefile: 441; sh: 236; perl: 26; xml: 11
file content (73 lines) | stat: -rw-r--r-- 2,361 bytes parent folder | download | duplicates (2)
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
69
70
71
72
73
# Copyright (C) 2014 Canonical Ltd.
# Author: Michael Vogt <mvo@ubuntu.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 of the License.
#
# 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/>.

"""List available frameworks."""

from __future__ import print_function

from argparse import ArgumentParser

import gi
gi.require_version('Click', '0.4')
from gi.repository import Click


def list(parser, args):
    for framework in Click.Framework.get_frameworks():
        print("%s" % framework.props.name)
    return 0


def info(parser, args):
    framework = Click.Framework.open(args.framework_name)
    for field in sorted(framework.get_fields()):
        print("%s: %s" % (field, framework.get_field(field)))


def get_field(parser, args):
    framework = Click.Framework.open(args.framework_name)
    print(framework.get_field(args.field_name))


def run(argv):
    parser = ArgumentParser("click framework")
    subparsers = parser.add_subparsers()
    list_parser = subparsers.add_parser(
        "list",
        help="list available frameworks")
    list_parser.set_defaults(func=list)
    info_parser = subparsers.add_parser(
        "info",
        help="show info about a specific framework")
    info_parser.add_argument(
        "framework_name",
        help="framework name with the information")
    info_parser.set_defaults(func=info)
    get_field_parser = subparsers.add_parser(
        "get-field",
        help="get a field from a given framework")
    get_field_parser.add_argument(
        "framework_name",
        help="framework name with the information")
    get_field_parser.add_argument(
        "field_name",
        help="the field name (e.g. base-version)")
    get_field_parser.set_defaults(func=get_field)

    args = parser.parse_args(argv)
    if not hasattr(args, "func"):
        parser.print_help()
        return 1
    return args.func(parser, args)