pkgmgr-kunrunic 0.1.1.dev3__tar.gz → 0.1.1.dev5__tar.gz

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.
Files changed (37) hide show
  1. {pkgmgr_kunrunic-0.1.1.dev3/pkgmgr_kunrunic.egg-info → pkgmgr_kunrunic-0.1.1.dev5}/PKG-INFO +1 -1
  2. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev5}/pkgmgr/__init__.py +1 -1
  3. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev5}/pkgmgr/cli.py +13 -1
  4. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev5}/pkgmgr/config.py +25 -1
  5. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev5}/pkgmgr/release.py +227 -4
  6. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev5/pkgmgr_kunrunic.egg-info}/PKG-INFO +1 -1
  7. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev5}/pkgmgr_kunrunic.egg-info/SOURCES.txt +1 -2
  8. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev5}/pkgmgr_kunrunic.egg-info/top_level.txt +1 -1
  9. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev5}/plugin/export_cksum.py +55 -7
  10. pkgmgr_kunrunic-0.1.1.dev5/plugin/export_pkgstore.py +122 -0
  11. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev5}/plugin/export_source_review.py +15 -6
  12. pkgmgr_kunrunic-0.1.1.dev3/test_data_root/plugin/export_cksum.py +0 -354
  13. pkgmgr_kunrunic-0.1.1.dev3/test_data_root/plugin/export_source_review.py +0 -490
  14. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev5}/LICENSE +0 -0
  15. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev5}/README.md +0 -0
  16. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev5}/pkgmgr/__main__.py +0 -0
  17. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev5}/pkgmgr/collectors/__init__.py +0 -0
  18. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev5}/pkgmgr/collectors/base.py +0 -0
  19. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev5}/pkgmgr/collectors/checksums.py +0 -0
  20. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev5}/pkgmgr/points.py +0 -0
  21. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev5}/pkgmgr/shell_integration.py +0 -0
  22. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev5}/pkgmgr/snapshot.py +0 -0
  23. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev5}/pkgmgr/templates/pkg.yaml.sample +0 -0
  24. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev5}/pkgmgr/templates/pkgmgr.yaml.sample +0 -0
  25. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev5}/pkgmgr/watch.py +0 -0
  26. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev5}/pkgmgr_kunrunic.egg-info/dependency_links.txt +0 -0
  27. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev5}/pkgmgr_kunrunic.egg-info/entry_points.txt +0 -0
  28. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev5}/pkgmgr_kunrunic.egg-info/not-zip-safe +0 -0
  29. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev5}/pkgmgr_kunrunic.egg-info/requires.txt +0 -0
  30. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev5}/pyproject.toml +0 -0
  31. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev5}/setup.cfg +0 -0
  32. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev5}/tests/test_cli_install.py +0 -0
  33. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev5}/tests/test_config.py +0 -0
  34. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev5}/tests/test_progress.py +0 -0
  35. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev5}/tests/test_release.py +0 -0
  36. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev5}/tests/test_snapshot.py +0 -0
  37. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev5}/tools/echo_args.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pkgmgr-kunrunic
3
- Version: 0.1.1.dev3
3
+ Version: 0.1.1.dev5
4
4
  Summary: Package management workflow scaffold.
5
5
  Author: pkgmgr maintainers
6
6
  License: MIT License
@@ -13,4 +13,4 @@ __all__ = [
13
13
  "points",
14
14
  ]
15
15
 
16
- __version__ = "0.1.1.dev3"
16
+ __version__ = "0.1.1.dev5"
@@ -220,20 +220,24 @@ def _handle_snapshot(args):
220
220
  def _handle_create_pkg(args):
221
221
  cfg = config.load_main(args.config)
222
222
  release.create_pkg(cfg, args.pkg_id)
223
+ _run_auto_actions(cfg, "create_pkg", config_path=args.config, context={"pkg_id": args.pkg_id, "event": "create_pkg"})
223
224
  return 0
224
225
 
225
226
  def _handle_update_pkg(args):
226
227
  cfg = config.load_main(args.config)
227
228
  if args.release:
228
229
  release.finalize_pkg_release(cfg, args.pkg_id)
