本文整理汇总了Python中git.cmd.Git.add方法的典型用法代码示例。如果您正苦于以下问题:Python Git.add方法的具体用法?Python Git.add怎么用?Python Git.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类git.cmd.Git
的用法示例。
在下文中一共展示了Git.add方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gitPush
# 需要导入模块: from git.cmd import Git [as 别名]
# 或者: from git.cmd.Git import add [as 别名]
def gitPush(self, path, comment=None):
# Announce changes to git
cmd = Git(path)
changed = False
for line in cmd.status("--porcelain").splitlines():
changed = True
line = line.lstrip()
self.log.info("staging changes for %s" % line.split(" ", 1)[1:])
mode, file_path = line.split(" ", 1)
file_path = os.path.join(*file_path.split("/")[0:])
# Remove data?
if mode == "D":
cmd.rm("-r", file_path)
# Add data...
else:
cmd.add(file_path)
# No need to deal...
if not changed:
return False
# Commit changes
if not comment:
comment = "Change made with no comment"
self.log.info("committing changes for module %s" % path)
cmd.commit("-m", comment)
cmd.push("origin")
return True
示例2: save
# 需要导入模块: from git.cmd import Git [as 别名]
# 或者: from git.cmd.Git import add [as 别名]
def save(self, *args, **kwargs):
message = kwargs.pop('message', self._next_message() or 'update')
super(Fork, self).save(*args, **kwargs)
with open(os.path.join(self.git_path, "BODY"), 'w') as f:
f.write(self.body)
git = Git(self.git_path)
git.add('BODY')
try:
git.commit(message=message)
except GitCommandError, e:
if e.status != 1:
raise
示例3: init_releaserc
# 需要导入模块: from git.cmd import Git [as 别名]
# 或者: from git.cmd.Git import add [as 别名]
def init_releaserc(debug, info):
path = getcwd()
git = Git(path)
another_env = 'y'
n_th = 'first'
branches = []
secrets = {}
commands = {
"test": "/usr/bin/true"
}
# get branch names and passwords
info('\nLet\'s setup your roll process.')
info('-------------------------------')
while another_env.lower() == 'y' or another_env.lower() == '':
env_name = raw_input('What\'s the name of the ' + n_th + ' environment? ')
branches.append(env_name)
password_required = raw_input('Should a password be required to roll here? (y/N) ')
password = None
if password_required.lower() == 'y':
password = sha.new(getpass()).hexdigest()
secrets[env_name] = password
another_env = raw_input('Is there another environment? (Y/n) ')
n_th = 'next'
info('')
info('Your roll process is:\nmaster -> ' + ' -> '.join(branches))
info('')
info('')
fd = open('.releaserc', 'w')
json.dump({
"branches": branches,
"commands": commands,
"secrets": secrets
}, fd, indent=4, separators=(',', ': '))
debug('adding .releaserc...')
debug(git.add('.releaserc'))
示例4: welcome_package
# 需要导入模块: from git.cmd import Git [as 别名]
# 或者: from git.cmd.Git import add [as 别名]
def welcome_package(debug, info):
path = getcwd()
git = Git(path)
fd = open('welcome.txt', 'w')
fd.write('''
Welcome to {tool_name}
=======================
This tool is a helper to be used along side git.
$ {tool_command} init # you just ran this!
$ {tool_command} update
$ {tool_command} roll to dev
$ {tool_command} roll qa to prod
'''.format(tool_name=tool_name, tool_command=tool_command))
debug('adding welcome.txt...')
debug(git.add('welcome.txt'))
info('Welcome to {tool_name}'.format(tool_name=tool_name))
示例5: website_gitrepo
# 需要导入模块: from git.cmd import Git [as 别名]
# 或者: from git.cmd.Git import add [as 别名]
def website_gitrepo(self, user, repo_name):
'''Create a new GitHub repository and populate it with content from
a newly generated jekyll website export created via :meth:`website`.
:param user: user
:param repo_name: name of the GitHub repository to be created;
raises :class:`GithubExportException` if the repository already
exists
:param vol: :class:`~readux.books.models.Volume` to be exported
(1.0 or 1.1)
:param tei: annotated TEI facsimile (e.g.,
:class:`~readux.books.tei.AnnotatedFacsimile`)
:param page_one: page where numbering should start from 1 in the export
:return: on success, returns a tuple of public repository url and
github pages url for the newly created repo and site
'''
# connect to github as the user in order to create the repository
self.use_github(user)
# NOTE: github pages sites now default to https
github_pages_url = 'https://%s.github.io/%s/' % \
(self.github_username, repo_name)
# before even starting to generate the jekyll site,
# check if requested repo name already exists; if so, bail out with an error
current_repos = self.github.list_repos(self.github_username)
current_repo_names = [repo['name'] for repo in current_repos]
if repo_name in current_repo_names:
raise GithubExportException('GitHub repo %s already exists.' \
% repo_name)
export_dir = self.generate_website()
# jekyll dir is *inside* the export directory;
# for the jekyll site to display correctly, we need to commit what
# is in the directory, not the directory itself
jekyll_dir = self.get_jekyll_site_dir(export_dir)
# modify the jekyll config for relative url on github.io
config_file_path = os.path.join(jekyll_dir, '_config.yml')
with open(config_file_path, 'r') as configfile:
config_data = yaml.load(configfile)
# split out github pages url into the site url and path
parsed_gh_url = urlparse(github_pages_url)
config_data['url'] = '%s://%s' % (parsed_gh_url.scheme,
parsed_gh_url.netloc)
config_data['baseurl'] = parsed_gh_url.path.rstrip('/')
with open(config_file_path, 'w') as configfile:
yaml.safe_dump(config_data, configfile,
default_flow_style=False)
# using safe_dump to generate only standard yaml output
# NOTE: pyyaml requires default_flow_style=false to output
# nested collections in block format
logger.debug('Creating github repo %s for %s', repo_name,
self.github_username)
if self.update_callback is not None:
self.update_callback('Creating GitHub repo %s' % repo_name)
self.github.create_repo(
repo_name, homepage=github_pages_url,
description='An annotated digital edition created with Readux')
# get auth repo url to use to push data
repo_url = self.github_auth_repo(repo_name=repo_name)
# add the jekyll site to github; based on these instructions:
# https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
# initialize export dir as a git repo, and commit the contents
# NOTE: to debug git commands, print the git return to see git output
gitcmd = Git(jekyll_dir)
# initialize jekyll site as a git repo
gitcmd.init()
# add and commit all contents
gitcmd.add(['.'])
gitcmd.commit(
['-m', 'Import Jekyll site generated by Readux %s' % __version__,
'--author="%s <%s>"' % (settings.GIT_AUTHOR_NAME,
settings.GIT_AUTHOR_EMAIL)])
# push local master to the gh-pages branch of the newly created repo,
# using the user's oauth token credentials
self.log_status('Pushing content to GitHub')
gitcmd.push([repo_url, 'master:gh-pages'])
# clean up temporary files after push to github
shutil.rmtree(export_dir)
# generate public repo url for display to user
public_repo_url = 'https://github.com/%s/%s' % (self.github_username,
repo_name)
return (public_repo_url, github_pages_url)
示例6: __init__
# 需要导入模块: from git.cmd import Git [as 别名]
# 或者: from git.cmd.Git import add [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))
示例7: createRelease
# 需要导入模块: from git.cmd import Git [as 别名]
# 或者: from git.cmd.Git import add [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