flyshell 1.6.1__tar.gz → 1.6.3__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 (92) hide show
  1. {flyshell-1.6.1/src/flyshell.egg-info → flyshell-1.6.3}/PKG-INFO +1 -1
  2. {flyshell-1.6.1 → flyshell-1.6.3}/src/flyshell/abstract/base_plugin.py +1 -1
  3. flyshell-1.6.3/src/flyshell/accounts/__init__.py +17 -0
  4. {flyshell-1.6.1 → flyshell-1.6.3}/src/flyshell/accounts/auth.py +1 -1
  5. {flyshell-1.6.1 → flyshell-1.6.3}/src/flyshell/builtin/fs.py +3 -4
  6. {flyshell-1.6.1 → flyshell-1.6.3}/src/flyshell/builtin/pkg.py +5 -5
  7. {flyshell-1.6.1 → flyshell-1.6.3}/src/flyshell/builtin/utils.py +1 -1
  8. {flyshell-1.6.1 → flyshell-1.6.3}/src/flyshell/constants.py +22 -7
  9. {flyshell-1.6.1 → flyshell-1.6.3}/src/flyshell/core/console.py +4 -5
  10. {flyshell-1.6.1 → flyshell-1.6.3}/src/flyshell/core/directory.py +4 -6
  11. flyshell-1.6.3/src/flyshell/data/__init__.py +49 -0
  12. flyshell-1.6.3/src/flyshell/data/auth.py +46 -0
  13. flyshell-1.6.3/src/flyshell/data/config.py +45 -0
  14. flyshell-1.6.3/src/flyshell/data/db_manager.py +85 -0
  15. flyshell-1.6.3/src/flyshell/data/env.py +91 -0
  16. flyshell-1.6.3/src/flyshell/data/history.py +42 -0
  17. flyshell-1.6.3/src/flyshell/data/plugins.py +105 -0
  18. flyshell-1.6.3/src/flyshell/main.py +47 -0
  19. flyshell-1.6.3/src/flyshell/misc/__init__.py +7 -0
  20. {flyshell-1.6.1/src/flyshell/startup → flyshell-1.6.3/src/flyshell/misc}/seasonal.py +1 -1
  21. flyshell-1.6.3/src/flyshell/pkgm/__init__.py +35 -0
  22. flyshell-1.6.3/src/flyshell/pkgm/inspection.py +51 -0
  23. flyshell-1.6.1/src/flyshell/startup/env.py → flyshell-1.6.3/src/flyshell/pkgm/keys.py +46 -94
  24. {flyshell-1.6.1/src/flyshell/startup → flyshell-1.6.3/src/flyshell/pkgm}/loader.py +7 -65
  25. flyshell-1.6.3/src/flyshell/startup/__init__.py +18 -0
  26. flyshell-1.6.3/src/flyshell/startup/boot.py +21 -0
  27. flyshell-1.6.3/src/flyshell/startup/checks.py +90 -0
  28. {flyshell-1.6.1 → flyshell-1.6.3/src/flyshell.egg-info}/PKG-INFO +1 -1
  29. {flyshell-1.6.1 → flyshell-1.6.3}/src/flyshell.egg-info/SOURCES.txt +15 -5
  30. flyshell-1.6.3/tests/test_auth.py +30 -0
  31. {flyshell-1.6.1 → flyshell-1.6.3}/tests/test_data.py +2 -1
  32. {flyshell-1.6.1 → flyshell-1.6.3}/tests/test_deps.py +12 -12
  33. {flyshell-1.6.1 → flyshell-1.6.3}/tests/test_env.py +18 -19
  34. {flyshell-1.6.1 → flyshell-1.6.3}/tests/test_loader.py +11 -11
  35. {flyshell-1.6.1 → flyshell-1.6.3}/tests/test_utils.py +1 -1
  36. flyshell-1.6.1/src/flyshell/core/data.py +0 -300
  37. flyshell-1.6.1/src/flyshell/main.py +0 -140
  38. flyshell-1.6.1/src/flyshell/native/legacy/__init__.py +0 -0
  39. flyshell-1.6.1/src/flyshell/startup/__init__.py +0 -0
  40. flyshell-1.6.1/src/flyshell/startup/deps.py +0 -24
  41. flyshell-1.6.1/tests/test_auth.py +0 -30
  42. {flyshell-1.6.1 → flyshell-1.6.3}/LICENSE +0 -0
  43. {flyshell-1.6.1 → flyshell-1.6.3}/MANIFEST.in +0 -0
  44. {flyshell-1.6.1 → flyshell-1.6.3}/README.md +0 -0
  45. {flyshell-1.6.1 → flyshell-1.6.3}/c_src/diskops/diskops.c +0 -0
  46. {flyshell-1.6.1 → flyshell-1.6.3}/c_src/diskops/posix/cat.c +0 -0
  47. {flyshell-1.6.1 → flyshell-1.6.3}/c_src/diskops/posix/cp.c +0 -0
  48. {flyshell-1.6.1 → flyshell-1.6.3}/c_src/diskops/posix/dir.c +0 -0
  49. {flyshell-1.6.1 → flyshell-1.6.3}/c_src/diskops/posix/mkdir.c +0 -0
  50. {flyshell-1.6.1 → flyshell-1.6.3}/c_src/diskops/posix/mv.c +0 -0
  51. {flyshell-1.6.1 → flyshell-1.6.3}/c_src/diskops/posix/rename.c +0 -0
  52. {flyshell-1.6.1 → flyshell-1.6.3}/c_src/diskops/posix/rm.c +0 -0
  53. {flyshell-1.6.1 → flyshell-1.6.3}/c_src/diskops/posix/rmdir.c +0 -0
  54. {flyshell-1.6.1 → flyshell-1.6.3}/c_src/diskops/posix/touch.c +0 -0
  55. {flyshell-1.6.1 → flyshell-1.6.3}/c_src/diskops/shared/dir_types.c +0 -0
  56. {flyshell-1.6.1 → flyshell-1.6.3}/c_src/diskops/shared/dir_types.h +0 -0
  57. {flyshell-1.6.1 → flyshell-1.6.3}/c_src/diskops/shared/native_errors.h +0 -0
  58. {flyshell-1.6.1 → flyshell-1.6.3}/c_src/diskops/shared/win32_utf.h +0 -0
  59. {flyshell-1.6.1 → flyshell-1.6.3}/c_src/diskops/win32/cat.c +0 -0
  60. {flyshell-1.6.1 → flyshell-1.6.3}/c_src/diskops/win32/cp.c +0 -0
  61. {flyshell-1.6.1 → flyshell-1.6.3}/c_src/diskops/win32/dir.c +0 -0
  62. {flyshell-1.6.1 → flyshell-1.6.3}/c_src/diskops/win32/mkdir.c +0 -0
  63. {flyshell-1.6.1 → flyshell-1.6.3}/c_src/diskops/win32/mv.c +0 -0
  64. {flyshell-1.6.1 → flyshell-1.6.3}/c_src/diskops/win32/rename.c +0 -0
  65. {flyshell-1.6.1 → flyshell-1.6.3}/c_src/diskops/win32/rm.c +0 -0
  66. {flyshell-1.6.1 → flyshell-1.6.3}/c_src/diskops/win32/rmdir.c +0 -0
  67. {flyshell-1.6.1 → flyshell-1.6.3}/c_src/diskops/win32/touch.c +0 -0
  68. {flyshell-1.6.1 → flyshell-1.6.3}/pyproject.toml +0 -0
  69. {flyshell-1.6.1 → flyshell-1.6.3}/setup.cfg +0 -0
  70. {flyshell-1.6.1 → flyshell-1.6.3}/setup.py +0 -0
  71. {flyshell-1.6.1 → flyshell-1.6.3}/src/flyshell/__init__.py +0 -0
  72. {flyshell-1.6.1 → flyshell-1.6.3}/src/flyshell/abstract/__init__.py +0 -0
  73. {flyshell-1.6.1 → flyshell-1.6.3}/src/flyshell/abstract/base_cmd.py +0 -0
  74. {flyshell-1.6.1 → flyshell-1.6.3}/src/flyshell/abstract/parent_cmd.py +0 -0
  75. {flyshell-1.6.1/src/flyshell/accounts → flyshell-1.6.3/src/flyshell/bin}/__init__.py +0 -0
  76. {flyshell-1.6.1/src/flyshell/bin → flyshell-1.6.3/src/flyshell/builtin}/__init__.py +0 -0
  77. {flyshell-1.6.1 → flyshell-1.6.3}/src/flyshell/builtin/system.py +0 -0
  78. {flyshell-1.6.1/src/flyshell/builtin → flyshell-1.6.3/src/flyshell/core}/__init__.py +0 -0
  79. {flyshell-1.6.1/src/flyshell/core → flyshell-1.6.3/src/flyshell/native}/__init__.py +0 -0
  80. {flyshell-1.6.1 → flyshell-1.6.3}/src/flyshell/native/diskops_bridge.py +0 -0
  81. {flyshell-1.6.1 → flyshell-1.6.3}/src/flyshell/native/diskops_handler.py +0 -0
  82. {flyshell-1.6.1/src/flyshell/native → flyshell-1.6.3/src/flyshell/native/legacy}/__init__.py +0 -0
  83. {flyshell-1.6.1 → flyshell-1.6.3}/src/flyshell/native/legacy/diskops.py +0 -0
  84. {flyshell-1.6.1 → flyshell-1.6.3}/src/flyshell.egg-info/dependency_links.txt +0 -0
  85. {flyshell-1.6.1 → flyshell-1.6.3}/src/flyshell.egg-info/entry_points.txt +0 -0
  86. {flyshell-1.6.1 → flyshell-1.6.3}/src/flyshell.egg-info/requires.txt +0 -0
  87. {flyshell-1.6.1 → flyshell-1.6.3}/src/flyshell.egg-info/top_level.txt +0 -0
  88. {flyshell-1.6.1 → flyshell-1.6.3}/tests/test_directory.py +0 -0
  89. {flyshell-1.6.1 → flyshell-1.6.3}/tests/test_diskops_ext.py +0 -0
  90. {flyshell-1.6.1 → flyshell-1.6.3}/tests/test_diskops_lgc.py +0 -0
  91. {flyshell-1.6.1 → flyshell-1.6.3}/tests/test_fs.py +0 -0
  92. {flyshell-1.6.1 → flyshell-1.6.3}/tests/test_pkg.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flyshell
