* [PATCH 0/2] git-p4 support for older python
@ 2013-01-25 20:43 Brandon Casey
2013-01-25 20:44 ` [PATCH 1/2] git-p4.py: support Python 2.5 Brandon Casey
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Brandon Casey @ 2013-01-25 20:43 UTC (permalink / raw)
To: git; +Cc: pw, esr, john, Brandon Casey
Offered for consideration.
These two patches allow git-p4 to run on python 2.4 which is shipped on
RHEL 5.X. The changes are minor and unintrusive in my opinion, but please
feel free to reject one or both of them for any reason (in which case the
version check at the top of git-p4.py should be updated).
Brandon Casey (2):
git-p4.py: support Python 2.5
git-p4.py: support Python 2.4
INSTALL | 2 +-
git-p4.py | 30 ++++++++++++++++++++++++++----
t/t9802-git-p4-filetype.sh | 11 ++++++-----
3 files changed, 33 insertions(+), 10 deletions(-)
--
1.8.1.1.297.gad3d74e
-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information. Any unauthorized review, use, disclosure or distribution
is prohibited. If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/2] git-p4.py: support Python 2.5
2013-01-25 20:43 [PATCH 0/2] git-p4 support for older python Brandon Casey
@ 2013-01-25 20:44 ` Brandon Casey
2013-01-26 12:45 ` Pete Wyckoff
2013-01-25 20:44 ` [PATCH 2/2] git-p4.py: support Python 2.4 Brandon Casey
2013-01-25 21:10 ` [PATCH 0/2] git-p4 support for older python Junio C Hamano
2 siblings, 1 reply; 8+ messages in thread
From: Brandon Casey @ 2013-01-25 20:44 UTC (permalink / raw)
To: git; +Cc: pw, esr, john, Brandon Casey, Brandon Casey
Python 2.5 and older do not accept None as the first argument to
translate() and complain with:
TypeError: expected a character buffer object
Satisfy this older python by calling maketrans() to generate an empty
translation table and supplying that to translate().
This allows git-p4 to be used with Python 2.5.
Signed-off-by: Brandon Casey <bcasey@nvidia.com>
---
INSTALL | 2 +-
git-p4.py | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/INSTALL b/INSTALL
index 28f34bd..fc723b3 100644
--- a/INSTALL
+++ b/INSTALL
@@ -131,7 +131,7 @@ Issues of note:
use English. Under autoconf the configure script will do this
automatically if it can't find libintl on the system.
- - Python version 2.6 or later is needed to use the git-p4
+ - Python version 2.5 or later is needed to use the git-p4
interface to Perforce.
- Some platform specific issues are dealt with Makefile rules,
diff --git a/git-p4.py b/git-p4.py
index 2da5649..4f95d7a 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -768,7 +768,8 @@ def wildcard_encode(path):
return path
def wildcard_present(path):
- return path.translate(None, "*#@%") != path
+ from string import maketrans
+ return path.translate(maketrans("",""), "*#@%") != path
class Command:
def __init__(self):
--
1.8.1.1.297.gad3d74e
-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information. Any unauthorized review, use, disclosure or distribution
is prohibited. If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/2] git-p4.py: support Python 2.4
2013-01-25 20:43 [PATCH 0/2] git-p4 support for older python Brandon Casey
2013-01-25 20:44 ` [PATCH 1/2] git-p4.py: support Python 2.5 Brandon Casey
@ 2013-01-25 20:44 ` Brandon Casey
2013-01-26 12:48 ` Pete Wyckoff
2013-01-25 21:10 ` [PATCH 0/2] git-p4 support for older python Junio C Hamano
2 siblings, 1 reply; 8+ messages in thread
From: Brandon Casey @ 2013-01-25 20:44 UTC (permalink / raw)
To: git; +Cc: pw, esr, john, Brandon Casey, Brandon Casey
Python 2.4 lacks the following features:
subprocess.check_call
struct.pack_into
Take a cue from 460d1026 and provide an implementation of the
CalledProcessError exception. Then replace the calls to
subproccess.check_call with calls to subprocess.call that check the return
status and raise a CalledProcessError exception if necessary.
The struct.pack_into in t/9802 can be converted into a single struct.pack
call which is available in Python 2.4.
Signed-off-by: Brandon Casey <bcasey@nvidia.com>
---
INSTALL | 2 +-
git-p4.py | 27 ++++++++++++++++++++++++---
t/t9802-git-p4-filetype.sh | 11 ++++++-----
3 files changed, 31 insertions(+), 9 deletions(-)
diff --git a/INSTALL b/INSTALL
index fc723b3..b96e16d 100644
--- a/INSTALL
+++ b/INSTALL
@@ -131,7 +131,7 @@ Issues of note:
use English. Under autoconf the configure script will do this
automatically if it can't find libintl on the system.
- - Python version 2.5 or later is needed to use the git-p4
+ - Python version 2.4 or later is needed to use the git-p4
interface to Perforce.
- Some platform specific issues are dealt with Makefile rules,
diff --git a/git-p4.py b/git-p4.py
index 4f95d7a..faec09d 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -18,6 +18,21 @@ import optparse, os, marshal, subprocess, shelve
import tempfile, getopt, os.path, time, platform
import re, shutil
+try:
+ from subprocess import CalledProcessError
+except ImportError:
+ # from python2.7:subprocess.py
+ # Exception classes used by this module.
+ class CalledProcessError(Exception):
+ """This exception is raised when a process run by check_call() returns
+ a non-zero exit status. The exit status will be stored in the
+ returncode attribute."""
+ def __init__(self, returncode, cmd):
+ self.returncode = returncode
+ self.cmd = cmd
+ def __str__(self):
+ return "Command '%s' returned non-zero exit status %d" % (self.cmd, self.returncode)
+
verbose = False
# Only labels/tags matching this will be imported/exported
@@ -158,13 +173,17 @@ def system(cmd):
expand = isinstance(cmd,basestring)
if verbose:
sys.stderr.write("executing %s\n" % str(cmd))
- subprocess.check_call(cmd, shell=expand)
+ retcode = subprocess.call(cmd, shell=expand)
+ if retcode:
+ raise CalledProcessError(retcode, cmd)
def p4_system(cmd):
"""Specifically invoke p4 as the system command. """
real_cmd = p4_build_cmd(cmd)
expand = isinstance(real_cmd, basestring)
- subprocess.check_call(real_cmd, shell=expand)
+ retcode = subprocess.call(real_cmd, shell=expand)
+ if retcode:
+ raise CalledProcessError(retcode, real_cmd)
def p4_integrate(src, dest):
p4_system(["integrate", "-Dt", wildcard_encode(src), wildcard_encode(dest)])
@@ -3174,7 +3193,9 @@ class P4Clone(P4Sync):
init_cmd = [ "git", "init" ]
if self.cloneBare:
init_cmd.append("--bare")
- subprocess.check_call(init_cmd)
+ retcode = subprocess.call(init_cmd)
+ if retcode:
+ raise CalledProcessError(retcode, init_cmd)
if not P4Sync.run(self, depotPaths):
return False
diff --git a/t/t9802-git-p4-filetype.sh b/t/t9802-git-p4-filetype.sh
index 21924df..be299dc 100755
--- a/t/t9802-git-p4-filetype.sh
+++ b/t/t9802-git-p4-filetype.sh
@@ -105,12 +105,13 @@ build_gendouble() {
cat >gendouble.py <<-\EOF
import sys
import struct
- import array
- s = array.array("c", '\0' * 26)
- struct.pack_into(">L", s, 0, 0x00051607) # AppleDouble
- struct.pack_into(">L", s, 4, 0x00020000) # version 2
- s.tofile(sys.stdout)
+ s = struct.pack(">LL18s",
+ 0x00051607, # AppleDouble
+ 0x00020000, # version 2
+ "" # pad to 26 bytes
+ )
+ sys.stdout.write(s);
EOF
}
--
1.8.1.1.297.gad3d74e
-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information. Any unauthorized review, use, disclosure or distribution
is prohibited. If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 0/2] git-p4 support for older python
2013-01-25 20:43 [PATCH 0/2] git-p4 support for older python Brandon Casey
2013-01-25 20:44 ` [PATCH 1/2] git-p4.py: support Python 2.5 Brandon Casey
2013-01-25 20:44 ` [PATCH 2/2] git-p4.py: support Python 2.4 Brandon Casey
@ 2013-01-25 21:10 ` Junio C Hamano
2 siblings, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2013-01-25 21:10 UTC (permalink / raw)
To: Brandon Casey, Pete Wyckoff; +Cc: git, esr, john
Both patches look simple enough. Pete, what do you think?
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] git-p4.py: support Python 2.5
2013-01-25 20:44 ` [PATCH 1/2] git-p4.py: support Python 2.5 Brandon Casey
@ 2013-01-26 12:45 ` Pete Wyckoff
2013-01-26 18:19 ` Brandon Casey
0 siblings, 1 reply; 8+ messages in thread
From: Pete Wyckoff @ 2013-01-26 12:45 UTC (permalink / raw)
To: Brandon Casey; +Cc: git, esr, john, Brandon Casey
drafnel@gmail.com wrote on Fri, 25 Jan 2013 12:44 -0800:
> Python 2.5 and older do not accept None as the first argument to
> translate() and complain with:
>
> TypeError: expected a character buffer object
>
> Satisfy this older python by calling maketrans() to generate an empty
> translation table and supplying that to translate().
>
> This allows git-p4 to be used with Python 2.5.
This was a lot easier than I imagined!
> def wildcard_present(path):
> - return path.translate(None, "*#@%") != path
> + from string import maketrans
> + return path.translate(maketrans("",""), "*#@%") != path
translate() was a bit too subtle already. Could you try
something like this instead?
m = re.search("[*#@%]", path)
return m is not None
I think that'll work everywhere and not force people to look
up how translate and maketrans work.
-- Pete
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] git-p4.py: support Python 2.4
2013-01-25 20:44 ` [PATCH 2/2] git-p4.py: support Python 2.4 Brandon Casey
@ 2013-01-26 12:48 ` Pete Wyckoff
2013-01-26 19:02 ` Brandon Casey
0 siblings, 1 reply; 8+ messages in thread
From: Pete Wyckoff @ 2013-01-26 12:48 UTC (permalink / raw)
To: Brandon Casey; +Cc: git, esr, john, Brandon Casey
drafnel@gmail.com wrote on Fri, 25 Jan 2013 12:44 -0800:
> Python 2.4 lacks the following features:
>
> subprocess.check_call
> struct.pack_into
>
> Take a cue from 460d1026 and provide an implementation of the
> CalledProcessError exception. Then replace the calls to
> subproccess.check_call with calls to subprocess.call that check the return
> status and raise a CalledProcessError exception if necessary.
>
> The struct.pack_into in t/9802 can be converted into a single struct.pack
> call which is available in Python 2.4.
Excellent. Should have used struct.pack() from the get-go.
Acked-by: Pete Wyckoff <pw@padd.com>
> diff --git a/t/t9802-git-p4-filetype.sh b/t/t9802-git-p4-filetype.sh
> index 21924df..be299dc 100755
> --- a/t/t9802-git-p4-filetype.sh
> +++ b/t/t9802-git-p4-filetype.sh
> @@ -105,12 +105,13 @@ build_gendouble() {
> cat >gendouble.py <<-\EOF
> import sys
> import struct
> - import array
>
> - s = array.array("c", '\0' * 26)
> - struct.pack_into(">L", s, 0, 0x00051607) # AppleDouble
> - struct.pack_into(">L", s, 4, 0x00020000) # version 2
> - s.tofile(sys.stdout)
> + s = struct.pack(">LL18s",
> + 0x00051607, # AppleDouble
> + 0x00020000, # version 2
> + "" # pad to 26 bytes
> + )
> + sys.stdout.write(s);
> EOF
One stray semicolon.
In terms of maintenance, I'll not run tests with 2.4 or 2.5
myself, but maybe you would be willing to check an RC candidate
each release?
-- Pete
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] git-p4.py: support Python 2.5
2013-01-26 12:45 ` Pete Wyckoff
@ 2013-01-26 18:19 ` Brandon Casey
0 siblings, 0 replies; 8+ messages in thread
From: Brandon Casey @ 2013-01-26 18:19 UTC (permalink / raw)
To: Pete Wyckoff; +Cc: git, esr, john, Brandon Casey
On Sat, Jan 26, 2013 at 4:45 AM, Pete Wyckoff <pw@padd.com> wrote:
> drafnel@gmail.com wrote on Fri, 25 Jan 2013 12:44 -0800:
>> Python 2.5 and older do not accept None as the first argument to
>> translate() and complain with:
>>
>> TypeError: expected a character buffer object
>>
>> Satisfy this older python by calling maketrans() to generate an empty
>> translation table and supplying that to translate().
>>
>> This allows git-p4 to be used with Python 2.5.
>
> This was a lot easier than I imagined!
>
>> def wildcard_present(path):
>> - return path.translate(None, "*#@%") != path
>> + from string import maketrans
>> + return path.translate(maketrans("",""), "*#@%") != path
>
> translate() was a bit too subtle already. Could you try
> something like this instead?
>
> m = re.search("[*#@%]", path)
> return m is not None
>
> I think that'll work everywhere and not force people to look
> up how translate and maketrans work.
Yes that's simpler and works fine.
-Brandon
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] git-p4.py: support Python 2.4
2013-01-26 12:48 ` Pete Wyckoff
@ 2013-01-26 19:02 ` Brandon Casey
0 siblings, 0 replies; 8+ messages in thread
From: Brandon Casey @ 2013-01-26 19:02 UTC (permalink / raw)
To: Pete Wyckoff; +Cc: git, esr, john, Brandon Casey
On Sat, Jan 26, 2013 at 4:48 AM, Pete Wyckoff <pw@padd.com> wrote:
> drafnel@gmail.com wrote on Fri, 25 Jan 2013 12:44 -0800:
>> + sys.stdout.write(s);
> One stray semicolon.
Whoops. Thanks.
> In terms of maintenance, I'll not run tests with 2.4 or 2.5
> myself, but maybe you would be willing to check an RC candidate
> each release?
Not a problem. I'm sure it will get run much more often then that.
-Brandon
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2013-01-26 19:02 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-25 20:43 [PATCH 0/2] git-p4 support for older python Brandon Casey
2013-01-25 20:44 ` [PATCH 1/2] git-p4.py: support Python 2.5 Brandon Casey
2013-01-26 12:45 ` Pete Wyckoff
2013-01-26 18:19 ` Brandon Casey
2013-01-25 20:44 ` [PATCH 2/2] git-p4.py: support Python 2.4 Brandon Casey
2013-01-26 12:48 ` Pete Wyckoff
2013-01-26 19:02 ` Brandon Casey
2013-01-25 21:10 ` [PATCH 0/2] git-p4 support for older python Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).