本文整理汇总了Python中gittle.Gittle.commit方法的典型用法代码示例。如果您正苦于以下问题:Python Gittle.commit方法的具体用法?Python Gittle.commit怎么用?Python Gittle.commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gittle.Gittle
的用法示例。
在下文中一共展示了Gittle.commit方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: git_commit
# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import commit [as 别名]
def git_commit(args):
if len(args) == 3:
try:
repo = Gittle('.')
print repo.commit(name=args[1],email=args[2],message=args[0])
except:
print 'Error: {0}'.format(sys.exc_value)
else:
print command_help['commit']
示例2: gitPush
# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import commit [as 别名]
def gitPush():
logging.info('*** Versioning files and pushing to remote repository ***')
destinations = [dataDestination, PDFdestination]
remotes = ['dataRemote', 'PDFRemote']
for d, r in zip(destinations, remotes):
repo = Gittle(d, origin_uri=config.get('Git', r))
repo.stage(repo.pending_files)
repo.commit(message=commitMessage)
repo.push()
示例3: __init__
# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import commit [as 别名]
class MyGit:
def __init__(self, gitdir):
self.git = Gittle(gitdir)
def add(self, files, message):
self.git.commit(message=message, files=files)
def rm(self, files, message):
self.git.rm(files)
self.git.commit(message=message)
示例4: Git
# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import commit [as 别名]
class Git(object):
@classmethod
def is_dir_git_repo(cls, directory):
return os.system("git rev-parse --is-inside-work-tree") == 0
def __init__(self, gitpath):
self._gitpath = gitpath
try:
self._gittle = Gittle(gitpath)
except dulwich.errors.NotGitRepository:
raise NoTesseraRepoError()
@property
def git_dir(self):
"""
Returns the git dir.
"""
return self._gittle.git_dir
def is_working(self):
"""
Checks if git is working
"""
return self._gittle.is_working
def commit_repo(self, tesserae, message):
"""
Commits the git tessera files.
"""
return self._gittle.commit(message=message, files=[os.path.relpath(tesserae.configpath, self._gitpath)])
def add_tessera(self, tessera):
"""
Commits a Tessera created by the create() method to the repository.
"""
return self._gittle.commit(message="tessera created: %s" % tessera.title, files=[os.path.relpath(tessera.tessera_file, self._gitpath), os.path.relpath(tessera.info_file, self._gitpath)])
def update_tessera(self, tessera):
"""
Commits an updated Tessera to the repository.
"""
return self._gittle.commit(message="tessera updated: %s" % tessera.title, files=[os.path.relpath(tessera.tessera_file, self._gitpath), os.path.relpath(tessera.info_file, self._gitpath)])
def rm_tessera(self, tessera):
"""
Removes a tessera and commits to git repository.
"""
files = [str(os.path.relpath(tessera.tessera_file, self._gitpath)), str(os.path.relpath(tessera.info_file, self._gitpath))]
self._gittle.rm(files)
return self._gittle.commit(message="tessera removed: %s" % tessera.title, files=files)
示例5: __init__
# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import commit [as 别名]
class GPassGit:
#Creates a Git object
def __init__(self, repoPath):
self.repoPath = repoPath
self.repo = None
if self.isRepoSet():
self.repo = Gittle(self.repoPath)
#Check For Git Repo
def isRepoSet(self):
if os.path.isfile(self.repoPath + '/.git/config'):
return True
return False
def init(self, repoPath):
self.repo = Gittle.init(repoPath)
print("Created Repo")
def add(self, filePath):
self.repo.stage([filePath])
def commit(self, user, em, msg):
self.repo.commit(
name=user,
email=em,
message=msg
)
# Authentication with RSA private key
def auth(self, key):
key_file = open(key)
repo.auth(pkey=key_file)
def push(self, key):
self.auth(key)
self.repo.push()
def pull(self, key):
self.auth(key)
self.repo.pull()
def acp(self, filepath, user, em, msg):
self.add(filepath)
self.commit(user, em, msg)
self.push(key)
示例6: __init__
# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import commit [as 别名]
class MyGit:
def __init__(self, gitdir):
self.git = Gittle(gitdir)
def add(self, files, message):
self.git.commit(message=message, files=files)
def rm(self, files, message):
self.git.rm(files)
self.git.commit(message=message)
def read_author(self, tessera_path):
author = "unknown"
author_time = 0;
walker = self.git.repo.get_walker(paths=[tessera_path])
try:
c = iter(walker).next().commit
except StopIteration:
print "git: author not found in %s" % tessera_path
else:
author = c.author
author_time = c.author_time
return (author, author_time)
示例7: Wiki
# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import commit [as 别名]
class Wiki(HookMixin):
path = None
base_path = '/'
default_ref = 'master'
default_committer_name = 'Anon'
default_committer_email = '[email protected]'
index_page = 'home'
gittle = None
repo = None
def __init__(self, path):
try:
self.gittle = Gittle(path)
except NotGitRepository:
self.gittle = Gittle.init(path)
# Dulwich repo
self.repo = self.gittle.repo
self.path = path
def __repr__(self):
return "Wiki: %s" % self.path
def revert_page(self, name, commit_sha, message, username):
page = self.get_page(name, commit_sha)
if not page:
# Page not found
return None
commit_info = gittle.utils.git.commit_info(self.gittle[commit_sha.encode('latin-1')])
message = commit_info['message']
return self.write_page(name, page['data'], message=message, username=username)
def write_page(self, name, content, message=None, create=False, username=None, email=None):
def escape_repl(m):
if m.group(1):
return "```" + escape(m.group(1)) + "```"
def unescape_repl(m):
if m.group(1):
return "```" + unescape(m.group(1)) + "```"
cname = to_canonical(name)
# prevents p tag from being added, we remove this later
content = '<div>' + content + '</div>'
content = re.sub(r"```(.*?)```", escape_repl, content, flags=re.DOTALL)
tree = lxml.html.fromstring(content)
cleaner = Cleaner(remove_unknown_tags=False,
kill_tags=set(['style']),
safe_attrs_only=False)
tree = cleaner.clean_html(tree)
content = lxml.html.tostring(tree, encoding='utf-8', method='html')
# remove added div tags
content = content[5:-6]
# FIXME this is for block quotes, doesn't work for double ">"
content = re.sub(r"(\n>)", "\n>", content)
content = re.sub(r"(^>)", ">", content)
# Handlebars partial ">"
content = re.sub(r"\{\{>(.*?)\}\}", r'{{>\1}}', content)
# Handlebars, allow {{}} inside HTML links
content = content.replace("%7B", "{")
content = content.replace("%7D", "}")
content = re.sub(r"```(.*?)```", unescape_repl, content, flags=re.DOTALL)
filename = cname_to_filename(cname)
with open(self.path + "/" + filename, 'w') as f:
f.write(content)
if create:
self.gittle.add(filename)
if not message:
message = "Updated %s" % name
if not username:
username = self.default_committer_name
if not email:
email = self.default_committer_email
ret = self.gittle.commit(name=username,
email=email,
message=message,
files=[filename])
cache.delete(cname)
return ret
def rename_page(self, old_name, new_name, user=None):
#.........这里部分代码省略.........
示例8: Wiki
# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import commit [as 别名]
class Wiki(HookMixin):
path = None
base_path = '/'
default_ref = 'master'
default_committer_name = 'Anon'
default_committer_email = '[email protected]'
index_page = 'home'
gittle = None
repo = None
def __init__(self, path):
try:
self.gittle = Gittle(path)
except NotGitRepository:
self.gittle = Gittle.init(path)
# Dulwich repo
self.repo = self.gittle.repo
self.path = path
def __repr__(self):
return "Wiki: %s" % self.path
def _get_user(self, username, email):
if not username:
username = self.default_committer_name
if not email:
email = self.default_committer_email
return username, email
def revert_page(self, name, commit_sha, message, username, email):
"""Revert page to passed commit sha1
:param name: Name of page to revert.
:param commit_sha: Commit Sha1 to revert to.
:param message: Commit message.
:param username: Committer name.
:param email: Committer email.
:return: Git commit sha1
"""
page = self.get_page(name, commit_sha)
if not page:
raise PageNotFound('Commit not found')
if not message:
commit_info = gittle.utils.git.commit_info(self.gittle[commit_sha.encode('latin-1')])
message = commit_info['message']
return self.write_page(name, page['data'], message=message, username=username, email=email)
def write_page(self, name, content, message=None, create=False, username=None, email=None):
"""Write page to git repo
:param name: Name of page.
:param content: Content of page.
:param message: Commit message.
:param create: Perform git add operation?
:param username: Commit Name.
:param email: Commit Email.
:return: Git commit sha1.
"""
cname = to_canonical(name)
filename = cname_to_filename(cname)
namespace_path = os.path.join(self.path, os.path.split(filename)[0])
if not os.path.exists(namespace_path):
os.makedirs(namespace_path)
with open(self.path + "/" + filename, 'w') as f:
f.write(content)
if create:
self.gittle.add(filename)
if not message:
message = "Updated %s" % name
username, email = self._get_user(username, email)
ret = self.gittle.commit(name=username,
email=email,
message=message,
files=[filename])
cache.delete(cname)
return ret
def rename_page(self, old_name, new_name, username=None, email=None, message=None):
"""Rename page.
:param old_name: Page that will be renamed.
:param new_name: New name of page.
:param username: Committer name
:param email: Committer email
#.........这里部分代码省略.........
示例9: Wiki
# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import commit [as 别名]
class Wiki(HookMixin):
path = None
base_path = '/'
default_ref = 'master'
default_committer_name = 'Anon'
default_committer_email = '[email protected]'
index_page = 'home'
gittle = None
repo = None
def __init__(self, path):
try:
self.gittle = Gittle(path)
except NotGitRepository:
self.gittle = Gittle.init(path)
# Dulwich repo
self.repo = self.gittle.repo
self.path = path
def __repr__(self):
return "Wiki: %s" % self.path
def commit(self, name, email, message, files):
"""Commit to the underlying git repo.
:param name: Committer name
:param email: Committer email
:param message: Commit message
:param files: list of file names that should be committed
:return:
"""
# Dulwich and gittle seem to want us to encode ourselves at the moment. see #152
if isinstance(name, unicode):
name = name.encode('utf-8')
if isinstance(email, unicode):
email = email.encode('utf-8')
if isinstance(message, unicode):
message = message.encode('utf-8')
return self.gittle.commit(name=name,
email=email,
message=message,
files=files)
def get_page(self, name, sha='HEAD'):
"""Get page data, partials, commit info.
:param name: Name of page.
:param sha: Commit sha.
:return: dict
"""
return WikiPage(name, self, sha=sha)
def get_index(self):
"""Get repo index of head.
:return: list -- List of dicts
"""
rv = []
index = self.repo.open_index()
for name in index:
rv.append(dict(name=filename_to_cname(name),
filename=name,
ctime=index[name].ctime[0],
mtime=index[name].mtime[0],
sha=index[name].sha,
size=index[name].size))
return rv
示例10: GitCommands
# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import commit [as 别名]
#.........这里部分代码省略.........
return False
#if self.git.is_dirty():
# stderr.write("repo is dirty\n")
# return False
if args:
title = " ".join(args)
else:
title = "tessera title goes here"
uuid = uuid1()
tessera_path = "%s/%s" % (Tessera._tesserae, uuid)
tessera_file = "%s/tessera" % tessera_path
os.mkdir(tessera_path)
fin = open("%s/template" % Tessera._tesserae, "r")
fout = open(tessera_file, "w")
for line in fin.readlines():
if line == "@[email protected]\n":
line = "# %s\n" % title
fout.write(line)
fin.close()
fout.close()
p = Popen(["sensible-editor", tessera_file])
p.communicate()
p.wait()
t = Tessera(tessera_path)
self.git_add(tessera_file, "tessera created: %s" % t.get_attribute("title"))
return True
def cmd_remove(self, args):
if len(args) != 1:
stderr.write("git tessera remove takes identifier as argument\n")
return False
#if self.git.is_dirty():
#stderr.write("repo is dirty\n")
#return False
key = args[0]
tessera_file = None
tessera_path = None
for i in os.listdir(Tessera._tesserae):
tessera_path = "%s/%s" % (Tessera._tesserae, i)
if not stat.S_ISDIR(os.lstat(tessera_path).st_mode):
continue
if i.split('-')[0] == key or i == key:
tessera_file = "%s/tessera" % tessera_path
break
if not tessera_file:
stderr.write("git tessera %s not found\n" % key)
return False
t = Tessera(tessera_path)
stdout.write("remove tessera %s: %s ? [Y/n] " % (key, t.get_attribute("title")))
try:
answer = stdin.readline().strip()
except KeyboardInterrupt:
return False
if not answer or answer.lower() == "y":
files = ["%s/%s" % (tessera_path, x) for x in os.listdir(tessera_path)]
self.git_rm(files, "tessera removed: %s" % t.get_attribute("title"))
from shutil import rmtree
rmtree(tessera_path)
def cmd_serve(self, args):
from tesseraweb import TesseraWeb
web = TesseraWeb()
web.serve()
def cmd_tag(self, args):
if len(args) != 2:
stderr.write("git tessera show takes identifier as argument and new tag\n")
return False
key = args[0]
for i in os.listdir(Tessera._tesserae):
tessera_path = "%s/%s" % (Tessera._tesserae, i)
if not stat.S_ISDIR(os.lstat(tessera_path).st_mode):
continue
if i.split('-')[0] == key or i == key:
break
if not tessera_path:
stderr.write("git tessera %s not found\n" % key)
return False
t = Tessera(tessera_path)
t.add_tag(args[1])
self.git_add(t.filename, "tessera updated: add tag %s to %s" % (args[1], t.get_attribute("title")))
return True
def git_add(self, files, message):
stderr.write("staging %s" % files)
self.git.commit(message=message, files=files)
def git_rm(self, files, message):
self.git.rm(files)
self.git.commit(message=message)