本文整理汇总了Python中dulwich.porcelain.add方法的典型用法代码示例。如果您正苦于以下问题:Python porcelain.add方法的具体用法?Python porcelain.add怎么用?Python porcelain.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dulwich.porcelain
的用法示例。
在下文中一共展示了porcelain.add方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_model
# 需要导入模块: from dulwich import porcelain [as 别名]
# 或者: from dulwich.porcelain import add [as 别名]
def add_model(self, model_type: str, model_uuid: str, meta: dict,
template_model: Template, update_default: bool=False):
"""Add a new model to the registry. Call `upload()` to update the remote side."""
if update_default or model_type not in self.meta:
self.meta[model_type] = meta["default"]
model_meta = meta["model"]
self.models.setdefault(model_type, {})[model_uuid] = model_meta
model_directory = os.path.join(self.cached_repo, model_type)
os.makedirs(model_directory, exist_ok=True)
model = os.path.join(model_directory, model_uuid + ".md")
if os.path.exists(model):
os.remove(model)
links = {}
for m_type, items in self.models.items():
for uuid in items:
if uuid in model_meta["dependencies"]:
links[uuid] = os.path.join("/", m_type, "%s.md" % uuid)
with open(model, "w") as fout:
fout.write(template_model.render(model_type=model_type, model_uuid=model_uuid,
meta=model_meta, links=links, spdx=LICENSES))
git.add(self.cached_repo, [model])
self._log.info("Added %s", model)
示例2: git_add
# 需要导入模块: from dulwich import porcelain [as 别名]
# 或者: from dulwich.porcelain import add [as 别名]
def git_add(args):
if len(args) > 0:
repo = _get_repo()
cwd = os.getcwd()
args = [os.path.join(os.path.relpath(cwd, repo.path), x) if not os.path.samefile(cwd, repo.path) else x for x in args]
for file in args:
if os.path.exists(os.path.join(repo.repo.path, file)):
print('Adding {0}'.format(file))
porcelain.add(repo.repo.path, [file])
else:
print('{} does not exist. skipping'.format(file))
else:
print(command_help['add'])
示例3: commit_and_push
# 需要导入模块: from dulwich import porcelain [as 别名]
# 或者: from dulwich.porcelain import add [as 别名]
def commit_and_push(
version: str,
repository: Repository,
paths: List[Path],
) -> None:
"""
Commit and push all changes.
"""
local_repository = Repo('.')
_, ignored = add(paths=[str(path) for path in paths])
assert not ignored
message = b'Update for release ' + version.encode('utf-8')
commit(message=message)
branch_name = 'master'
push(
repo=local_repository,
remote_location=repository.ssh_url,
refspecs=branch_name.encode('utf-8'),
)
示例4: refresh_gittle
# 需要导入模块: from dulwich import porcelain [as 别名]
# 或者: from dulwich.porcelain import add [as 别名]
def refresh_gittle(self):
#untracked
#unstaged modified
#staged add
#staged rm
#staged modify
#unmodified
self.g=self._get_repo()
def refresh_thread():
if self.g:
self.list[0]=list(self.g.untracked_files)
#self.view['tableview1'].reload()
self.list[1]=porcelain.status(self.g.path).unstaged
#self.view['tableview1'].reload()
self.list[2]=porcelain.status(self.g.path).staged['add']
#self.view['tableview1'].reload()
self.list[3]=porcelain.status(self.g.path).staged['delete']
#self.view['tableview1'].reload()
self.list[4]=porcelain.status(self.g.path).staged['modify']
#self.view['tableview1'].reload()
self.list[5]=list(self.g.tracked_files-set(itertools.chain(*self.list[1:4])))
refresh_thread()
示例5: update_readme
# 需要导入模块: from dulwich import porcelain [as 别名]
# 或者: from dulwich.porcelain import add [as 别名]
def update_readme(self, template_readme: Template):
"""Generate the new README file locally."""
readme = os.path.join(self.cached_repo, "README.md")
if os.path.exists(readme):
os.remove(readme)
links = {model_type: {} for model_type in self.models.keys()}
for model_type, model_uuids in self.models.items():
for model_uuid in model_uuids:
links[model_type][model_uuid] = os.path.join("/", model_type, "%s.md" % model_uuid)
with open(readme, "w") as fout:
fout.write(template_readme.render(models=self.models, meta=self.meta, links=links))
git.add(self.cached_repo, [readme])
self._log.info("Updated %s", readme)
示例6: upload
# 需要导入模块: from dulwich import porcelain [as 别名]
# 或者: from dulwich.porcelain import add [as 别名]
def upload(self, cmd: str, meta: dict):
"""Push the current state of the registry to Git."""
index = os.path.join(self.cached_repo, self.INDEX_FILE)
if os.path.exists(index):
os.remove(index)
self._log.info("Writing the new index.json ...")
with open(index, "w") as _out:
json.dump(self.contents, _out, sort_keys=True, indent=4)
git.add(self.cached_repo, [index])
message = self.COMMIT_MESSAGES[cmd].format(**meta)
if self.signoff:
global_conf_path = os.path.expanduser("~/.gitconfig")
if os.path.exists(global_conf_path):
with open(global_conf_path, "br") as _in:
conf = ConfigFile.from_file(_in)
try:
name = conf.get(b"user", b"name").decode()
email = conf.get(b"user", b"email").decode()
message += self.DCO_MESSAGE.format(name=name, email=email)
except KeyError:
self._log.warning(
"Did not find name or email in %s, committing without DCO",
global_conf_path)
else:
self._log.warning("Global git configuration file %s does not exist, "
"committing without DCO", global_conf_path)
else:
self._log.info("Committing the index without DCO")
git.commit(self.cached_repo, message=message)
self._log.info("Pushing the updated index ...")
# TODO: change when https://github.com/dulwich/dulwich/issues/631 gets addressed
git.push(self.cached_repo, self.remote_url, b"master")
if self._are_local_and_remote_heads_different():
self._log.error("Push has failed")
raise ValueError("Push has failed")
示例7: add_file
# 需要导入模块: from dulwich import porcelain [as 别名]
# 或者: from dulwich.porcelain import add [as 别名]
def add_file(self, data, filename):
"""Add a file to the commit."""
try:
full_filename = os.path.join(self.repo_path, filename)
with open(full_filename, "w") as f:
f.write(data)
porcelain.add(self.repo, full_filename)
except Exception:
# Anonymizing exceptions
log.exception("GitHandler::add_file()")
raise InvalidCommand("Adding file failed: Please check your log files...")
示例8: unstage
# 需要导入模块: from dulwich import porcelain [as 别名]
# 或者: from dulwich.porcelain import add [as 别名]
def unstage(self,repo,paths=None):
from dulwich import porcelain
from dulwich.index import index_entry_from_stat
# if tree_entry does not exist, this was an add, so remove index entry to undo
# if index_ entry does not exist, this was a remove.. add back in
if paths:
for path in paths:
#print path
full_path = os.path.join(repo.path, path)
index=repo.open_index()
tree_id=repo.object_store[repo.head()]._tree
try:
tree_entry=repo.object_store[tree_id]._entries[path]
except KeyError:
try:
del(index[path])
index.write()
except KeyError:
console.hud_alert('file not in index...')
return
try:
index_entry=list(index[path])
except KeyError:
if os.path.exists(full_path):
index_entry=list(index_entry_from_stat(posix.lstat(full_path),tree_entry[1] ,0 ))
else:
index_entry=[[0]*11,tree_entry[1],0]
index_entry[4]=tree_entry[0] #mode
index_entry[7]=len(repo.object_store [tree_entry[1]].data) #size
index_entry[8]=tree_entry[1] #sha
index_entry[0]=repo.object_store[repo.head()].commit_time #ctime
index_entry[1]=repo.object_store[repo.head()].commit_time #mtime
index[path]=index_entry
index.write()
示例9: has_uncommitted_changes
# 需要导入模块: from dulwich import porcelain [as 别名]
# 或者: from dulwich.porcelain import add [as 别名]
def has_uncommitted_changes(self):
if(porcelain.status(self.g.path).unstaged or
porcelain.status(self.g.path).staged['add'] or
porcelain.status(self.g.path).staged['modify'] or
porcelain.status(self.g.path).staged['delete']):
return True
示例10: merge_trees
# 需要导入模块: from dulwich import porcelain [as 别名]
# 或者: from dulwich.porcelain import add [as 别名]
def merge_trees(store, base, mine, theirs):
''' takes tree ids for base, mine, and theirs. merge trees into current working tee'''
num_conflicts = 0
added = []
removed = []
w = walk_trees(store, [base, mine, theirs], True)
count = 0
for b, m, t in w:
if _is_tree(b) or _is_tree(m) or _is_tree(t):
#todo... handle mkdir, rmdir
continue
# if mine == theirs match, use either
elif m == t:
if not b.path:
print(' ', m.path, 'was added, but matches already')
continue #leave workng tree alone
# if base==theirs, but not mine, already deleted (do nothing)
elif b == t and not m.path:
print(' ', b.path, ' already deleted in head')
continue
# if base==mine, but not theirs, delete
elif b == m and not t.path:
print(' -', m.path, ' was deleted in theirs.')
os.remove(m.path)
removed.append(m.path)
elif not b.path and m.path and not t.path: #add in mine
print(' ', m.path, 'added in mine')
continue
elif not b.path and t.path and not m.path: # add theirs to mine
# add theirs
print(' +', t.path, ': adding to head')
with open(t.path, 'w') as f:
f.write(store[t.sha].data)
added.append(t.path)
elif not m == t: # conflict
print(' ?', m.path, ': merging conflicts')
result = diff3.merge(
store[m.sha].data.splitlines(True),
store[b.sha].data.splitlines(True) if b.sha else [''],
store[t.sha].data.splitlines(True)
)
mergedfile = result['body']
had_conflict = result['conflict']
with open(m.path, 'w') as f:
for line in mergedfile:
f.write(line)
if had_conflict:
num_conflicts += 1
print(
' !!! {} had a conflict that could not be resolved.\n conflict markers added to file in working tree.\n you need to resolve manually '
.format(m.path)
)
added.append(m.path)
return num_conflicts, added, removed