Skip to content
Browse files

Made script to automatically update the wordpress plugin

  • Loading branch information...
1 parent a0d7289 commit 323ab5ddd7ac56afb6b60e223406fdaa04b3863c @aduston aduston committed Jan 18, 2012
Showing with 70 additions and 4 deletions.
  1. +2 −0 .gitignore
  2. +68 −4 build.py
View
2 .gitignore
@@ -1,4 +1,6 @@
*~
incrwd/build.php
build/*
+build_settings.py
+*.pyc
.DS_Store
View
72 build.py
@@ -10,12 +10,13 @@
def _rel(*x):
return os.path.join(PROJECT_ROOT, *x)
-def _run(cmd):
+def _run(cmd, cwd=None):
print("Running {0}".format(" ".join(cmd)))
process = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
- stderr=subprocess.PIPE)
+ stderr=subprocess.PIPE,
+ cwd=cwd)
output, err = process.communicate()
print(output)
print(err)
@@ -36,17 +37,80 @@ def _zip(version):
"incrwd",
"-x", "*~"])
+def _readme_version(file_name):
+ with open(file_name) as f:
+ text = f.read()
+ version_string = \
+ re.search(r"Stable tag:\s*([\d\.]+)", text).group(1)
+ return [int(x) for x in version_string.split('.')]
+
+def _svn_needs_update(svn_dir):
+ git_version = _readme_version(_rel('incrwd/readme.txt'))
+ svn_version = _readme_version(os.path.join(svn_dir, 'trunk/readme.txt'))
+ comp = cmp(git_version, svn_version)
+ if comp == 1:
+ print(("Got a git version of {0} and svn "
+ "version of {1}. Updating!").format(
+ git_version, svn_version))
+ return comp
+
+def _get_svn_password():
+ import build_settings
+ return build_settings.svn_password
+
+def _readme_string(version_array):
+ return '.'.join(str(v) for v in version_array)
+
+def _copy_to_svn_dst(src, dst):
+ names = os.listdir(src)
+ added_files = []
+ if not os.path.exists(dst):
+ os.makedirs(dst)
+ for name in names:
+ if name[-1] == '~':
+ continue
+ srcname = os.path.join(src, name)
+ dstname = os.path.join(dst, name)
+ if os.path.isdir(srcname):
+ _copy_to_svn_dst(srcname, dstname)
+ else:
+ preexisting = os.path.exists(dstname)
+ shutil.copy2(srcname, dstname)
+ if not preexisting:
+ added_files.append(dstname)
+ return added_files
+
+def _update_svn(svn_dir):
+ svn_password = _get_svn_password()
+ svn_rel = lambda *x: os.path.join(svn_dir, *x)
+ version = _readme_string(_readme_version(_rel('incrwd/readme.txt')))
+ added_files = _copy_to_svn_dst(_rel('incrwd'), svn_rel('trunk'))
+ for file in added_files:
+ _run(['svn', 'add', file], cwd=svn_dir)
+ _run(['svn', 'cp', svn_rel('trunk'), svn_rel('tags', version)],
+ cwd=svn_dir)
+ _run(['svn', 'ci', '-m', 'Version {0}'.format(version),
+ '--username', 'incrwd', '--password', svn_password],
+ cwd=svn_dir)
+
def _main(argv):
- opts, args = getopt.getopt(argv, "r", ["release"])
+ opts, args = getopt.getopt(argv, "rs:", ["release", "svndir"])
local_only = True
+ git_dir = None
+ svn_dir = None
for opt, arg in opts:
if opt in ("-r", "--release"):
local_only = False
+ elif opt in ("-s", "--svndir"):
+ svn_dir = arg
+ if svn_dir is None:
+ raise Exception("The -s arguments isn't optional, homeboy!")
print("You are running the {0} deployment.\n".format(
"local" if local_only else "production"))
version = _find_version()
_copy_build(local_only)
_zip(version)
-
+ if _svn_needs_update(svn_dir):
+ _update_svn(svn_dir)
_main(sys.argv[1:])

0 comments on commit 323ab5d

Please sign in to comment.
Something went wrong with that request. Please try again.