flyshell 1.6.0__tar.gz → 1.6.2__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.
- {flyshell-1.6.0/src/flyshell.egg-info → flyshell-1.6.2}/PKG-INFO +1 -1
- {flyshell-1.6.0 → flyshell-1.6.2}/src/flyshell/abstract/base_plugin.py +1 -1
- {flyshell-1.6.0 → flyshell-1.6.2}/src/flyshell/accounts/auth.py +1 -1
- {flyshell-1.6.0 → flyshell-1.6.2}/src/flyshell/builtin/fs.py +1 -1
- {flyshell-1.6.0 → flyshell-1.6.2}/src/flyshell/builtin/pkg.py +5 -5
- {flyshell-1.6.0 → flyshell-1.6.2}/src/flyshell/builtin/utils.py +1 -1
- {flyshell-1.6.0 → flyshell-1.6.2}/src/flyshell/constants.py +12 -7
- {flyshell-1.6.0 → flyshell-1.6.2}/src/flyshell/core/console.py +3 -3
- {flyshell-1.6.0 → flyshell-1.6.2}/src/flyshell/core/directory.py +1 -1
- flyshell-1.6.2/src/flyshell/data/__init__.py +49 -0
- flyshell-1.6.2/src/flyshell/data/auth.py +46 -0
- flyshell-1.6.2/src/flyshell/data/config.py +45 -0
- flyshell-1.6.2/src/flyshell/data/db_manager.py +85 -0
- flyshell-1.6.2/src/flyshell/data/env.py +91 -0
- flyshell-1.6.2/src/flyshell/data/history.py +42 -0
- flyshell-1.6.2/src/flyshell/data/plugins.py +105 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/src/flyshell/main.py +6 -1
- flyshell-1.6.0/src/flyshell/startup/env.py → flyshell-1.6.2/src/flyshell/startup/deps.py +35 -92
- {flyshell-1.6.0 → flyshell-1.6.2}/src/flyshell/startup/loader.py +4 -4
- {flyshell-1.6.0 → flyshell-1.6.2/src/flyshell.egg-info}/PKG-INFO +1 -1
- {flyshell-1.6.0 → flyshell-1.6.2}/src/flyshell.egg-info/SOURCES.txt +7 -2
- flyshell-1.6.2/tests/test_data.py +96 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/tests/test_deps.py +22 -22
- flyshell-1.6.2/tests/test_directory.py +106 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/tests/test_diskops_ext.py +219 -85
- {flyshell-1.6.0 → flyshell-1.6.2}/tests/test_diskops_lgc.py +135 -51
- flyshell-1.6.2/tests/test_env.py +255 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/tests/test_fs.py +12 -9
- {flyshell-1.6.0 → flyshell-1.6.2}/tests/test_loader.py +41 -11
- flyshell-1.6.2/tests/test_pkg.py +33 -0
- flyshell-1.6.2/tests/test_utils.py +57 -0
- flyshell-1.6.0/src/flyshell/core/data.py +0 -300
- flyshell-1.6.0/src/flyshell/startup/deps.py +0 -24
- flyshell-1.6.0/tests/test_data.py +0 -76
- flyshell-1.6.0/tests/test_directory.py +0 -75
- flyshell-1.6.0/tests/test_env.py +0 -202
- flyshell-1.6.0/tests/test_pkg.py +0 -50
- flyshell-1.6.0/tests/test_utils.py +0 -87
- {flyshell-1.6.0 → flyshell-1.6.2}/LICENSE +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/MANIFEST.in +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/README.md +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/c_src/diskops/diskops.c +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/c_src/diskops/posix/cat.c +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/c_src/diskops/posix/cp.c +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/c_src/diskops/posix/dir.c +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/c_src/diskops/posix/mkdir.c +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/c_src/diskops/posix/mv.c +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/c_src/diskops/posix/rename.c +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/c_src/diskops/posix/rm.c +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/c_src/diskops/posix/rmdir.c +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/c_src/diskops/posix/touch.c +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/c_src/diskops/shared/dir_types.c +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/c_src/diskops/shared/dir_types.h +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/c_src/diskops/shared/native_errors.h +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/c_src/diskops/shared/win32_utf.h +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/c_src/diskops/win32/cat.c +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/c_src/diskops/win32/cp.c +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/c_src/diskops/win32/dir.c +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/c_src/diskops/win32/mkdir.c +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/c_src/diskops/win32/mv.c +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/c_src/diskops/win32/rename.c +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/c_src/diskops/win32/rm.c +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/c_src/diskops/win32/rmdir.c +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/c_src/diskops/win32/touch.c +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/pyproject.toml +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/setup.cfg +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/setup.py +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/src/flyshell/__init__.py +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/src/flyshell/abstract/__init__.py +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/src/flyshell/abstract/base_cmd.py +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/src/flyshell/abstract/parent_cmd.py +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/src/flyshell/accounts/__init__.py +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/src/flyshell/bin/__init__.py +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/src/flyshell/builtin/__init__.py +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/src/flyshell/builtin/system.py +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/src/flyshell/core/__init__.py +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/src/flyshell/native/__init__.py +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/src/flyshell/native/diskops_bridge.py +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/src/flyshell/native/diskops_handler.py +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/src/flyshell/native/legacy/__init__.py +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/src/flyshell/native/legacy/diskops.py +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/src/flyshell/startup/__init__.py +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/src/flyshell/startup/seasonal.py +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/src/flyshell.egg-info/dependency_links.txt +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/src/flyshell.egg-info/entry_points.txt +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/src/flyshell.egg-info/requires.txt +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/src/flyshell.egg-info/top_level.txt +0 -0
- {flyshell-1.6.0 → flyshell-1.6.2}/tests/test_auth.py +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# src/flyshell/builtin/fs.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
6
|
from flyshell.abstract.parent_cmd import ParentCmd
|
|
6
|
-
from flyshell.core import data
|
|
7
7
|
from flyshell.startup import seasonal
|
|
8
8
|
|
|
9
9
|
import os
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
from typing import List, Tuple
|
|
4
4
|
from flyshell.abstract.base_cmd import BaseCmd
|
|
5
5
|
from flyshell.abstract.parent_cmd import ParentCmd
|
|
6
|
-
from flyshell.startup import
|
|
6
|
+
from flyshell.startup import deps
|
|
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 =
|
|
29
|
+
code, output = deps.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 =
|
|
39
|
+
code, output = deps.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 =
|
|
43
|
+
code, output = deps.get_all_keys()
|
|
44
44
|
else:
|
|
45
45
|
package_name = remaining_args[0]
|
|
46
|
-
code, output =
|
|
46
|
+
code, output = deps.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")
|
|
@@ -5,9 +5,9 @@ import os
|
|
|
5
5
|
import platform
|
|
6
6
|
import time
|
|
7
7
|
|
|
8
|
-
BUILD =
|
|
9
|
-
VERFULL = "1.6.
|
|
10
|
-
VERSION = "1.6.
|
|
8
|
+
BUILD = 215
|
|
9
|
+
VERFULL = "1.6.2d"
|
|
10
|
+
VERSION = "1.6.2"
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
def _resolve_app_dir() -> Path:
|
|
@@ -36,8 +36,6 @@ SESSION_CMD_COUNT = 0
|
|
|
36
36
|
|
|
37
37
|
PLUGINS = {}
|
|
38
38
|
|
|
39
|
-
BLOCKED_COMMANDS = frozenset({"format", "diskpart", "dd"})
|
|
40
|
-
DANGER_COMMANDS = frozenset({"del", "rmdir", "rd", "rm", "taskkill", "killall"})
|
|
41
39
|
SUPPORTED_OS = frozenset({"Windows", "Darwin", "Linux"})
|
|
42
40
|
SUPPORTED_PYTHON = (3, 10)
|
|
43
41
|
|
|
@@ -66,8 +64,15 @@ REQUIRED_COMPONENTS = [
|
|
|
66
64
|
"core",
|
|
67
65
|
"core/__init__.py",
|
|
68
66
|
"core/console.py",
|
|
69
|
-
"core/data.py",
|
|
70
67
|
"core/directory.py",
|
|
68
|
+
"data",
|
|
69
|
+
"data/__init__.py",
|
|
70
|
+
"data/auth.py",
|
|
71
|
+
"data/config.py",
|
|
72
|
+
"data/db_manager.py",
|
|
73
|
+
"data/env.py",
|
|
74
|
+
"data/history.py",
|
|
75
|
+
"data/plugins.py",
|
|
71
76
|
"__init__.py",
|
|
72
77
|
"main.py",
|
|
73
78
|
"native",
|
|
@@ -79,8 +84,8 @@ REQUIRED_COMPONENTS = [
|
|
|
79
84
|
"startup",
|
|
80
85
|
"startup/__init__.py",
|
|
81
86
|
"startup/deps.py",
|
|
82
|
-
"startup/env.py",
|
|
83
87
|
"startup/loader.py",
|
|
88
|
+
"startup/seasonal.py",
|
|
84
89
|
]
|
|
85
90
|
|
|
86
91
|
GREETINGS = [
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# src/flyshell/core/console.py
|
|
2
2
|
|
|
3
3
|
from flyshell import constants as c
|
|
4
|
-
from flyshell
|
|
4
|
+
from flyshell import data
|
|
5
5
|
from flyshell.core.directory import execute_line
|
|
6
|
-
from flyshell.startup import
|
|
6
|
+
from flyshell.startup import seasonal
|
|
7
7
|
|
|
8
8
|
import os
|
|
9
9
|
import random
|
|
@@ -39,7 +39,7 @@ def load_history() -> None:
|
|
|
39
39
|
|
|
40
40
|
def boot() -> None:
|
|
41
41
|
load_history()
|
|
42
|
-
|
|
42
|
+
data.create_env()
|
|
43
43
|
print(c.CLEAR_SCREEN, end="")
|
|
44
44
|
icon = seasonal.get_season(return_icons=True)
|
|
45
45
|
badge = f" {icon}" if icon else ""
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# src/flyshell/core/directory.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
6
|
from flyshell.abstract.parent_cmd import ParentCmd
|
|
6
7
|
from flyshell.accounts import auth
|
|
7
8
|
from flyshell.builtin import fs, pkg, system, utils
|
|
8
|
-
from flyshell.core import data
|
|
9
9
|
from flyshell.native import diskops_handler as diskops
|
|
10
10
|
from flyshell.startup import deps
|
|
11
11
|
|
|
@@ -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
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# src/flyshell/data/plugins.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
|
+
import time
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def register_plugin(plugin_name: str, filename: str | Path | None = None) -> None:
|
|
12
|
+
db.initialise(filename)
|
|
13
|
+
now_utc = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())
|
|
14
|
+
with db.get_connection(filename) as conn:
|
|
15
|
+
with conn:
|
|
16
|
+
conn.execute(
|
|
17
|
+
"""
|
|
18
|
+
INSERT OR IGNORE INTO plugins (plugin_name, installed_at, is_enabled)
|
|
19
|
+
VALUES (?, ?, 1)
|
|
20
|
+
""",
|
|
21
|
+
(plugin_name, now_utc),
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def get_plugin_data(
|
|
26
|
+
plugin_name: str, key: str, default: Any = None, filename: str | Path | None = None
|
|
27
|
+
) -> Any:
|
|
28
|
+
db.initialise(filename)
|
|
29
|
+
with db.get_connection(filename) as conn:
|
|
30
|
+
row = conn.execute(
|
|
31
|
+
"""
|
|
32
|
+
SELECT value FROM plugin_kv WHERE plugin_name = ? AND key = ?
|
|
33
|
+
""",
|
|
34
|
+
(plugin_name, key),
|
|
35
|
+
).fetchone()
|
|
36
|
+
if not row:
|
|
37
|
+
return default
|
|
38
|
+
try:
|
|
39
|
+
return json.loads(row[0])
|
|
40
|
+
except (ValueError, TypeError):
|
|
41
|
+
return row[0]
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def set_plugin_data(
|
|
45
|
+
plugin_name: str, key: str, value: Any, filename: str | Path | None = None
|
|
46
|
+
) -> None:
|
|
47
|
+
db.initialise(filename)
|
|
48
|
+
register_plugin(plugin_name, filename=filename)
|
|
49
|
+
serialized = json.dumps(value)
|
|
50
|
+
with db.get_connection(filename) as conn:
|
|
51
|
+
with conn:
|
|
52
|
+
conn.execute(
|
|
53
|
+
"""
|
|
54
|
+
INSERT OR REPLACE INTO plugin_kv (plugin_name, key, value)
|
|
55
|
+
VALUES (?, ?, ?)
|
|
56
|
+
""",
|
|
57
|
+
(plugin_name, key, serialized),
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def get_all_plugin_data(plugin_name: str, filename: str | Path | None = None) -> dict:
|
|
62
|
+
db.initialise(filename)
|
|
63
|
+
with db.get_connection(filename) as conn:
|
|
64
|
+
rows = conn.execute(
|
|
65
|
+
"SELECT key, value FROM plugin_kv WHERE plugin_name = ?", (plugin_name,)
|
|
66
|
+
).fetchall()
|
|
67
|
+
result = {}
|
|
68
|
+
for k, v in rows:
|
|
69
|
+
try:
|
|
70
|
+
result[k] = json.loads(v)
|
|
71
|
+
except (ValueError, TypeError):
|
|
72
|
+
result[k] = v
|
|
73
|
+
return result
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def purge_plugin(plugin_name: str, filename: str | Path | None = None) -> bool:
|
|
77
|
+
db.initialise(filename)
|
|
78
|
+
with db.get_connection(filename) as conn:
|
|
79
|
+
with conn:
|
|
80
|
+
cursor = conn.execute(
|
|
81
|
+
"DELETE FROM plugins WHERE plugin_name = ?", (plugin_name,)
|
|
82
|
+
)
|
|
83
|
+
return cursor.rowcount > 0
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def purge_all_plugin_data(filename: str | Path | None = None) -> bool:
|
|
87
|
+
db.initialise(filename)
|
|
88
|
+
with db.get_connection(filename) as conn:
|
|
89
|
+
with conn:
|
|
90
|
+
conn.execute("DELETE FROM plugin_kv")
|
|
91
|
+
conn.execute("DELETE FROM plugins")
|
|
92
|
+
return True
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def delete_plugin_data(
|
|
96
|
+
plugin_name: str, key: str, filename: str | Path | None = None
|
|
97
|
+
) -> bool:
|
|
98
|
+
db.initialise(filename)
|
|
99
|
+
with db.get_connection(filename) as conn:
|
|
100
|
+
with conn:
|
|
101
|
+
cursor = conn.execute(
|
|
102
|
+
"DELETE FROM plugin_kv WHERE plugin_name = ? AND key = ?",
|
|
103
|
+
(plugin_name, key),
|
|
104
|
+
)
|
|
105
|
+
return cursor.rowcount > 0
|
|
@@ -133,7 +133,12 @@ def main() -> None:
|
|
|
133
133
|
print(f"Exception message: '{e}'")
|
|
134
134
|
sys.exit(1)
|
|
135
135
|
finally:
|
|
136
|
-
|
|
136
|
+
try:
|
|
137
|
+
from flyshell.startup import loader
|
|
138
|
+
|
|
139
|
+
loader.unload_plugins()
|
|
140
|
+
except ImportError:
|
|
141
|
+
pass
|
|
137
142
|
|
|
138
143
|
|
|
139
144
|
if __name__ == "__main__":
|