Skip to content

Commit

Permalink
DeploymentManager::configs: Removed OpenCV component with their pytho…
Browse files Browse the repository at this point in the history
…n folder. (openvinotoolkit#9367)

DeploymentManager::main: Refactored code with python-black module. Added compressing for Win-archives. Added shortcuts for options.
  • Loading branch information
artanokhov authored Dec 23, 2021
1 parent 41ace9d commit a94a6a7
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 86 deletions.
12 changes: 0 additions & 12 deletions tools/deployment_manager/configs/darwin.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,10 @@
"runtime/lib/intel64/pcie-ma2x8x.mvcmd"
]
},
"opencv": {
"ui_name": "OpenCV",
"group": ["opencv"],
"dependencies" : [],
"files": [
"extras/opencv/version.txt",
"extras/opencv/setupvars.sh",
"extras/opencv/lib",
"extras/opencv/bin"
]
},
"python_common": {
"group": ["python"],
"dependencies" : ["ie_core"],
"files": [
"python/python3",
"python/requirements.txt"
]
},
Expand Down
12 changes: 0 additions & 12 deletions tools/deployment_manager/configs/linux.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,10 @@
"runtime/3rdparty/hddl"
]
},
"opencv": {
"ui_name": "OpenCV",
"group": ["opencv"],
"dependencies" : [],
"files": [
"extras/opencv/version.txt",
"extras/opencv/setupvars.sh",
"extras/opencv/lib",
"extras/opencv/bin"
]
},
"python_common": {
"group": ["python"],
"dependencies" : ["ie_core"],
"files": [
"python/python3",
"python/requirements.txt"
]
},
Expand Down
12 changes: 0 additions & 12 deletions tools/deployment_manager/configs/windows.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,10 @@
"runtime/3rdparty/hddl"
]
},
"opencv": {
"ui_name": "OpenCV",
"group": ["opencv"],
"dependencies" : [],
"files": [
"extras/opencv/version.txt",
"extras/opencv/setupvars.bat",
"extras/opencv/lib",
"extras/opencv/bin"
]
},
"python_common": {
"group": ["python"],
"dependencies" : ["ie_core"],
"files": [
"python/python3",
"python/requirements.txt"
]
},
Expand Down
143 changes: 93 additions & 50 deletions tools/deployment_manager/deployman/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
"""

__version__ = '0.6'
__version__ = "0.6"

import os
import argparse
Expand All @@ -26,7 +26,7 @@
from deployman.config import ConfigReader, ComponentFactory, Component
from deployman.ui import UserInterface

logger = init_logger('WARNING')
logger = init_logger("WARNING")


# main class
Expand All @@ -42,7 +42,7 @@ def get_dependencies(self):
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))
Expand All @@ -58,68 +58,87 @@ def get_dependencies(self):
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
full_path = os.path.join(root, file)
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
full_path = os.path.join(root, file)
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
Expand All @@ -135,7 +154,7 @@ def process(self):
# 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
Expand All @@ -150,14 +169,16 @@ def process(self):
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():
Expand All @@ -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:
Expand All @@ -183,24 +204,44 @@ 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")
args = parser.parse_args()

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:
Expand All @@ -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)
Expand Down

0 comments on commit a94a6a7

Please sign in to comment.