From d88171d89e754118a775a83e52a3ac860379610d Mon Sep 17 00:00:00 2001 From: Lilfade Date: Thu, 25 Apr 2024 01:36:42 -0500 Subject: [PATCH] file updates, making more work --- main.py | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- setup.py | 41 ++++++++++++++++++++++++++++++++++-- 2 files changed, 99 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index cd4446f..ce55ee9 100644 --- a/main.py +++ b/main.py @@ -26,24 +26,81 @@ function ai1wm_activate_plugins( $plugins ) { return update_option( AI1WM_ACTIVE_PLUGINS, $current ); } ''' + +def setup_args(): + parser = argparse.ArgumentParser( + prog='AiO-Restore', + description='Unpack and Restore All-in-One WP Migration Packages', + epilog='aio_restore ', + ) + parser.add_argument( + 'source', + type=str, + help='Source Path' + ) + parser.add_argument( + 'target', + type=str, + help='Target Path' + ) + parser.add_argument( + 'db_name', + type=str, + help='Database Name' + ) + parser.add_argument( + 'db_pass', + type=str, + help='Database Password' + ) + parser.add_argument( + name='site_url', + name='-s', + name='--site', + type=str, + help='Site URL, domain only' + ) + parser.add_argument( + '-h', + '--home', + 'home_url', + type=str, + help='Home URL, domain only' + ) + parser.add_argument( + '-v', + '--version', + action='version', + version='%(prog)s v0.0.1', + help='Show version information' + ) + + return parser + plugin_prefix = 'SERVMASK_PREFIX_' if __name__ == '__main__': """ Entry of the ai1wm program. """ - parser = argparse.ArgumentParser(prog='ai1wm', description='Unpack All-in-One WP Migration Packages') - parser.add_argument('source', help='source path') - parser.add_argument('target', help='target path') + parser = setup_args() args = parser.parse_args() try: + # Ensure we have source and target + if not args.source or not args.target: + parser.print_help() + exit(1) + + # Unpack the archive and files to the source destination if os.path.isfile(args.source): unpacker.Ai1wmUnpacker().unpack(args.source, args.target) except Exception as e: print(e) sys.exit(-1) + # Process WordPress setup and install try: + # TODO: check for package.json for processing or exit if os.path.isfile(args.target): # check for database.sql and package.json # Setup Site files diff --git a/setup.py b/setup.py index 7765a01..c344751 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,41 @@ +import subprocess + + class Setup(): + def __check_wp_cli(): + """Checks if WP-CLI is installed.""" + try: + subprocess.call(["wp", "--info"]) + return True + except Exception: + return False - def WPSetup(): - print('holder') + def __download_core(): + print('') + + def __format_mysql(): + print('') + + def __move_folders(): + print('') + + def __write_config(): + print('') + + def __import_mysql(): + print('') + + def wp_setup(self): + # Initial setup for restore + self.__format_mysql() + self.__move_folders() + + # Depending on if WP Cli is installed + manual = False if self.__check_wp_cli() else True + + # File management + self.__download_core(manual) + self.__write_config() # TODO: Get data from input + self.__import_mysql(manual) + + return 'Completed' \ No newline at end of file