|
|
|
|
@@ -14,7 +14,7 @@
|
|
|
|
|
limitations under the License.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
__version__ = '0.6'
|
|
|
|
|
__version__ = "0.6"
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
import argparse
|
|
|
|
|
@@ -26,7 +26,7 @@ from deployman.logger import init_logger
|
|
|
|
|
from deployman.config import ConfigReader, ComponentFactory, Component
|
|
|
|
|
from deployman.ui import UserInterface
|
|
|
|
|
|
|
|
|
|
logger = init_logger('WARNING')
|
|
|
|
|
logger = init_logger("WARNING")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# main class
|
|
|
|
|
@@ -42,7 +42,7 @@ class DeploymentManager:
|
|
|
|
|
dependencies_names = []
|
|
|
|
|
logger.debug("Updating dependencies...")
|
|
|
|
|
for target in self.selected_targets:
|
|
|
|
|
if hasattr(target, 'dependencies'):
|
|
|
|
|
if hasattr(target, "dependencies"):
|
|
|
|
|
dependencies_names.extend(target.dependencies)
|
|
|
|
|
# remove duplications
|
|
|
|
|
dependencies_names = list(dict.fromkeys(dependencies_names))
|
|
|
|
|
@@ -58,33 +58,42 @@ class DeploymentManager:
|
|
|
|
|
def get_mandatory_component(self):
|
|
|
|
|
for _target in self.components:
|
|
|
|
|
_target: Component
|
|
|
|
|
if hasattr(_target, 'mandatory'):
|
|
|
|
|
if hasattr(_target, "mandatory"):
|
|
|
|
|
if not _target.is_exist():
|
|
|
|
|
FileNotFoundError("Mandatory component {} not available.".format(_target.name))
|
|
|
|
|
self.mandatory_components.append(_target)
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def packing_binaries(archive_name: str, target_dir: str, source_dir: str):
|
|
|
|
|
logger.info('Archiving deploy package')
|
|
|
|
|
if os.name == 'posix':
|
|
|
|
|
archive_path = DeploymentManager.packing_binaries_posix(archive_name, target_dir, source_dir)
|
|
|
|
|
logger.info("Archiving deploy package")
|
|
|
|
|
if os.name == "posix":
|
|
|
|
|
archive_path = DeploymentManager.packing_binaries_posix(
|
|
|
|
|
archive_name, target_dir, source_dir
|
|
|
|
|
)
|
|
|
|
|
else:
|
|
|
|
|
archive_path = DeploymentManager.packing_binaries_windows(archive_name, target_dir, source_dir)
|
|
|
|
|
logger.setLevel('INFO')
|
|
|
|
|
logger.info("Deployment archive is ready. "
|
|
|
|
|
"You can find it here:\n\t{}".format(os.path.join(target_dir, archive_path)))
|
|
|
|
|
archive_path = DeploymentManager.packing_binaries_windows(
|
|
|
|
|
archive_name, target_dir, source_dir
|
|
|
|
|
)
|
|
|
|
|
logger.setLevel("INFO")
|
|
|
|
|
logger.info(
|
|
|
|
|
"Deployment archive is ready. "
|
|
|
|
|
"You can find it here:\n\t{}".format(os.path.join(target_dir, archive_path))
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def packing_binaries_posix(archive_name: str, target_dir: str, source_dir: str) -> str:
|
|
|
|
|
extension = 'tar.gz'
|
|
|
|
|
archive_file_name = '{}.{}'.format(archive_name, extension)
|
|
|
|
|
extension = "tar.gz"
|
|
|
|
|
archive_file_name = "{}.{}".format(archive_name, extension)
|
|
|
|
|
archive_path = os.path.join(target_dir, archive_file_name)
|
|
|
|
|
|
|
|
|
|
import tarfile
|
|
|
|
|
|
|
|
|
|
with tarfile.open(archive_path, "w:gz") as tar_pac:
|
|
|
|
|
total_files_number = DeploymentManager.count_files_number(source_dir)
|
|
|
|
|
count = 0
|
|
|
|
|
logger.info('Total number of files to add to the package: {}'.format(total_files_number))
|
|
|
|
|
logger.info(
|
|
|
|
|
"Total number of files to add to the package: {}".format(total_files_number)
|
|
|
|
|
)
|
|
|
|
|
for root, dirs, files in os.walk(source_dir):
|
|
|
|
|
for file in files:
|
|
|
|
|
count += 1
|
|
|
|
|
@@ -92,23 +101,29 @@ class DeploymentManager:
|
|
|
|
|
if not os.path.isfile(full_path):
|
|
|
|
|
continue
|
|
|
|
|
relative_path = str(Path(full_path).relative_to(source_dir))
|
|
|
|
|
logger.info('Add {} {}/{} file to the package'.format(relative_path,
|
|
|
|
|
count,
|
|
|
|
|
total_files_number))
|
|
|
|
|
logger.info(
|
|
|
|
|
"Add {} {}/{} file to the package".format(
|
|
|
|
|
relative_path, count, total_files_number
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
tar_pac.add(full_path, arcname=relative_path)
|
|
|
|
|
return archive_path
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def packing_binaries_windows(archive_name: str, target_dir: str, source_dir: str) -> str:
|
|
|
|
|
extension = 'zip'
|
|
|
|
|
archive_file_name = '{}.{}'.format(archive_name, extension)
|
|
|
|
|
extension = "zip"
|
|
|
|
|
archive_file_name = "{}.{}".format(archive_name, extension)
|
|
|
|
|
archive_path = os.path.join(target_dir, archive_file_name)
|
|
|
|
|
|
|
|
|
|
from zipfile import ZipFile
|
|
|
|
|
from zipfile import ZipFile, ZIP_DEFLATED
|
|
|
|
|
|
|
|
|
|
compression = ZIP_DEFLATED
|
|
|
|
|
with ZipFile(archive_path, "w") as zip_pac:
|
|
|
|
|
total_files_number = DeploymentManager.count_files_number(source_dir)
|
|
|
|
|
count = 0
|
|
|
|
|
logger.info('Total number of files to add to the package: {}'.format(total_files_number))
|
|
|
|
|
logger.info(
|
|
|
|
|
"Total number of files to add to the package: {}".format(total_files_number)
|
|
|
|
|
)
|
|
|
|
|
for root, dirs, files in os.walk(source_dir):
|
|
|
|
|
for file in files:
|
|
|
|
|
count += 1
|
|
|
|
|
@@ -116,10 +131,14 @@ class DeploymentManager:
|
|
|
|
|
if not os.path.isfile(full_path):
|
|
|
|
|
continue
|
|
|
|
|
relative_path = str(Path(full_path).relative_to(source_dir))
|
|
|
|
|
logger.info('Add {} {}/{} file to the package'.format(relative_path,
|
|
|
|
|
count,
|
|
|
|
|
total_files_number))
|
|
|
|
|
zip_pac.write(os.path.join(root, file), arcname=relative_path)
|
|
|
|
|
logger.info(
|
|
|
|
|
"Add {} {}/{} file to the package".format(
|
|
|
|
|
relative_path, count, total_files_number
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
zip_pac.write(
|
|
|
|
|
os.path.join(root, file), arcname=relative_path, compress_type=compression
|
|
|
|
|
)
|
|
|
|
|
return archive_path
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
@@ -135,7 +154,7 @@ class DeploymentManager:
|
|
|
|
|
# get mandatory components
|
|
|
|
|
self.get_mandatory_component()
|
|
|
|
|
|
|
|
|
|
logger.info('Collection information for components')
|
|
|
|
|
logger.info("Collection information for components")
|
|
|
|
|
with tempfile.TemporaryDirectory() as tmpdirname:
|
|
|
|
|
for target in self.selected_targets:
|
|
|
|
|
target: Component
|
|
|
|
|
@@ -150,14 +169,16 @@ class DeploymentManager:
|
|
|
|
|
target.copy_files(tmpdirname)
|
|
|
|
|
if self.args.user_data and os.path.exists(self.args.user_data):
|
|
|
|
|
from shutil import copytree
|
|
|
|
|
logger.info('Storing user data for deploy package ')
|
|
|
|
|
copytree(self.args.user_data,
|
|
|
|
|
os.path.join(
|
|
|
|
|
tmpdirname,
|
|
|
|
|
os.path.basename(self.args.user_data.rstrip(os.path.sep))),
|
|
|
|
|
symlinks=True)
|
|
|
|
|
self.packing_binaries(self.args.archive_name,
|
|
|
|
|
self.args.output_dir, tmpdirname)
|
|
|
|
|
|
|
|
|
|
logger.info("Storing user data for deploy package ")
|
|
|
|
|
copytree(
|
|
|
|
|
self.args.user_data,
|
|
|
|
|
os.path.join(
|
|
|
|
|
tmpdirname, os.path.basename(self.args.user_data.rstrip(os.path.sep))
|
|
|
|
|
),
|
|
|
|
|
symlinks=True,
|
|
|
|
|
)
|
|
|
|
|
self.packing_binaries(self.args.archive_name, self.args.output_dir, tmpdirname)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
@@ -168,13 +189,13 @@ def main():
|
|
|
|
|
components = []
|
|
|
|
|
|
|
|
|
|
for component in cfg.components:
|
|
|
|
|
components.append(ComponentFactory.create_component(component,
|
|
|
|
|
cfg.components[component],
|
|
|
|
|
logger))
|
|
|
|
|
components.append(
|
|
|
|
|
ComponentFactory.create_component(component, cfg.components[component], logger)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# list for only available components
|
|
|
|
|
available_targets = []
|
|
|
|
|
help_msg = ''
|
|
|
|
|
help_msg = ""
|
|
|
|
|
|
|
|
|
|
for component in components:
|
|
|
|
|
if component.is_exist() and not component.invisible:
|
|
|
|
|
@@ -183,15 +204,33 @@ def main():
|
|
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description="", formatter_class=argparse.RawTextHelpFormatter)
|
|
|
|
|
|
|
|
|
|
parser.add_argument("--targets", nargs="+", help="List of targets. "
|
|
|
|
|
"Possible values: \n{}".format(help_msg))
|
|
|
|
|
parser.add_argument("--user_data", type=str, help="Path to user data that will be added to "
|
|
|
|
|
"the deployment package", default=None)
|
|
|
|
|
parser.add_argument("--output_dir", type=str, help="Output directory for deployment archive",
|
|
|
|
|
default=os.getenv("HOME", os.path.join(os.path.join(
|
|
|
|
|
os.path.dirname(__file__), os.pardir))))
|
|
|
|
|
parser.add_argument("--archive_name", type=str, help="Name for deployment archive",
|
|
|
|
|
default="openvino_deploy_package", )
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
"--targets",
|
|
|
|
|
"-t",
|
|
|
|
|
nargs="+",
|
|
|
|
|
help="List of targets. " "Possible values: \n{}".format(help_msg),
|
|
|
|
|
)
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
"--user_data",
|
|
|
|
|
"-u",
|
|
|
|
|
type=str,
|
|
|
|
|
help="Path to user data that will be added to " "the deployment package",
|
|
|
|
|
default=None,
|
|
|
|
|
)
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
"--output_dir",
|
|
|
|
|
"-o",
|
|
|
|
|
type=str,
|
|
|
|
|
help="Output directory for deployment archive",
|
|
|
|
|
default=os.getenv("HOME", os.path.join(os.path.join(os.path.dirname(__file__), os.pardir))),
|
|
|
|
|
)
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
"--archive_name",
|
|
|
|
|
"-name",
|
|
|
|
|
type=str,
|
|
|
|
|
help="Name for deployment archive",
|
|
|
|
|
default="openvino_deploy_package",
|
|
|
|
|
)
|
|
|
|
|
parser.add_argument("--version", action="version", version="%(prog)s " + __version__)
|
|
|
|
|
|
|
|
|
|
logger.info("Parsing command line arguments")
|
|
|
|
|
@@ -199,8 +238,10 @@ def main():
|
|
|
|
|
|
|
|
|
|
selected_targets = []
|
|
|
|
|
if not available_targets:
|
|
|
|
|
exit("No available targets to packaging detected.\n"
|
|
|
|
|
"Please check your OpenVINO installation.")
|
|
|
|
|
exit(
|
|
|
|
|
"No available targets to packaging detected.\n"
|
|
|
|
|
"Please check your OpenVINO installation."
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
ui = UserInterface(__version__, args, available_targets, logger)
|
|
|
|
|
if not args.targets:
|
|
|
|
|
@@ -211,7 +252,9 @@ def main():
|
|
|
|
|
for target in args.targets:
|
|
|
|
|
target_name = target.lower()
|
|
|
|
|
if not any(target_name == _target.name.lower() for _target in available_targets):
|
|
|
|
|
raise ValueError("You input incorrect target. {} is not available.".format(target_name))
|
|
|
|
|
raise ValueError(
|
|
|
|
|
"You input incorrect target. {} is not available.".format(target_name)
|
|
|
|
|
)
|
|
|
|
|
for _target in available_targets:
|
|
|
|
|
if _target.name.lower() == target_name:
|
|
|
|
|
selected_targets.append(_target)
|
|
|
|
|
|