pkgmgr-kunrunic 0.1.1.dev3__tar.gz → 0.1.1.dev4__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.dev4}/PKG-INFO +1 -1
  2. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev4}/pkgmgr/__init__.py +1 -1
  3. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev4}/pkgmgr/cli.py +12 -0
  4. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev4}/pkgmgr/config.py +25 -1
  5. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev4}/pkgmgr/release.py +204 -3
  6. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev4/pkgmgr_kunrunic.egg-info}/PKG-INFO +1 -1
  7. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev4}/pkgmgr_kunrunic.egg-info/SOURCES.txt +1 -2
  8. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev4}/pkgmgr_kunrunic.egg-info/top_level.txt +1 -1
  9. pkgmgr_kunrunic-0.1.1.dev4/plugin/export_pkgstore.py +117 -0
  10. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev4}/plugin/export_source_review.py +15 -6
  11. pkgmgr_kunrunic-0.1.1.dev3/test_data_root/plugin/export_cksum.py +0 -354
  12. pkgmgr_kunrunic-0.1.1.dev3/test_data_root/plugin/export_source_review.py +0 -490
  13. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev4}/LICENSE +0 -0
  14. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev4}/README.md +0 -0
  15. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev4}/pkgmgr/__main__.py +0 -0
  16. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev4}/pkgmgr/collectors/__init__.py +0 -0
  17. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev4}/pkgmgr/collectors/base.py +0 -0
  18. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev4}/pkgmgr/collectors/checksums.py +0 -0
  19. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev4}/pkgmgr/points.py +0 -0
  20. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev4}/pkgmgr/shell_integration.py +0 -0
  21. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev4}/pkgmgr/snapshot.py +0 -0
  22. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev4}/pkgmgr/templates/pkg.yaml.sample +0 -0
  23. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev4}/pkgmgr/templates/pkgmgr.yaml.sample +0 -0
  24. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev4}/pkgmgr/watch.py +0 -0
  25. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev4}/pkgmgr_kunrunic.egg-info/dependency_links.txt +0 -0
  26. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev4}/pkgmgr_kunrunic.egg-info/entry_points.txt +0 -0
  27. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev4}/pkgmgr_kunrunic.egg-info/not-zip-safe +0 -0
  28. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev4}/pkgmgr_kunrunic.egg-info/requires.txt +0 -0
  29. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev4}/plugin/export_cksum.py +0 -0
  30. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev4}/pyproject.toml +0 -0
  31. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev4}/setup.cfg +0 -0
  32. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev4}/tests/test_cli_install.py +0 -0
  33. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev4}/tests/test_config.py +0 -0
  34. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev4}/tests/test_progress.py +0 -0
  35. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev4}/tests/test_release.py +0 -0
  36. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev4}/tests/test_snapshot.py +0 -0
  37. {pkgmgr_kunrunic-0.1.1.dev3 → pkgmgr_kunrunic-0.1.1.dev4}/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.dev4
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.dev4"
@@ -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)
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)
229
231
  return 0
230
232
  release.update_pkg(cfg, args.pkg_id)
233
+ _run_auto_actions(cfg, "update_pkg", config_path=args.config)
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)
237
241
  return 0
238
242
 
239
243
 
@@ -270,6 +274,14 @@ def _handle_actions(args):
270
274
  return 0
271
275
 
272
276
 
277
+ def _run_auto_actions(cfg, event, config_path=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)
283
+
284
+
273
285
  def _print_actions(actions):
274
286
  ordered = sorted(actions.keys())
275
287
  print("[actions] available:")
@@ -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
 
@@ -263,6 +398,60 @@ def _git_repo_root(pkg_root, git_cfg):
263
398
  return None
264
399
 
265
400
 
401
+ def _text_type():
402
+ try:
403
+ return unicode # type: ignore[name-defined]
404
+ except Exception:
405
+ return str
406
+
407
+
408
+ def _decode_git_output(raw, encodings):
409
+ if raw is None:
410
+ return ""
411
+ text_type = _text_type()
412
+ if isinstance(raw, text_type):
413
+ return raw
414
+ if not encodings:
415
+ encodings = []
416
+ candidates = [e for e in encodings if e]
417
+ candidates.extend(["utf-8", "euc-kr", "cp949"])
418
+ best_text = None
419
+ best_score = None
420
+ for enc in candidates:
421
+ try:
422
+ text = raw.decode(enc, errors="replace")
423
+ except Exception:
424
+ continue
425
+ score = text.count(u"\ufffd")
426
+ if best_score is None or score < best_score:
427
+ best_score = score
428
+ best_text = text
429
+ if score == 0:
430
+ break
431
+ if best_text is not None:
432
+ return best_text
433
+ try:
434
+ return raw.decode("utf-8", errors="replace")
435
+ except Exception:
436
+ return str(raw)
437
+
438
+
439
+ def _git_output_encoding(repo_root):
440
+ for key in ("i18n.logOutputEncoding", "i18n.commitEncoding"):
441
+ try:
442
+ out = subprocess.check_output(
443
+ ["git", "config", "--get", key],
444
+ cwd=repo_root,
445
+ stderr=subprocess.STDOUT,
446
+ universal_newlines=True,
447
+ ).strip()
448
+ except Exception:
449
+ out = ""
450
+ if out:
451
+ return out
452
+ return "utf-8"
453
+
454
+
266
455
  def _collect_git_hits(pkg_cfg, pkg_root):
