Code Repositories xandikos / 3824d40
Prefer using .xandikos file. Jelmer Vernooń≥ 8 months ago
2 changed file(s) with 28 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
2020 """
2121
2222 import configparser
23 from io import BytesIO
23 from io import BytesIO, StringIO
2424 import logging
2525 import os
2626 import shutil
6969 def __init__(self, repo):
7070 self._repo = repo
7171
72 @classmethod
73 def present(cls, repo):
74 config = repo.get_config()
75 return config.has_section((b'xandikos', ))
76
7277 def get_color(self):
7378 config = self._repo.get_config()
7479 color = config.get(b'xandikos', b'color')
167172 self._check_for_duplicate_uids = check_for_duplicate_uids
168173 # Set of blob ids that have already been scanned
169174 self._fname_to_uid = {}
170 try:
171 cf = self._get_raw(CONFIG_FILENAME)
172 except KeyError:
173 self.config = RepoCollectionMetadata(self.repo)
175
176 @property
177 def config(self):
178 if RepoCollectionMetadata.present(self.repo):
179 return RepoCollectionMetadata(self.repo)
174180 else:
175181 cp = configparser.ConfigParser()
176 cp.read_string(cf)
182 try:
183 cf = self._get_raw(CONFIG_FILENAME)
184 except KeyError:
185 pass
186 else:
187 cp.read_string(cf)
177188
178189 def save_config(cp):
179 f = BytesIO()
190 f = StringIO()
180191 cp.write(f)
181192 self._import_one(
182 CONFIG_FILENAME, f.getvalue(), "Update configuration")
183 self.config = FileBasedCollectionMetadata(cp, save=save_config)
193 CONFIG_FILENAME, [f.getvalue().encode('utf-8')],
194 "Update configuration")
195 return FileBasedCollectionMetadata(cp, save=save_config)
184196
185197 def __repr__(self):
186198 return "%s(%r, ref=%r)" % (type(self).__name__, self.repo, self.ref)
261261 [('foo.ics', 'text/calendar', bid)],
262262 list(gc.iter_with_etag()))
263263
264 def test_get_description(self):
265 gc = self.create_store()
266 try:
267 gc.repo.set_description(b'a repo description')
268 except NotImplementedError:
269 self.skipTest('old dulwich version without '
270 'MemoryRepo.set_description')
264 def test_get_description_from_git_config(self):
265 gc = self.create_store()
266 config = gc.repo.get_config()
267 config.set(b'xandikos', b'test', b'test')
268 if getattr(config, 'path', None):
269 config.write_to_path()
270 gc.repo.set_description(b'a repo description')
271271 self.assertEqual(gc.get_description(), 'a repo description')
272272
273273 def test_displayname(self):