3
- Version: 1.6.1
3
+ Version: 1.6.3
4
4
  Summary: A modular, zero-dependency command-line environment in Python.
5
5
  License-Expression: MIT
6
6
  Requires-Python: >=3.10
@@ -1,6 +1,6 @@
1
1
  # src/flyshell/abstract/base_plugin.py
2
2
 
3
- from flyshell.core import data
3
+ from flyshell import data
4
4
 
5
5
  from pathlib import Path
6
6
  from typing import Any, Optional
@@ -0,0 +1,17 @@
1
+ # src/flyshell/accounts/__init__.py
2
+
3
+ from flyshell.accounts.auth import (
4
+ Lock,
5
+ hash_password,
6
+ login_flow,
7
+ setup_acc,
8
+ verify_password,
9
+ )
10
+
11
+ __all__ = [
12
+ "Lock",
13
+ "hash_password",
14
+ "login_flow",
15
+ "setup_acc",
16
+ "verify_password",
17
+ ]
@@ -1,7 +1,7 @@
1
1
  # src/flyshell/accounts/auth.py
2
2
 
3
+ from flyshell import data
3
4
  from flyshell.abstract.base_cmd import BaseCmd
4
- from flyshell.core import data
5
5
 
6
6
  import getpass
7
7
  import hashlib
@@ -1,10 +1,9 @@
1
1
  # src/flyshell/builtin/fs.py
2
2
 
3
3
  from flyshell import constants as c
4
+ from flyshell import data, misc
4
5
  from flyshell.abstract.base_cmd import BaseCmd
5
6
  from flyshell.abstract.parent_cmd import ParentCmd
6
- from flyshell.core import data
7
- from flyshell.startup import seasonal
8
7
 
9
8
  import os
10
9
  import sys
@@ -148,10 +147,10 @@ class FsSeason(BaseCmd):
148
147
  aliases = []
149
148
 
150
149
  def execute(self, args: list[str]) -> tuple[int, str]:
151
- season = seasonal.get_season(return_icons=False)
150
+ season = misc.get_season(return_icons=False)
152
151
  if not season:
153
152
  return (0, "\nNo seasonal modes are active at present.\n")
154
- icon = seasonal.get_season(return_icons=True)
153
+ icon = misc.get_season(return_icons=True)
155
154
  return (0, f"\nCurrent seasonal mode: {season} {icon}\n")
156
155
 
157
156
 
@@ -1,9 +1,9 @@
1
1
  # src/flyshell/builtin/pkg.py
2
2
 
3
3
  from typing import List, Tuple
4
+ from flyshell import pkgm
4
5
  from flyshell.abstract.base_cmd import BaseCmd
