Mercurial > repos > dcouvin > resfinder4
comparison resfinder/cge/out/util/generator.py @ 0:55051a9bc58d draft default tip
Uploaded
| author | dcouvin |
|---|---|
| date | Mon, 10 Jan 2022 20:06:07 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:55051a9bc58d |
|---|---|
| 1 #!/usr/bin/env python3 | |
| 2 | |
| 3 from git import Repo | |
| 4 from git.exc import InvalidGitRepositoryError | |
| 5 from datetime import datetime, timezone | |
| 6 | |
| 7 from ..result import Result | |
| 8 | |
| 9 | |
| 10 class Generator(): | |
| 11 """ """ | |
| 12 | |
| 13 @staticmethod | |
| 14 def init_software_result(name, gitdir): | |
| 15 """""" | |
| 16 version, commit = Generator.get_version_commit(gitdir) | |
| 17 date = datetime.now(timezone.utc).date().isoformat() | |
| 18 | |
| 19 result_dict = { | |
| 20 "type": "software_result", | |
| 21 "software_name": name, | |
| 22 "software_version": version, | |
| 23 "software_commit": commit, | |
| 24 "run_date": date, | |
| 25 "key": "{}-{}".format(name, version) | |
| 26 } | |
| 27 return Result(**result_dict) | |
| 28 | |
| 29 @staticmethod | |
| 30 def get_version_commit(gitdir): | |
| 31 try: | |
| 32 repo = Repo(gitdir) | |
| 33 except InvalidGitRepositoryError: | |
| 34 return ("unknown", "unknown") | |
| 35 | |
| 36 com2tag = {} | |
| 37 for tag in repo.tags: | |
| 38 com2tag[tag.commit.hexsha] = str(tag) | |
| 39 | |
| 40 version = com2tag.get(repo.commit().hexsha, repo.commit().hexsha[:7]) | |
| 41 | |
| 42 return (version, repo.commit().hexsha) |
