pkgmgr-kunrunic 0.1.1.dev0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pkgmgr-kunrunic might be problematic. Click here for more details.
- pkgmgr/__init__.py +17 -0
- pkgmgr/__main__.py +5 -0
- pkgmgr/cli.py +278 -0
- pkgmgr/collectors/__init__.py +5 -0
- pkgmgr/collectors/base.py +15 -0
- pkgmgr/collectors/checksums.py +35 -0
- pkgmgr/config.py +380 -0
- pkgmgr/gitcollect.py +10 -0
- pkgmgr/points.py +98 -0
- pkgmgr/release.py +579 -0
- pkgmgr/shell_integration.py +83 -0
- pkgmgr/snapshot.py +306 -0
- pkgmgr/templates/pkg.yaml.sample +16 -0
- pkgmgr/templates/pkgmgr.yaml.sample +51 -0
- pkgmgr/watch.py +79 -0
- pkgmgr_kunrunic-0.1.1.dev0.dist-info/METADATA +147 -0
- pkgmgr_kunrunic-0.1.1.dev0.dist-info/RECORD +21 -0
- pkgmgr_kunrunic-0.1.1.dev0.dist-info/WHEEL +5 -0
- pkgmgr_kunrunic-0.1.1.dev0.dist-info/entry_points.txt +2 -0
- pkgmgr_kunrunic-0.1.1.dev0.dist-info/licenses/LICENSE +21 -0
- pkgmgr_kunrunic-0.1.1.dev0.dist-info/top_level.txt +1 -0
pkgmgr/__init__.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from __future__ import print_function
|
|
2
|
+
"""
|
|
3
|
+
Modernized pkg manager scaffold.
|
|
4
|
+
This package will grow to replace the legacy single-file script.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"cli",
|
|
9
|
+
"config",
|
|
10
|
+
"snapshot",
|
|
11
|
+
"release",
|
|
12
|
+
"gitcollect",
|
|
13
|
+
"watch",
|
|
14
|
+
"points",
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
__version__ = "0.1.1.dev0"
|
pkgmgr/__main__.py
ADDED
pkgmgr/cli.py
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
from __future__ import print_function
|
|
2
|
+
"""CLI entrypoint scaffold for the pkg manager."""
|
|
3
|
+
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
try:
|
|
7
|
+
import argparse
|
|
8
|
+
except Exception:
|
|
9
|
+
argparse = None
|
|
10
|
+
|
|
11
|
+
from . import config, snapshot, release, gitcollect, watch, __version__
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _add_make_config(sub):
|
|
15
|
+
p = sub.add_parser("make-config", help="create a pkgmgr.yaml template to edit")
|
|
16
|
+
p.add_argument(
|
|
17
|
+
"-o",
|
|
18
|
+
"--output",
|
|
19
|
+
default=config.DEFAULT_MAIN_CONFIG,
|
|
20
|
+
help="path to write the main config (default: %(default)s)",
|
|
21
|
+
)
|
|
22
|
+
p.set_defaults(func=_handle_make_config)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _add_install(sub):
|
|
26
|
+
p = sub.add_parser("install", help="prepare environment and collect initial baseline")
|
|
27
|
+
p.add_argument(
|
|
28
|
+
"--config",
|
|
29
|
+
default=None,
|
|
30
|
+
help="config file path (default: auto-discover under %s)" % config.BASE_DIR,
|
|
31
|
+
)
|
|
32
|
+
p.set_defaults(func=_handle_install)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _add_snapshot(sub):
|
|
36
|
+
p = sub.add_parser(
|
|
37
|
+
"snapshot", help="take a snapshot (baseline update after install)"
|
|
38
|
+
)
|
|
39
|
+
p.add_argument(
|
|
40
|
+
"--config",
|
|
41
|
+
default=None,
|
|
42
|
+
help="config file path (default: auto-discover under %s)" % config.BASE_DIR,
|
|
43
|
+
)
|
|
44
|
+
p.set_defaults(func=_handle_snapshot)
|
|
45
|
+
|
|
46
|
+
def _add_actions(sub):
|
|
47
|
+
p = sub.add_parser("actions", help="run one or more configured actions")
|
|
48
|
+
p.add_argument("names", nargs="+", help="action names to run")
|
|
49
|
+
p.add_argument(
|
|
50
|
+
"--config",
|
|
51
|
+
default=None,
|
|
52
|
+
help="config file path (default: auto-discover under %s)" % config.BASE_DIR,
|
|
53
|
+
)
|
|
54
|
+
p.set_defaults(func=_handle_actions)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _add_create_pkg(sub):
|
|
58
|
+
p = sub.add_parser("create-pkg", help="create a pkg folder and template")
|
|
59
|
+
p.add_argument("pkg_id", help="package identifier (e.g. 20240601)")
|
|
60
|
+
p.add_argument(
|
|
61
|
+
"--config",
|
|
62
|
+
default=None,
|
|
63
|
+
help="config file path (default: auto-discover under %s)" % config.BASE_DIR,
|
|
64
|
+
)
|
|
65
|
+
p.set_defaults(func=_handle_create_pkg)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _add_update_pkg(sub):
|
|
69
|
+
p = sub.add_parser("update-pkg", help="collect git keyword hits and checksums for a pkg")
|
|
70
|
+
p.add_argument("pkg_id", help="package identifier to update")
|
|
71
|
+
p.add_argument(
|
|
72
|
+
"--config",
|
|
73
|
+
default=None,
|
|
74
|
+
help="config file path (default: auto-discover under %s)" % config.BASE_DIR,
|
|
75
|
+
)
|
|
76
|
+
p.set_defaults(func=_handle_update_pkg)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def _add_close_pkg(sub):
|
|
80
|
+
p = sub.add_parser("close-pkg", help="mark a pkg as closed and stop watching")
|
|
81
|
+
p.add_argument("pkg_id", help="package identifier to close")
|
|
82
|
+
p.add_argument(
|
|
83
|
+
"--config",
|
|
84
|
+
default=None,
|
|
85
|
+
help="config file path (default: auto-discover under %s)" % config.BASE_DIR,
|
|
86
|
+
)
|
|
87
|
+
p.set_defaults(func=_handle_close_pkg)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _add_watch(sub):
|
|
91
|
+
p = sub.add_parser("watch", help="start watcher/daemon to monitor pkgs")
|
|
92
|
+
p.add_argument(
|
|
93
|
+
"--config",
|
|
94
|
+
default=None,
|
|
95
|
+
help="config file path (default: auto-discover under %s)" % config.BASE_DIR,
|
|
96
|
+
)
|
|
97
|
+
p.add_argument(
|
|
98
|
+
"--once",
|
|
99
|
+
action="store_true",
|
|
100
|
+
help="run a single poll iteration then exit (useful for cron)",
|
|
101
|
+
)
|
|
102
|
+
p.add_argument("--pkg", help="package id to scope watch/points (optional)")
|
|
103
|
+
p.add_argument(
|
|
104
|
+
"--auto-point",
|
|
105
|
+
action="store_true",
|
|
106
|
+
help="create a checkpoint automatically after changes are handled",
|
|
107
|
+
)
|
|
108
|
+
p.add_argument(
|
|
109
|
+
"--point-label",
|
|
110
|
+
help="label to use when auto-creating a checkpoint (default: watch-auto)",
|
|
111
|
+
)
|
|
112
|
+
p.set_defaults(func=_handle_watch)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _add_collect(sub):
|
|
116
|
+
p = sub.add_parser("collect", help="run collectors for a pkg")
|
|
117
|
+
p.add_argument("--pkg", required=True, help="package identifier")
|
|
118
|
+
p.add_argument(
|
|
119
|
+
"--collector",
|
|
120
|
+
action="append",
|
|
121
|
+
dest="collectors",
|
|
122
|
+
help="specific collectors to run (default: all enabled)",
|
|
123
|
+
)
|
|
124
|
+
p.add_argument(
|
|
125
|
+
"--config",
|
|
126
|
+
default=None,
|
|
127
|
+
help="config file path (default: auto-discover under %s)" % config.BASE_DIR,
|
|
128
|
+
)
|
|
129
|
+
p.set_defaults(func=_handle_collect)
|
|
130
|
+
|
|
131
|
+
def _add_point(sub):
|
|
132
|
+
p = sub.add_parser("point", help="create or list checkpoints for a pkg")
|
|
133
|
+
p.add_argument("--pkg", required=True, help="package identifier")
|
|
134
|
+
p.add_argument("--label", help="optional label for this point")
|
|
135
|
+
p.add_argument(
|
|
136
|
+
"--actions-run",
|
|
137
|
+
action="append",
|
|
138
|
+
dest="actions_run",
|
|
139
|
+
help="actions that were executed before creating this point",
|
|
140
|
+
)
|
|
141
|
+
p.add_argument(
|
|
142
|
+
"--list",
|
|
143
|
+
action="store_true",
|
|
144
|
+
help="list existing points instead of creating a new one",
|
|
145
|
+
)
|
|
146
|
+
p.add_argument(
|
|
147
|
+
"--config",
|
|
148
|
+
default=None,
|
|
149
|
+
help="config file path (default: auto-discover under %s)" % config.BASE_DIR,
|
|
150
|
+
)
|
|
151
|
+
p.set_defaults(func=_handle_point)
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def _add_export(sub):
|
|
155
|
+
p = sub.add_parser("export", help="export pkg data (excel/word/etc)")
|
|
156
|
+
p.add_argument("--pkg", required=True, help="package identifier")
|
|
157
|
+
p.add_argument("--format", choices=["excel", "word", "json"], required=True)
|
|
158
|
+
p.add_argument(
|
|
159
|
+
"--config",
|
|
160
|
+
default=None,
|
|
161
|
+
help="config file path (default: auto-discover under %s)" % config.BASE_DIR,
|
|
162
|
+
)
|
|
163
|
+
p.set_defaults(func=_handle_export)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def build_parser():
|
|
167
|
+
if argparse is None:
|
|
168
|
+
raise RuntimeError("argparse not available; install argparse")
|
|
169
|
+
parser = argparse.ArgumentParser(prog="pkgmgr", description="Pkg manager CLI scaffold")
|
|
170
|
+
# keep %(prog)s for argparse's mapping and append package version
|
|
171
|
+
parser.add_argument("-V", "--version", action="version", version="%(prog)s " + __version__)
|
|
172
|
+
sub = parser.add_subparsers(dest="command")
|
|
173
|
+
|
|
174
|
+
_add_make_config(sub)
|
|
175
|
+
_add_install(sub)
|
|
176
|
+
_add_snapshot(sub)
|
|
177
|
+
_add_create_pkg(sub)
|
|
178
|
+
_add_update_pkg(sub)
|
|
179
|
+
_add_close_pkg(sub)
|
|
180
|
+
_add_watch(sub)
|
|
181
|
+
_add_collect(sub)
|
|
182
|
+
_add_export(sub)
|
|
183
|
+
_add_actions(sub)
|
|
184
|
+
_add_point(sub)
|
|
185
|
+
return parser
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def _handle_make_config(args):
|
|
189
|
+
config.write_template(args.output)
|
|
190
|
+
return 0
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def _handle_install(args):
|
|
194
|
+
cfg = config.load_main(args.config)
|
|
195
|
+
print("[install] step 1/2: shell integration")
|
|
196
|
+
release.ensure_environment()
|
|
197
|
+
print("[install] step 2/2: baseline snapshot")
|
|
198
|
+
progress = snapshot.ProgressReporter("scan")
|
|
199
|
+
snapshot.create_baseline(cfg, prompt_overwrite=True, progress=progress)
|
|
200
|
+
return 0
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def _handle_snapshot(args):
|
|
204
|
+
cfg = config.load_main(args.config)
|
|
205
|
+
snapshot.create_snapshot(cfg)
|
|
206
|
+
return 0
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def _handle_create_pkg(args):
|
|
210
|
+
cfg = config.load_main(args.config)
|
|
211
|
+
release.create_pkg(cfg, args.pkg_id)
|
|
212
|
+
return 0
|
|
213
|
+
|
|
214
|
+
def _handle_update_pkg(args):
|
|
215
|
+
cfg = config.load_main(args.config)
|
|
216
|
+
release.update_pkg(cfg, args.pkg_id)
|
|
217
|
+
return 0
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def _handle_close_pkg(args):
|
|
221
|
+
cfg = config.load_main(args.config)
|
|
222
|
+
release.close_pkg(cfg, args.pkg_id)
|
|
223
|
+
return 0
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def _handle_watch(args):
|
|
227
|
+
cfg = config.load_main(args.config)
|
|
228
|
+
watch.run(
|
|
229
|
+
cfg,
|
|
230
|
+
run_once=args.once,
|
|
231
|
+
pkg_id=args.pkg,
|
|
232
|
+
auto_point=args.auto_point,
|
|
233
|
+
point_label=args.point_label,
|
|
234
|
+
)
|
|
235
|
+
return 0
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def _handle_collect(args):
|
|
239
|
+
cfg = config.load_main(args.config)
|
|
240
|
+
release.collect_for_pkg(cfg, args.pkg, args.collectors)
|
|
241
|
+
return 0
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def _handle_export(args):
|
|
245
|
+
cfg = config.load_main(args.config)
|
|
246
|
+
release.export_pkg(cfg, args.pkg, args.format)
|
|
247
|
+
return 0
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
def _handle_actions(args):
|
|
251
|
+
cfg = config.load_main(args.config)
|
|
252
|
+
release.run_actions(cfg, args.names)
|
|
253
|
+
return 0
|
|
254
|
+
|
|
255
|
+
def _handle_point(args):
|
|
256
|
+
cfg = config.load_main(args.config)
|
|
257
|
+
if args.list:
|
|
258
|
+
release.list_points(cfg, args.pkg)
|
|
259
|
+
return 0
|
|
260
|
+
release.create_point(cfg, args.pkg, label=args.label, actions_run=args.actions_run)
|
|
261
|
+
return 0
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def main(argv=None):
|
|
265
|
+
argv = argv if argv is not None else sys.argv[1:]
|
|
266
|
+
parser = build_parser()
|
|
267
|
+
if not argv:
|
|
268
|
+
parser.print_help()
|
|
269
|
+
return 0
|
|
270
|
+
args = parser.parse_args(argv)
|
|
271
|
+
if not hasattr(args, "func"):
|
|
272
|
+
parser.print_help()
|
|
273
|
+
return 0
|
|
274
|
+
return args.func(args)
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
if __name__ == "__main__":
|
|
278
|
+
sys.exit(main())
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from __future__ import print_function
|
|
2
|
+
"""Collector interface definitions."""
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class CollectorResult(dict):
|
|
6
|
+
"""Lightweight result mapping for collector outputs."""
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Collector:
|
|
10
|
+
"""Base collector contract."""
|
|
11
|
+
|
|
12
|
+
name = "base"
|
|
13
|
+
|
|
14
|
+
def run(self, pkg_ctx, cfg):
|
|
15
|
+
raise NotImplementedError
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from __future__ import print_function
|
|
2
|
+
"""Checksum collector stub."""
|
|
3
|
+
|
|
4
|
+
import hashlib
|
|
5
|
+
import os
|
|
6
|
+
|
|
7
|
+
from .base import Collector, CollectorResult
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ChecksumsCollector(Collector):
|
|
11
|
+
name = "checksums"
|
|
12
|
+
|
|
13
|
+
def run(self, pkg_ctx, cfg):
|
|
14
|
+
"""
|
|
15
|
+
Placeholder: walk pkg_ctx['paths'] and compute sha256.
|
|
16
|
+
pkg_ctx is expected to contain 'paths' list of absolute file paths.
|
|
17
|
+
"""
|
|
18
|
+
res = CollectorResult()
|
|
19
|
+
paths = pkg_ctx.get("paths", [])
|
|
20
|
+
for path in paths:
|
|
21
|
+
if not os.path.exists(path):
|
|
22
|
+
continue
|
|
23
|
+
res[path] = sha256_of_file(path)
|
|
24
|
+
return res
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def sha256_of_file(path, chunk=1024 * 1024):
|
|
28
|
+
h = hashlib.sha256()
|
|
29
|
+
with open(path, "rb") as f:
|
|
30
|
+
while True:
|
|
31
|
+
b = f.read(chunk)
|
|
32
|
+
if not b:
|
|
33
|
+
break
|
|
34
|
+
h.update(b)
|
|
35
|
+
return h.hexdigest()
|