import argparse import os import sys import unpacker import setup ''' package.json function ai1wm_activate_plugins( $plugins ) { $current = get_option( AI1WM_ACTIVE_PLUGINS, array() ); // Add plugins foreach ( $plugins as $plugin ) { if ( ! in_array( $plugin, $current ) && ! is_wp_error( validate_plugin( $plugin ) ) ) { $current[] = $plugin; } } 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 [source] [target]', ) parser.add_argument( 'source', type=str, help='Source Path as string' ) parser.add_argument( 'target', type=str, help='Target Path as string' ) parser.add_argument( '--db_name', type=str, help='Database Name as string' ) parser.add_argument( '--db_pass', type=str, help='Database Password as string' ) parser.add_argument( '--site_url', type=str, help='Site URL, domain only' ) parser.add_argument( '--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 = 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 setup.WPSetup(plugin_prefix) except Exception as e: print(e) sys.exit(-1) sys.exit(0)