""" Copyright (c) , All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """ __author__ = "Michael Walker" __copyright__ = "BSD (2-clause)" __credits__ = ["Michael Walker"] try: from time import time from logging import getLogger from resources.init_script import init_script, Options, set_logger from resources.init_miration import init_migration from resources.server_api import Server from resources.cloud_api import Cloud from resources.adapter import CoreAdapter def main(options: Options, printable_args: str) -> None: logger = getLogger("migrate") logger.debug('Parsing "env.py" for credentials') server_url, server_session, cloud_session = init_migration() if not options.test: logger.debug(f"Selected data types to migrate: {printable_args}") logger.info("Starting Server Checks") server = Server(server_url, server_session, options) logger.info("Starting Cloud Checks") cloud = Cloud(cloud_session, options) if options.test: logger.info( "Test flag present, no further tasks to complete.\n" "If you have already migrated and would like to proceed with migrating your configurations, " 're-run this script without the "test" feature flag. See the --help for more information.' ) exit() logger.info(f"Collecting desired items from Server: {printable_args}") CoreAdapter.collect_server_migration_data(server) logger.info(f"Posting desired item(s) to Cloud: {printable_args}") CoreAdapter.migrate_data_to_cloud(cloud, server) logger.info("Migration complete. Closing...\n") exit() try: if __name__ == "__main__": start_time = time() options, printable_args = init_script() set_logger(options.verbose) main(options, printable_args) end_time = time() run_time = end_time - start_time print( f"Completed runtime in {run_time:.2f} seconds, check logs for any additional information. Closing..." ) except KeyboardInterrupt: print("(FATAL) - Cancelled by Keyboard Interrupt.\nClosing...\n") exit() except ModuleNotFoundError: print( "(FATAL) - One or more dependencies are missing, " "please install via readme instructions and try again.\nClosing...\n" ) exit()