publish master branch snapshot, revision cdcab9d7ab48ffb0ee5629fabbfa06cb45debd9b
This commit is contained in:
15
scripts/utils/create_package.py
Normal file
15
scripts/utils/create_package.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import argparse
|
||||
import os
|
||||
from shutil import rmtree
|
||||
|
||||
from utils import Automation
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--build_number", type=int, help="Build number to be added to package version", default=0, )
|
||||
args = parser.parse_args()
|
||||
|
||||
auto = Automation()
|
||||
base_dir = os.path.dirname(__file__)
|
||||
bom_path = os.path.join(base_dir, "package_BOM.txt")
|
||||
bom = auto.parse_bom(bom_path=bom_path)
|
||||
dir_to_tar = auto.copy_files_from_bom(root_path=os.path.join(os.path.dirname(__file__), ".."), bom=bom)
|
||||
56
scripts/utils/utils.py
Normal file
56
scripts/utils/utils.py
Normal file
@@ -0,0 +1,56 @@
|
||||
import os
|
||||
import subprocess
|
||||
import tarfile
|
||||
from datetime import datetime
|
||||
from shutil import copyfile, copytree, rmtree
|
||||
|
||||
major_version = 0
|
||||
minor_version = 3
|
||||
|
||||
|
||||
class Automation:
|
||||
@staticmethod
|
||||
def parse_bom(bom_path):
|
||||
files = []
|
||||
for file in open(bom_path):
|
||||
files.append(file)
|
||||
return files
|
||||
|
||||
@staticmethod
|
||||
def copy_files_from_bom(root_path, bom):
|
||||
target_dir = os.path.join(os.path.dirname(__file__), "tools_package")
|
||||
if os.path.exists(target_dir):
|
||||
rmtree(target_dir)
|
||||
os.makedirs(target_dir)
|
||||
for file in bom:
|
||||
src = os.path.join(root_path, file.strip('\n'))
|
||||
dst = os.path.join(target_dir, file.strip('\n'))
|
||||
if not os.path.exists(os.path.dirname(dst)):
|
||||
os.makedirs(os.path.dirname(dst))
|
||||
if os.path.isdir(src):
|
||||
copytree(src, dst)
|
||||
else:
|
||||
copyfile(src, dst)
|
||||
return target_dir
|
||||
|
||||
@staticmethod
|
||||
def add_version_txt(dst_path, build_number, git_hash_short):
|
||||
git_hash = subprocess.check_output(["git", "rev-parse", "HEAD"]).decode("utf-8").strip("\n")
|
||||
if git_hash_short == "0":
|
||||
git_hash_short = subprocess.check_output(["git", "rev-parse", "--short", "HEAD"]).decode("utf-8").strip(
|
||||
"\n")
|
||||
verson = "{0}.{1}.{2}.{3}".format(major_version, minor_version, build_number, git_hash_short)
|
||||
timestamp = datetime.now().strftime("%I:%M%p %B %d, %Y")
|
||||
with open(os.path.join(dst_path, "version.txt"), 'w') as f:
|
||||
f.write(timestamp + '\n')
|
||||
f.write(verson + '\n')
|
||||
f.write(git_hash + '\n')
|
||||
return verson
|
||||
|
||||
@staticmethod
|
||||
def make_tarfile(out_file_name, source_dir):
|
||||
archive_path = os.path.join(os.path.dirname(__file__), out_file_name)
|
||||
if os.path.exists(archive_path):
|
||||
os.remove(archive_path)
|
||||
with tarfile.open(out_file_name, "w:gz") as tar:
|
||||
tar.add(source_dir, arcname=os.path.basename(source_dir))
|
||||
Reference in New Issue
Block a user