This repository was archived by the owner on Apr 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathplugin_install.py
More file actions
53 lines (48 loc) · 1.8 KB
/
plugin_install.py
File metadata and controls
53 lines (48 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import zipfile
import requests
from io import BytesIO
import fire
import os
from shutil import copytree
def _get_plugin(repo: str, extra:dict):
url_schema = 'https://github.com/{repo}/{resofurl}'
default_url = 'https://github.com/HXSecurityBusiness/DongTai-webapi/archive/refs/heads/main.zip'
default_url = 'https://github.com/Bidaya0/DongTai-openapi/archive/refs/tags/v1.0.3.zip'
if 'branch' in extra.keys():
resofurl = f'archive/refs/heads/{extra["branch"]}.zip'
elif 'tag' in extra.keys():
resofurl = f'archive/refs/tags/{extra["tag"]}.zip'
elif 'commit' in extra.keys():
resofurl = f'zip/{extra["commit"]}'
else:
resofurl = 'archive/refs/heads/main.zip'
final_url = f'https://github.com/{repo}/{resofurl}'
if 'uri' in extra.keys():
final_url = extra['uri']
r = requests.get(final_url, stream=True)
z = zipfile.ZipFile(BytesIO(r.content))
owner, repo_name = repo.split('/')
z.extractall(f'/tmp/plugin/{repo_name}')
def _install_plugin(repo: str):
owner,repo_name = repo.split('/')
base_path = f"/tmp/plugin/{repo_name}/{os.listdir(f'/tmp/plugin/{repo_name}')[0]}"
copyapp_path = f"{base_path}/logs"
copytree(copyapp_path,f'./{repo_name}')
copyapp_path = f"{base_path}/logs"
copytree(copyapp_path,f'./plugin/{repo_name}/')
def get_plugin(repo: str,
branch: [str, None] = None,
tag: [str, None] = None,
commit: [str, None] = None,
uri: [str, None] = None):
extra = {
key: value
for key, value in filter(
lambda x: x[1],
zip(['branch', 'tag', 'commit', 'uri'],
[branch, tag, commit, uri]))
}
_get_plugin(repo,extra)
_install_plugin(repo)
if __name__ == '__main__':
fire.Fire(get_plugin)