230
+ _run_auto_actions(cfg, "update_pkg_release", config_path=args.config, context={"pkg_id": args.pkg_id, "event": "update_pkg_release"})
229
231
  return 0
230
232
  release.update_pkg(cfg, args.pkg_id)
233
+ _run_auto_actions(cfg, "update_pkg", config_path=args.config, context={"pkg_id": args.pkg_id, "event": "update_pkg"})
231
234
  return 0
232
235
 
233
236
 
234
237
  def _handle_close_pkg(args):
235
238
  cfg = config.load_main(args.config)
236
239
  release.close_pkg(cfg, args.pkg_id)
240
+ _run_auto_actions(cfg, "close_pkg", config_path=args.config, context={"pkg_id": args.pkg_id, "event": "close_pkg"})
237
241
  return 0
238
242
 
239
243
 
@@ -270,8 +274,16 @@ def _handle_actions(args):
270
274
  return 0
271
275
 
272
276
 
277
+ def _run_auto_actions(cfg, event, config_path=None, context=None):
278
+ auto_actions = cfg.get("auto_actions") or {}
279
+ names = auto_actions.get(event) or []
280
+ if not names:
281
+ return []
282
+ return release.run_actions(cfg, names, config_path=config_path, context=context)
283
+
284
+
273
285
  def _print_actions(actions):
274
- ordered = sorted(actions.keys())
286
+ ordered = sorted([name for name in actions.keys() if not str(name).startswith("auto_")])
275
287
  print("[actions] available:")
276
288
  for idx, name in enumerate(ordered, 1):
277
289
  entries = actions.get(name) or []
@@ -75,6 +75,12 @@ actions:
75
75
  noti_email:
76
76
  - cmd: sh noti_email.sh
77
77
  cwd: /app/script
78
+
79
+ auto_actions:
80
+ create_pkg: []
81
+ update_pkg: []
82
+ update_pkg_release: []
83
+ close_pkg: []
78
84
  """
79
85
 
80
86
  PKG_TEMPLATE = """\
@@ -104,6 +110,12 @@ MAIN_DEFAULTS = {
104
110
  "watch": {"interval_sec": 60, "on_change": []},
105
111
  "collectors": {"enabled": ["checksums"]},
106
112
  "actions": {},
113
+ "auto_actions": {
114
+ "create_pkg": [],
115
+ "update_pkg": [],
116
+ "update_pkg_release": [],
117
+ "close_pkg": [],
118
+ },
107
119
  }
108
120
 
109
121
 
@@ -167,6 +179,16 @@ def _validate_watch(watch_cfg):
167
179
  return {"interval_sec": interval, "on_change": on_change}
168
180
 
169
181
 
182
+ def _validate_auto_actions(auto_actions):
183
+ cfg = auto_actions if isinstance(auto_actions, dict) else {}
184
+ return {
185
+ "create_pkg": _ensure_list_of_strings(cfg.get("create_pkg"), "auto_actions.create_pkg"),
186
+ "update_pkg": _ensure_list_of_strings(cfg.get("update_pkg"), "auto_actions.update_pkg"),
187
+ "update_pkg_release": _ensure_list_of_strings(cfg.get("update_pkg_release"), "auto_actions.update_pkg_release"),
188
+ "close_pkg": _ensure_list_of_strings(cfg.get("close_pkg"), "auto_actions.close_pkg"),
189
+ }
190
+
191
+
170
192
  def _validate_main_config(data):
171
193
  if not isinstance(data, dict):
172
194
  raise RuntimeError("main config must be a mapping")
@@ -197,6 +219,7 @@ def _validate_main_config(data):
197
219
  }
198
220
 
199
221
  cfg["actions"] = _validate_actions(cfg.get("actions"))
222
+ cfg["auto_actions"] = _validate_auto_actions(cfg.get("auto_actions"))
200
223
 
201
224
  return cfg
202
225
 
@@ -359,7 +382,7 @@ def load_main(path=None, base_dir=None, allow_interactive=True):
359
382
  abs_path = os.path.abspath(path)
360
383
  if not os.path.exists(abs_path):
361
384
  raise RuntimeError("config not found: %s" % abs_path)
362
- with open(abs_path, "r") as f:
385
+ with open(abs_path, "r", encoding="utf-8") as f:
363
386
  data = yaml.safe_load(f) or {}
