Last active
December 21, 2015 09:49
-
-
Save halkeye/6288018 to your computer and use it in GitHub Desktop.
Simple little script I use to update wordpress plugins
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Simple little script I use to update wordpress plugins | |
# Author: Gavin Mogan <[email protected]> | |
# | |
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment