You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@community.apache.org by se...@apache.org on 2015/07/13 01:28:27 UTC
svn commit: r1690552 -
/comdev/projects.apache.org/scripts/cronjobs/pubsubber.py
Author: sebb
Date: Sun Jul 12 23:28:26 2015
New Revision: 1690552
URL: http://svn.apache.org/r1690552
Log:
COMDEV-149 - pubsubber.py - handle multiple workspaces
Modified:
comdev/projects.apache.org/scripts/cronjobs/pubsubber.py (contents, props changed)
Modified: comdev/projects.apache.org/scripts/cronjobs/pubsubber.py
URL: http://svn.apache.org/viewvc/comdev/projects.apache.org/scripts/cronjobs/pubsubber.py?rev=1690552&r1=1690551&r2=1690552&view=diff
==============================================================================
--- comdev/projects.apache.org/scripts/cronjobs/pubsubber.py (original)
+++ comdev/projects.apache.org/scripts/cronjobs/pubsubber.py Sun Jul 12 23:28:26 2015
@@ -21,6 +21,7 @@ else:
debug = False
+watching={} # dict: key = path to watch, value = set() of paths to update on match
###########################################################
# Daemon class, curtesy of an anonymous good-hearted soul #
@@ -203,27 +204,31 @@ class PubSubClient(Thread):
if "commit" in obj and "repository" in obj['commit']:
# If it's our public svn repo, then...
if obj['commit']['repository'] == "13f79535-47bb-0310-9956-ffa450edef68":
-
#Grab some vars
commit = obj['commit']
svnuser = commit['committer']
- match = False
+ revision = commit['id']
+ filePaths = set()
# commit['changed'] = { "path" : { "flags": "value"}}
for path in commit['changed']:
- # Check if the commit is for our part of the repo
- match = re.match("^%s" % watchPath, path)
- if match:
- break # no need to check further
-
- if match:
- if debug:
- print("Matched '" + path + "' against '" + watchPath + "'; would run 'svn up " + filePath + "'")
- else:
- time.sleep(3)
- subprocess.call(['svn','up',filePath])
+ for watchPath in watching:
+ # Check if the commit is for our part of the repo
+ match = re.match("^%s" % watchPath, path)
+ if match:
+ filePath = str(watching[watchPath])
+ if debug:
+ print("Matched '" + path + "' against '" + watchPath + "'; would run 'svn up " + filePath + "'")
+ filePaths.update(watching[watchPath])
+ if filePaths:
+ for filePath in filePaths:
+ if debug:
+ print("Matched 'r" + str(revision) + "'; would run 'svn up " + filePath + "'")
+ else:
+ time.sleep(3)
+ subprocess.call(['svn','up', filePath])
else:
if debug:
- print("Did not match '" + path + "' against ' " + watchPath + "'")
+ print("Did not match 'r" + str(revision) + "' against ' " + str(watching.keys()) + "'")
except ValueError as detail:
@@ -255,7 +260,8 @@ According to https://svn.apache.org/repo
def main():
if debug:
print("Foreground test mode enabled, no updates will be made")
- print("Watching: '" + watchPath + "' for updates to '" + filePath + "'")
+ for watchPath in watching:
+ print("Watching: '" + watchPath + "' for updates to '" + str(watching[watchPath]) + "'")
@@ -275,24 +281,33 @@ class MyDaemon(daemon):
main()
def usage():
- print("usage: %s start|stop|restart|foreground [repo-path] [file-path]" % sys.argv[0])
+ print("usage: %s start|stop|restart|foreground ([repo-path] [file-path])*" % sys.argv[0])
print("for example: %s start comdev/projects.apache.org /var/www/projects.apache.org" % sys.argv[0])
-
+
+def handle_args(args):
+ if len(args) % 2 != 0:
+ usage()
+ sys.exit("Need an even number of repo/file paths, found "+str(len(args)))
+ else:
+ for i in range(0, len(args), 2):
+ try:
+ watching[args[i]].update(args[i+1])
+ except KeyError:
+ watching[args[i]] = set([args[i+1]])
+
if __name__ == "__main__":
daemon = MyDaemon('/tmp/pubsubber.pid')
if len(sys.argv) >= 2:
- if 'start' == sys.argv[1] and len(sys.argv) >= 4:
- watchPath = sys.argv[2]
- filePath = sys.argv[3]
+ if 'start' == sys.argv[1]:
+ handle_args(sys.argv[2:])
daemon.start()
elif 'stop' == sys.argv[1]:
daemon.stop()
elif 'restart' == sys.argv[1]:
daemon.restart()
- elif 'foreground' == sys.argv[1] and len(sys.argv) >= 4:
+ elif 'foreground' == sys.argv[1]:
debug = True
- watchPath = sys.argv[2]
- filePath = sys.argv[3]
+ handle_args(sys.argv[2:])
main()
else:
usage()
Propchange: comdev/projects.apache.org/scripts/cronjobs/pubsubber.py
------------------------------------------------------------------------------
svn:eol-style = native