WP CLI in Python?
-
I wrote a bash script to run wp cli commands automatically. However I need to run it on a windows server, so I can’t run bash. So I was thinking python.
Except, I don’t know much about python. Could anyone get me started?
or, is there a better way? I’ve already asked and my ops teams doesn’t want to install win-bash or any other program to run bash scripts on windows servers.
-
The Windows equivalent of bash is the old DOS batch script. Any batch file with a .bat extension that is double clicked should open a command window and execute. Each batch line is executed as though at the command prompt.
Yeah, I’ve kinda been learning that. Dangers of being a front end guy pushed into having to do more coding work on the backend.
If I may inquire, in my bash script I was running some php code to set the variables for environments and paths like…
export WP_DEV_PROJ="site.dev" export WP_PROD_PROJ="site.com" if [ "$DM_DEV_BOX" ]; then export ACT_PATH="/websites/$WP_DEV_PROJ/" else export ACT_PATH="/var/www/wp/$WP_PROD_PROJ/" fi # Uninstall unused plugins wp plugin uninstall advanced-cron-manager --path=$ACT_PATH --quiet wp plugin uninstall all-in-one-seo-pack-pro --path=$ACT_PATH --quiet wp plugin uninstall asynchronous-javascript --path=$ACT_PATH --quiet wp plugin uninstall buddypress-verified --path=$ACT_PATH --quiet wp plugin uninstall cubepoints --path=$ACT_PATH --quiet wp plugin uninstall cubepoints-buddypress-integration --path=$ACT_PATH --quiet wp plugin uninstall digg-digg --path=$ACT_PATH --quiet wp plugin uninstall dzs-videogallery --path=$ACT_PATH --quiet wp plugin uninstall feedwordpress --path=$ACT_PATH --quiet wp plugin uninstall fix_broken_ids --path=$ACT_PATH --quiet wp plugin uninstall fix-my-feed-rss-repair --path=$ACT_PATH --quiet wp plugin uninstall footer-javascript --path=$ACT_PATH --quiet wp plugin uninstall front-content --path=$ACT_PATH --quiet wp plugin uninstall google-document-embedder --path=$ACT_PATH --quiet wp plugin uninstall google-news-widget --path=$ACT_PATH --quiet wp plugin uninstall liveblog --path=$ACT_PATH --quiet wp plugin uninstall wysija-newsletters --path=$ACT_PATH --quiet wp plugin uninstall wysija-newsletters-premium --path=$ACT_PATH --quiet wp plugin uninstall math-comment-spam-protection --path=$ACT_PATH --quiet wp plugin uninstall menu-exporter --path=$ACT_PATH --quiet wp plugin uninstall nextgen-gallery-optimizer-premium --path=$ACT_PATH --quiet wp plugin uninstall nextgen-gallery --path=$ACT_PATH --quiet wp plugin uninstall p3-profiler --path=$ACT_PATH --quiet wp plugin uninstall rss-just-better --path=$ACT_PATH --quiet wp plugin uninstall site-layout-customizer --path=$ACT_PATH --quiet wp plugin uninstall ultimate-social-media-icons --path=$ACT_PATH --quiet wp plugin uninstall sucuri-scanner --path=$ACT_PATH --quiet wp plugin uninstall swiftype-search --path=$ACT_PATH --quiet wp plugin uninstall unconfirmed --path=$ACT_PATH --quiet wp plugin uninstall w3-total-cache --path=$ACT_PATH --quiet wp plugin uninstall wunderground --path=$ACT_PATH --quiet wp plugin uninstall widget-settings-importexport --path=$ACT_PATH --quiet wp plugin uninstall widget-shortcode --path=$ACT_PATH --quiet wp plugin uninstall wordpress-importer --path=$ACT_PATH --quiet wp plugin uninstall wp-exporter --path=$ACT_PATH --quiet wp plugin uninstall wp-fastest-cache --path=$ACT_PATH --quiet wp plugin uninstall wp-missed-schedule --path=$ACT_PATH --quiet wp plugin uninstall wp-super-minify --path=$ACT_PATH --quiet wp plugin uninstall wp-system-health --path=$ACT_PATH --quiet wp plugin uninstall wp-memory-usage --path=$ACT_PATH --quiet wp plugin uninstall wptouch-pro --path=$ACT_PATH --quiet #Deactivate and Uninstall Plugins wp plugin uninstall wp-media-player --path=$ACT_PATH --deactivate --quiet wp plugin uninstall syntax-highlighter --path=$ACT_PATH --deactivate --quiet wp plugin uninstall wp-syntaxhighlighter --path=$ACT_PATH --deactivate --quiet # Install and Activate New Plugins wp plugin install https://downloads.wordpress.org/plugin/enlighter.3.0.zip --path=$ACT_PATH --activate --quiet wp plugin install https://downloads.wordpress.org/plugin/video-player.1.1.4.zip --path=$ACT_PATH --activate --quiet wp plugin install https://downloads.wordpress.org/plugin/add-to-any.1.6.14.zip --path=$ACT_PATH --activate --quiet #Update Plugins wp plugin update --path=$ACT_PATH --all --quiet STATUS=$? unset WP_DEV_PROJ unset WP_PROD_PROJ exit $STATUSYou can see there where I finish up unsetting and setting status after the commands.
I understand from your comment all I need to do is directly copy the commands to a batch script. But is there a way to do something like I am doing with that PHP?
Sorry, again this isn’t my forte- I’ve never touched a batch script and I’ve inherited all of these sites.
Batch files have some primitive scripting abilities, and there are some native commands for setting environment vars, etc. I haven’t worked with batch files in a serious way in decades, so I’m not sure what the equivalent batch code would be. Sorry.
It’s okay, I appreciate the input regardless. Just super stumped here.
Perhaps this is of use to you or others
https://github.com/ericmann/WP-PowerShellJust noticed it is an abandoned project so maybe less useful
-
This reply was modified 9 years, 3 months ago by
yolabingo.
-
This reply was modified 9 years, 3 months ago by
The topic ‘WP CLI in Python?’ is closed to new replies.