+def read_format_version():
+ try:
+ (status, stdout, stderr) = _git(
+ args=['cat-file', 'blob', 'master:FORMAT'],
+ stdout=_subprocess.PIPE, stderr=_subprocess.PIPE, wait=True)
+ except SubprocessError as e:
+ _LOG.debug("failed to read FORMAT file from git, assuming format version 0")
+ return 0
+
+ return int(stdout)
+
+# based on BaseDirectory.save_data_path from pyxdg (LGPL2+)
+def xdg_data_path(profile):
+ resource = _os.path.join('notmuch',profile,'git')
+ assert not resource.startswith('/')
+ _home = _os.path.expanduser('~')
+ xdg_data_home = _os.environ.get('XDG_DATA_HOME') or \
+ _os.path.join(_home, '.local', 'share')
+ path = _os.path.join(xdg_data_home, resource)
+ return path
+