53 lines
1.9 KiB
Python
53 lines
1.9 KiB
Python
# -*- coding: utf-8 -*-
|
||
from .mlog import log
|
||
from .common import run_cmd
|
||
import os
|
||
import shutil
|
||
|
||
|
||
class GitRepository():
|
||
def __init__(self):
|
||
self.base_dir = "/data/publish/git"
|
||
|
||
def checkout(self, git_addr, project, tag):
|
||
git_dir = "{0}/{1}".format(self.base_dir, tag)
|
||
if os.path.isdir(git_dir):
|
||
shutil.rmtree(git_dir)
|
||
|
||
clone_cmd = "cd {0} && git clone --recursive --branch {2} {1} {2} ".format(self.base_dir, git_addr, tag)
|
||
status, out = run_cmd(clone_cmd)
|
||
if status:
|
||
log.info("git clone {0} success".format(project))
|
||
else:
|
||
log.error("git clone {0} Failed,out was {1}".format(project, out))
|
||
raise Exception("git clone Failed")
|
||
|
||
# tag_dir = "{0}/{1}".format(self.base_dir, tag)
|
||
# get_tag_cmd = "cd {0} && git checkout {1} && git submodule update ".format(tag_dir, tag)
|
||
# status, out = run_cmd(get_tag_cmd)
|
||
# if status:
|
||
# log.info("git tag {0} {1} success".format(project, tag))
|
||
# else:
|
||
# log.error("git tag {0} {1} Failed,out was {2}".format(project, tag, out))
|
||
# raise Exception("git tag Failed")
|
||
|
||
return True
|
||
|
||
|
||
class SubversionRepository():
|
||
def __init__(self):
|
||
self.base_dir = "/data/publish/svn"
|
||
|
||
def checkout(self, svn_add, project, tag, git_dir=None):
|
||
# 实际tag无用,只记录,显示
|
||
if not git_dir:
|
||
git_dir = "{0}/{1}".format(self.base_dir, project)
|
||
check_out_cmd = "svn export --force --no-auth-cache --non-interactive {0} {1}".format(svn_add, git_dir)
|
||
status, out = run_cmd(check_out_cmd)
|
||
if status:
|
||
log.info("svn co {0} ,tag {1} success".format(project, tag))
|
||
return True
|
||
else:
|
||
log.error("svn co {0} {1} Failed,out was {2}".format(project, tag, out))
|
||
raise Exception("SVN checkout Failed!")
|