sitrtech 1.2.3__tar.gz → 1.2.5__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sitrtech
3
- Version: 1.2.3
3
+ Version: 1.2.5
4
4
  Summary: SitrTech Python code encryption CLI — protect Odoo, Django, Flask, FastAPI and Tornado projects
5
5
  Author-email: SitrTech <info@sitrtech.com>
6
6
  License: Proprietary
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "sitrtech"
7
- version = "1.2.3"
7
+ version = "1.2.5"
8
8
  description = "SitrTech Python code encryption CLI — protect Odoo, Django, Flask, FastAPI and Tornado projects"
9
9
  readme = "README.md"
10
10
  license = { text = "Proprietary" }
@@ -1,5 +1,5 @@
1
1
  """SitrTech — Python code encryption SDK."""
2
- __version__ = "1.2.3"
2
+ __version__ = "1.2.5"
3
3
  __all__ = ["encrypt", "balance", "encrypt_local", "encrypt_dir_local"]
4
4
 
5
5
  try: # optional: local-mode API (needs cryptography + bundled loaders)
@@ -1,8 +1,8 @@
1
1
  """
2
- sitrtech — Python code encryption CLI v1.0.2
2
+ sitrtech — Python code encryption CLI v1.2.5
3
3
  ==============================================
4
4
 
5
- Encrypt Odoo, Django, Flask, FastAPI and Tornado projects with AES-256-GCM
5
+ Encrypt Odoo, Frappe, Django, Flask, FastAPI, Tornado (and WordPress, Laravel, PHP) projects with AES-256-GCM
6
6
  in a single command. Supports incremental updates, expiry dates, and IP-based
7
7
  network restrictions.
8
8
 
@@ -44,7 +44,7 @@ from rich.table import Table
44
44
  # Constants
45
45
  # ─────────────────────────────────────────────────────────────────────────────
46
46
 
47
- __version__ = "1.2.3"
47
+ __version__ = "1.2.5"
48
48
  API_BASE_DEFAULT = "https://sitrtech.com"
49
49
  MANIFEST_SUFFIX = ".sitr_manifest.json"
50
50
 
@@ -434,6 +434,26 @@ def encrypt(
434
434
  f"[dim]{e}[/]")
435
435
  sys.exit(1)
436
436
  console.print("[dim]Local mode — your source never leaves this machine.[/]")
437
+
438
+ # Incremental: meter only the files that changed since the last run. The
439
+ # whole project is still re-encrypted (free, local CPU) so a single job
440
+ # key keeps every file decryptable — you just pay for what changed.
441
+ current_checksums = _get_checksums(file)
442
+ manifest = _load_manifest(output_path)
443
+ bill_members: Optional[set] = None
444
+ if not full and manifest is not None and output_path.exists():
445
+ prev = (manifest or {}).get("files", {})
446
+ changed = {n for n, h in current_checksums.items() if prev.get(n) != h}
447
+ if not changed:
448
+ console.print("\n[green]✓ No changes detected.[/] Output is already up to date.")
449
+ return
450
+ console.print("[dim]▸ Manifest found — incremental mode[/]")
451
+ console.print(f"[bold cyan]Incremental:[/] {len(changed)} file(s) changed")
452
+ for n in sorted(changed):
453
+ tag = "[green]+new[/]" if n not in prev else "[yellow]~mod[/]"
454
+ console.print(f" {tag} {n}")
455
+ bill_members = changed
456
+
437
457
  with Progress(SpinnerColumn(), TextColumn("[progress.description]{task.description}"),
438
458
  BarColumn(bar_width=30), TimeElapsedColumn(),
439
459
  console=console, transient=True) as prog:
@@ -445,7 +465,8 @@ def encrypt(
445
465
  try:
446
466
  res = _local.encrypt_local(
447
467
  str(file), str(output_path), fw, base, resolved_secret,
448
- protection=protection, version=version, on_status=_status,
468
+ protection=protection, version=version,
469
+ bill_members=bill_members, on_status=_status,
449
470
  )
450
471
  except _local.LocalError as e:
451
472
  err_console.print(f"[red]Error:[/] {e}")
@@ -458,6 +479,8 @@ def encrypt(
458
479
  f"{res.get('tokens_left', '?'):,} left[/]")
459
480
  if res.get("protection"):
460
481
  console.print("[dim]Binding rules embedded (license enforced at runtime).[/]")
482
+ mp = _save_manifest(output_path, fw, current_checksums)
483
+ console.print(f"[dim]Manifest: {mp.name} — next run is incremental.[/]")
461
484
  console.print()
462
485
  return
463
486
 
@@ -54,6 +54,30 @@ FRAMEWORK_SKIP_ENCRYPT: Dict[str, set] = {
54
54
  "frappe": {"hooks.py", "modules.txt", "patches.txt"},
55
55
  }
56
56
 
57
+ # Runnable entry files (kept in plaintext) that a framework executes first. We
58
+ # prepend the loader bootstrap here so the encrypted importer is installed before
59
+ # any .pye is imported — essential for frameworks launched as a script / WSGI /
60
+ # ASGI target (Django, gunicorn), which never import the project-root package and
61
+ # so would never trigger the root __init__.py bootstrap. Odoo/Frappe are imported
62
+ # as packages, so their __init__.py bootstrap is enough (and __manifest__.py must
63
+ # stay a pure dict literal — never touched here).
64
+ FRAMEWORK_ENTRY_BOOTSTRAP: Dict[str, set] = {
65
+ "django": {"manage.py", "wsgi.py", "asgi.py"},
66
+ "flask": {"app.py", "application.py", "wsgi.py"},
67
+ "fastapi": {"main.py", "asgi.py"},
68
+ "tornado": {"main.py", "server.py"},
69
+ }
70
+
71
+
72
+ def _entry_boot(framework: str) -> str:
73
+ return (
74
+ "try:\n"
75
+ " import sitr as _sitr_boot\n"
76
+ f" _sitr_boot.install_encrypted_importer(__file__, framework=\"{framework}\")\n"
77
+ "except Exception:\n"
78
+ " pass\n"
79
+ )
80
+
57
81
 
58
82
  def _b64e(b: bytes) -> str:
59
83
  return base64.urlsafe_b64encode(b).decode("ascii").rstrip("=")
@@ -285,4 +309,30 @@ def encrypt_project(
285
309
  with open(root_init, "w", encoding="utf-8") as f:
286
310
  f.write(_root_init(original_root_init, framework))
287
311
 
312
+ # prepend the bootstrap to runnable entry files (Django/gunicorn/etc.)
313
+ entry_names = FRAMEWORK_ENTRY_BOOTSTRAP.get(framework, set())
314
+ if entry_names:
315
+ boot = _entry_boot(framework)
316
+ for root, _dirs, files in os.walk(project_root):
317
+ for fname in files:
318
+ if fname not in entry_names:
319
+ continue
320
+ fp = os.path.join(root, fname)
321
+ try:
322
+ with open(fp, "r", encoding="utf-8", errors="ignore") as f:
323
+ orig = f.read()
324
+ # keep a shebang on line 1 if present
325
+ if orig.startswith("#!"):
326
+ nl = orig.find("\n") + 1
327
+ new = orig[:nl] + boot + orig[nl:]
328
+ else:
329
+ new = boot + orig
330
+ # never emit a file that no longer compiles (e.g. leading
331
+ # __future__ import) — fall back to the original untouched.
332
+ compile(new, fp, "exec")
333
+ with open(fp, "w", encoding="utf-8") as f:
334
+ f.write(new)
335
+ except Exception:
336
+ pass
337
+
288
338
  return {"lines": total_lines, "files": file_count}
@@ -300,9 +300,16 @@ def encrypt_local(
300
300
  protection: Optional[Dict[str, Any]] = None,
301
301
  version: str = "",
302
302
  loaders_dir: Optional[str] = None,
303
+ bill_members: Optional[set] = None,
303
304
  on_status=None,
304
305
  ) -> Dict[str, Any]:
305
- """Encrypt `zip_path` locally; contact `base_url` only to authorize + meter."""
306
+ """Encrypt `zip_path` locally; contact `base_url` only to authorize + meter.
307
+
308
+ Incremental billing: when `bill_members` is given (the set of changed source
309
+ files, relative to the zip root), only those lines are authorized and charged.
310
+ The whole project is still re-encrypted locally — that is free CPU and keeps a
311
+ single per-job key so every file decrypts — but you only pay for what changed.
312
+ """
306
313
  framework = (framework or "odoo").lower()
307
314
  protection = protection or {}
308
315
  say = on_status or (lambda *_: None)
@@ -328,6 +335,21 @@ def encrypt_local(
328
335
  if est_lines <= 0:
329
336
  raise LocalError("No encryptable Python files found.")
330
337
 
338
+ # Incremental: meter only the changed encryptable files.
339
+ if bill_members is not None:
340
+ skip = engine.FRAMEWORK_SKIP_ENCRYPT.get(framework, set())
341
+ changed_lines = 0
342
+ for m in bill_members:
343
+ if not m.endswith(".py") or os.path.basename(m) in skip:
344
+ continue
345
+ fp = os.path.join(extract, m)
346
+ if os.path.isfile(fp):
347
+ with open(fp, "r", encoding="utf-8", errors="ignore") as f:
348
+ changed_lines += sum(1 for _ in f)
349
+ bill_lines = max(1, changed_lines)
350
+ else:
351
+ bill_lines = est_lines
352
+
331
353
  # 2) authorize online; if the platform is unreachable, fall back to a
332
354
  # cached signed offline grant so encryption never stops.
333
355
  say("authorize")
@@ -337,7 +359,7 @@ def encrypt_local(
337
359
  try:
338
360
  r = _post_signed(
339
361
  base_url, "/api/authorize", secret,
340
- {"framework": framework, "version": version, "est_lines": est_lines,
362
+ {"framework": framework, "version": version, "est_lines": bill_lines,
341
363
  "client_pub": client_pub},
342
364
  )
343
365
  if r.status_code == 401:
@@ -360,7 +382,7 @@ def encrypt_local(
360
382
  "Platform unreachable and no offline grant cached. "
361
383
  "While online run: sitr offline fetch")
362
384
  say("offline")
363
- job_kek, wrapped = _offline_acquire(cache, est_lines)
385
+ job_kek, wrapped = _offline_acquire(cache, bill_lines)
364
386
  offline = True
365
387
 
366
388
  try:
@@ -389,7 +411,7 @@ def encrypt_local(
389
411
  say("commit")
390
412
  c = _post_signed(
391
413
  base_url, "/api/commit", secret,
392
- {"job_id": job_id, "actual_lines": stats["lines"],
414
+ {"job_id": job_id, "actual_lines": bill_lines,
393
415
  "module_name": os.path.basename(zip_path), "framework": framework,
394
416
  "version": version, "modules": stats.get("files")},
395
417
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sitrtech
3
- Version: 1.2.3
3
+ Version: 1.2.5
4
4
  Summary: SitrTech Python code encryption CLI — protect Odoo, Django, Flask, FastAPI and Tornado projects
5
5
  Author-email: SitrTech <info@sitrtech.com>
6
6
  License: Proprietary
File without changes
File without changes
File without changes