Prefer using .xandikos file.
Jelmer Vernooij
2 years ago
20 | 20 |
"""
|
21 | 21 |
|
22 | 22 |
import configparser
|
23 | |
from io import BytesIO
|
|
23 |
from io import BytesIO, StringIO
|
24 | 24 |
import logging
|
25 | 25 |
import os
|
26 | 26 |
import shutil
|
|
69 | 69 |
def __init__(self, repo):
|
70 | 70 |
self._repo = repo
|
71 | 71 |
|
|
72 |
@classmethod
|
|
73 |
def present(cls, repo):
|
|
74 |
config = repo.get_config()
|
|
75 |
return config.has_section((b'xandikos', ))
|
|
76 |
|
72 | 77 |
def get_color(self):
|
73 | 78 |
config = self._repo.get_config()
|
74 | 79 |
color = config.get(b'xandikos', b'color')
|
|
167 | 172 |
self._check_for_duplicate_uids = check_for_duplicate_uids
|
168 | 173 |
# Set of blob ids that have already been scanned
|
169 | 174 |
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)
|
174 | 180 |
else:
|
175 | 181 |
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)
|
177 | 188 |
|
178 | 189 |
def save_config(cp):
|
179 | |
f = BytesIO()
|
|
190 |
f = StringIO()
|
180 | 191 |
cp.write(f)
|
181 | 192 |
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)
|
184 | 196 |
|
185 | 197 |
def __repr__(self):
|
186 | 198 |
return "%s(%r, ref=%r)" % (type(self).__name__, self.repo, self.ref)
|
261 | 261 |
[('foo.ics', 'text/calendar', bid)],
|
262 | 262 |
list(gc.iter_with_etag()))
|
263 | 263 |
|
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')
|
271 | 271 |
self.assertEqual(gc.get_description(), 'a repo description')
|
272 | 272 |
|
273 | 273 |
def test_displayname(self):
|