python 脚本应用svn自动检出,修改配置文件,启动服务

import os       #os模块调用linux命令
import sys      #调用实参
import time

source_path = sys.argv[1]

def mkdir(path):
    # 去除首位空格
    path=path.strip()
    # 判断路径是否存在
    # 存在     True
    # 不存在   False
    isExists=os.path.exists(path)

    # 判断结果
    if not isExists:
        # 如果不存在则创建目录
        # 创建目录操作函数
        os.makedirs(path)
        print('目录创建成功,开始执行svn检出')
        return True
    else:
        # 如果目录存在则不创建,并提示目录已存在
        print('目录已存在')
        return False

# 定义要创建的目录
mkpath="/data/game/b/%s" % (source_path)
# 调用函数
mkdir(mkpath)

def checkout():
    os.system('svn checkout svn://url路径   --username  用户名 --password 密码 --no-auth-cache --force %s ' % (source_path) )

def start():            #启动脚本
    os.system('dos2uniox service.sh')
    os.system('bash service.sh start')


def Startup_log():      #查看启动日志
    os.system('tailf xxx/xx/xxx.log')


checkout()

#文件修改
fr = open("/data/svn/svn_configuration/servers_old.info",'r')  #打开旧文件,设置权限为读
os.chdir("/data/svn/%s"  % (source_path))
fr_new = open("servers.info",'w')                                 #打开新文件,设置权限为写
for line in fr:
    if ":23" in line:
        line = line.replace(":23",":45")                #替换
    if "23you_2" in line:
        line = line.replace("23_sy","46_go")
    if "2020-05-26 15:00:00" in line:
        line = line.replace("2020-05-26 15:00:00","2020-02-12 10:00:00")
    if "1=" in line:
        line = line.replace("1=","#1=")
    fr_new.write(line)                                  #将内容写入新文件中

fr.close()
fr_new.close()                                          #关闭两个文件

fr1 = open("/data/svn/svn_configuration/server-config_old.properties",'r')
os.chdir("/data/svn/b/%s"  % (source_path))
fr1_new = open("server-config.properties",'w')
for line in fr1:
    if "id=1" in line:
        
        line = line.replace("id=1", 'id=%s' % (source_path))
    if "ip=127.0.0.1" in line:
        line = line.replace("ip=127.0.0.1","ip=47.xxx.xx.xx")
    if "DEBUG" in line:
        line = line.replace("DEBUG","RELEASE")
    if "10008" in line:
        line = line.replace("10008","10010")
    if "10009" in line:
        line = line.replace("10009","10011")
    if "=a" in line:
        line = line.replace("=a","=dachui")
    fr1_new.write(line)

fr1.close()
fr1_new.close()
os.chdir("/data/game/b/%s"  % (source_path))
time.sleep(1)

while 1:
    input=input('启动(y)or拒绝(n): ')
    if input == 'y':
        start()
        print('启动ing...')
        break
    elif input == 'n':
        print('暂时不启动')
        break

Startup_log()   #查看启动日志,确保服务启动成功

#脚本执行方式:  python 脚本名  路径(path)
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容