{"thread":{"id":"32727","subject":"[PATCH 1/2] git-p4.py: support Python 2.5","startedAt":"2013-01-25T20:43:59Z","lastAt":"2013-01-26T19:02:02Z","messageCount":8,"participants":["Brandon Casey","Junio C Hamano","Pete Wyckoff"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"207835","messageId":"1359146641-27810-1-git-send-email-drafnel@gmail.com","threadId":"32727","inReplyTo":null,"subject":"[PATCH 0/2] git-p4 support for older python","fromName":"Brandon Casey","fromEmail":"drafnel@gmail.com","sentAt":"2013-01-25T20:43:59Z","receivedAt":"2013-01-25T20:43:59Z","isPatch":true,"sender":{"key":"drafnel@gmail.com","avatar":"https://avatars.githubusercontent.com/u/921167?v=4"},"body":"Offered for consideration.\n\nThese two patches allow git-p4 to run on python 2.4 which is shipped on\nRHEL 5.X.  The changes are minor and unintrusive in my opinion, but please\nfeel free to reject one or both of them for any reason (in which case the\nversion check at the top of git-p4.py should be updated).\n\nBrandon Casey (2):\n  git-p4.py: support Python 2.5\n  git-p4.py: support Python 2.4\n\n INSTALL                    |  2 +-\n git-p4.py                  | 30 ++++++++++++++++++++++++++----\n t/t9802-git-p4-filetype.sh | 11 ++++++-----\n 3 files changed, 33 insertions(+), 10 deletions(-)\n\n-- \n1.8.1.1.297.gad3d74e\n\n\n-----------------------------------------------------------------------------------\nThis email message is for the sole use of the intended recipient(s) and may contain\nconfidential information.  Any unauthorized review, use, disclosure or distribution\nis prohibited.  If you are not the intended recipient, please contact the sender by\nreply email and destroy all copies of the original message.\n-----------------------------------------------------------------------------------\n"},{"id":"207834","messageId":"1359146641-27810-2-git-send-email-drafnel@gmail.com","threadId":"32727","inReplyTo":"1359146641-27810-1-git-send-email-drafnel@gmail.com","subject":"[PATCH 1/2] git-p4.py: support Python 2.5","fromName":"Brandon Casey","fromEmail":"drafnel@gmail.com","sentAt":"2013-01-25T20:44:00Z","receivedAt":"2013-01-25T20:44:00Z","isPatch":true,"sender":{"key":"drafnel@gmail.com","avatar":"https://avatars.githubusercontent.com/u/921167?v=4"},"body":"Python 2.5 and older do not accept None as the first argument to\ntranslate() and complain with:\n\n   TypeError: expected a character buffer object\n\nSatisfy this older python by calling maketrans() to generate an empty\ntranslation table and supplying that to translate().\n\nThis allows git-p4 to be used with Python 2.5.\n\nSigned-off-by: Brandon Casey <bcasey@nvidia.com>\n---\n INSTALL   | 2 +-\n git-p4.py | 3 ++-\n 2 files changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/INSTALL b/INSTALL\nindex 28f34bd..fc723b3 100644\n--- a/INSTALL\n+++ b/INSTALL\n@@ -131,7 +131,7 @@ Issues of note:\n \t  use English. Under autoconf the configure script will do this\n \t  automatically if it can't find libintl on the system.\n \n-\t- Python version 2.6 or later is needed to use the git-p4\n+\t- Python version 2.5 or later is needed to use the git-p4\n \t  interface to Perforce.\n \n  - Some platform specific issues are dealt with Makefile rules,\ndiff --git a/git-p4.py b/git-p4.py\nindex 2da5649..4f95d7a 100755\n--- a/git-p4.py\n+++ b/git-p4.py\n@@ -768,7 +768,8 @@ def wildcard_encode(path):\n     return path\n \n def wildcard_present(path):\n-    return path.translate(None, \"*#@%\") != path\n+    from string import maketrans\n+    return path.translate(maketrans(\"\",\"\"), \"*#@%\") != path\n \n class Command:\n     def __init__(self):\n-- \n1.8.1.1.297.gad3d74e\n\n\n-----------------------------------------------------------------------------------\nThis email message is for the sole use of the intended recipient(s) and may contain\nconfidential information.  Any unauthorized review, use, disclosure or distribution\nis prohibited.  If you are not the intended recipient, please contact the sender by\nreply email and destroy all copies of the original message.\n-----------------------------------------------------------------------------------\n"},{"id":"207836","messageId":"1359146641-27810-3-git-send-email-drafnel@gmail.com","threadId":"32727","inReplyTo":"1359146641-27810-1-git-send-email-drafnel@gmail.com","subject":"[PATCH 2/2] git-p4.py: support Python 2.4","fromName":"Brandon Casey","fromEmail":"drafnel@gmail.com","sentAt":"2013-01-25T20:44:01Z","receivedAt":"2013-01-25T20:44:01Z","isPatch":true,"sender":{"key":"drafnel@gmail.com","avatar":"https://avatars.githubusercontent.com/u/921167?v=4"},"body":"Python 2.4 lacks the following features:\n\n   subprocess.check_call\n   struct.pack_into\n\nTake a cue from 460d1026 and provide an implementation of the\nCalledProcessError exception.  Then replace the calls to\nsubproccess.check_call with calls to subprocess.call that check the return\nstatus and raise a CalledProcessError exception if necessary.\n\nThe struct.pack_into in t/9802 can be converted into a single struct.pack\ncall which is available in Python 2.4.\n\nSigned-off-by: Brandon Casey <bcasey@nvidia.com>\n---\n INSTALL                    |  2 +-\n git-p4.py                  | 27 ++++++++++++++++++++++++---\n t/t9802-git-p4-filetype.sh | 11 ++++++-----\n 3 files changed, 31 insertions(+), 9 deletions(-)\n\ndiff --git a/INSTALL b/INSTALL\nindex fc723b3..b96e16d 100644\n--- a/INSTALL\n+++ b/INSTALL\n@@ -131,7 +131,7 @@ Issues of note:\n \t  use English. Under autoconf the configure script will do this\n \t  automatically if it can't find libintl on the system.\n \n-\t- Python version 2.5 or later is needed to use the git-p4\n+\t- Python version 2.4 or later is needed to use the git-p4\n \t  interface to Perforce.\n \n  - Some platform specific issues are dealt with Makefile rules,\ndiff --git a/git-p4.py b/git-p4.py\nindex 4f95d7a..faec09d 100755\n--- a/git-p4.py\n+++ b/git-p4.py\n@@ -18,6 +18,21 @@ import optparse, os, marshal, subprocess, shelve\n import tempfile, getopt, os.path, time, platform\n import re, shutil\n \n+try:\n+    from subprocess import CalledProcessError\n+except ImportError:\n+    # from python2.7:subprocess.py\n+    # Exception classes used by this module.\n+    class CalledProcessError(Exception):\n+        \"\"\"This exception is raised when a process run by check_call() returns\n+        a non-zero exit status.  The exit status will be stored in the\n+        returncode attribute.\"\"\"\n+        def __init__(self, returncode, cmd):\n+            self.returncode = returncode\n+            self.cmd = cmd\n+        def __str__(self):\n+            return \"Command '%s' returned non-zero exit status %d\" % (self.cmd, self.returncode)\n+\n verbose = False\n \n # Only labels/tags matching this will be imported/exported\n@@ -158,13 +173,17 @@ def system(cmd):\n     expand = isinstance(cmd,basestring)\n     if verbose:\n         sys.stderr.write(\"executing %s\\n\" % str(cmd))\n-    subprocess.check_call(cmd, shell=expand)\n+    retcode = subprocess.call(cmd, shell=expand)\n+    if retcode:\n+        raise CalledProcessError(retcode, cmd)\n \n def p4_system(cmd):\n     \"\"\"Specifically invoke p4 as the system command. \"\"\"\n     real_cmd = p4_build_cmd(cmd)\n     expand = isinstance(real_cmd, basestring)\n-    subprocess.check_call(real_cmd, shell=expand)\n+    retcode = subprocess.call(real_cmd, shell=expand)\n+    if retcode:\n+        raise CalledProcessError(retcode, real_cmd)\n \n def p4_integrate(src, dest):\n     p4_system([\"integrate\", \"-Dt\", wildcard_encode(src), wildcard_encode(dest)])\n@@ -3174,7 +3193,9 @@ class P4Clone(P4Sync):\n         init_cmd = [ \"git\", \"init\" ]\n         if self.cloneBare:\n             init_cmd.append(\"--bare\")\n-        subprocess.check_call(init_cmd)\n+        retcode = subprocess.call(init_cmd)\n+        if retcode:\n+            raise CalledProcessError(retcode, init_cmd)\n \n         if not P4Sync.run(self, depotPaths):\n             return False\ndiff --git a/t/t9802-git-p4-filetype.sh b/t/t9802-git-p4-filetype.sh\nindex 21924df..be299dc 100755\n--- a/t/t9802-git-p4-filetype.sh\n+++ b/t/t9802-git-p4-filetype.sh\n@@ -105,12 +105,13 @@ build_gendouble() {\n \tcat >gendouble.py <<-\\EOF\n \timport sys\n \timport struct\n-\timport array\n \n-\ts = array.array(\"c\", '\\0' * 26)\n-\tstruct.pack_into(\">L\", s,  0, 0x00051607)  # AppleDouble\n-\tstruct.pack_into(\">L\", s,  4, 0x00020000)  # version 2\n-\ts.tofile(sys.stdout)\n+\ts = struct.pack(\">LL18s\",\n+\t\t\t0x00051607,  # AppleDouble\n+\t\t\t0x00020000,  # version 2\n+\t\t\t\"\"           # pad to 26 bytes\n+\t)\n+\tsys.stdout.write(s);\n \tEOF\n }\n \n-- \n1.8.1.1.297.gad3d74e\n\n\n-----------------------------------------------------------------------------------\nThis email message is for the sole use of the intended recipient(s) and may contain\nconfidential information.  Any unauthorized review, use, disclosure or distribution\nis prohibited.  If you are not the intended recipient, please contact the sender by\nreply email and destroy all copies of the original message.\n-----------------------------------------------------------------------------------\n"},{"id":"207839","messageId":"7vham52ckc.fsf@alter.siamese.dyndns.org","threadId":"32727","inReplyTo":"1359146641-27810-1-git-send-email-drafnel@gmail.com","subject":"Re: [PATCH 0/2] git-p4 support for older python","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-01-25T21:10:59Z","receivedAt":"2013-01-25T21:10:59Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Both patches look simple enough.  Pete, what do you think?\n"},{"id":"207877","messageId":"20130126124510.GA31052@padd.com","threadId":"32727","inReplyTo":"1359146641-27810-2-git-send-email-drafnel@gmail.com","subject":"Re: [PATCH 1/2] git-p4.py: support Python 2.5","fromName":"Pete Wyckoff","fromEmail":"pw@padd.com","sentAt":"2013-01-26T12:45:10Z","receivedAt":"2013-01-26T12:45:10Z","isPatch":true,"sender":{"key":"pw@padd.com","avatar":null},"body":"drafnel@gmail.com wrote on Fri, 25 Jan 2013 12:44 -0800:\n> Python 2.5 and older do not accept None as the first argument to\n> translate() and complain with:\n> \n>    TypeError: expected a character buffer object\n> \n> Satisfy this older python by calling maketrans() to generate an empty\n> translation table and supplying that to translate().\n> \n> This allows git-p4 to be used with Python 2.5.\n\nThis was a lot easier than I imagined!\n\n>  def wildcard_present(path):\n> -    return path.translate(None, \"*#@%\") != path\n> +    from string import maketrans\n> +    return path.translate(maketrans(\"\",\"\"), \"*#@%\") != path\n\ntranslate() was a bit too subtle already.  Could you try\nsomething like this instead?\n\n    m = re.search(\"[*#@%]\", path)\n    return m is not None\n\nI think that'll work everywhere and not force people to look\nup how translate and maketrans work.\n\n\t\t-- Pete\n"},{"id":"207878","messageId":"20130126124854.GB31052@padd.com","threadId":"32727","inReplyTo":"1359146641-27810-3-git-send-email-drafnel@gmail.com","subject":"Re: [PATCH 2/2] git-p4.py: support Python 2.4","fromName":"Pete Wyckoff","fromEmail":"pw@padd.com","sentAt":"2013-01-26T12:48:54Z","receivedAt":"2013-01-26T12:48:54Z","isPatch":true,"sender":{"key":"pw@padd.com","avatar":null},"body":"drafnel@gmail.com wrote on Fri, 25 Jan 2013 12:44 -0800:\n> Python 2.4 lacks the following features:\n> \n>    subprocess.check_call\n>    struct.pack_into\n> \n> Take a cue from 460d1026 and provide an implementation of the\n> CalledProcessError exception.  Then replace the calls to\n> subproccess.check_call with calls to subprocess.call that check the return\n> status and raise a CalledProcessError exception if necessary.\n> \n> The struct.pack_into in t/9802 can be converted into a single struct.pack\n> call which is available in Python 2.4.\n\nExcellent.  Should have used struct.pack() from the get-go.\n\nAcked-by: Pete Wyckoff <pw@padd.com>\n\n> diff --git a/t/t9802-git-p4-filetype.sh b/t/t9802-git-p4-filetype.sh\n> index 21924df..be299dc 100755\n> --- a/t/t9802-git-p4-filetype.sh\n> +++ b/t/t9802-git-p4-filetype.sh\n> @@ -105,12 +105,13 @@ build_gendouble() {\n>  \tcat >gendouble.py <<-\\EOF\n>  \timport sys\n>  \timport struct\n> -\timport array\n>  \n> -\ts = array.array(\"c\", '\\0' * 26)\n> -\tstruct.pack_into(\">L\", s,  0, 0x00051607)  # AppleDouble\n> -\tstruct.pack_into(\">L\", s,  4, 0x00020000)  # version 2\n> -\ts.tofile(sys.stdout)\n> +\ts = struct.pack(\">LL18s\",\n> +\t\t\t0x00051607,  # AppleDouble\n> +\t\t\t0x00020000,  # version 2\n> +\t\t\t\"\"           # pad to 26 bytes\n> +\t)\n> +\tsys.stdout.write(s);\n>  \tEOF\n\nOne stray semicolon.\n\nIn terms of maintenance, I'll not run tests with 2.4 or 2.5\nmyself, but maybe you would be willing to check an RC candidate\neach release?\n\n\t\t-- Pete\n"},{"id":"207884","messageId":"CA+sFfMfxQUqe-Nqp-2CjZ0ShLuwOYqPUCOQMrGASUmhEhxNMNg@mail.gmail.com","threadId":"32727","inReplyTo":"20130126124510.GA31052@padd.com","subject":"Re: [PATCH 1/2] git-p4.py: support Python 2.5","fromName":"Brandon Casey","fromEmail":"drafnel@gmail.com","sentAt":"2013-01-26T18:19:37Z","receivedAt":"2013-01-26T18:19:37Z","isPatch":true,"sender":{"key":"drafnel@gmail.com","avatar":"https://avatars.githubusercontent.com/u/921167?v=4"},"body":"On Sat, Jan 26, 2013 at 4:45 AM, Pete Wyckoff <pw@padd.com> wrote:\n> drafnel@gmail.com wrote on Fri, 25 Jan 2013 12:44 -0800:\n>> Python 2.5 and older do not accept None as the first argument to\n>> translate() and complain with:\n>>\n>>    TypeError: expected a character buffer object\n>>\n>> Satisfy this older python by calling maketrans() to generate an empty\n>> translation table and supplying that to translate().\n>>\n>> This allows git-p4 to be used with Python 2.5.\n>\n> This was a lot easier than I imagined!\n>\n>>  def wildcard_present(path):\n>> -    return path.translate(None, \"*#@%\") != path\n>> +    from string import maketrans\n>> +    return path.translate(maketrans(\"\",\"\"), \"*#@%\") != path\n>\n> translate() was a bit too subtle already.  Could you try\n> something like this instead?\n>\n>     m = re.search(\"[*#@%]\", path)\n>     return m is not None\n>\n> I think that'll work everywhere and not force people to look\n> up how translate and maketrans work.\n\nYes that's simpler and works fine.\n\n-Brandon\n"},{"id":"207886","messageId":"CA+sFfMdkr1rwG3dTfVc2Nxemm88wbadu=q5eJWUprd3m+GU=3w@mail.gmail.com","threadId":"32727","inReplyTo":"20130126124854.GB31052@padd.com","subject":"Re: [PATCH 2/2] git-p4.py: support Python 2.4","fromName":"Brandon Casey","fromEmail":"drafnel@gmail.com","sentAt":"2013-01-26T19:02:02Z","receivedAt":"2013-01-26T19:02:02Z","isPatch":true,"sender":{"key":"drafnel@gmail.com","avatar":"https://avatars.githubusercontent.com/u/921167?v=4"},"body":"On Sat, Jan 26, 2013 at 4:48 AM, Pete Wyckoff <pw@padd.com> wrote:\n> drafnel@gmail.com wrote on Fri, 25 Jan 2013 12:44 -0800:\n\n>> +     sys.stdout.write(s);\n\n> One stray semicolon.\n\nWhoops.  Thanks.\n\n> In terms of maintenance, I'll not run tests with 2.4 or 2.5\n> myself, but maybe you would be willing to check an RC candidate\n> each release?\n\nNot a problem.  I'm sure it will get run much more often then that.\n\n-Brandon\n"}]}