Skip to content

Commit

Permalink
Update archive_build.py script
Browse files Browse the repository at this point in the history
  • Loading branch information
kennedy0 committed Feb 4, 2021
1 parent 8fca104 commit c8d9f0f
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion tools/archive_build.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import os
import re
import sys
import zipfile


version_re = re.compile(r"^__version__ = \"(.*)\"$", re.I)


def create_archive(folder_path: str) -> int:
if not os.path.isdir(folder_path):
print(f"{folder_path} is not a directory.")
return 1

zip_file = f"{folder_path}.zip"
version = get_version()
zip_file = f"{folder_path}_{version}_win.zip"

if os.path.isfile(zip_file):
print(f"{zip_file} already exists.")
return 1
Expand All @@ -22,6 +28,20 @@ def create_archive(folder_path: str) -> int:
return 0


def get_version() -> str:
tools_dir = os.path.abspath(os.path.dirname(__file__))
project_dir = os.path.dirname(tools_dir)
version_file = os.path.join(project_dir, "__version__.py")

with open(version_file, 'r') as fp:
line = fp.read().strip()

match = version_re.match(line)
version = match.group(1)

return version


if __name__ == "__main__":
if len(sys.argv) == 1:
sys.exit(1)
Expand Down

0 comments on commit c8d9f0f

Please sign in to comment.