-
Notifications
You must be signed in to change notification settings - Fork 24
/
main.py
executable file
·88 lines (73 loc) · 2.73 KB
/
main.py
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
#!/usr/bin/env python3
# SPDX-FileCopyrightText: 2023 Technology Innovation Institute (TII)
# SPDX-License-Identifier: Apache-2.0
""" Python script for summarizing nixpkgs meta-attributes """
import argparse
import pathlib
from nixmeta.scanner import NixMetaScanner
from common.utils import set_log_verbosity, exit_unless_command_exists
################################################################################
def _getargs():
"""Parse command line arguments"""
desc = (
"Summarize nixpkgs meta-attributes from the given nixpkgs version "
"to a csv output file."
)
epil = "Example: nixmeta --flakeref=github:NixOS/nixpkgs?ref=master"
parser = argparse.ArgumentParser(description=desc, epilog=epil)
helps = (
"Flake reference specifying the location of the flake "
"from which the pinned nixpkgs target version is read. "
"The default value is the "
"current nixpkgs version in its 'nixos-unstable' branch. "
"For more details, see: "
"https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake"
"#flake-references and "
"https://nixos.wiki/wiki/Nix_channels "
"(default: --flakeref=github:NixOS/nixpkgs?ref=nixos-unstable)."
)
parser.add_argument(
"-f",
"--flakeref",
help=helps,
type=str,
default="github:NixOS/nixpkgs?ref=nixos-unstable",
)
helps = "Path to output file (default: --out=nixmeta.csv)."
parser.add_argument(
"-o",
"--out",
help=helps,
type=pathlib.Path,
default="nixmeta.csv",
)
helps = (
"Append to output file - removing duplicate entries - instead of "
"completely overwriting possible earlier output file."
)
parser.add_argument(
"-a",
"--append",
help=helps,
action="store_true",
)
helps = "Set the debug verbosity level between 0-3 (default: --verbose=1)."
parser.add_argument("-v", "--verbose", help=helps, type=int, default=1)
return parser.parse_args()
###############################################################################
def main():
"""main entry point"""
args = _getargs()
set_log_verbosity(args.verbose)
# Fail early if the following commands are not in PATH
exit_unless_command_exists("nix")
exit_unless_command_exists("nix-env")
# Scan metadata from the flakeref pinned nixpkgs
scanner = NixMetaScanner()
scanner.scan(args.flakeref)
# Output to csv file
scanner.to_csv(args.out, args.append)
################################################################################
if __name__ == "__main__":
main()
################################################################################