This commit is contained in:
chendelin1982 2021-09-28 18:34:18 +08:00
parent ba4142e7fe
commit 76c58aabef
12 changed files with 110 additions and 23 deletions

View file

@ -12,3 +12,7 @@
1. 避免API使用需要授权或超时
2. 避免未发布的应用被安装
#### 如何获取所有已占用的端口号?
基于 psutil 模块打印所有端口信息,然后匹配关键词

Binary file not shown.

View file

@ -1,4 +1,5 @@
import model, os
import model, os, sys, subprocess
from model import GitOp
path_repo = "./data/application.list"
path_project = ""
@ -29,14 +30,27 @@ class Create:
self.folder = self.app_name
def downRepo(self):
'''download repository'''
cmd = "git clone --depth=1 " + model.SmoothUrl.res(github_url) + "/websoft9/docker-" + self.app_name + " " + self.folder
if os.path.exists("./"+self.folder):
print(os.path.abspath(self.folder)+" folder already exists")
sys.exit(0)
else:
os.system(cmd)
GitOp.gitClone(cmd)
def setEnv(self):
'''set the usable port for application'''
pass
def upRepo(self):
'''docker-compose up repository'''
cmd = "docker-compose -f docker-compose-production.yml --env-file .env_all up -d"
print(cmd)
os.chdir(self.folder)
os.system(cmd)
def printResult(self):
pass

@ -1 +0,0 @@
Subproject commit 8531fd12cacfb9881de3c270f2b81e17b20f5a99

View file

@ -1 +1 @@
yum install git pwgen jq wget curl figlet boxes -y
yum install git wget figlet boxes -y

1
cli/joomla Submodule

@ -0,0 +1 @@
Subproject commit 93735135cf4529fc7830446bb6604f7c15daae2f

View file

@ -1,12 +1,12 @@
import os, io, sys, platform, shutil, urllib3, json, time, subprocess, pprint
import os, io, sys, platform, psutil, json, secrets, string
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type, Union
import urllib.parse
import urllib.request
class SmoothUrl:
''' get url '''
''' Get the best smooth url for Git or Download'''
def __init__(self):
pass
@ -14,28 +14,31 @@ class SmoothUrl:
def res(url_list: Tuple):
for item in url_list:
req = urllib.request.Request(item)
try:
urllib.request.urlopen(item,timeout=3).read()
print("Smooth URL is: " + item)
return item
except urllib.error.URLError as e:
print(e.reason)
except:
continue
return None
print("Necessary resource URL can not reachable, system exit!")
sys.exit(0)
class Github:
'''Github operation'''
class GitOp:
'''Git operation'''
def __init__(self):
pass
def gitClone():
pass
def gitClone(cmd: str):
'''git clone'''
try:
print("Command is "+cmd)
os.system(cmd)
except:
print("Git clone failed, try again and check your URL can be accessed")
sys.exit(0)
class FileOp:
'''File operation'''
@ -46,3 +49,54 @@ class FileOp:
def printJson(path: str):
with open(path,newline='') as file:
print(file.read())
def convertToJson(path: str):
pass
class NetOp:
'''Network and port manage'''
def __init__(self):
pass
def checkPort(self, port: int):
'''check the target port's status'''
search_key = "port="+str(port)
if str(psutil.net_connections()).find(search_key) != -1:
print(str(port)+" is used")
return False
else:
print(str(port)+" is free")
return True
def setPort(self, port: int):
'''set usable port'''
while self.checkPort(port) == False:
port=port+1
print(port)
return port
class SecurityOp:
'''Password and security operation'''
def __int__(self):
pass
def randomPass(self, length: Optional[int] = 16):
'''set password'''
alphabet = string.ascii_letters + string.digits
while True:
password = ''.join(secrets.choice(alphabet) for i in range(length))
if (any(c.islower() for c in password)
and any(c.isupper() for c in password)
and sum(c.isdigit() for c in password) >= 3):
break
print(password)
test=SecurityOp()
#test.setPort(9001)
test.randomPass(25)

View file

@ -1 +1,3 @@
typer
psutil
jq

View file

@ -19,6 +19,13 @@ def create(app_name: str, project_name: Optional[str] = None):
create = controller.Create(app_name, project_name)
create.downRepo()
create.upRepo()
create.setEnv()
create.printResult()
@app.command()
def start(app_name: str, project_name: Optional[str] = None):
'''start one application'''
pass
@app.command()
def update(name: str):

View file

@ -0,0 +1,4 @@
import json
with open("./joomla/.env_all","r") as file:
jsonData = json.dump(file, tempfile)

2
cli/version Normal file
View file

@ -0,0 +1,2 @@
stable: 1.3
compatible: 1.23