Added code/charms (for python code) and version bumping script

This commit is contained in:
aewens 2020-01-21 11:36:38 -05:00
parent e0de07d1fd
commit 46a3b2ae73
5 changed files with 40 additions and 0 deletions

1
.version Normal file
View File

@ -0,0 +1 @@
1

1
VERSION Normal file
View File

@ -0,0 +1 @@
1.20200120.1

5
code/bump_version Executable file
View File

@ -0,0 +1,5 @@
#!/usr/bin/env python3
from charms.automate import generate_version
generate_version()

31
code/charms/automate.py Normal file
View File

@ -0,0 +1,31 @@
from shlex import split as shell_split
from subprocess import PIPE, getoutput, run as shell_run
from pathlib import Path
def shell_execute(command, err=PIPE, out=PIPE):
return shell_run(shell_split(command), stderr=err, stdout=out)
def shell_output(command):
return getoutput(command)
def simple_shell_execute(command, **kwargs):
result = shell_execute(command, **kwargs)
exit_code = result.returncode
error = result.stderr
output = result.stdout
return output.decode() if exit_code == 0 else error.decode()
def generate_version(debug=False):
charms_path = Path(__file__).resolve().parent
root_path = charms_path.parent.parent
dot_version_path = root_path / ".version"
major = dot_version_path.read_text().strip()
minor = shell_output("git log -1 --format='%cd' --date=short | sed s/-//g")
patch = simple_shell_execute("git rev-list --count HEAD")
version = f"{major}.{minor}.{patch}"
if debug:
print(version)
else:
version_path = root_path / "VERSION"
version_path.write_text(version)

View File

@ -0,0 +1,2 @@
from base64 import urlsafe_b64encode as ub64e, urlsafe_b64decode as ub64d