5
6
  from flyshell.abstract.parent_cmd import ParentCmd
6
- from flyshell.startup import env
7
7
 
8
8
 
9
9
  class PkgApi(BaseCmd):
@@ -26,7 +26,7 @@ class PkgApi(BaseCmd):
26
26
  plugin_name = remaining_args[0]
27
27
  key_name = remaining_args[1]
28
28
  val = " ".join(remaining_args[2:])
29
- code, output = env.set_plugin_api_key(plugin_name, key_name, val)
29
+ code, output = pkgm.set_plugin_api_key(plugin_name, key_name, val)
30
30
  return (code, f"\n{output}\n")
31
31
  case "del" | "rm":
32
32
  if len(remaining_args) < 2:
@@ -36,14 +36,14 @@ class PkgApi(BaseCmd):
36
36
  )
37
37
  plugin_name = remaining_args[0]
38
38
  key_name = remaining_args[1]
39
- code, output = env.remove_plugin_api_key(plugin_name, key_name)
39
+ code, output = pkgm.remove_plugin_api_key(plugin_name, key_name)
40
40
  return (code, f"\n{output}\n")
41
41
  case "view":
42
42
  if not remaining_args:
43
- code, output = env.get_all_keys()
43
+ code, output = pkgm.get_all_keys()
44
44
  else:
45
45
  package_name = remaining_args[0]
46
- code, output = env.get_plugin_keys_formatted(package_name)
46
+ code, output = pkgm.get_plugin_keys_formatted(package_name)
47
47
  return (code, f"\n{output}\n")
48
48
  case _:
49
49
  return (1, f"\nCommand Error: Unknown target '{arg}'\n")
@@ -1,8 +1,8 @@
1
1
  # src/flyshell/builtin/utils.py
2
2
 
3
3
  from flyshell import constants as c
4
+ from flyshell import data
4
5
  from flyshell.abstract.base_cmd import BaseCmd
5
- from flyshell.core import data
6
6
 
7
7
  import codecs
8
8
  import os
@@ -5,9 +5,9 @@ import os
5
5
  import platform
6
6
  import time
7
7
 
8
- BUILD = 211
9
- VERFULL = "1.6.1e"
10
- VERSION = "1.6.1"
8
+ BUILD = 219
9
+ VERFULL = "1.6.3d"
10
+ VERSION = "1.6.3"
11
11
 
12
12
 
13
13
  def _resolve_app_dir() -> Path:
@@ -35,6 +35,7 @@ SESSION_START_TIME = time.time()
35
35
  SESSION_CMD_COUNT = 0
36
36
 
37
37
  PLUGINS = {}
38
+ RESERVED_NAMES: set[str] = set()
38
39
 
39
40
  SUPPORTED_OS = frozenset({"Windows", "Darwin", "Linux"})
40
41
  SUPPORTED_PYTHON = (3, 10)
@@ -64,21 +65,35 @@ REQUIRED_COMPONENTS = [
64
65
  "core",
65
66
  "core/__init__.py",
66
67
  "core/console.py",
67
- "core/data.py",
68
68
  "core/directory.py",
69
+ "data",
70
+ "data/__init__.py",
71
+ "data/auth.py",
72
+ "data/config.py",
73
+ "data/db_manager.py",
74
+ "data/env.py",
75
+ "data/history.py",
76
+ "data/plugins.py",
69
77
  "__init__.py",
70
78
  "main.py",
79
+ "misc",
80
+ "misc/__init__.py",
81
+ "misc/seasonal.py",
71
82
  "native",
72
83
  "native/__init__.py",
73
84
  "native/legacy/__init__.py",
74
85
  "native/legacy/diskops.py",
75
86
  "native/diskops_bridge.py",
76
87
  "native/diskops_handler.py",
88
+ "pkgm",
89
+ "pkgm/__init__.py",
90
+ "pkgm/inspection.py",
91
+ "pkgm/keys.py",
92
+ "pkgm/loader.py",
77
93
  "startup",
78
94
  "startup/__init__.py",
79
- "startup/deps.py",
80
- "startup/env.py",
81
- "startup/loader.py",
95
+ "startup/boot.py",
96
+ "startup/checks.py",
82
97
  ]