364
387
  return _validate_main_config(data)
365
388
 
@@ -380,5 +403,6 @@ def describe_expected_fields():
380
403
  - cmd: shell command string (required, often relative to cwd)
381
404
  - cwd: working directory (optional)
382
405
  - env: key/value env overrides for that command only (optional)
406
+ auto_actions: mapping of lifecycle events to action names (create_pkg/update_pkg/update_pkg_release/close_pkg)
383
407
  """
384
408
  ).strip()
@@ -36,6 +36,14 @@ def _pkg_state_path(pkg_id):
36
36
  return os.path.join(_pkg_state_dir(pkg_id), "state.json")
37
37
 
38
38
 
39
+ def _pkg_summary_path():
40
+ return os.path.join(config.DEFAULT_STATE_DIR, "pkg-summary.json")
41
+
42
+
43
+ def _pkg_release_history_dir(pkg_id):
44
+ return os.path.join(config.DEFAULT_STATE_DIR, "pkg", str(pkg_id), "release")
45
+
46
+
39
47
  def _timestamp():
40
48
  return time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime())
41
49
 
@@ -75,6 +83,131 @@ def _write_pkg_state(pkg_id, status, extra=None):
75
83
  return state
76
84
 
77
85
 
86
+ def _parse_ts(value):
87
+ if not value:
88
+ return 0
89
+ for fmt in ("%Y-%m-%dT%H:%M:%S", "%Y%m%dT%H%M%S"):
90
+ try:
91
+ return int(time.mktime(time.strptime(str(value), fmt)))
92
+ except Exception:
93
+ continue
94
+ return 0
95
+
96
+
97
+ def _load_pkg_summary():
98
+ path = _pkg_summary_path()
99
+ if not os.path.exists(path):
100
+ return {"generated_at": _timestamp(), "pkgs": []}
101
+ try:
102
+ with open(path, "r") as f:
103
+ data = json.load(f)
104
+ if isinstance(data, dict) and isinstance(data.get("pkgs"), list):
105
+ return data
106
+ except Exception:
107
+ pass
108
+ return {"generated_at": _timestamp(), "pkgs": []}
109
+
110
+
111
+ def _find_latest_update(pkg_id):
112
+ updates_dir = os.path.join(config.DEFAULT_STATE_DIR, "pkg", str(pkg_id), "updates")
113
+ if not os.path.isdir(updates_dir):
114
+ return None, None
115
+ candidates = []
116
+ for name in os.listdir(updates_dir):
117
+ if not name.startswith("update-") or not name.endswith(".json"):
118
+ continue
119
+ ts = name[len("update-"):-len(".json")]
120
+ candidates.append((ts, name))
121
+ if not candidates:
122
+ return None, None
123
+ candidates.sort(key=lambda item: _parse_ts(item[0]))
124
+ latest_ts, latest_name = candidates[-1]
125
+ return os.path.join(updates_dir, latest_name), latest_ts
126
+
127
+
128
+ def _build_pkg_summary_entry(pkg_id):
129
+ state = _load_pkg_state(pkg_id) or {}
130
+ update_path, update_ts = _find_latest_update(pkg_id)
131
+ update_data = {}
132
+ if update_path:
133
+ try:
134
+ with open(update_path, "r") as f:
135
+ update_data = json.load(f) or {}
136
+ except Exception:
137
+ update_data = {}
138
+ git_info = update_data.get("git") or {}
139
+ release_info = update_data.get("release") or []
140
+ checksums = update_data.get("checksums") or {}
141
+ git_files = checksums.get("git_files") or {}
142
+ release_files = checksums.get("release_files") or {}
143
+
144
+ entry = {
145
+ "pkg_id": str(pkg_id),
146
+ "status": state.get("status") or "unknown",
147
+ "opened_at": state.get("opened_at"),
148
+ "updated_at": state.get("updated_at"),
149
+ "closed_at": state.get("closed_at"),
150
+ "last_update_id": os.path.basename(update_path) if update_path else None,
151
+ "last_update_at": update_ts,
152
+ "git": {
153
+ "keywords": git_info.get("keywords") or [],
154
+ "commit_count": len(git_info.get("commits") or []),
155
+ },
156
+ "release": {
157
+ "bundle_count": len(release_info),
158
+ "roots": sorted({b.get("root") for b in release_info if b.get("root")}),
159
+ "names": sorted({b.get("release_name") for b in release_info if b.get("release_name")}),
160
+ },
161
+ "artifacts": {
162
+ "git_files": len(git_files),
163
+ "release_files": len(release_files),
164
+ },
165
+ }
166
+ return entry
167
+
168
+
169
+ def _update_pkg_summary(pkg_id):
170
+ data = _load_pkg_summary()
171
+ pkgs = data.get("pkgs") or []
172
+ by_id = {p.get("pkg_id"): p for p in pkgs if isinstance(p, dict)}
173
+ entry = _build_pkg_summary_entry(pkg_id)
174
+ by_id[entry["pkg_id"]] = entry
175
+
176
+ def _sort_key(item):
177
+ status = item.get("status") or ""
178
+ updated_ts = max(_parse_ts(item.get("updated_at")), _parse_ts(item.get("last_update_at")))
179
+ return (0 if status == "open" else 1, -updated_ts)
180
+
181
+ ordered = sorted(by_id.values(), key=_sort_key)
182
+ data = {
183
+ "generated_at": _timestamp(),
184
+ "pkgs": ordered,
185
+ }
186
+ path = _pkg_summary_path()
187
+ if not os.path.exists(os.path.dirname(path)):
188
+ os.makedirs(os.path.dirname(path))
189
+ with open(path, "w") as f:
190
+ json.dump(data, f, ensure_ascii=False, indent=2, sort_keys=True)
191
+
192
+
193
+ def _write_release_history(pkg_id, run_at, bundles):
194
+ if not bundles:
195
+ return None
196
+ rel_dir = _pkg_release_history_dir(pkg_id)
197
+ if not os.path.exists(rel_dir):
198
+ os.makedirs(rel_dir)
199
+ payload = {
200
+ "pkg_id": str(pkg_id),
201
+ "run_at": run_at,
202
+ "generated_at": _timestamp(),
203
+ "bundles": bundles,
204
+ }
205
+ out_path = os.path.join(rel_dir, "release-%s.json" % run_at)
206
+ with open(out_path, "w") as f:
207
+ json.dump(payload, f, ensure_ascii=False, indent=2, sort_keys=True)
208
+ return out_path
209
+
210
+
78
211
  def pkg_is_closed(pkg_id):
79
212
  state = _load_pkg_state(pkg_id)
80
213
  return bool(state and state.get("status") == "closed")
@@ -122,6 +255,7 @@ def create_pkg(cfg, pkg_id):
122
255
  else:
123
256
  print("[create-pkg] baseline already exists; skipping baseline creation")
124
257
  _write_pkg_state(pkg_id, "open")
258
+ _update_pkg_summary(pkg_id)
125
259
  print("[create-pkg] prepared %s" % dest)
126
260
 
127
261
 
@@ -135,6 +269,7 @@ def close_pkg(cfg, pkg_id):
135
269
  with open(marker, "w") as f:
136
270
  f.write("closed\n")
137
271
  _write_pkg_state(pkg_id, "closed")
272
+ _update_pkg_summary(pkg_id)
138
273
  print("[close-pkg] marked closed: %s" % dest)
139
274
 
140
275
 
@@ -150,7 +285,7 @@ def collect_for_pkg(cfg, pkg_id, collectors=None):
150
285
 
151
286
 
152
287
 
153
- def run_actions(cfg, names, extra_args=None, config_path=None):
288
+ def run_actions(cfg, names, extra_args=None, config_path=None, context=None):
154
289
  """Run configured actions by name. Returns result list."""
155
290
  actions = cfg.get("actions", {}) or {}
156
291
  if not names:
@@ -162,6 +297,7 @@ def run_actions(cfg, names, extra_args=None, config_path=None):
162
297
  quoted = [shlex.quote(str(arg)) for arg in extra_args]
163
298
  extra_suffix = " " + " ".join(quoted)
164
299
  results = []
300
+ context = context or {}
165
301
  for name in names:
166
302
  entries = actions.get(name)
167
303
  if not entries:
@@ -180,6 +316,9 @@ def run_actions(cfg, names, extra_args=None, config_path=None):
180
316
  if not cmd:
181
317
  print("[actions] skip empty cmd for %s #%d" % (name, idx + 1))
182
318
  continue
319
+ cmd = _render_action_value(cmd, context)
320
+ cwd = _render_action_value(cwd, context)
321
+ env = _render_action_env(env, context)
183
322
  if config_path:
184
323
  env = dict(env or {})
185
324
  env.setdefault("PKGMGR_CONFIG", config_path)
@@ -196,6 +335,24 @@ def run_actions(cfg, names, extra_args=None, config_path=None):
196
335
  return results
197
336
 
198
337
 
338
+ def _render_action_value(value, context):
339
+ if not value or not context:
340
+ return value
341
+ text = str(value)
342
+ for key, val in context.items():
343
+ text = text.replace("{%s}" % key, str(val))
344
+ return text
345
+
346
+
347
+ def _render_action_env(env, context):
348
+ if not env or not isinstance(env, dict):
349
+ return env
350
+ rendered = {}
351
+ for k, v in env.items():
352
+ rendered[k] = _render_action_value(v, context)
353
+ return rendered
354
+
355
+
199
356
  def _parse_action_entry(entry):
200
357
  if isinstance(entry, dict):
201
358
  cmd = entry.get("cmd")
@@ -263,6 +420,60 @@ def _git_repo_root(pkg_root, git_cfg):
263
420
  return None
264
421
 
265
422
 
423
+ def _text_type():
424
+ try:
425
+ return unicode # type: ignore[name-defined]
426
+ except Exception:
427
+ return str
428
+
429
+
430
+ def _decode_git_output(raw, encodings):
431
+ if raw is None:
432
+ return ""
433
+ text_type = _text_type()
434
+ if isinstance(raw, text_type):
435
+ return raw
436
+ if not encodings:
437
+ encodings = []
438
+ candidates = [e for e in encodings if e]
439
+ candidates.extend(["utf-8", "euc-kr", "cp949"])
440
+ best_text = None
441
+ best_score = None
442
+ for enc in candidates:
443
+ try:
444
+ text = raw.decode(enc, errors="replace")
445
+ except Exception:
446
+ continue
447
+ score = text.count(u"\ufffd")
448
+ if best_score is None or score < best_score:
449
+ best_score = score
450
+ best_text = text
451
+ if score == 0:
452
+ break
453
+ if best_text is not None:
454
+ return best_text
455
+ try:
456
+ return raw.decode("utf-8", errors="replace")
457
+ except Exception:
458
+ return str(raw)
459
+
460
+
461
+ def _git_output_encoding(repo_root):
462
+ for key in ("i18n.logOutputEncoding", "i18n.commitEncoding"):
463
+ try:
464
+ out = subprocess.check_output(
465
+ ["git", "config", "--get", key],
466
+ cwd=repo_root,
467
+ stderr=subprocess.STDOUT,
468
+ universal_newlines=True,
469
+ ).strip()
470
+ except Exception:
471
+ out = ""
472
+ if out:
473
+ return out
474
+ return "utf-8"
475
+
476
+
266
477
  def _collect_git_hits(pkg_cfg, pkg_root):
267
478
  git_cfg = pkg_cfg.get("git") or {}
268
479
  keywords = [str(k) for k in (git_cfg.get("keywords") or []) if str(k).strip()]
@@ -280,6 +491,7 @@ def _collect_git_hits(pkg_cfg, pkg_root):
280
491
  commits = {}
281
492
  current = None
282
493
 
494
+ output_encoding = _git_output_encoding(repo_root)
283
495
  for kw in keywords:
284
496
  cmd = [
285
497
  "git",
@@ -297,7 +509,13 @@ def _collect_git_hits(pkg_cfg, pkg_root):
297
509
  if until:
298
510
  cmd.append("--until=%s" % until)
299
511
  try:
300
- out = subprocess.check_output(cmd, cwd=repo_root, stderr=subprocess.STDOUT, universal_newlines=True)
512
+ out_raw = subprocess.check_output(
513
+ cmd,
514
+ cwd=repo_root,
515
+ stderr=subprocess.STDOUT,
516
+ universal_newlines=False,
517
+ )
518
+ out = _decode_git_output(out_raw, [output_encoding])
301
519
  except Exception as e:
302
520
  print("[git] log failed for keyword %s: %s" % (kw, str(e)))
303
521
  continue
@@ -325,12 +543,13 @@ def _collect_git_hits(pkg_cfg, pkg_root):
325
543
  c["commit"] = c.get("hash")
326
544
  # fetch author and full commit message body for richer context
327
545
  try:
328
- info = subprocess.check_output(
546
+ info_raw = subprocess.check_output(
329
547
  ["git", "show", "-s", "--format=%an\t%ae\t%ad%n%s%n%b", c["hash"]],
330
548
  cwd=repo_root,
331
549
  stderr=subprocess.STDOUT,
332
- universal_newlines=True,
550
+ universal_newlines=False,
333
551
  )
552
+ info = _decode_git_output(info_raw, [output_encoding])
334
553
  header, _, body = info.partition("\n")
335
554
  parts = header.split("\t")
336
555
  c["author_name"] = parts[0] if len(parts) > 0 else ""
@@ -664,6 +883,8 @@ def _prepare_release(pkg_dir, pkg_cfg):
664
883
  "root": root,
665
884
  "release_dir": release_dir,
666
885
  "release_name": release_name,
886
+ "created_at": ts,
887
+ "files": all_files,
667
888
  "copied": copied,
668
889
  "skipped": skipped,
669
890
  "added": added,
@@ -827,4 +1048,6 @@ def update_pkg(cfg, pkg_id):
827
1048
  with open(out_path, "w") as f:
828
1049
  json.dump(data, f, ensure_ascii=False, indent=2, sort_keys=True)
829
1050
  print("[update-pkg] wrote %s" % out_path)
1051
+ _write_release_history(pkg_id, ts, release_bundle)
1052
+ _update_pkg_summary(pkg_id)
830
1053
  return out_path
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pkgmgr-kunrunic
3
- Version: 0.1.1.dev3
3
+ Version: 0.1.1.dev5
4
4
  Summary: Package management workflow scaffold.
5
5
  Author: pkgmgr maintainers
6
6
  License: MIT License
@@ -23,9 +23,8 @@ pkgmgr_kunrunic.egg-info/not-zip-safe
23
23
  pkgmgr_kunrunic.egg-info/requires.txt
24
24
  pkgmgr_kunrunic.egg-info/top_level.txt
25
25
  plugin/export_cksum.py
26
+ plugin/export_pkgstore.py
26
27
  plugin/export_source_review.py
27
- test_data_root/plugin/export_cksum.py
28
- test_data_root/plugin/export_source_review.py
29
28
  tests/test_cli_install.py
30
29
  tests/test_config.py
31
30
  tests/test_progress.py
@@ -2,5 +2,5 @@ design
2
2
  dist
3
3
  pkgmgr
4
4
  plugin
5
- test_data_root
5
+ test_data
6
6
  tools
@@ -2,8 +2,10 @@
2
2
  # -*- coding: utf-8 -*-
3
3
  import argparse
4
4
  import os
5
+ import re
5
6
  import subprocess
6
7
  import sys
8
+ import time
7
9
  from copy import copy
8
10
 
9
11
  try:
@@ -96,6 +98,53 @@ def _cksum(path):
96
98
  return parts[0], parts[1], " ".join(parts[2:])
97
99
 
98
100
 
101
+ def _normalize_excel_template(excel_arg, pkg_dir):
102
+ path_template = excel_arg
103
+ if os.sep not in path_template:
104
+ export_dir = os.path.join(pkg_dir, "export")
105
+ path_template = os.path.join(export_dir, path_template)
106
+ if not path_template.lower().endswith(".xlsx"):
107
+ path_template = path_template + ".xlsx"
108
+ return path_template
109
+
110
+
111
+ def _next_version(path_template):
112
+ dir_path = os.path.dirname(path_template) or "."
113
+ name_template = os.path.basename(path_template)
114
+ regex = re.escape(name_template)
115
+ regex = regex.replace(re.escape("{YYYYMMDD}"), r"\d{8}")
116
+ regex = regex.replace(re.escape("{date}"), r"\d{8}")
117
+ regex = regex.replace(re.escape("{version}"), r"v(\d+)")
118
+ regex = "^" + regex + "$"
119
+ max_ver = 0
120
+ if os.path.isdir(dir_path):
121
+ for name in os.listdir(dir_path):
122
+ m = re.match(regex, name)
123
+ if not m:
124
+ continue
125
+ try:
126
+ ver = int(m.group(1))
127
+ except Exception:
128
+ continue
129
+ if ver > max_ver:
130
+ max_ver = ver
131
+ return max_ver + 1
132
+
133
+
134
+ def _resolve_excel_path(excel_arg, pkg_dir):
135
+ date_str = time.strftime("%Y%m%d", time.localtime())
136
+ template_path = _normalize_excel_template(excel_arg, pkg_dir)
137
+ if "{version}" in template_path:
138
+ version = _next_version(template_path)
139
+ else:
140
+ version = None
141
+ output_path = template_path
142
+ output_path = output_path.replace("{YYYYMMDD}", date_str).replace("{date}", date_str)
143
+ if version is not None:
144
+ output_path = output_path.replace("{version}", "v%d" % version)
145
+ return output_path
146
+
147
+
99
148
  def _default_styles():
100
149
  base_font = Font(name="맑은 고딕", size=11)
101
150
  bold_font = Font(name="맑은 고딕", size=11, bold=True)
@@ -262,7 +311,11 @@ def main(argv=None):
262
311
  parser = argparse.ArgumentParser(description="Export cksum results into an Excel template.")
263
312
  parser.add_argument("--config", help="pkgmgr main config path")
264
313
  parser.add_argument("--pkg-id", required=True, help="pkg id (resolved via pkg_release_root)")
265
- parser.add_argument("--excel", required=True, help="output xlsx path")
314
+ parser.add_argument(
315
+ "--excel",
316
+ required=True,
317
+ help="output xlsx path (supports {YYYYMMDD}/{date} and {version})",
318
+ )
266
319
  parser.add_argument("--template", help="xlsx template path (optional)")
267
320
  args = parser.parse_args(argv)
268
321
 
@@ -288,12 +341,7 @@ def main(argv=None):
288
341
  print("[export_cksum] no release entries found in %s" % pkg_yaml)
289
342
  return 1
290
343
 
291
- excel_path = args.excel
292
- if not excel_path.lower().endswith(".xlsx"):
293
- excel_path = excel_path + ".xlsx"
294
- if os.sep not in excel_path:
295
- export_dir = os.path.join(pkg_dir, "export")
296
- excel_path = os.path.join(export_dir, excel_path)
344
+ excel_path = _resolve_excel_path(args.excel, pkg_dir)
297
345
  template_path = args.template or excel_path
298
346
  template_available = template_path and os.path.exists(template_path)
299
347
  if template_available:
@@ -0,0 +1,122 @@
1
+ from __future__ import print_function
2
+
3
+ import argparse
4
+ import os
5
+ import shutil
6
+ import sys
7
+ import socket
8
+ import subprocess
9
+ import tempfile
10
+
11
+
12
+ def _default_src():
13
+ home = os.path.expanduser("~")
14
+ return os.path.join(home, "pkgmgr", "local", "state")
15
+
16
+
17
+ def _copy_tree(src, dest):
18
+ for base, dirs, files in os.walk(src):
19
+ rel = os.path.relpath(base, src)
20
+ dest_dir = dest if rel == "." else os.path.join(dest, rel)
21
+ if not os.path.exists(dest_dir):
22
+ os.makedirs(dest_dir)
23
+ for name in files:
24
+ s = os.path.join(base, name)
25
+ d = os.path.join(dest_dir, name)
26
+ shutil.copy2(s, d)
27
+ for name in dirs:
28
+ d = os.path.join(dest_dir, name)
29
+ if not os.path.exists(d):
30
+ os.makedirs(d)
31
+
32
+
33
+ def _default_release_root():
34
+ home = os.path.expanduser("~")
35
+ return os.path.join(home, "PKG", "RELEASE")
36
+
37
+
38
+ def _copy_export_dirs(release_root, dest_state_root):
39
+ if not os.path.isdir(release_root):
40
+ return
41
+ pkg_root = os.path.join(dest_state_root, "pkg")
42
+ if not os.path.exists(pkg_root):
43
+ os.makedirs(pkg_root)
44
+ for name in os.listdir(release_root):
45
+ pkg_dir = os.path.join(release_root, name)
46
+ if not os.path.isdir(pkg_dir):
47
+ continue
48
+ export_dir = os.path.join(pkg_dir, "export")
49
+ if not os.path.isdir(export_dir):
50
+ continue
51
+ dest_export = os.path.join(pkg_root, name, "export")
52
+ _copy_tree(export_dir, dest_export)
53
+
54
+
55
+ def export_pkgstore(src, dest, clean=False, release_root=None):
56
+ if not os.path.isdir(src):
57
+ raise RuntimeError("source not found: %s" % src)
58
+ if clean and os.path.exists(dest):
59
+ shutil.rmtree(dest)
60
+ if not os.path.exists(dest):
61
+ os.makedirs(dest)
62
+ _copy_tree(src, dest)
63
+ if release_root:
64
+ _copy_export_dirs(release_root, dest)
65
+
66
+
67
+ def main(argv=None):
68
+ parser = argparse.ArgumentParser(description="Export pkgmgr state into a pkgstore directory.")
69
+ parser.add_argument("--src", default=_default_src(), help="pkgmgr state root (default: ~/pkgmgr/local/state)")
70
+ parser.add_argument("--dest", help="pkgstore destination root (will create /state)")
71
+ parser.add_argument("--clean", action="store_true", help="clean destination state before export")
72
+ parser.add_argument("--release-root", default=_default_release_root(), help="PKG/RELEASE root (default: ~/PKG/RELEASE)")
73
+ parser.add_argument("--system", help="system identifier (writes to pkgstore/state/systems/<system>)")
74
+ parser.add_argument("--push", help="rsync target like user@host (pushes to remote)")
75
+ parser.add_argument("--remote-dest", default="~/data/pkgstore", help="remote pkgstore root (default: ~/data/pkgstore)")
76
+ parser.add_argument("--identity", help="ssh private key path for rsync (optional)")
77
+ args = parser.parse_args(argv)
78
+ if not args.dest and not args.push:
79
+ parser.error("--dest is required when --push is not set")
80
+
81
+ src = os.path.abspath(os.path.expanduser(args.src))
82
+ tmp_root = None
83
+ if args.dest:
84
+ dest_root = os.path.abspath(os.path.expanduser(args.dest))
85
+ else:
86
+ tmp_root = tempfile.mkdtemp(prefix="pkgstore_")
87
+ dest_root = tmp_root
88
+ system_name = args.system or socket.gethostname()
89
+ if system_name:
90
+ dest_state = os.path.join(dest_root, "state", "systems", system_name)
91
+ else:
92
+ dest_state = os.path.join(dest_root, "state")
93
+ release_root = os.path.abspath(os.path.expanduser(args.release_root)) if args.release_root else None
94
+
95
+ export_pkgstore(src, dest_state, clean=args.clean, release_root=release_root)
96
+ print("[export_pkgstore] synced %s -> %s" % (src, dest_state))
97
+
98
+ if args.push:
99
+ remote_root = args.remote_dest.rstrip("/")
100
+ if system_name:
101
+ remote_state = "%s/state/systems/%s" % (remote_root, system_name)
102
+ else:
103
+ remote_state = "%s/state" % remote_root
104
+ src_dir = dest_state.rstrip("/") + "/"
105
+ subprocess.check_call(
106
+ ["ssh", args.push, "mkdir", "-p", remote_state]
107
+ )
108
+ rsync_cmd = ["rsync", "-avzc", "--delete"]
109
+ if args.identity:
110
+ rsync_cmd.extend(["-e", "ssh -i %s" % args.identity])
111
+ rsync_cmd.extend([src_dir, "%s:%s" % (args.push, remote_state)])
112
+ print("[export_pkgstore] rsync -> %s" % (remote_state,))
113
+ subprocess.check_call(rsync_cmd)
114
+ else:
115
+ print("[export_pkgstore] push skipped (no --push)")
116
+ if tmp_root:
117
+ shutil.rmtree(tmp_root)
118
+ return 0
119
+
120
+
121
+ if __name__ == "__main__":
122
+ sys.exit(main())