aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2024-11-11 01:12:29 +0800
committerYuqian Yang <crupest@crupest.life>2024-12-22 17:45:13 +0800
commitb834953fa61d816b9a955640ad12d244316ce904 (patch)
tree4197980a04943b42941d3fce7cb16d1f7ea400bd
parent7e85627eb0d0126baf1e698ffdeae0f3c5fc693d (diff)
downloadcrupest-b834953fa61d816b9a955640ad12d244316ce904.tar.gz
crupest-b834953fa61d816b9a955640ad12d244316ce904.tar.bz2
crupest-b834953fa61d816b9a955640ad12d244316ce904.zip
HALF WORK: 2024.12.22
code.
-rw-r--r--templates/README.md (renamed from template/README.md)0
-rw-r--r--templates/docker-compose.yaml.template (renamed from template/docker-compose.yaml.template)0
-rw-r--r--templates/forgejo.app.ini.init.template (renamed from template/forgejo.app.ini.init.template)0
-rw-r--r--templates/mailserver.env.template (renamed from template/mailserver.env.template)0
-rw-r--r--templates/nginx/2fa.conf.template (renamed from template/nginx/2fa.conf.template)0
-rw-r--r--templates/nginx/code.conf.template (renamed from template/nginx/code.conf.template)0
-rw-r--r--templates/nginx/common/acme-challenge (renamed from template/nginx/common/acme-challenge)0
-rw-r--r--templates/nginx/common/https-redirect (renamed from template/nginx/common/https-redirect)0
-rw-r--r--templates/nginx/common/proxy-common (renamed from template/nginx/common/proxy-common)0
-rw-r--r--templates/nginx/forbid_unknown_domain.conf (renamed from template/nginx/forbid_unknown_domain.conf)0
-rw-r--r--templates/nginx/git.conf.template (renamed from template/nginx/git.conf.template)0
-rw-r--r--templates/nginx/mail.conf.template (renamed from template/nginx/mail.conf.template)0
-rw-r--r--templates/nginx/root.conf.template (renamed from template/nginx/root.conf.template)0
-rw-r--r--templates/nginx/ssl.conf.template (renamed from template/nginx/ssl.conf.template)0
-rw-r--r--templates/nginx/timeline.conf.template (renamed from template/nginx/timeline.conf.template)0
-rw-r--r--templates/nginx/websocket.conf (renamed from template/nginx/websocket.conf)0
-rw-r--r--templates/v2ray-config.json.template (renamed from template/v2ray-config.json.template)0
-rw-r--r--tools/cru-py/.gitignore6
-rw-r--r--tools/cru-py/cru/app.py40
-rw-r--r--tools/cru-py/cru/service/__main__.py11
-rw-r--r--tools/cru-py/cru/service/_base.py23
-rw-r--r--tools/cru-py/cru/service/_docker.py (renamed from tools/cru-py/cru/service/docker.py)0
-rw-r--r--tools/cru-py/cru/service/_manager.py2
-rw-r--r--tools/cru-py/cru/service/_template.py20
24 files changed, 82 insertions, 20 deletions
diff --git a/template/README.md b/templates/README.md
index 729e596..729e596 100644
--- a/template/README.md
+++ b/templates/README.md
diff --git a/template/docker-compose.yaml.template b/templates/docker-compose.yaml.template
index cebdfb3..cebdfb3 100644
--- a/template/docker-compose.yaml.template
+++ b/templates/docker-compose.yaml.template
diff --git a/template/forgejo.app.ini.init.template b/templates/forgejo.app.ini.init.template
index 7dc3800..7dc3800 100644
--- a/template/forgejo.app.ini.init.template
+++ b/templates/forgejo.app.ini.init.template
diff --git a/template/mailserver.env.template b/templates/mailserver.env.template
index 031c196..031c196 100644
--- a/template/mailserver.env.template
+++ b/templates/mailserver.env.template
diff --git a/template/nginx/2fa.conf.template b/templates/nginx/2fa.conf.template
index aad66c1..aad66c1 100644
--- a/template/nginx/2fa.conf.template
+++ b/templates/nginx/2fa.conf.template
diff --git a/template/nginx/code.conf.template b/templates/nginx/code.conf.template
index a67500d..a67500d 100644
--- a/template/nginx/code.conf.template
+++ b/templates/nginx/code.conf.template
diff --git a/template/nginx/common/acme-challenge b/templates/nginx/common/acme-challenge
index 26054b8..26054b8 100644
--- a/template/nginx/common/acme-challenge
+++ b/templates/nginx/common/acme-challenge
diff --git a/template/nginx/common/https-redirect b/templates/nginx/common/https-redirect
index 56d095d..56d095d 100644
--- a/template/nginx/common/https-redirect
+++ b/templates/nginx/common/https-redirect
diff --git a/template/nginx/common/proxy-common b/templates/nginx/common/proxy-common
index 4193548..4193548 100644
--- a/template/nginx/common/proxy-common
+++ b/templates/nginx/common/proxy-common
diff --git a/template/nginx/forbid_unknown_domain.conf b/templates/nginx/forbid_unknown_domain.conf
index ae96393..ae96393 100644
--- a/template/nginx/forbid_unknown_domain.conf
+++ b/templates/nginx/forbid_unknown_domain.conf
diff --git a/template/nginx/git.conf.template b/templates/nginx/git.conf.template
index ea2a627..ea2a627 100644
--- a/template/nginx/git.conf.template
+++ b/templates/nginx/git.conf.template
diff --git a/template/nginx/mail.conf.template b/templates/nginx/mail.conf.template
index ba2e44e..ba2e44e 100644
--- a/template/nginx/mail.conf.template
+++ b/templates/nginx/mail.conf.template
diff --git a/template/nginx/root.conf.template b/templates/nginx/root.conf.template
index 3f20cf1..3f20cf1 100644
--- a/template/nginx/root.conf.template
+++ b/templates/nginx/root.conf.template
diff --git a/template/nginx/ssl.conf.template b/templates/nginx/ssl.conf.template
index 54205f1..54205f1 100644
--- a/template/nginx/ssl.conf.template
+++ b/templates/nginx/ssl.conf.template
diff --git a/template/nginx/timeline.conf.template b/templates/nginx/timeline.conf.template
index db908e8..db908e8 100644
--- a/template/nginx/timeline.conf.template
+++ b/templates/nginx/timeline.conf.template
diff --git a/template/nginx/websocket.conf b/templates/nginx/websocket.conf
index 32af4c3..32af4c3 100644
--- a/template/nginx/websocket.conf
+++ b/templates/nginx/websocket.conf
diff --git a/template/v2ray-config.json.template b/templates/v2ray-config.json.template
index 33d3f16..33d3f16 100644
--- a/template/v2ray-config.json.template
+++ b/templates/v2ray-config.json.template
diff --git a/tools/cru-py/.gitignore b/tools/cru-py/.gitignore
index d40cb9b..bee8a64 100644
--- a/tools/cru-py/.gitignore
+++ b/tools/cru-py/.gitignore
@@ -1,7 +1 @@
-.idea
-venv
-
__pycache__
-
-.continuerc.json
-.continuerules
diff --git a/tools/cru-py/cru/app.py b/tools/cru-py/cru/app.py
index 6a60926..c9e57f4 100644
--- a/tools/cru-py/cru/app.py
+++ b/tools/cru-py/cru/app.py
@@ -21,45 +21,57 @@ class ApplicationPathError(CruException):
class ApplicationPath:
- def __init__(self, p: str | Path, is_dir: bool) -> None:
- self._path = CruPath(p)
+ def __init__(self, app_dir: str, subpath: str, is_dir: bool) -> None:
+ self._app_dir = app_dir
+ self._subpath = subpath
+ self._full_path = CruPath(app_dir, subpath)
self._is_dir = is_dir
@property
- def path(self) -> CruPath:
- return self._path
+ def app_dir(self) -> str:
+ return self._app_dir
+
+ @property
+ def subpath(self) -> str:
+ return self._subpath
+
+ @property
+ def full_path(self) -> CruPath:
+ return self._full_path
@property
def is_dir(self) -> bool:
return self._is_dir
def check_parents(self, must_exist: bool = False) -> bool:
- return self._path.check_parents_dir(must_exist)
+ return self.full_path.check_parents_dir(must_exist)
def check_self(self, must_exist: bool = False) -> bool:
if not self.check_parents(must_exist):
return False
- if not self.path.exists():
+ if not self.full_path.exists():
if not must_exist:
return False
- raise ApplicationPathError("Not exist.", self.path)
+ raise ApplicationPathError("Not exist.", self.full_path)
if self.is_dir:
- if not self.path.is_dir():
- raise ApplicationPathError("Should be a directory, but not.", self.path)
+ if not self.full_path.is_dir():
+ raise ApplicationPathError(
+ "Should be a directory, but not.", self.full_path
+ )
else:
return False
else:
- if not self.path.is_file():
- raise ApplicationPathError("Should be a file, but not.", self.path)
+ if not self.full_path.is_file():
+ raise ApplicationPathError("Should be a file, but not.", self.full_path)
else:
return False
def ensure(self, create_file: bool = False) -> None:
e = self.check_self(False)
if not e:
- os.makedirs(self.path.parent, exist_ok=True)
+ os.makedirs(self.full_path.parent, exist_ok=True)
if self.is_dir:
- os.mkdir(self.path)
+ os.mkdir(self.full_path)
elif create_file:
- with open(self.path, "w") as f:
+ with open(self.full_path, "w") as f:
f.write("")
diff --git a/tools/cru-py/cru/service/__main__.py b/tools/cru-py/cru/service/__main__.py
new file mode 100644
index 0000000..a7add4d
--- /dev/null
+++ b/tools/cru-py/cru/service/__main__.py
@@ -0,0 +1,11 @@
+import argparse
+
+
+arg_parser = argparse.ArgumentParser(description="Service management")
+command_subparser = arg_parser.add_subparsers(dest="command")
+
+template_parser = command_subparser.add_parser("template", help="Template management")
+template_subparser = template_parser.add_subparsers(dest="template_command")
+
+template_subparser.add_parser('list', description="List templates")
+template_subparser.add_parser('generate')
diff --git a/tools/cru-py/cru/service/_base.py b/tools/cru-py/cru/service/_base.py
new file mode 100644
index 0000000..707fb66
--- /dev/null
+++ b/tools/cru-py/cru/service/_base.py
@@ -0,0 +1,23 @@
+from argparse import ArgumentParser, Namespace
+from typing import Protocol
+from cru.app import ApplicationPath, CruApplication
+
+
+class AppFunction(Protocol):
+ @property
+ def name(self) -> str: ...
+
+ def add_arg_parser(self, arg_parser: ArgumentParser) -> None: ...
+
+ def run_command(self, args: Namespace) -> None: ...
+
+
+class AppBase(CruApplication):
+ def __init__(self, name: str, app_dir: str):
+ super().__init__(name)
+ self._app_dir = app_dir
+ self._template_dir = ApplicationPath(app_dir, "templates", True)
+
+ @property
+ def app_dir(self) -> str:
+ return self._app_dir
diff --git a/tools/cru-py/cru/service/docker.py b/tools/cru-py/cru/service/_docker.py
index 5958f4f..5958f4f 100644
--- a/tools/cru-py/cru/service/docker.py
+++ b/tools/cru-py/cru/service/_docker.py
diff --git a/tools/cru-py/cru/service/_manager.py b/tools/cru-py/cru/service/_manager.py
index 45a9e47..c1af428 100644
--- a/tools/cru-py/cru/service/_manager.py
+++ b/tools/cru-py/cru/service/_manager.py
@@ -1,2 +1,4 @@
class CruServiceManager:
"TODO: Continue here tomorrow!"
+ def __init__(self):
+ \ No newline at end of file
diff --git a/tools/cru-py/cru/service/_template.py b/tools/cru-py/cru/service/_template.py
new file mode 100644
index 0000000..0ca4b63
--- /dev/null
+++ b/tools/cru-py/cru/service/_template.py
@@ -0,0 +1,20 @@
+from argparse import ArgumentParser, Namespace
+
+from ._base import AppBase, AppFunction
+
+
+class TemplateManager(AppFunction):
+ def __init__(self, app: AppBase):
+ self._app = app
+ pass
+
+ @property
+ def name(self):
+ return "template-manager"
+
+ def add_arg_parser(self, arg_parser: ArgumentParser) -> None:
+ subparsers = arg_parser.add_subparsers(dest="template_command")
+ list_parser = subparsers.add_parser("list", help="List templates")
+ generate_parser = subparsers.add_parser("generate", help="Generate template")
+
+ def run_command(self, args: Namespace) -> None: ...