83
98
 
84
99
  GREETINGS = [
@@ -1,9 +1,8 @@
1
1
  # src/flyshell/core/console.py
2
2
 
3
3
  from flyshell import constants as c
4
- from flyshell.core import data
4
+ from flyshell import data, misc
5
5
  from flyshell.core.directory import execute_line
6
- from flyshell.startup import env, seasonal
7
6
 
8
7
  import os
9
8
  import random
@@ -39,9 +38,9 @@ def load_history() -> None:
39
38
 
40
39
  def boot() -> None:
41
40
  load_history()
42
- env.create_env()
41
+ data.create_env()
43
42
  print(c.CLEAR_SCREEN, end="")
44
- icon = seasonal.get_season(return_icons=True)
43
+ icon = misc.get_season(return_icons=True)
45
44
  badge = f" {icon}" if icon else ""
46
45
  print(f"\nBoot successful, welcome to Flyshell! (Version {c.VERSION}){badge}")
47
46
  user_info = data.get_auth() or {}
@@ -51,7 +50,7 @@ def boot() -> None:
51
50
  while True:
52
51
  try:
53
52
  folder = os.path.basename(os.getcwd())
54
- icon = seasonal.get_season(return_icons=True)
53
+ icon = misc.get_season(return_icons=True)
55
54
  badge = f" {icon}" if icon else ""
56
55
  print(f"Flyshell [v{c.VERSION}]{badge} ({folder})>>", end="", flush=True)
57
56
  raw_cmd = input()
@@ -1,13 +1,11 @@
1
1
  # src/flyshell/core/directory.py
2
2
 
3
3
  from flyshell import constants as c
4
+ from flyshell import accounts, data, pkgm
4
5
  from flyshell.abstract.base_cmd import BaseCmd
5
6
  from flyshell.abstract.parent_cmd import ParentCmd
6
- from flyshell.accounts import auth
7
7
  from flyshell.builtin import fs, pkg, system, utils
8
- from flyshell.core import data
9
8
  from flyshell.native import diskops_handler as diskops
10
- from flyshell.startup import deps
11
9
 
12
10
  from datetime import datetime, timezone
13
11
  import copy
@@ -64,7 +62,7 @@ INSTALLED_COMMANDS: list[BaseCmd] = [
64
62
  fs.Fs(),
65
63
  utils.History(),
66
64
  utils.Kill(),
67
- auth.Lock(),
65
+ accounts.Lock(),
68
66
  diskops.MkDir(),
69
67
  diskops.Move(),
70
68
  system.OpenFile(),
@@ -84,7 +82,7 @@ for cmd_obj in INSTALLED_COMMANDS:
84
82
  for alias_name in cmd_obj.aliases:
85
83
  COMMAND_REGISTRY[alias_name] = cmd_obj
86
84
 
87
- RESERVED_NAMES = set(COMMAND_REGISTRY.keys())
85
+ c.RESERVED_NAMES = set(COMMAND_REGISTRY.keys())
88
86
 
89
87
 
90
88
  def log(cmd: str) -> None:
@@ -176,7 +174,7 @@ def _execute_single(raw_cmd: str) -> int:
176
174
  )
177
175
  print(f"Define them in {env_path} and retry.\n")
178
176
  return 1
179
- _, missing_deps = deps.verify_plugin_dependencies(plugin)
177
+ _, missing_deps = pkgm.verify_plugin_dependencies(plugin)
180
178
  if missing_deps:
181
179
  print(
182
180
  f"\nPlugin Error: Cannot execute '{cmd_name}'. Missing dependency/dependencies: {', '.join(missing_deps)}"
@@ -0,0 +1,49 @@
1
+ # src/flyshell/data/__init__.py
2
+
3
+ from flyshell.data.auth import clear_auth, get_auth, set_auth
4
+ from flyshell.data.config import delete_config, get_config, set_config
5
+ from flyshell.data.db_manager import get_connection, get_storage_size, initialise
6
+ from flyshell.data.env import (
7
+ create_env,
8
+ delete_env_entry,
9
+ get_env_path,
10
+ read_env_file,
11
+ set_env_entry,
12
+ )
13
+ from flyshell.data.history import append_history, clear_history, get_history
14
+ from flyshell.data.plugins import (
15
+ delete_plugin_data,
16
+ get_all_plugin_data,
17
+ get_plugin_data,
18
+ purge_all_plugin_data,
19
+ purge_plugin,
20
+ register_plugin,
21
+ set_plugin_data,
22
+ )
23
+
24
+ __all__ = [
25
+ "append_history",
26
+ "clear_auth",
27
+ "clear_history",
28
+ "create_env",
29
+ "delete_config",
30
+ "delete_env_entry",
31
+ "delete_plugin_data",
32
+ "get_all_plugin_data",
33
+ "get_auth",
34
+ "get_config",
35
+ "get_connection",
36
+ "get_env_path",
37
+ "get_history",
38
+ "get_plugin_data",
39
+ "get_storage_size",
40
+ "initialise",
41
+ "purge_all_plugin_data",
42
+ "purge_plugin",
43
+ "read_env_file",
44
+ "register_plugin",
45
+ "set_auth",
46
+ "set_config",
47
+ "set_env_entry",
48
+ "set_plugin_data",
49
+ ]
@@ -0,0 +1,46 @@
1
+ # src/flyshell/data/auth.py
2
+
3
+ from flyshell.data import db_manager as db
4
+
5
+ from pathlib import Path
6
+ import time
7
+
8
+
9
+ def get_auth(filename: str | Path | None = None) -> dict | None:
10
+ db.initialise(filename)
11
+ with db.get_connection(filename) as conn:
12
+ row = conn.execute(
13
+ "SELECT username, hash, salt, created_at FROM auth WHERE id = 1"
14
+ ).fetchone()
15
+ if not row:
16
+ return None
17
+ return {
18
+ "username": row[0],
19
+ "hash": row[1],
20
+ "salt": row[2],
21
+ "created_at": row[3],
22
+ }
23
+
24
+
25
+ def set_auth(
26
+ username: str, pwd_hash: str, salt: str, filename: str | Path | None = None
27
+ ) -> None:
28
+ db.initialise(filename)
29
+ now_utc = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())
30
+ with db.get_connection(filename) as conn:
31
+ with conn:
32
+ conn.execute(
33
+ """
34
+ INSERT OR REPLACE INTO auth (id, username, hash, salt, created_at)
35
+ VALUES (1, ?, ?, ?, ?)
36
+ """,
37
+ (username, pwd_hash, salt, now_utc),
38
+ )
39
+
40
+
41
+ def clear_auth(filename: str | Path | None = None) -> bool:
42
+ db.initialise(filename)
43
+ with db.get_connection(filename) as conn:
44
+ with conn:
45
+ cursor = conn.execute("DELETE FROM auth WHERE id = 1")
46
+ return cursor.rowcount > 0
@@ -0,0 +1,45 @@
1
+ # src/flyshell/data/config.py
2
+
3
+ from flyshell.data import db_manager as db
4
+
5
+ from pathlib import Path
6
+ from typing import Any
7
+ import json
8
+
9
+
10
+ def get_config(
11
+ key: str, default: Any = None, filename: str | Path | None = None
12
+ ) -> Any:
13
+ db.initialise(filename)
14
+ with db.get_connection(filename) as conn:
15
+ row = conn.execute(
16
+ "SELECT value FROM core_config WHERE key = ?", (key,)
17
+ ).fetchone()
18
+ if not row:
19
+ return default
20
+ try:
21
+ return json.loads(row[0])
22
+ except (ValueError, TypeError):
23
+ return row[0]
24
+
25
+
26
+ def set_config(key: str, value: Any, filename: str | Path | None = None) -> None:
27
+ db.initialise(filename)
28
+ serialized = json.dumps(value)
29
+ with db.get_connection(filename) as conn:
30
+ with conn:
31
+ conn.execute(
32
+ """
33
+ INSERT OR REPLACE INTO core_config (key, value)
34
+ VALUES (?, ?)
35
+ """,
36
+ (key, serialized),
37
+ )
38
+
39
+
40
+ def delete_config(key: str, filename: str | Path | None = None) -> bool:
41
+ db.initialise(filename)
42
+ with db.get_connection(filename) as conn:
43
+ with conn:
44
+ cursor = conn.execute("DELETE FROM core_config WHERE key = ?", (key,))
45
+ return cursor.rowcount > 0
@@ -0,0 +1,85 @@
1
+ # src/flyshell/data/db_manager.py
2
+
3
+ from flyshell import constants as c
4
+
5
+ from pathlib import Path
6
+ import sqlite3
7
+
8
+
9
+ def get_storage_size(filename: str | Path | None = None) -> str:
10
+ target = Path(filename) if filename is not None else c.FILE_PATH
11
+ if not target.exists():
12
+ return "File not found"
13
+ num_bytes = float(target.stat().st_size)
14
+ for unit in ["B", "KB", "MB", "GB"]:
15
+ if num_bytes < 1024.0:
16
+ return (
17
+ f"{int(num_bytes)} {unit}" if unit == "B" else f"{num_bytes:.2f} {unit}"
18
+ )
19
+ num_bytes /= 1024.0
20
+ return f"{num_bytes:.2f} TB"
21
+
22
+
23
+ def get_connection(filename: str | Path | None = None) -> sqlite3.Connection:
24
+ target = Path(filename) if filename is not None else c.FILE_PATH
25
+ if str(target) != ":memory:":
26
+ target.parent.mkdir(parents=True, exist_ok=True)
27
+ conn = sqlite3.connect(target)
28
+ conn.execute("PRAGMA foreign_keys = ON;")
29
+ return conn
30
+
31
+
32
+ def initialise(
33
+ filename: str | Path | None = None, initialised: set[str] | None = None
34
+ ) -> None:
35
+ target = filename if filename is not None else c.FILE_PATH
36
+ if initialised is None:
37
+ initialised = c.INITIALISED
38
+ target = str(target)
39
+ if target in initialised:
40
+ return
41
+ with get_connection(filename) as conn:
42
+ conn.execute("PRAGMA foreign_keys = ON;")
43
+ current_version = conn.execute("PRAGMA user_version;").fetchone()[0]
44
+ if current_version == 0:
45
+ with conn:
46
+ conn.execute("""
47
+ CREATE TABLE IF NOT EXISTS auth (
48
+ id INTEGER PRIMARY KEY CHECK (id = 1),
49
+ username TEXT NOT NULL,
50
+ hash TEXT NOT NULL,
51
+ salt TEXT NOT NULL,
52
+ created_at TEXT NOT NULL
53
+ );
54
+ """)
55
+ conn.execute("""
56
+ CREATE TABLE IF NOT EXISTS cmd_history (
57
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
58
+ command TEXT NOT NULL,
59
+ timestamp TEXT NOT NULL
60
+ );
61
+ """)
62
+ conn.execute("""
63
+ CREATE TABLE IF NOT EXISTS core_config (
64
+ key TEXT PRIMARY KEY,
65
+ value TEXT NOT NULL
66
+ );
67
+ """)
68
+ conn.execute("""
69
+ CREATE TABLE IF NOT EXISTS plugins (
70
+ plugin_name TEXT PRIMARY KEY,
71
+ installed_at TEXT NOT NULL,
72
+ is_enabled INTEGER NOT NULL DEFAULT 1
73
+ );
74
+ """)
75
+ conn.execute("""
76
+ CREATE TABLE IF NOT EXISTS plugin_kv (
77
+ plugin_name TEXT NOT NULL,
78
+ key TEXT NOT NULL,
79
+ value TEXT NOT NULL,
80
+ PRIMARY KEY (plugin_name, key),
81
+ FOREIGN KEY (plugin_name) REFERENCES plugins(plugin_name) ON DELETE CASCADE
82
+ );
83
+ """)
84
+ conn.execute("PRAGMA user_version = 1;")
85
+ initialised.add(target)
@@ -0,0 +1,91 @@
1
+ # src/flyshell/data/env.py
2
+
3
+ from pathlib import Path
4
+ from flyshell import constants as c
5
+
6
+
7
+ def get_env_path() -> Path:
8
+ primary = c.APP_DIR / "flyshell_keys.env"
9
+ if primary.exists():
10
+ return primary
11
+ fallback = c.APP_DIR / ".env"
12
+ if fallback.exists():
13
+ return fallback
14
+ return primary
15
+
16
+
17
+ def create_env() -> None:
18
+ env_path = get_env_path()
19
+ if not env_path.exists():
20
+ env_path.touch()
21
+
22
+
23
+ def read_env_file() -> dict[str, str]:
24
+ env_path = get_env_path()
25
+ if not env_path.exists():
26
+ return {}
27
+ entries = {}
28
+ with open(env_path, "r", encoding="utf-8") as f:
29
+ for line in f:
30
+ line = line.strip()
31
+ if not line or line.startswith("#") or "=" not in line:
32
+ continue
33
+ raw_k, raw_v = line.split("=", 1)
34
+ clean_k = raw_k.strip()
35
+ clean_v = raw_v.strip().strip("\"'")
36
+ if clean_k:
37
+ entries[clean_k] = clean_v
38
+ return entries
39
+
40
+
41
+ def set_env_entry(key: str, value: str) -> tuple[bool, str]:
42
+ clean_val = value.strip().strip("\"'")
43
+ env_path = get_env_path()
44
+ try:
45
+ env_path.parent.mkdir(parents=True, exist_ok=True)
46
+ if not env_path.exists():
47
+ env_path.touch()
48
+ lines = env_path.read_text(encoding="utf-8").splitlines()
49
+ updated = False
50
+ new_lines = []
51
+ for line in lines:
52
+ stripped = line.strip()
53
+ if stripped and not stripped.startswith("#") and "=" in stripped:
54
+ k, _ = stripped.split("=", 1)
55
+ clean_k = k.strip().replace("[", "").replace("]", "")
56
+ if clean_k.lower() == key.lower():
57
+ new_lines.append(f"{key}={clean_val}")
58
+ updated = True
59
+ continue
60
+ new_lines.append(line)
61
+ if not updated:
62
+ new_lines.append(f"{key}={clean_val}")
63
+ env_path.write_text("\n".join(new_lines) + "\n", encoding="utf-8")
64
+ return (True, "Updated" if updated else "Added")
65
+ except Exception as e:
66
+ return (False, f"File Error: Failed to write to '{env_path}': {e}")
67
+
68
+
69
+ def delete_env_entry(key: str) -> tuple[bool, str]:
70
+ env_path = get_env_path()
71
+ if not env_path.exists():
72
+ return (False, f"File Config Error: Environment file not found at '{env_path}'")
73
+ try:
74
+ lines = env_path.read_text(encoding="utf-8").splitlines()
75
+ new_lines = []
76
+ found = False
77
+ for line in lines:
78
+ stripped = line.strip()
79
+ if stripped and not stripped.startswith("#") and "=" in stripped:
80
+ k, _ = stripped.split("=", 1)
81
+ clean_k = k.strip().lower()
82
+ if clean_k == key.lower():
83
+ found = True
84
+ continue
85
+ new_lines.append(line)
86
+ if not found:
87
+ return (False, f"Command Error: Key '{key}' not found in '{env_path.name}'")
88
+ env_path.write_text("\n".join(new_lines) + "\n", encoding="utf-8")
89
+ return (True, env_path.name)
90
+ except Exception as e:
91
+ return (False, f"File Error: Failed to update '{env_path}': {e}")
@@ -0,0 +1,42 @@
1
+ # src/flyshell/data/history.py
2
+
3
+ from flyshell.data import db_manager as db
4
+
5
+ from pathlib import Path
6
+
7
+
8
+ def append_history(
9
+ cmd: str, timestamp: str, filename: str | Path | None = None
10
+ ) -> None:
11
+ db.initialise(filename)
12
+ with db.get_connection(filename) as conn:
13
+ with conn:
14
+ conn.execute(
15
+ "INSERT INTO cmd_history (command, timestamp) VALUES (?, ?)",
16
+ (cmd, timestamp),
17
+ )
18
+
19
+
20
+ def get_history(
21
+ limit: int | None = None, filename: str | Path | None = None
22
+ ) -> list[dict]:
23
+ db.initialise(filename)
24
+ with db.get_connection(filename) as conn:
25
+ if limit is not None and limit > 0:
26
+ query = (
27
+ "SELECT command, timestamp FROM cmd_history ORDER BY id DESC LIMIT ?"
28
+ )
29
+ rows = conn.execute(query, (limit,)).fetchall()
30
+ rows.reverse()
31
+ else:
32
+ query = "SELECT command, timestamp FROM cmd_history ORDER BY id ASC"
33
+ rows = conn.execute(query).fetchall()
34
+ return [{"command": r[0], "timestamp": r[1]} for r in rows]
35
+
36
+
37
+ def clear_history(filename: str | Path | None = None) -> bool:
38
+ db.initialise(filename)
39
+ with db.get_connection(filename) as conn:
40
+ with conn:
41
+ conn.execute("DELETE FROM cmd_history")
42
+ return True