mirror of
https://github.com/Websoft9/websoft9.git
synced 2025-01-23 01:00:20 +08:00
add files.py
This commit is contained in:
parent
0a1e0a540b
commit
c0983f3f9a
@ -161,7 +161,7 @@ def get_update_list():
|
||||
|
||||
if compared_version(local_version, version) == -1:
|
||||
ret['update'] = True
|
||||
cmd = "wget -O CHANGELOG.md " + const.ARTIFACT_URL + "/CHANGELOG.md && cat CHANGELOG.md"
|
||||
cmd = "wget -O CHANGELOG.md " + const.ARTIFACT_URL + "/CHANGELOG.md && head -n 20 CHANGELOG.md "
|
||||
change_log_contents = shell_execute.execute_command_output_all(cmd)['result']
|
||||
change_log = change_log_contents.split('## ')[1].split('\n')
|
||||
date = change_log[0].split()[-1]
|
||||
|
69
appmanage/api/utils/files.py
Normal file
69
appmanage/api/utils/files.py
Normal file
@ -0,0 +1,69 @@
|
||||
from api.utils.common_log import myLogger
|
||||
from api.utils.helper import Singleton
|
||||
|
||||
|
||||
# This class is add/modify/list/delete item to item=value(键值对) model settings file
|
||||
__all__ = ['settings']
|
||||
|
||||
class SettingsFile(object):
|
||||
|
||||
__metaclass__ = Singleton
|
||||
|
||||
def __init__(self, path):
|
||||
self._config = {}
|
||||
self.config_file = path
|
||||
|
||||
def build_config(self):
|
||||
try:
|
||||
with open(self.config_file, 'r') as f:
|
||||
data = f.readlines()
|
||||
except Exception as e:
|
||||
data = []
|
||||
for i in data:
|
||||
if i.startswith('#'):
|
||||
continue
|
||||
i = i.replace('\n', '').replace('\r\n', '')
|
||||
if not i:
|
||||
continue
|
||||
tmp = i.split('=')
|
||||
if len(tmp) != 2:
|
||||
myLogger.error_logger(f'invalid format {i}')
|
||||
continue
|
||||
|
||||
key, value = i.split('=')
|
||||
if self._config.get(key) != value:
|
||||
self._config[key] = value
|
||||
return self._config
|
||||
|
||||
def init_config_from_file(self, config_file: str=None):
|
||||
if config_file:
|
||||
self.config_file = config_file
|
||||
self.build_config()
|
||||
|
||||
def update_setting(self, key: str, value: str):
|
||||
self._config[key] = value
|
||||
self.flush_config()
|
||||
|
||||
def get_setting(self, key: str, default=None):
|
||||
return self._config.get(key, default)
|
||||
|
||||
def list_all_settings(self) -> dict:
|
||||
self.build_config()
|
||||
return self._config
|
||||
|
||||
def delete_setting(self, key: str, value: str):
|
||||
if self._config.get(key) == value:
|
||||
del self._config[key]
|
||||
self.flush_config()
|
||||
|
||||
def flush_config(self):
|
||||
try:
|
||||
with open(self.config_file, 'w') as f:
|
||||
for key, value in self._config.items():
|
||||
f.write(f'{key}={value}\n')
|
||||
except Exception as e:
|
||||
myLogger.error_logger(e)
|
||||
|
||||
|
||||
# This class is add/modify/cat/delete content from file
|
||||
# src: path | URL
|
@ -4,13 +4,20 @@ from api.utils.common_log import myLogger
|
||||
from api.exception.command_exception import CommandException
|
||||
from api.utils import const
|
||||
|
||||
|
||||
# This fuction is for running shell commands on container
|
||||
# cmd_str e.g: "ls -a"
|
||||
# return string limit: 4000 chars? to do
|
||||
def execute_command_output(cmd_str):
|
||||
print(cmd_str)
|
||||
out_str = subprocess.getoutput(cmd_str)
|
||||
print(out_str)
|
||||
return out_str
|
||||
|
||||
# cmd_str: 执行的command命令
|
||||
|
||||
# This fuction is for running shell commands on host machine
|
||||
# cmd_str e.g: "ls -a"
|
||||
# return string limit: 4000 chars
|
||||
def execute_command_output_all(cmd_str):
|
||||
|
||||
myLogger.info_logger("Start to execute cmd: " + cmd_str)
|
||||
@ -25,6 +32,9 @@ def execute_command_output_all(cmd_str):
|
||||
myLogger.info_logger(process)
|
||||
raise CommandException(const.ERROR_SERVER_COMMAND,"Docker returns the original error", process.stderr)
|
||||
|
||||
|
||||
|
||||
# This fuction is convert container commands to host machine commands
|
||||
def convert_command(cmd_str):
|
||||
convert_cmd = ""
|
||||
if cmd_str == "":
|
||||
|
@ -7,4 +7,6 @@
|
||||
#smtp_server=smtp.websoft9.com
|
||||
#smtp_tls/ssl=true
|
||||
#smtp_user=admin
|
||||
#smtp_password=password
|
||||
#smtp_password=password
|
||||
#install_path=/data
|
||||
#artifact_url=https://w9artifact.blob.core.windows.net/release/websoft9
|
||||
|
@ -28,7 +28,18 @@ This repository only support deployment on Linux:
|
||||
cd websoft9/docker/appmanage && export APP_VERSION=latest-pr && docker compose up -d
|
||||
```
|
||||
|
||||
## API
|
||||
## Structure
|
||||
|
||||
### API
|
||||
|
||||
```
|
||||
├── api
|
||||
│ ├── exception
|
||||
│ ├── model -- Data models and database schema
|
||||
│ ├── service -- Controllers
|
||||
│ ├── utils -- Common modules and tools
|
||||
│ └── v1 -- Views
|
||||
```
|
||||
|
||||
### Route
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
git clone --depth=1 https://github.com/Websoft9/websoft9.git
|
||||
rm -rf /etc/cockpit/*.override.json
|
||||
cp -r websoft9/cockpit/menu_override/* /etc/cockpit
|
||||
cp -r websoft9/cockpit/menu_override/* /etc/cockpit
|
||||
rm -rf websoft9
|
Loading…
Reference in New Issue
Block a user