Skip to main content
The Nameless Site

Updating Wordpress Plugins Helper

Note, I've recently found WP Cli which makes all of this moot because i can now just do "wp plugin upgrade --all" or "wp plugin install blah"

Original post:

I decided a while ago to put pull all the plugin source codes for this wordpress install directly from subversion. This makes it easier when files need manual patching or more likely, a file gets deleted.

So I created this little helper script that I can use to do a mass update when I get too out of date.

Gist: halkeye/6288018
#!/usr/bin/env python
# Simple little script I use to update wordpress plugins
# Author: Gavin Mogan <gavin@kodekoan.com>
#
# Usage:
# for i in ~/wp-plugins/*; do svn sw $(updateWPPlugin $i) $i; done
# Changelog:
# Ignore any tag that has characters other than 0-9 and .
# This usually means that its a beta tag
from pkg_resources import parse_version as V
import re
import pysvn
import os.path
import sys
loc = "."
if (len(sys.argv) > 1):
loc = sys.argv[1]
client = pysvn.Client()
client_info = client.info(loc)
url = client_info.url.rstrip()
rootdir = os.path.dirname(url)
currentVersion = V(os.path.basename(url))
latestVersion = None
latestVersionStr = None
svnlist = client.list(rootdir + "/", depth=pysvn.depth.immediates)
# Ignore whole words (^\w+$)
# Ignore versions with letters in them (usually betas) /\w+/
#versioncheck = re.compile('/\w+|^\w+$/')
versioncheck = re.compile('[^0-9.]+')
for tuple in svnlist:
for dirent in tuple:
if dirent:
ver = os.path.basename(dirent['repos_path'])
if versioncheck.search(ver):
continue
ver = V(ver)
if (ver > latestVersion):
latestVersionStr = dirent['repos_path']
latestVersion = ver
if latestVersionStr:
new_url = client_info.repos + latestVersionStr
else:
new_url = url
if (url != new_url):
print >> sys.stderr, ("Converting %s to %s" % (url, new_url))
print new_url