summaryrefslogtreecommitdiffstats
path: root/subcmds
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@sonymobile.com>2013-05-17 10:49:33 +0900
committerDavid Pursehouse <david.pursehouse@sonymobile.com>2013-05-23 07:28:53 +0000
commit59bbb580e34bbc5dce76dacaad9ff94f21fa396f (patch)
tree4d19216215edc174851baa10a00a3bccba9d4e45 /subcmds
parentda45e5d8848246cddbce80ff56786bd7330ba5af (diff)
downloadgit-repo-59bbb580e34bbc5dce76dacaad9ff94f21fa396f.tar.gz
Move Python version checking to a separate module
Add a new module with methods for checking the Python version. Instead of handling Python3 imports with try...except blocks, first check the python version and then import the relevant modules. This makes the code a bit cleaner and will result in less diff when/if we remove support for Python < 3 later. Use the same mechanism to handle `input` vs. `raw_input` and add suppression of pylint warnings caused by redefinition of the built-in method `input`. Change-Id: Ia403e525b88d77640a741ac50382146e7d635924 Also-by: Chirayu Desai <cdesai@cyanogenmod.org> Signed-off-by: Chirayu Desai <cdesai@cyanogenmod.org>
Diffstat (limited to 'subcmds')
-rw-r--r--subcmds/init.py8
-rw-r--r--subcmds/status.py11
-rw-r--r--subcmds/sync.py17
-rw-r--r--subcmds/upload.py7
4 files changed, 20 insertions, 23 deletions
diff --git a/subcmds/init.py b/subcmds/init.py
index 1f915268..a44fb7a9 100644
--- a/subcmds/init.py
+++ b/subcmds/init.py
@@ -19,11 +19,11 @@ import platform
19import re 19import re
20import shutil 20import shutil
21import sys 21import sys
22try: 22
23 # For python3 23from pyversion import is_python3
24if is_python3():
24 import urllib.parse 25 import urllib.parse
25except ImportError: 26else:
26 # For python2
27 import imp 27 import imp
28 import urlparse 28 import urlparse
29 urllib = imp.new_module('urllib') 29 urllib = imp.new_module('urllib')
diff --git a/subcmds/status.py b/subcmds/status.py
index 9810337f..41c4429a 100644
--- a/subcmds/status.py
+++ b/subcmds/status.py
@@ -21,12 +21,13 @@ except ImportError:
21 import dummy_threading as _threading 21 import dummy_threading as _threading
22 22
23import glob 23import glob
24try: 24
25 # For python2 25from pyversion import is_python3
26 import StringIO as io 26if is_python3():
27except ImportError:
28 # For python3
29 import io 27 import io
28else:
29 import StringIO as io
30
30import itertools 31import itertools
31import os 32import os
32import sys 33import sys
diff --git a/subcmds/sync.py b/subcmds/sync.py
index 8fb94885..b34787d2 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -24,22 +24,17 @@ import socket
24import subprocess 24import subprocess
25import sys 25import sys
26import time 26import time
27try: 27
28 # For python3 28from pyversion import is_python3
29if is_python3():
29 import urllib.parse 30 import urllib.parse
30except ImportError: 31 import xmlrpc.client
31 # For python2 32else:
32 import imp 33 import imp
33 import urlparse 34 import urlparse
35 import xmlrpclib
34 urllib = imp.new_module('urllib') 36 urllib = imp.new_module('urllib')
35 urllib.parse = urlparse 37 urllib.parse = urlparse
36try:
37 # For python3
38 import xmlrpc.client
39except ImportError:
40 # For python2
41 import imp
42 import xmlrpclib
43 xmlrpc = imp.new_module('xmlrpc') 38 xmlrpc = imp.new_module('xmlrpc')
44 xmlrpc.client = xmlrpclib 39 xmlrpc.client = xmlrpclib
45 40
diff --git a/subcmds/upload.py b/subcmds/upload.py
index a34938e5..13b87784 100644
--- a/subcmds/upload.py
+++ b/subcmds/upload.py
@@ -23,10 +23,11 @@ from editor import Editor
23from error import HookError, UploadError 23from error import HookError, UploadError
24from project import RepoHook 24from project import RepoHook
25 25
26try: 26from pyversion import is_python3
27if not is_python3():
28 # pylint:disable=W0622
27 input = raw_input 29 input = raw_input
28except NameError: 30 # pylint:enable=W0622
29 pass
30 31
31UNUSUAL_COMMIT_THRESHOLD = 5 32UNUSUAL_COMMIT_THRESHOLD = 5
32 33