File: __main__.py

package info (click to toggle)
python-popcon 3.0.3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 112 kB
  • sloc: python: 225; makefile: 35
file content (88 lines) | stat: -rw-r--r-- 2,370 bytes parent folder | download
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import argparse

from popcon import packages, packages_raw


def main(args=None):
    """Main entrypoint for the CLI.

    Parameters
    ----------
    args list[str]
        optional parameters, used for testing

    """
    args = parse_args(args)
    pkg = args.package
    # respective withs for package and numbers
    pwidth = 20
    nwidth = 10
    if not args.verbose:
        results = packages(pkg)
        if not results:
            return
        # calculate pwidth based on maximum length of package name, but at
        # least 7 characters to accommodate for the "PACKAGE" string in the
        # header
        pwidth = max(7, max(len(i) for i in results.keys()))
        print(f'{"PACKAGE":>{pwidth}} {"SUM":<{nwidth}}')
        for package, number in results.items():
            print(f'{package:>{pwidth}} {number:<{nwidth}}')
    else:
        results = packages_raw(pkg)
        if not results:
            return
        # calculate pwidth based on maximum length of package name, but at
        # least 7 characters to accommodate for the "PACKAGE" string in the
        # header
        pwidth = max(7, max(len(i) for i in results.keys()))
        print(
            f'{"PACKAGE":>{pwidth}} {"SUM":<{nwidth}} '
            f'{"VOTE":<{nwidth}} {"OLD":<{nwidth}} '
            f'{"RECENT":<{nwidth}} {"NO FILES":<{nwidth}}'
        )
        for package, values in results.items():
            vote = values.vote
            old = values.old
            recent = values.recent
            no_files = values.no_files
            sum_ = sum([vote, old, recent, no_files])
            print(
                f'{package:>{pwidth}} {sum_:<{nwidth}} '
                f'{vote:<{nwidth}} {old:<{nwidth}} '
                f'{recent:<{nwidth}} {no_files:<{nwidth}}'
            )


def parse_args(args=None):
    """Parse command line arguments.

    Parameters
    ----------
    args list[str]
        optional parameters, used for testing

    Returns
    -------
    argparse.Namespace

    """
    parser = argparse.ArgumentParser()

    parser.add_argument(
        'package',
        nargs="+",
        help="the package name(s)",
    )

    parser.add_argument(
        '-v', '--verbose',
        help="more verbose package output",
        action="store_true",
    )

    return parser.parse_args(args)


if __name__ == '__main__':
    main()