You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by br...@apache.org on 2013/05/27 04:52:10 UTC
svn commit: r1486500 - in /subversion/trunk/tools/server-side/svnpubsub:
commit-hook.py revprop-change-hook.py svnpubsub/util.py svnwcsub.py
Author: brane
Date: Mon May 27 02:52:10 2013
New Revision: 1486500
URL: http://svn.apache.org/r1486500
Log:
In SvnPubSub, extract wrapper for subprocess.check_output into a common utility
module. And make problems in the server hooks more visible by exiting with an
error if the hook fails to run.
[in tools/server-side/svnpubsub]
* svnpubsub/util.py: New module.
(check_output): Wrapper for subprocess.check_output to make it available
on versions of Python older than 2.7.
* svnwcsub.py (check_output): Removed. Imported from svnpubsub.util instead.
(svn_info): Updated call to check_output.
* commit-hook.py: Do 'import svnpubsub.util' and do not 'import subprocess'.
(svnlook): Renamed from svncmd; calls svnpubsub.util.check_output and
expects the command to be a list, not a string. All callers updated.
(svnlook_uuid): Renamed from svncmd_uuid. All callers updated.
(svnlook_info): Renamed from svncmd_info. All callers updated.
(svnlook_changed): Renamed from svncmd_changed. All callers updated.
At top level: Exit with an error code if the number of arguments is wrong.
* revprop-change-hook.py: Same changes as in commit-hook.py, except that the
renamed functions are: svnlook (from svncmd), svnlook_uuid (from svncmd_uuid)
and svnlook_revprop (from svncmd_revprop).
Added:
subversion/trunk/tools/server-side/svnpubsub/svnpubsub/util.py
Modified:
subversion/trunk/tools/server-side/svnpubsub/commit-hook.py
subversion/trunk/tools/server-side/svnpubsub/revprop-change-hook.py
subversion/trunk/tools/server-side/svnpubsub/svnwcsub.py
Modified: subversion/trunk/tools/server-side/svnpubsub/commit-hook.py
URL: http://svn.apache.org/viewvc/subversion/trunk/tools/server-side/svnpubsub/commit-hook.py?rev=1486500&r1=1486499&r2=1486500&view=diff
==============================================================================
--- subversion/trunk/tools/server-side/svnpubsub/commit-hook.py (original)
+++ subversion/trunk/tools/server-side/svnpubsub/commit-hook.py Mon May 27 02:52:10 2013
@@ -23,7 +23,6 @@ HOST="127.0.0.1"
PORT=2069
import sys
-import subprocess
try:
import simplejson as json
except ImportError:
@@ -31,32 +30,32 @@ except ImportError:
import urllib2
-def svncmd(cmd):
- return subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE)
+import svnpubsub.util
-def svncmd_uuid(repo):
- cmd = "%s uuid %s" % (SVNLOOK, repo)
- p = svncmd(cmd)
- return p.stdout.read().strip()
-
-def svncmd_info(repo, revision):
- cmd = "%s info -r %s %s" % (SVNLOOK, revision, repo)
- p = svncmd(cmd)
- data = p.stdout.read().split("\n")
+def svnlook(cmd, **kwargs):
+ args = [SVNLOOK] + cmd
+ return svnpubsub.util.check_output(args, **kwargs)
+
+def svnlook_uuid(repo):
+ cmd = ["uuid", repo]
+ return svnlook(cmd).strip()
+
+def svnlook_info(repo, revision):
+ cmd = ["info", "-r", revision, repo]
+ data = svnlook(cmd, universal_newlines=True).split("\n")
#print data
return {'author': data[0].strip(),
'date': data[1].strip(),
'log': "\n".join(data[3:]).strip()}
-def svncmd_changed(repo, revision):
- cmd = "%s changed -r %s %s" % (SVNLOOK, revision, repo)
- p = svncmd(cmd)
+def svnlook_changed(repo, revision):
+ cmd = ["changed", "-r", revision, repo]
+ lines = svnlook(cmd, universal_newlines=True).split("\n")
changed = {}
- while True:
- line = p.stdout.readline()
- if not line:
- break
+ for line in lines:
line = line.strip()
+ if not line:
+ continue
(flags, filename) = (line[0:3], line[4:])
changed[filename] = {'flags': flags}
return changed
@@ -71,23 +70,23 @@ def do_put(body):
def main(repo, revision):
revision = revision.lstrip('r')
- i = svncmd_info(repo, revision)
+ i = svnlook_info(repo, revision)
data = {'type': 'svn',
'format': 1,
'id': int(revision),
'changed': {},
- 'repository': svncmd_uuid(repo),
+ 'repository': svnlook_uuid(repo),
'committer': i['author'],
'log': i['log'],
'date': i['date'],
}
- data['changed'].update(svncmd_changed(repo, revision))
+ data['changed'].update(svnlook_changed(repo, revision))
body = json.dumps(data)
do_put(body)
if __name__ == "__main__":
if len(sys.argv) not in (3, 4):
sys.stderr.write("invalid args\n")
- sys.exit(0)
+ sys.exit(1)
main(*sys.argv[1:3])
Modified: subversion/trunk/tools/server-side/svnpubsub/revprop-change-hook.py
URL: http://svn.apache.org/viewvc/subversion/trunk/tools/server-side/svnpubsub/revprop-change-hook.py?rev=1486500&r1=1486499&r2=1486500&view=diff
==============================================================================
--- subversion/trunk/tools/server-side/svnpubsub/revprop-change-hook.py (original)
+++ subversion/trunk/tools/server-side/svnpubsub/revprop-change-hook.py Mon May 27 02:52:10 2013
@@ -23,7 +23,6 @@ HOST="127.0.0.1"
PORT=2069
import sys
-import subprocess
try:
import simplejson as json
except ImportError:
@@ -31,18 +30,20 @@ except ImportError:
import urllib2
-def svncmd(cmd):
- return subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE)
-def svncmd_uuid(repo):
- cmd = "%s uuid %s" % (SVNLOOK, repo)
- p = svncmd(cmd)
- return p.stdout.read().strip()
-
-def svncmd_revprop(repo, revision, propname):
- cmd = "%s propget -r %s --revprop %s %s" % (SVNLOOK, revision, repo, propname)
- p = svncmd(cmd)
- data = p.stdout.read()
+import svnpubsub.util
+
+def svnlook(cmd, **kwargs):
+ args = [SVNLOOK] + cmd
+ return svnpubsub.util.check_output(args, **kwargs)
+
+def svnlook_uuid(repo):
+ cmd = ["uuid", repo]
+ return svnlook(cmd).strip()
+
+def svnlook_revprop(repo, revision, propname):
+ cmd = ["propget", "-r", revision, "--revprop", repo, propname]
+ data = svnlook(cmd)
#print data
return data
@@ -57,7 +58,7 @@ def do_put(body):
def main(repo, revision, author, propname, action):
revision = revision.lstrip('r')
if action in ('A', 'M'):
- new_value = svncmd_revprop(repo, revision, propname)
+ new_value = svnlook_revprop(repo, revision, propname)
elif action == 'D':
new_value = None
else:
@@ -70,7 +71,7 @@ def main(repo, revision, author, propnam
data = {'type': 'svn',
'format': 1,
'id': int(revision),
- 'repository': svncmd_uuid(repo),
+ 'repository': svnlook_uuid(repo),
'revprop': {
'name': propname,
'committer': author,
@@ -84,6 +85,6 @@ def main(repo, revision, author, propnam
if __name__ == "__main__":
if len(sys.argv) != 6:
sys.stderr.write("invalid args\n")
- sys.exit(0)
+ sys.exit(1)
main(*sys.argv[1:6])
Added: subversion/trunk/tools/server-side/svnpubsub/svnpubsub/util.py
URL: http://svn.apache.org/viewvc/subversion/trunk/tools/server-side/svnpubsub/svnpubsub/util.py?rev=1486500&view=auto
==============================================================================
--- subversion/trunk/tools/server-side/svnpubsub/svnpubsub/util.py (added)
+++ subversion/trunk/tools/server-side/svnpubsub/svnpubsub/util.py Mon May 27 02:52:10 2013
@@ -0,0 +1,36 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+import subprocess as __subprocess
+
+# check_output() is only available in Python 2.7. Allow us to run with
+# earlier versions
+try:
+ __check_output = __subprocess.check_output
+ def check_output(args, env=None, universal_newlines=False):
+ return __check_output(args, shell=False, env=env,
+ universal_newlines=universal_newlines)
+except AttributeError:
+ def check_output(args, env=None, universal_newlines=False):
+ # note: we only use these three args
+ pipe = __subprocess.Popen(args, shell=False, env=env,
+ stdout=__subprocess.PIPE,
+ universal_newlines=universal_newlines)
+ output, _ = pipe.communicate()
+ if pipe.returncode:
+ raise subprocess.CalledProcessError(pipe.returncode, args)
+ return output
Modified: subversion/trunk/tools/server-side/svnpubsub/svnwcsub.py
URL: http://svn.apache.org/viewvc/subversion/trunk/tools/server-side/svnpubsub/svnwcsub.py?rev=1486500&r1=1486499&r2=1486500&view=diff
==============================================================================
--- subversion/trunk/tools/server-side/svnpubsub/svnwcsub.py (original)
+++ subversion/trunk/tools/server-side/svnpubsub/svnwcsub.py Mon May 27 02:52:10 2013
@@ -69,18 +69,7 @@ except ImportError:
import daemonize
import svnpubsub.client
-
-# check_output() is only available in Python 2.7. Allow us to run with
-# earlier versions
-try:
- check_output = subprocess.check_output
-except AttributeError:
- def check_output(args, env): # note: we only use these two args
- pipe = subprocess.Popen(args, stdout=subprocess.PIPE, env=env)
- output, _ = pipe.communicate()
- if pipe.returncode:
- raise subprocess.CalledProcessError(pipe.returncode, args)
- return output
+import svnpubsub.util
assert hasattr(subprocess, 'check_call')
def check_call(*args, **kwds):
@@ -103,7 +92,7 @@ def check_call(*args, **kwds):
def svn_info(svnbin, env, path):
"Run 'svn info' on the target path, returning a dict of info data."
args = [svnbin, "info", "--non-interactive", "--", path]
- output = check_output(args, env=env).strip()
+ output = svnpubsub.util.check_output(args, env=env).strip()
info = { }
for line in output.split('\n'):
idx = line.index(':')
Re: svn commit: r1486500 - in /subversion/trunk/tools/server-side/svnpubsub:
commit-hook.py revprop-change-hook.py svnpubsub/util.py svnwcsub.py
Posted by Branko Čibej <br...@wandisco.com>.
On 27.05.2013 06:35, Daniel Shahaf wrote:
> On Mon, May 27, 2013 at 02:52:10AM -0000, brane@apache.org wrote:
>> Author: brane
>> Date: Mon May 27 02:52:10 2013
>> New Revision: 1486500
>>
>> URL: http://svn.apache.org/r1486500
>> Log:
>> In SvnPubSub, extract wrapper for subprocess.check_output into a common utility
>> module. And make problems in the server hooks more visible by exiting with an
>> error if the hook fails to run.
>>
> Should the exit code fix be backported?
IMO, we can backport the whole set of changes in 1.8.1.
-- Brane
--
Branko Čibej
Director of Subversion | WANdisco | www.wandisco.com
Re: svn commit: r1486500 - in /subversion/trunk/tools/server-side/svnpubsub: commit-hook.py revprop-change-hook.py svnpubsub/util.py svnwcsub.py
Posted by Daniel Shahaf <da...@apache.org>.
On Mon, May 27, 2013 at 02:52:10AM -0000, brane@apache.org wrote:
> Author: brane
> Date: Mon May 27 02:52:10 2013
> New Revision: 1486500
>
> URL: http://svn.apache.org/r1486500
> Log:
> In SvnPubSub, extract wrapper for subprocess.check_output into a common utility
> module. And make problems in the server hooks more visible by exiting with an
> error if the hook fails to run.
>
Should the exit code fix be backported?
Re: svn commit: r1486500 - in /subversion/trunk/tools/server-side/svnpubsub: commit-hook.py revprop-change-hook.py svnpubsub/util.py svnwcsub.py
Posted by Daniel Shahaf <da...@apache.org>.
On Mon, May 27, 2013 at 02:52:10AM -0000, brane@apache.org wrote:
> Author: brane
> Date: Mon May 27 02:52:10 2013
> New Revision: 1486500
>
> URL: http://svn.apache.org/r1486500
> Log:
> In SvnPubSub, extract wrapper for subprocess.check_output into a common utility
> module. And make problems in the server hooks more visible by exiting with an
> error if the hook fails to run.
>
Should the exit code fix be backported?