changed the way on how to get the version to a json file, added helper to libreftit
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
|
||||
from .refit_logger import logger
|
||||
|
||||
@@ -247,3 +248,30 @@ def create_parallel_directories(input_path: str, target_depth: int, width: int,
|
||||
current_depth=0,
|
||||
name=name,
|
||||
)
|
||||
|
||||
|
||||
def get_version_from_file(input_path) -> str:
|
||||
"""Returns the version of the program.
|
||||
|
||||
The function accepts an path to a version file as a string and it
|
||||
returns it version number formatted.
|
||||
|
||||
Arg:
|
||||
input_path (str): The absolute or relative path to the
|
||||
version file.
|
||||
|
||||
Example:
|
||||
>>>get_version_from_file("/path/to/file.json")
|
||||
'0.2.1'"""
|
||||
# Expands the input path
|
||||
expanded_path = os.path.expanduser(input_path)
|
||||
|
||||
# Opening the file and reading its contents, saving as as an dict.
|
||||
file_path = open(expanded_path)
|
||||
prog_version = json.load(file_path)
|
||||
|
||||
# Formatting the output before returning the string again
|
||||
pretty_version = (
|
||||
f"{prog_version['major']}.{prog_version['minor']}.{prog_version['patch']}"
|
||||
)
|
||||
return pretty_version
|
||||
|
||||
Reference in New Issue
Block a user