Code Repositories xandikos / f63034e
Add type to configuration. Jelmer Vernooń≥ 2 months ago
3 changed file(s) with 34 addition(s) and 34 deletion(s). Raw diff Collapse all Expand all
5555 self._configparser = cp
5656 self._save_cb = save
5757
58 def _save(self):
58 def _save(self, message):
5959 if self._save_cb is None:
6060 return
61 self._save_cb(self._configparser)
61 self._save_cb(self._configparser, message)
6262
6363 @classmethod
6464 def from_file(cls, f):
8383 self._configparser['DEFAULT']['color'] = color
8484 else:
8585 del self._configparser['DEFAULT']['color']
86 self._save()
86 self._save("Set color.")
8787
8888 def set_displayname(self, displayname):
8989 if displayname is not None:
9090 self._configparser['DEFAULT']['displayname'] = displayname
9191 else:
9292 del self._configparser['DEFAULT']['displayname']
93 self._save()
93 self._save("Set display name.")
9494
9595 def set_description(self, description):
9696 if description is not None:
9797 self._configparser['DEFAULT']['description'] = description
9898 else:
9999 del self._configparser['DEFAULT']['description']
100 self._save()
100 self._save("Set description.")
101101
102102 def set_comment(self, comment):
103103 if comment is not None:
104104 self._configparser['DEFAULT']['comment'] = comment
105105 else:
106106 del self._configparser['DEFAULT']['comment']
107 self._save()
107 self._save("Set comment.")
108
109 def set_type(self, store_type):
110 self._configparser['DEFAULT']['type'] = store_type
111 self._save("Set collection type.")
112
113 def get_type(self):
114 return self._configparser['DEFAULT']['type']
141141 config.set(b'xandikos', b'comment', b'')
142142 self._write_config(config)
143143
144 def set_type(self, store_type):
145 config = self._repo.get_config()
146 config.set(b'xandikos', b'type', store_type.encode(DEFAULT_ENCODING))
147 self._write_config(config)
148
149 def get_type(self):
150 config = self._repo.get_config()
151 store_type = config.get(b'xandikos', b'type')
152 store_type = store_type.decode(DEFAULT_ENCODING)
153 if store_type not in VALID_STORE_TYPES:
154 logging.warning(
155 'Invalid store type %s set for %r.',
156 store_type, self.repo)
157 return store_type
158
144159
145160 class locked_index(object):
146161
186201 else:
187202 cp.read_string(cf)
188203
189 def save_config(cp):
204 def save_config(cp, message):
190205 f = StringIO()
191206 cp.write(f)
192207 self._import_one(
193208 CONFIG_FILENAME, [f.getvalue().encode('utf-8')],
194 "Update configuration")
209 message)
195210 return FileBasedCollectionMetadata(cp, save=save_config)
196211
197212 def __repr__(self):
421436
422437 :param store_type: New store type (one of VALID_STORE_TYPES)
423438 """
424 config = self.repo.get_config()
425 config.set(b'xandikos', b'type', store_type.encode(DEFAULT_ENCODING))
426 config.write_to_path()
439 self.config.set_type(store_type)
427440
428441 def get_type(self):
429442 """Get store type.
430443
431444 This looks in git config first, then falls back to guessing.
432445 """
433 config = self.repo.get_config()
434 try:
435 store_type = config.get(b'xandikos', b'type')
446 try:
447 return self.config.get_type()
436448 except KeyError:
437449 return super(GitStore, self).get_type()
438 else:
439 store_type = store_type.decode(DEFAULT_ENCODING)
440 if store_type not in VALID_STORE_TYPES:
441 logging.warning(
442 'Invalid store type %s set for %r.',
443 store_type, self.repo)
444 return store_type
445450
446451 def iter_changes(self, old_ctag, new_ctag):
447452 """Get changes between two versions of this store.
6666 cp = configparser.ConfigParser()
6767 cp.read([os.path.join(self.path, CONFIG_FILENAME)])
6868
69 def save_config(cp):
69 def save_config(cp, message):
7070 with open(os.path.join(self.path, CONFIG_FILENAME), 'wb') as f:
7171 cp.write(f)
7272 self.config = FileBasedCollectionMetadata(cp, save=save_config)
305305 """
306306 self._write_metadata('displayname', displayname)
307307
308 def set_type(self, store_type):
309 """Set store type.
310
311 :param store_type: New store type (one of VALID_STORE_TYPES)
312 """
313 raise NotImplementedError(self.set_type)
314
315 def get_type(self):
316 """Get store type.
317 """
318 raise NotImplementedError(self.get_type)
319
320308 def iter_changes(self, old_ctag, new_ctag):
321309 """Get changes between two versions of this store.
322310