本文整理汇总了Python中git.cmd.Git.clone方法的典型用法代码示例。如果您正苦于以下问题:Python Git.clone方法的具体用法?Python Git.clone怎么用?Python Git.clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类git.cmd.Git
的用法示例。
在下文中一共展示了Git.clone方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fork
# 需要导入模块: from git.cmd import Git [as 别名]
# 或者: from git.cmd.Git import clone [as 别名]
def fork(self, new_body):
git_path = mkdtemp(prefix=settings.GIT_ROOT_PATH)
git = Git(git_path)
git.clone(os.path.abspath(self.git_path), git_path)
new_fork = Fork.objects.create(body=new_body, parent=self, git_path=git_path)
return new_fork
示例2: __init__
# 需要导入模块: from git.cmd import Git [as 别名]
# 或者: from git.cmd.Git import clone [as 别名]
def __init__(self, manager):
super(PuppetInstallMethod, self).__init__(manager)
self.log = logging.getLogger(__name__)
# Use effective agent user's home directory
self.__path = pwd.getpwuid(os.getuid()).pw_dir
# Load install items
for entry in pkg_resources.iter_entry_points("puppet.items"):
module = entry.load()
self.log.info("repository handler %s included" % module.__name__)
self._supportedItems.update({
module.__name__ : {
'name': module._name,
'description': module._description,
'container': module._container,
'options': module._options,
'module': module,
},
})
# Get a backend instance for that path
self.__repo_path = os.path.join(self.__path, "repo")
self.__work_path = os.path.join(self.__path, "work")
# Purge path if wanted
db_purge = self.env.config.get('repository.db_purge',)
if db_purge == "True":
if os.path.exists(self.__repo_path):
shutil.rmtree(self.__repo_path)
if os.path.exists(self.__work_path):
shutil.rmtree(self.__work_path)
# Create path if it doesn't exist
if not os.path.exists(self.__path):
os.makedirs(self.__path, 0750)
if not os.path.exists(self.__repo_path):
os.makedirs(self.__repo_path, 0750)
if not os.path.exists(self.__work_path):
os.makedirs(self.__work_path, 0750)
# Initialize git repository if not present
if not os.path.exists(os.path.join(self.__repo_path, "config")):
repo = Repo.create(self.__repo_path)
assert repo.bare == True
os.chmod(self.__repo_path, 0750)
# Create master branch
tmp_path = os.path.join(self.__work_path, "master")
cmd = Git(self.__work_path)
cmd.clone(self.__repo_path, "master")
with open(os.path.join(tmp_path, "README"), "w") as f:
f.write("This is an automatically managed GOsa puppet repository. Please do not modify.")
logdir = self.env.config.get("puppet.report-dir",
"/var/log/puppet")
with open(os.path.join(tmp_path, "puppet.conf"), "w") as f:
f.write("""[main]
logdir=%s
vardir=/var/lib/puppet
ssldir=/var/lib/puppet/ssl
rundir=/var/run/puppet
factpath=$vardir/lib/facter
templatedir=$confdir/templates
report=true
reports=store_gosa
reportdir=$logdir
""" % logdir)
# Add manifests and write initial size.pp
os.mkdir(os.path.join(tmp_path, "manifests"))
with open(os.path.join(tmp_path, "manifests", "site.pp"), "w") as f:
f.write('\nimport "nodes.pp"\n')
# Add manifests and write initial size.pp
with open(os.path.join(tmp_path, "manifests", "nodes.pp"), "w") as f:
f.write('# Automatically managed by GOsa\n')
cmd = Git(tmp_path)
cmd.add("README")
cmd.add("puppet.conf")
cmd.add("manifests")
cmd.commit(m="Initially created puppet master branch")
cmd.push("origin", "master")
shutil.rmtree(tmp_path)
# Create SSH directory?
self.ssh_path = os.path.join(self.__path, '.ssh')
if not os.path.exists(self.ssh_path):
os.makedirs(self.ssh_path)
host = self.env.id
user = pwd.getpwuid(os.getuid()).pw_name
self.gen_ssh_key(os.path.join(self.ssh_path, 'id_dsa'),
"%[email protected]%s" % (user, host))
示例3: get_all_remote_branch
# 需要导入模块: from git.cmd import Git [as 别名]
# 或者: from git.cmd.Git import clone [as 别名]
def get_all_remote_branch(url):
tmp = tempfile.mkdtemp(prefix="repo_br")
git = Git(tmp)
git.clone(url, tmp)
return [b.strip()[len('origin/'):] for b in git.branch('--remote').splitlines() if not 'HEAD' in b]
示例4: createRelease
# 需要导入模块: from git.cmd import Git [as 别名]
# 或者: from git.cmd.Git import clone [as 别名]
def createRelease(self, name, parent=None):
super(PuppetInstallMethod, self).createRelease(name, parent)
with puppet_lock:
# Move to concrete directory name
orig_name = name
name = name.replace("/", "@")
# Clone repository
cmd = Git(self.__work_path)
if parent:
if isinstance(parent, StringTypes):
parent = parent.replace("/", "@")
else:
parent = parent.name.replace("/", "@")
self.log.debug("cloning new git branch '%s' from '%s'"
% (name, parent))
cmd.clone(self.__repo_path, name, b=parent)
else:
self.log.debug("creating new git branch '%s'" % name)
cmd.clone(self.__repo_path, name)
# Switch branch, add information
cmd = Git(os.path.join(self.__work_path, name))
host = self.env.id
cmd.config("--global", "user.name", "GOsa management agent on %s" % host)
self.log.debug("switching to newly created branch")
cmd.checkout(b=name)
# Remove refs if there's no parent
current_dir = os.path.join(self.__work_path, name)
if not parent:
self.log.debug("no parent set - removing refs")
cmd.symbolic_ref("HEAD", "refs/heads/newbranch")
os.remove(os.path.join(current_dir, ".git", "index"))
files = os.listdir(current_dir)
# Remove all but .git
for f in files:
if f== ".git":
continue
if os.path.isdir(f):
shutil.rmtree(os.path.join(current_dir, f))
else:
os.unlink(os.path.join(current_dir, f))
# Create release info file
self.log.debug("writing release info file in %s" % current_dir)
with open(os.path.join(current_dir, "release.info"), "w") as f:
now = datetime.now()
f.write("Release: %s\n" % orig_name)
f.write("Date: %s\n" % now.strftime("%Y-%m-%d %H:%M:%S"))
self.log.debug("comitting new release")
cmd.add("release.info")
cmd.commit(m="Created release information")
# Push to origin
self.log.debug("pushing change to central repository")
cmd.push("origin", name)
return True