267
456
  git_cfg = pkg_cfg.get("git") or {}
268
457
  keywords = [str(k) for k in (git_cfg.get("keywords") or []) if str(k).strip()]
@@ -280,6 +469,7 @@ def _collect_git_hits(pkg_cfg, pkg_root):
280
469
  commits = {}
281
470
  current = None
282
471
 
472
+ output_encoding = _git_output_encoding(repo_root)
283
473
  for kw in keywords:
284
474
  cmd = [
285
475
  "git",
@@ -297,7 +487,13 @@ def _collect_git_hits(pkg_cfg, pkg_root):
297
487
  if until:
298
488
  cmd.append("--until=%s" % until)
299
489
  try:
300
- out = subprocess.check_output(cmd, cwd=repo_root, stderr=subprocess.STDOUT, universal_newlines=True)
490
+ out_raw = subprocess.check_output(
491
+ cmd,
492
+ cwd=repo_root,
493
+ stderr=subprocess.STDOUT,
494
+ universal_newlines=False,
495
+ )
496
+ out = _decode_git_output(out_raw, [output_encoding])
301
497
  except Exception as e:
302
498
  print("[git] log failed for keyword %s: %s" % (kw, str(e)))
303
499
  continue
@@ -325,12 +521,13 @@ def _collect_git_hits(pkg_cfg, pkg_root):
325
521
  c["commit"] = c.get("hash")
326
522
  # fetch author and full commit message body for richer context
327
523
  try:
328
- info = subprocess.check_output(
524
+ info_raw = subprocess.check_output(
329
525
  ["git", "show", "-s", "--format=%an\t%ae\t%ad%n%s%n%b", c["hash"]],
330
526
  cwd=repo_root,
331
527
  stderr=subprocess.STDOUT,
332
- universal_newlines=True,
528
+ universal_newlines=False,
333
529
  )
530
+ info = _decode_git_output(info_raw, [output_encoding])
334
531
  header, _, body = info.partition("\n")
335
532
  parts = header.split("\t")
336
533
  c["author_name"] = parts[0] if len(parts) > 0 else ""
@@ -664,6 +861,8 @@ def _prepare_release(pkg_dir, pkg_cfg):
664
861
  "root": root,
665
862
  "release_dir": release_dir,
666
863
  "release_name": release_name,
864
+ "created_at": ts,
865
+ "files": all_files,
667
866
  "copied": copied,
668
867
  "skipped": skipped,
669
868
  "added": added,
@@ -827,4 +1026,6 @@ def update_pkg(cfg, pkg_id):
827
1026
  with open(out_path, "w") as f:
828
1027
  json.dump(data, f, ensure_ascii=False, indent=2, sort_keys=True)
829
1028
  print("[update-pkg] wrote %s" % out_path)
1029
+ _write_release_history(pkg_id, ts, release_bundle)
1030
+ _update_pkg_summary(pkg_id)
830
1031
  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.dev4
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
@@ -0,0 +1,117 @@
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
+ rsync_cmd = ["rsync", "-avzc", "--delete"]
106
+ if args.identity:
107
+ rsync_cmd.extend(["-e", "ssh -i %s" % args.identity])
108
+ rsync_cmd.extend([src_dir, "%s:%s" % (args.push, remote_state)])
109
+ print("[export_pkgstore] rsync -> %s" % (remote_state,))
110
+ subprocess.check_call(rsync_cmd)
111
+ if tmp_root:
112
+ shutil.rmtree(tmp_root)
113
+ return 0
114
+
115
+
116
+ if __name__ == "__main__":
117
+ sys.exit(main())
@@ -28,8 +28,14 @@ def _load_pkg_yaml(pkg_dir, pkg_yaml):
28
28
 
29
29
 
30
30
  def _read_update_json(path):
31
- with open(path, "r", encoding="utf-8") as f:
32
- return json.load(f)
31
+ with open(path, "rb") as f:
32
+ raw = f.read()
33
+ for encoding in ("utf-8", "euc-kr", "cp949"):
34
+ try:
35
+ return json.loads(raw.decode(encoding))
36
+ except Exception:
37
+ continue
38
+ return json.loads(raw.decode("utf-8", errors="replace"))
33
39
 
34
40
 
35
41
  def _find_latest_update(pkg_id):
@@ -203,6 +209,9 @@ def _is_ignored(path, repo_root, patterns):
203
209
  if not patterns:
204
210
  return False
205
211
  candidates = [path]
212
+ basename = os.path.basename(path)
213
+ if basename:
214
+ candidates.append(basename)
206
215
  if repo_root and not os.path.isabs(path):
207
216
  candidates.append(os.path.join(repo_root, path))
208
217
  if repo_root and os.path.isabs(path):
@@ -303,8 +312,8 @@ def _git_diff(repo_root, start_commit, path):
303
312
  "-U3",
304
313
  start_commit,
305
314
  "HEAD",
306
- "--find-renames",
307
- "--find-copies",
315
+ "-M",
316
+ "-C",
308
317
  "--",
309
318
  path,
310
319
  ]
@@ -335,8 +344,8 @@ def _git_diff(repo_root, start_commit, path):
335
344
  "-U3",
336
345
  start_commit,
337
346
  last_commit,
338
- "--find-renames",
339
- "--find-copies",
347
+ "-M",
348
+ "-C",
340
349
  "--",
341
350
  path,
342
351
  ]