config.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # config.py - Reading and writing Git config files
  2. # Copyright (C) 2011 Jelmer Vernooij <jelmer@samba.org>
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; version 2
  7. # of the License or (at your option) a later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  17. # MA 02110-1301, USA.
  18. """Reading and writing Git configuration files.
  19. """
  20. from dulwich.file import GitFile
  21. class ConfigFile(object):
  22. """A Git configuration file, like .git/config or ~/.gitconfig."""
  23. def __init__(self):
  24. """Create a new ConfigFile."""
  25. def __eq__(self, other):
  26. return isinstance(other, self.__class__)
  27. @classmethod
  28. def from_file(cls, f):
  29. """Read configuration from a file-like object."""
  30. ret = cls()
  31. # FIXME
  32. return ret
  33. @classmethod
  34. def from_path(cls, path):
  35. """Read configuration from a file on disk."""
  36. f = GitFile(path, 'r')
  37. try:
  38. return cls.from_file(f)
  39. finally:
  40. f.close()
  41. def write_to_path(self, path):
  42. """Write configuration to a file on disk."""
  43. f = GitFile(path, 'w')
  44. try:
  45. self.write_to_file(f)
  46. finally:
  47. f.close()
  48. def write_to_file(self, f):
  49. """Write configuration to a file-like object."""
  50. # FIXME