本文整理汇总了Python中dulwich.config.ConfigFile类的典型用法代码示例。如果您正苦于以下问题:Python ConfigFile类的具体用法?Python ConfigFile怎么用?Python ConfigFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ConfigFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_config
def get_config(self):
"""Retrieve the config object.
:return: `ConfigFile` object for the ``.git/config`` file.
"""
from dulwich.config import ConfigFile
path = os.path.join(self._controldir, 'config')
try:
return ConfigFile.from_path(path)
except (IOError, OSError) as e:
if e.errno != errno.ENOENT:
raise
ret = ConfigFile()
ret.path = path
return ret
示例2: testSubmodules
def testSubmodules(self):
cf = ConfigFile.from_file(BytesIO(b"""\
[submodule "core/lib"]
path = core/lib
url = https://github.com/phhusson/QuasselC.git
"""))
got = list(parse_submodules(cf))
self.assertEqual([
(b'core/lib', b'https://github.com/phhusson/QuasselC.git', b'core/lib')], got)
示例3: fetch_refs
def fetch_refs(remote_name = 'origin', local='.'):
"""
Fetch references from a Git remote repository
:param remote_name: <str> git name of remote repository, _default='origin'_
:param local: <str> full path to local repository, _default='.'_
:return entries: <TreeEntry> named tuples
"""
#import rpdb; rpdb.set_trace()
# **Fetch refs from remote**
# create a dulwich Repo object from path to local repo
r = Repo(local) # local repository
objsto = r.object_store # create a ObjectStore object from the local repo
determine_wants = objsto.determine_wants_all # built in dulwich function
gitdir = os.path.join(local, r.controldir()) # the git folder
cnf_file = os.path.join(gitdir, 'config') # path to config
cnf = ConfigFile.from_path(cnf_file) # config
remote = cnf.get(('remote', remote_name), 'url') # url of remote
# correctly parse host path and create dulwich Client object from it
client, host_path = get_transport_and_path(remote)
remote_refs = client.fetch(host_path, r, determine_wants, sys.stdout.write)
# **Store refs fetched by dulwich**
dulwich_refs = os.path.join(gitdir, DULWICH_REFS)
with open(dulwich_refs, 'wb') as file:
writer = csv.writer(file, delimiter=' ')
for key, value in remote_refs.items():
writer.writerow([key, value])
# **save remote refs shas for future checkout**
remote_dir = os.path.join(gitdir, 'refs', 'remotes', remote_name) # .git/refs/remotes
ensure_dir_exists(remote_dir) # built in dulwich function
headref = 0
# head branch ref
if remote_refs.has_key('HEAD'):
headref = remote_refs.pop('HEAD') # sha of HEAD
i_head = remote_refs.values().index(headref) # index of head ref
head_branch = remote_refs.keys()[i_head] # name of head branch
branch_key = head_branch.rsplit('/',1)[-1] # branch
head_file = os.path.join(remote_dir, 'HEAD') # path to branch shas file
head_ref = '/'.join(['refs','remotes',remote_name,branch_key])
with open(head_file, 'wb') as GitFile:
GitFile.write('ref: ' + head_ref + '\n')
# remote branch refs
for key, value in remote_refs.items():
key = key.rsplit('/',1)[-1] # get just the remote's branch
reffile = os.path.join(remote_dir, key) # path to branch shas file
with open(reffile, 'wb') as GitFile:
GitFile.write(value + '\n')
if headref:
remote_refs['HEAD'] = headref # restore HEAD sha
return remote_refs
示例4: from_file
def from_file(self, text):
return ConfigFile.from_file(StringIO(text))
示例5: test_write_to_file_subsection
def test_write_to_file_subsection(self):
c = ConfigFile()
c.set(("branch", "blie"), "foo", "bar")
f = StringIO()
c.write_to_file(f)
self.assertEquals("[branch \"blie\"]\nfoo = bar\n", f.getvalue())
示例6: test_write_to_file_section
def test_write_to_file_section(self):
c = ConfigFile()
c.set(("core", ), "foo", "bar")
f = StringIO()
c.write_to_file(f)
self.assertEquals("[core]\nfoo = bar\n", f.getvalue())
示例7: test_write_to_file_empty
def test_write_to_file_empty(self):
c = ConfigFile()
f = StringIO()
c.write_to_file(f)
self.assertEquals("", f.getvalue())
示例8: _init_files
def _init_files(self, bare):
"""Initialize a default set of named files."""
from dulwich.config import ConfigFile
self._put_named_file('description', b"Unnamed repository")
f = BytesIO()
cf = ConfigFile()
cf.set(b"core", b"repositoryformatversion", b"0")
if self._determine_file_mode():
cf.set(b"core", b"filemode", True)
else:
cf.set(b"core", b"filemode", False)
cf.set(b"core", b"bare", bare)
cf.set(b"core", b"logallrefupdates", True)
cf.write_to_file(f)
self._put_named_file('config', f.getvalue())
self._put_named_file(os.path.join('info', 'exclude'), b'')
示例9: from_file
def from_file(self, text):
return ConfigFile.from_file(BytesIO(text))
示例10: test_write_to_file_subsection
def test_write_to_file_subsection(self):
c = ConfigFile()
c.set((b"branch", b"blie"), b"foo", b"bar")
f = BytesIO()
c.write_to_file(f)
self.assertEqual(b"[branch \"blie\"]\n\tfoo = bar\n", f.getvalue())
示例11: test_write_to_file_section
def test_write_to_file_section(self):
c = ConfigFile()
c.set((b"core", ), b"foo", b"bar")
f = BytesIO()
c.write_to_file(f)
self.assertEqual(b"[core]\n\tfoo = bar\n", f.getvalue())
示例12: test_write_to_file_empty
def test_write_to_file_empty(self):
c = ConfigFile()
f = BytesIO()
c.write_to_file(f)
self.assertEqual(b"", f.getvalue())
示例13: test_set_hash_gets_quoted
def test_set_hash_gets_quoted(self):
c = ConfigFile()
c.set(b"xandikos", b"color", b"#665544")
f = BytesIO()
c.write_to_file(f)
self.assertEqual(b"[xandikos]\n\tcolor = \"#665544\"\n", f.getvalue())
示例14: gen_configs
def gen_configs():
for path in config_file + self._config_files:
try:
yield ConfigFile.from_path(path)
except (IOError, OSError, ValueError):
continue
示例15: _init_files
def _init_files(self, bare):
"""Initialize a default set of named files."""
from dulwich.config import ConfigFile
self._put_named_file('description', "Unnamed repository")
f = StringIO()
cf = ConfigFile()
cf.set("core", "repositoryformatversion", "0")
cf.set("core", "filemode", "true")
cf.set("core", "bare", str(bare).lower())
cf.set("core", "logallrefupdates", "true")
cf.write_to_file(f)
self._put_named_file('config', f.getvalue())
self._put_named_file(os.path.join('info', 'exclude'), '')