-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor inject_sketch_name.py for improved readability and consisten…
…cy in subprocess calls
- Loading branch information
Showing
1 changed file
with
16 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,29 @@ | ||
from datetime import datetime, timezone | ||
from datetime import datetime | ||
import os | ||
from pathlib import Path | ||
import subprocess | ||
from subprocess import check_output, CalledProcessError | ||
from subprocess import CalledProcessError | ||
|
||
def get_git_revision_short_hash() -> str: | ||
try: | ||
return subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD'],shell=True).decode('utf-8').strip() | ||
except CalledProcessError: | ||
return "N/A" | ||
try: | ||
return subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD'], shell=True).decode('utf-8').strip() | ||
except CalledProcessError: | ||
return "N/A" | ||
|
||
def get_git_current_branch() -> str: | ||
try: | ||
return subprocess.check_output(['git', 'branch', '--show-current'],shell=True).decode('utf-8').strip() | ||
except CalledProcessError: | ||
return "N/A" | ||
try: | ||
return subprocess.check_output(['git', 'branch', '--show-current'], shell=True).decode('utf-8').strip() | ||
except CalledProcessError: | ||
return "N/A" | ||
|
||
Import("env") | ||
proj_path = env["PROJECT_DIR"] | ||
|
||
proj_path = os.path.join(proj_path, "dummy") | ||
|
||
macro_value = r"\"" + os.path.split(os.path.dirname(proj_path))[1] + r"\"" | ||
proj_path = os.path.join(env["PROJECT_DIR"], "dummy") | ||
|
||
macro_value = f"\"{os.path.split(os.path.dirname(proj_path))[1]}\"" | ||
tz_dt = datetime.now().replace(microsecond=0).astimezone().isoformat(' ') | ||
|
||
env.Append(CPPDEFINES=[ | ||
("PROJECT_PATH", macro_value), | ||
("CURRENT_TIME", "\\\"" + tz_dt + "\\\""), | ||
("BRANCH_NAME", r"\"" + get_git_current_branch() + r"\""), | ||
("COMMIT_HASH", r"\"" + get_git_revision_short_hash() + r"\"") | ||
("PROJECT_PATH", macro_value), | ||
("CURRENT_TIME", f"\"{tz_dt}\""), | ||
("BRANCH_NAME", f"\"{get_git_current_branch()}\""), | ||
("COMMIT_HASH", f"\"{get_git_revision_short_hash()}\"") | ||
]) |