Verified Commit d27d67f5 authored by Markus Shepherd's avatar Markus Shepherd 🙈
Browse files

proper version of version_env.py

parent daf3c77b
# the following line will be updated automatically from board_game_scraper.__version__
LIBRARY_VERSION=
# environment variables
LOG_LEVEL=DEBUG
LOG_SCRAPED_ITEMS=0
......
......@@ -6,6 +6,10 @@ import argparse
import logging
import sys
from pathlib import Path
from shutil import copyfileobj
from tempfile import TemporaryFile
from .__version__ import __version__
LOGGER = logging.getLogger(__name__)
......@@ -13,6 +17,18 @@ LOGGER = logging.getLogger(__name__)
def _parse_args():
parser = argparse.ArgumentParser(description="TODO.")
parser.add_argument(
"--target",
"-t",
default=".env",
help="TODO",
)
parser.add_argument(
"--variable",
"-V",
default="LIBRARY_VERSION",
help="TODO",
)
parser.add_argument(
"--verbose",
"-v",
......@@ -37,8 +53,30 @@ def main():
LOGGER.info(args)
with open("VERSION", "w") as f:
f.write(__version__)
target = Path(args.target).resolve()
LOGGER.info("Trying to write version %s to file <%s>...", __version__, target)
if not target.exists():
LOGGER.error("Target file <%s> does not exist, aborting", target)
sys.exit(1)
LOGGER.info("Looking for environment variable <%s>", args.variable)
with TemporaryFile("w+") as temp:
with target.open() as in_file:
for line in in_file:
if line.startswith(f"{args.variable}="):
temp.write(f"{args.variable}={__version__}\n")
else:
temp.write(line)
temp.seek(0)
with target.open("w") as out_file:
copyfileobj(temp, out_file)
LOGGER.info("Done.")
if __name__ == "__main__":
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment