mirror of
https://github.com/gnh1201/caterpillar.git
synced 2025-05-23 18:11:05 +00:00
Merge pull request #27 from gnh1201/importlib_with_env
Change the `Extension.register()` process / 확장 등록 프로세스 변경
This commit is contained in:
commit
83b46d3ede
|
@ -36,6 +36,7 @@ CERT_KEY=cert.key
|
||||||
CERT_DIR=certs/
|
CERT_DIR=certs/
|
||||||
OPENSSL_BINPATH=openssl
|
OPENSSL_BINPATH=openssl
|
||||||
CLIENT_ENCODING=utf-8
|
CLIENT_ENCODING=utf-8
|
||||||
|
USE_EXTENSIONS=wayback.Wayback,bio.PyBio
|
||||||
```
|
```
|
||||||
|
|
||||||
- (Optional) Create a certificate for SSL decryption
|
- (Optional) Create a certificate for SSL decryption
|
||||||
|
|
9
base.py
9
base.py
|
@ -7,7 +7,7 @@
|
||||||
# Namyheon Go (Catswords Research) <gnh1201@gmail.com>
|
# Namyheon Go (Catswords Research) <gnh1201@gmail.com>
|
||||||
# https://github.com/gnh1201/caterpillar
|
# https://github.com/gnh1201/caterpillar
|
||||||
# Created at: 2024-05-20
|
# Created at: 2024-05-20
|
||||||
# Updated at: 2024-07-06
|
# Updated at: 2024-07-09
|
||||||
#
|
#
|
||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
|
@ -72,13 +72,16 @@ class Extension():
|
||||||
cls.buffer_size = _buffer_size
|
cls.buffer_size = _buffer_size
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def register(cls, module_path, class_name):
|
def register(cls, s):
|
||||||
|
module_name, class_name = s.strip().split('.')[0:2]
|
||||||
|
module_path = 'plugins.' + module_name
|
||||||
|
|
||||||
try:
|
try:
|
||||||
module = importlib.import_module(module_path)
|
module = importlib.import_module(module_path)
|
||||||
_class = getattr(module, class_name)
|
_class = getattr(module, class_name)
|
||||||
cls.extensions.append(_class())
|
cls.extensions.append(_class())
|
||||||
except (ImportError, AttributeError) as e:
|
except (ImportError, AttributeError) as e:
|
||||||
raise ImportError(class_name + " in " + module_path)
|
raise ImportError(class_name + " in the extension " + module_name)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_filters(cls):
|
def get_filters(cls):
|
||||||
|
|
11
server.py
11
server.py
|
@ -7,7 +7,7 @@
|
||||||
# Namyheon Go (Catswords Research) <gnh1201@gmail.com>
|
# Namyheon Go (Catswords Research) <gnh1201@gmail.com>
|
||||||
# https://github.com/gnh1201/caterpillar
|
# https://github.com/gnh1201/caterpillar
|
||||||
# Created at: 2022-10-06
|
# Created at: 2022-10-06
|
||||||
# Updated at: 2024-07-04
|
# Updated at: 2024-07-09
|
||||||
#
|
#
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
@ -47,6 +47,7 @@ try:
|
||||||
client_encoding = config('CLIENT_ENCODING', default='utf-8')
|
client_encoding = config('CLIENT_ENCODING', default='utf-8')
|
||||||
local_domain = config('LOCAL_DOMAIN', default='')
|
local_domain = config('LOCAL_DOMAIN', default='')
|
||||||
proxy_pass = config('PROXY_PASS', default='')
|
proxy_pass = config('PROXY_PASS', default='')
|
||||||
|
use_extensions = config('USE_EXTENSIONS', default='')
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("\n[*] User has requested an interrupt")
|
print("\n[*] User has requested an interrupt")
|
||||||
print("[*] Application Exiting.....")
|
print("[*] Application Exiting.....")
|
||||||
|
@ -498,10 +499,8 @@ def start(): #Main Program
|
||||||
|
|
||||||
if __name__== "__main__":
|
if __name__== "__main__":
|
||||||
# load extensions
|
# load extensions
|
||||||
#Extension.register("plugins.fediverse", "Fediverse")
|
for s in use_extensions.split(','):
|
||||||
#Extension.register("plugins.container", "Container")
|
Extension.register(s)
|
||||||
Extension.register("plugins.wayback", "Wayback")
|
|
||||||
#Extension.register("plugins.bio", "PyBio")
|
|
||||||
|
|
||||||
# start Caterpillar
|
# start Caterpillar
|
||||||
start()
|
start()
|
||||||
|
|
5
web.py
5
web.py
|
@ -7,7 +7,7 @@
|
||||||
# Namyheon Go (Catswords Research) <gnh1201@gmail.com>
|
# Namyheon Go (Catswords Research) <gnh1201@gmail.com>
|
||||||
# https://github.com/gnh1201/caterpillar
|
# https://github.com/gnh1201/caterpillar
|
||||||
# Created at: 2024-05-20
|
# Created at: 2024-05-20
|
||||||
# Updated at: 2024-07-06
|
# Updated at: 2024-07-10
|
||||||
#
|
#
|
||||||
|
|
||||||
from flask import Flask, request, redirect, url_for, render_template
|
from flask import Flask, request, redirect, url_for, render_template
|
||||||
|
@ -94,6 +94,7 @@ if __name__ == "__main__":
|
||||||
Extension.set_protocol('http')
|
Extension.set_protocol('http')
|
||||||
|
|
||||||
# load extensions
|
# load extensions
|
||||||
#Extension.register("plugins.YOUR_OWN_MODULE_NAME", "YOUR_OWN_CLASS_NAME");
|
for s in use_extensions.split(','):
|
||||||
|
Extension.register(s)
|
||||||
|
|
||||||
app.run(debug=True, host='0.0.0.0', port=listening_port)
|
app.run(debug=True, host='0.0.0.0', port=listening_port)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user