本文整理汇总了Python中gittle.Gittle.rm方法的典型用法代码示例。如果您正苦于以下问题:Python Gittle.rm方法的具体用法?Python Gittle.rm怎么用?Python Gittle.rm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gittle.Gittle
的用法示例。
在下文中一共展示了Gittle.rm方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import rm [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)
示例2: Git
# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import rm [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)
示例3: __init__
# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import rm [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)
示例4: Wiki
# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import rm [as 别名]
#.........这里部分代码省略.........
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):
old_filename, new_filename = map(cname_to_filename, [old_name, new_name])
if old_filename not in self.gittle.index:
# old doesn't exist
return None
if new_filename in self.gittle.index:
# file is being overwritten, but that is ok, it's git!
pass
os.rename(os.path.join(self.path, old_filename), os.path.join(self.path, new_filename))
self.gittle.add(new_filename)
self.gittle.rm(old_filename)
self.gittle.commit(name=getattr(user, 'username', self.default_committer_name),
email=getattr(user, 'email', self.default_committer_email),
message="Moved %s to %s" % (old_name, new_name),
files=[old_filename, new_filename])
cache.delete_many(old_filename, new_filename)
def get_page(self, name, sha='HEAD'):
cached = cache.get(name)
if cached:
return cached
# commit = gittle.utils.git.commit_info(self.repo[sha])
filename = cname_to_filename(name).encode('latin-1')
sha = sha.encode('latin-1')
try:
data = self.gittle.get_commit_files(sha, paths=[filename]).get(filename)
if not data:
return None
partials = {}
if data.get('data'):
meta = self.get_meta(data['data'])
if meta and 'import' in meta:
for partial_name in meta['import']:
partials[partial_name] = self.get_page(partial_name)
data['partials'] = partials
data['info'] = self.get_history(name, limit=1)[0]
return data
except KeyError:
示例5: git_rm
# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import rm [as 别名]
def git_rm(args):
if len(args) > 0:
repo = Gittle('.')
repo.rm(args)
else:
print command_help['rm']
示例6: Wiki
# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import rm [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
#.........这里部分代码省略.........
示例7: GitCommands
# 需要导入模块: from gittle import Gittle [as 别名]
# 或者: from gittle.Gittle import rm [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)