Add checks to Python scripts for version dependencies.

Signed-off-by: Eric S. Raymond <esr@thyrsus.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric S. Raymond committed Dec 28, 2012 at 11:40 UTC a33faf2827bfc7baea5d83ef1be8fe659a963355
8 files changed +44 -3
contrib/ciabot/ciabot.py
+7 -1
@@ -47,7 +47,13 @@
47 # we default to that.
48 #
49
50 -import os, sys, commands, socket, urllib
50 +import sys
51 +if sys.hexversion < 0x02000000:
52 + # The limiter is the xml.sax module
53 + sys.stderr.write("ciabot.py: requires Python 2.0.0 or later.\n")
54 + sys.exit(1)
55 +
56 +import os, commands, socket, urllib
57 from xml.sax.saxutils import escape
58
59 # Changeset URL prefix for your repo: when the commit ID is appended
contrib/fast-import/import-zips.py
+6 -1
@@ -9,10 +9,15 @@
9 ## git log --stat import-zips
10
11 from os import popen, path
12 -from sys import argv, exit
12 +from sys import argv, exit, hexversion, stderr
13 from time import mktime
14 from zipfile import ZipFile
15
16 +if hexversion < 0x01060000:
17 + # The limiter is the zipfile module
18 + sys.stderr.write("import-zips.py: requires Python 1.6.0 or later.\n")
19 + sys.exit(1)
20 +
21 if len(argv) < 2:
22 print 'Usage:', argv[0], '<zipfile>...'
23 exit(1)
contrib/hg-to-git/hg-to-git.py
+5
@@ -23,6 +23,11 @@ import os, os.path, sys
23 import tempfile, pickle, getopt
24 import re
25
26 +if sys.hexversion < 0x02030000:
27 + # The behavior of the pickle module changed significantly in 2.3
28 + sys.stderr.write("hg-to-git.py: requires Python 2.3 or later.\n")
29 + sys.exit(1)
30 +
31 # Maps hg version -> git version
32 hgvers = {}
33 # List of children for each hg revision
contrib/p4import/git-p4import.py
+5
@@ -14,6 +14,11 @@ import sys
14 import time
15 import getopt
16
17 +if sys.hexversion < 0x02020000:
18 + # The behavior of the marshal module changed significantly in 2.2
19 + sys.stderr.write("git-p4import.py: requires Python 2.2 or later.\n")
20 + sys.exit(1)
21 +
22 from signal import signal, \
23 SIGPIPE, SIGINT, SIG_DFL, \
24 default_int_handler
contrib/svn-fe/svnrdump_sim.py
+4
@@ -7,6 +7,10 @@ to the highest revision that should be available.
7 """
8 import sys, os
9
10 +if sys.hexversion < 0x02040000:
11 + # The limiter is the ValueError() calls. This may be too conservative
12 + sys.stderr.write("svnrdump-sim.py: requires Python 2.4 or later.\n")
13 + sys.exit(1)
14
15 def getrevlimit():
16 var = 'SVNRMAX'
git-p4.py
+7 -1
@@ -8,7 +8,13 @@
8 # License: MIT <http://www.opensource.org/licenses/mit-license.php>
9 #
10
11 -import optparse, sys, os, marshal, subprocess, shelve
11 +import sys
12 +if sys.hexversion < 0x02040000:
13 + # The limiter is the subprocess module
14 + sys.stderr.write("git-p4: requires Python 2.4 or later.\n")
15 + sys.exit(1)
16 +
17 +import optparse, os, marshal, subprocess, shelve
18 import tempfile, getopt, os.path, time, platform
19 import re, shutil
20
git-remote-testgit.py
+5
@@ -31,6 +31,11 @@ from git_remote_helpers.git.exporter import GitExporter
31 from git_remote_helpers.git.importer import GitImporter
32 from git_remote_helpers.git.non_local import NonLocalGit
33
34 +if sys.hexversion < 0x01050200:
35 + # os.makedirs() is the limiter
36 + sys.stderr.write("git-remote-testgit: requires Python 1.5.2 or later.\n")
37 + sys.exit(1)
38 +
39 def get_repo(alias, url):
40 """Returns a git repository object initialized for usage.
41 """
git_remote_helpers/git/__init__.py
+5
@@ -0,0 +1,5 @@
1 +import sys
2 +if sys.hexversion < 0x02040000:
3 + # The limiter is the subprocess module
4 + sys.stderr.write("git_remote_helpers: requires Python 2.4 or later.\n")
5 + sys.exit(1)