1 Star 0 Fork 0

Da yang/Devops

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
gitclone.py 3.54 KB
一键复制 编辑 原始数据 按行查看 历史
Da yang 提交于 2021-03-08 20:39 +08:00 . Initial commit
# coding=utf-8
import datetime
import os
from git.repo import Repo
from utils import Codezip
def git(projectinfo, taskinfo):
date = datetime.datetime.now().strftime('%Y%m%d%H')
codepath = '/Users/dayang/PycharmProjects/Devops/codes/' + date + '/' + taskinfo.uid + \
'/' + 'codes'
scriptpath = '/Users/dayang/PycharmProjects/Devops/codes/' + date + '/' + taskinfo.uid + \
'/' + 'scripts'
taskpath = '/Users/dayang/PycharmProjects/Devops/codes/' + date + '/' + taskinfo.uid
if os.path.exists(taskpath):
Repo.clone_from(url=projectinfo.repo, to_path=codepath, branch=taskinfo.tag) # 下载代码
before_download = os.path.join(scriptpath, "before_download.sh")
with open(before_download, mode='w', encoding='utf-8') as f:
f.write(taskinfo.before_download)
after_download = os.path.join(scriptpath, "after_download.sh")
with open(after_download, mode='w', encoding='utf-8') as f:
f.write(taskinfo.after_download)
before_deploy_sc = os.path.join(scriptpath, "before_deploy_sc.sh")
with open(before_deploy_sc, mode='w', encoding='utf-8') as f:
f.write(taskinfo.before_deploy_sc)
after_deploy_sc = os.path.join(scriptpath, "after_deploy_sc.sh")
with open(after_deploy_sc, mode='w', encoding='utf-8') as f:
f.write(taskinfo.after_deploy_sc)
filepath = Codezip(taskpath, taskpath)
return str(filepath)
else:
os.makedirs(taskpath)
os.makedirs(codepath)
os.makedirs(scriptpath)
Repo.clone_from(url=projectinfo.repo, to_path=codepath, branch=taskinfo.tag) # 下载代码
before_download = os.path.join(scriptpath, "before_download.sh")
with open(before_download, mode='w', encoding='utf-8') as f:
f.write(taskinfo.before_download)
after_download = os.path.join(scriptpath, "after_download.sh")
with open(after_download, mode='w', encoding='utf-8') as f:
f.write(taskinfo.after_download)
before_deploy_sc = os.path.join(scriptpath, "before_deploy_sc.sh")
with open(before_deploy_sc, mode='w', encoding='utf-8') as f:
f.write(taskinfo.before_deploy_sc)
after_deploy_sc = os.path.join(scriptpath, "after_deploy_sc.sh")
with open(after_deploy_sc, mode='w', encoding='utf-8') as f:
f.write(taskinfo.after_deploy_sc)
filepath = Codezip(taskpath, taskpath)
return str(filepath)
# print("line25server:%s" % prinfo.servers)
# print(filepath)
# Exists = os.path.exists(path)
# print(" lin 19 exits status %s" % Exists)
# if os.path.exists(path):
# print("21:path:%s" % path)
# print("文件夹存在删除掉")
# serverlist = prinfo.servers.split(',')
# # for host in serverlist:
# # hostinfo = Hosts.query.filter_by(hostname=host).first()
# # with SSHProxy(hostname=host, port=hostinfo.port, username=hostinfo.username,
# # password=hostinfo.passwd) as ssh:
# # ssh.upload(filepath, prinfo.path)
# # os.remove(path)
# else:
# print("文件夹不存在")
# print("32:path:%s" % path)
# os.makedirs(path)
# Repo.clone_from(url=prinfo.repo, to_path=path, branch=taskinfo.tag)
# codezip(path, path)
# # print(prinfo.servers)
# serverlists = prinfo.servers.split('', )
# # print(type(serverlists))
# # for server in serverlists:
# # print(server)
# # print(type(server))
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/shyanglin/Devops.git
git@gitee.com:shyanglin/Devops.git
shyanglin
Devops
Devops
master

搜索帮助