Commit 3abc4ae7 by sikang

update script

parent 841d17b0
......@@ -13,8 +13,8 @@ import chardet
class Function:
# 随机生成包名
@staticmethod
def new_appid(config):
def new_appid(self,config):
app_name = config['app_name'].replace(" ", "").lower()
start_name = ["com", "cn", "id", "app", "host", "in"]
middle_name = ["android", "main", "home", "base", "play", "release", "full", "kredit", "cepat",
......@@ -40,11 +40,11 @@ class Function:
"version_code": version_code,
"version_name": version_name
}
Function.update_properties(config,lines)
self.update_properties(config,lines)
# 加载shell变量
@staticmethod
def load_properties(path):
def load_properties(self,path):
with open(path, "r", encoding="utf-8") as f:
lines = f.readlines()
......@@ -57,8 +57,8 @@ class Function:
return config
# 创建签名文件
@staticmethod
def new_keystore(config):
def new_keystore(self,config):
# 只保留最近10个签名
count = 0
for root, dirs, files in os.walk(config['jks_path']):
......@@ -84,11 +84,11 @@ class Function:
"signging_certificatePassword": key_name,
"signging_storePassword": key_name,
}
Function.update_properties(config, reset)
self.update_properties(config, reset)
# 更新properties字段
@staticmethod
def update_properties(config, dict):
def update_properties(self,config, dict):
file_content = ""
replace_line = {}
with open(config['properties'], "r", encoding="utf-8") as f:
......@@ -110,8 +110,8 @@ class Function:
f_w.write(file_content)
# 移动apk
@staticmethod
def move_apk(config):
def move_apk(self,config):
file_name = "%s_%s" % (
config['corp_id'], config['app_name'].replace(" ", "_"))
apk_local = "%s/resGuardApks/%s_release.apk" % (
......@@ -126,8 +126,8 @@ class Function:
shutil.copy(apk_local, apk1)
# FB秘钥散列
@staticmethod
def getFbSign(config):
def getFbSign(self,config):
with open("%s/app/src/main/AndroidManifest.xml" % config['root'], "r") as f:
file_content = f.read()
info = re.compile(r'package=\"(.*)\"')
......@@ -145,8 +145,8 @@ class Function:
os.system(command)
# 更新Gateway
@staticmethod
def update_gateway(config):
def update_gateway(self,config):
gateway = requests.get(config['gateway_url']).json()
jsonStr = json.dumps(gateway).replace("http://", "https://")
gateway = json.loads(jsonStr)
......@@ -166,11 +166,11 @@ class Function:
"agreement_url": "\"%s\"" % gateway['privacy'][0],
"home": "\"%s\"" % gateway['home'][0],
}
Function.update_properties(config, replaces)
self.update_properties(config, replaces)
# 切换主包马甲包
@staticmethod
def cutover(config):
def cutover(self,config):
print("1、切换到主包")
print("2、切换到马甲包")
......@@ -189,8 +189,8 @@ class Function:
"host_app": "true"
}
# 更新gw
Function.update_properties(config, replace_lines)
Function.update_gateway(config)
self.update_properties(config, replace_lines)
self.update_gateway(config)
elif command == 2:
shutil.copy(img_path+"logo_majia.png", img_path+"logo.png")
......@@ -205,12 +205,12 @@ class Function:
"host_app": "false"
}
# 更新gw
Function.update_properties(config, replace_lines)
Function.update_gateway(config)
self.update_properties(config, replace_lines)
self.update_gateway(config)
# 创建描述文件
@staticmethod
def create_desc(config):
def create_desc(self,config):
desc = ""
with open("/Users/connor/StudioProjects/WorkSpace/app_desc.txt", "r") as f:
file_content = f.read().replace("\n", "--line--")
......@@ -235,8 +235,8 @@ class Function:
f_w.write(desc)
# 打印checklist
@staticmethod
def print_checklist(config, just_print):
def print_checklist(self,config, just_print):
print(" ")
print("%s %s" % (config['corp_id'], config['app_name']))
print("包名:%s" % config['app_id'])
......@@ -254,7 +254,7 @@ class Function:
if not os.path.exists(target+"/"+file_name):
os.makedirs(target+"/"+file_name)
Function.create_desc(config)
self.create_desc(config)
try:
shutil.move("%s/%s.apk" % (target, file_name),
......@@ -275,8 +275,8 @@ class Function:
print("截图制作完成")
# 更新本地隐私协议
@staticmethod
def update_local_privacy(config):
def update_local_privacy(self,config):
path = config['root'] + "/app/src/main/assets/web/"
if not os.path.exists(path):
os.makedirs(path)
......@@ -297,8 +297,8 @@ class Function:
print("本地KSP协议已更新!" + ksp_url)
# 创建新协议
@staticmethod
def new_privacy(config):
def new_privacy(self,config):
permissions = "1235"
if config['contact'] != "true":
permissions = "235"
......@@ -316,8 +316,8 @@ class Function:
print("privacy done\n")
# 转移出所有素材
@staticmethod
def move_resources(config):
def move_resources(self,config):
target = "/Users/connor/Documents/apks"
img_path = "../../app/src/main/res/drawable-xxhdpi"
......@@ -331,7 +331,7 @@ class Function:
config['root'], "%s/cache/api_mapping" % target)
except:
print("no api_mapping")
new_config = Function.load_properties("../../gradle.properties")
new_config = self.load_properties("../../gradle.properties")
os.system("cd %s\ngit reset --hard origin/%s" % (config['root'],config['git_branch']))
......@@ -345,7 +345,7 @@ class Function:
print("no api_mapping")
new_config['properties'] = config['properties']
Function.update_gateway(new_config)
self.update_gateway(new_config)
lines = {
"app_id": "\"%s\"" % new_config['app_id'],
......@@ -355,4 +355,4 @@ class Function:
"signging_certificatePassword": "\"%s\"" % new_config['signging_certificatePassword'],
"signging_storePassword": "\"%s\"" % new_config['signging_storePassword'],
}
Function.update_properties(config, lines)
self.update_properties(config, lines)
# -*-coding:utf-8-*-
from func import Function
from shell import Shell
from tools.garble import Garble
import os
import shutil
# properties 配置
config = Function.load_properties("../../gradle.properties")
config = Function().load_properties("../../gradle.properties")
config['root'] = "../.."
config['jks_path'] = "../../jks"
config['properties'] = "../../gradle.properties"
......@@ -28,57 +29,60 @@ print("12、马甲包切换")
print("13、打印checklist")
print("14、生成隐协议文件")
print("15、刷新本地协议")
print("16、api混淆")
print("21、reset project")
command = int(input("请输入指令编号:"))
# 命令
if command == 1:
Shell.build_release()
Shell().build_release()
elif command == 2:
Function.new_appid(config)
Function().new_appid(config)
elif command == 3:
Function.new_keystore(config)
Function().new_keystore(config)
elif command == 4:
Shell.push_project(config)
Shell().push_project(config)
elif command == 5:
Shell.pull_base(config)
Shell().pull_base(config)
elif command == 6:
Shell.push_base(config)
Shell().push_base(config)
elif command == 7:
Function.getFbSign(config)
Function().getFbSign(config)
elif command == 8:
Shell.push_with_tag(config)
Shell().push_with_tag(config)
elif command == 9:
Shell.reset_by_pkgname(config)
Function.move_resources(config)
Shell().reset_by_pkgname(config)
Function().move_resources(config)
elif command == 10:
Function.update_gateway(config)
Function().update_gateway(config)
elif command == 11:
Function.move_apk(config)
Function().move_apk(config)
elif command == 12:
Function.cutover(config)
Function().cutover(config)
elif command == 13 or command == 133:
Function.print_checklist(config, command == 133)
Function().print_checklist(config, command == 133)
elif command == 14:
Function.new_privacy(config)
Function().new_privacy(config)
elif command == 15:
Function.update_local_privacy(config)
Function().update_local_privacy(config)
elif command == 16:
Garble().api_garble(config)
elif command == 21:
Shell.reset_project(config)
Shell().reset_project(config)
......@@ -5,8 +5,7 @@ import os
class Shell:
#编译 待开发
@staticmethod
def build_release():
def build_release(self):
command = "%s\n%s\n" \
% (
"cd ../script",
......@@ -16,8 +15,7 @@ class Shell:
#commit&push project
@staticmethod
def push_project(config):
def push_project(self,config):
command = "%s\n%s\n%s\n%s\n" \
% (
"cd "+config['root'],
......@@ -28,8 +26,7 @@ class Shell:
os.system(command)
#commit&push lib_base
@staticmethod
def push_base(config):
def push_base(self,config):
commit_msg = input("输入commit msg: ")
command = "%s\n%s\n%s\n%s\n" \
% (
......@@ -41,8 +38,7 @@ class Shell:
os.system(command)
#pull lib_base & cash_plugin_toolbox
@staticmethod
def pull_base(config):
def pull_base(self,config):
command = "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n" \
% (
"cd %s" % config['root'],
......@@ -60,9 +56,8 @@ class Shell:
os.system(command)
#push with tag
@staticmethod
def push_with_tag(config):
Shell.push_project(config)
def push_with_tag(self,config):
self.push_project(config)
tagName="t%s-%s" % (config['corp_id'],config['app_id'])
command = "%s\n%s\n%s\n%s\n%s\n" \
% (
......@@ -77,8 +72,7 @@ class Shell:
#push with tag
@staticmethod
def reset_by_pkgname(config):
def reset_by_pkgname(self,config):
pkgname = input("输入包名: ")
command = "%s\n%s" \
% (
......@@ -100,8 +94,7 @@ class Shell:
#reset project
@staticmethod
def reset_project(config):
def reset_project(self,config):
command = "%s\n%s\n%s\n%s\n%s\n" \
% (
"cd %s" % config['root'],
......
#!/usr/bin/env python3
import glob, os
class Garble:
#api混淆
def __rename_api(self,path,config):
with open("%s/script/api_mapping"%config['root'], "r", encoding="utf-8") as f:
lines = f.readlines()
for line in lines:
if "/sysdict/$1/$2" in line:
continue
#去除无用字符
line = line.replace(" "," ").replace("rewrite ^/","").replace("rewrite /","").replace("/(.+)","")\
.replace("/(.*)","").replace(" last;","").replace("\n","") \
.replace("/$1","").replace("/$2","").replace("/$3","").replace("/$4","").replace("/$5","")
if "$ /" in line:
line = line.replace("$ /","*-*")
else:
line = line.replace(" /","*-*")
api_map = line.split("*-*")
api_map[0].replace(" ","")
api_map[1].replace(" ","")
print(api_map[1]+ " -> " + api_map[0])
with open(path, "r", encoding="utf-8") as api_file:
api_lines = api_file.readlines()
#替换api
with open(path, "w", encoding="utf-8") as f_w:
for api_l in api_lines:
old_line = "//" + api_l.replace("\n","//rewrited\n")
if "loanapp/{loanAppId}/bank" in api_l:
api_l = api_l.replace("loanapp/{loanAppId}/bank","loanapp/bank/{loanAppId}")
if "*Keep*" not in api_l and (api_map[1]+"/{" in api_l or api_map[1]+"\"" in api_l) and ( "@GET" in api_l or "@PUT" in api_l or "@POST" in api_l):
api_l = api_l.replace(api_map[1], api_map[0])
api_l = old_line + api_l.replace("\n","//rewrited\n")
print(api_map[1]+ " -> " + api_map[0])
f_w.write(api_l)
print(path + " done\n")
return
def api_garble(self,config):
#java目录的路径
for root, dirs, files in os.walk("%s/src/main"%config['root']):
dir = os.path.join(os.getcwd(), root)
for file in files:
#要检索的文件名
if file.endswith("LoanApi.java") or file.endswith("UploadApi.java") or file.endswith("UserApi.java"):
# get the path of the java file
path = os.path.join(dir, file)
self.__rename_api(path,config)
\ No newline at end of file
......@@ -49,10 +49,10 @@ def rename_api(path):
#java目录的路径
for root, dirs, files in os.walk("../../src/main"):
directory = os.path.join(os.getcwd(), root)
dir = os.path.join(os.getcwd(), root)
for file in files:
#要检索的文件名
if file.endswith("LoanApi.java") or file.endswith("UploadApi.java") or file.endswith("UserApi.java"):
# get the path of the java file
path = os.path.join(directory, file)
path = os.path.join(dir, file)
rename_api(path)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment