{"thread":{"id":"32734","subject":"[PATCH v2 1/2] git-p4.py: support Python 2.5","startedAt":"2013-01-26T19:14:32Z","lastAt":"2013-01-26T19:14:33Z","messageCount":2,"participants":["Brandon Casey"],"isPatch":true,"patchVersion":2,"patchTotal":2},"messages":[{"id":"207887","messageId":"1359227673-5673-1-git-send-email-bcasey@nvidia.com","threadId":"32734","inReplyTo":null,"subject":"[PATCH v2 1/2] git-p4.py: support Python 2.5","fromName":"Brandon Casey","fromEmail":"bcasey@nvidia.com","sentAt":"2013-01-26T19:14:32Z","receivedAt":"2013-01-26T19:14:32Z","isPatch":true,"sender":{"key":"bcasey@nvidia.com","avatar":null},"body":"From: Brandon Casey <drafnel@gmail.com>\n\nPython 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\nAs suggested by Pete Wyckoff, let's just replace the call to translate()\nwith a regex search which should be more clear and more portable.\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..de1a0b9 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+    m = re.search(\"[*#@%]\", path)\n+    return m is not None\n \n class Command:\n     def __init__(self):\n-- \n1.8.1.1.442.g413e803\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":"207888","messageId":"1359227673-5673-2-git-send-email-bcasey@nvidia.com","threadId":"32734","inReplyTo":"1359227673-5673-1-git-send-email-bcasey@nvidia.com","subject":"[PATCH v2 2/2] git-p4.py: support Python 2.4","fromName":"Brandon Casey","fromEmail":"bcasey@nvidia.com","sentAt":"2013-01-26T19:14:33Z","receivedAt":"2013-01-26T19:14:33Z","isPatch":true,"sender":{"key":"bcasey@nvidia.com","avatar":null},"body":"From: Brandon Casey <drafnel@gmail.com>\n\nPython 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>\nAcked-by: Pete Wyckoff <pw@padd.com>\n---\n\nOn 1/26/2013 4:48 AM, Pete Wyckoff wrote:\n> One stray semicolon.\n\nFixed.\n\n-Brandon\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 de1a0b9..625a396 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..aae1a3f 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.442.g413e803\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"}]}