dist: get commit from Ubuntu PPA directory name if no git information

This commit is contained in:
Peter F. Patel-Schneider 2022-11-24 12:42:10 -05:00
parent 934b486b13
commit 0547b1895a
1 changed files with 10 additions and 2 deletions

View File

@ -1,5 +1,8 @@
#!/usr/bin/env python3
import os
import re
import subprocess
import sys
from glob import glob as _glob
@ -17,8 +20,13 @@ try:
commit = subprocess.check_output(['git', 'describe', '--always'], stderr=subprocess.DEVNULL).strip().decode()
with open('lib/solaar/commit', 'w') as vfile:
vfile.write(f'{commit}\n')
except Exception:
pass
except Exception: # get commit from Ubuntu PPA directory name
dir = os.path.basename(sys.path[0])
print('DIRECTORY', dir)
commit_match = re.search(r'git[0-9]*-([0-9a-f]*)~', dir)
if commit_match:
with open('lib/solaar/commit', 'w') as vfile:
vfile.write(f'{version}-g{commit_match[1]}\n')
def _data_files():