summaryrefslogtreecommitdiffstats
path: root/main.py
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 /main.py
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 'main.py')
-rwxr-xr-xmain.py15
1 files changed, 7 insertions, 8 deletions
diff --git a/main.py b/main.py
index 49d24823..e4cdeb0f 100755
--- a/main.py
+++ b/main.py
@@ -22,13 +22,12 @@ import optparse
22import os 22import os
23import sys 23import sys
24import time 24import time
25try: 25
26 import urllib2 26from pyversion import is_python3
27except ImportError: 27if is_python3():
28 # For python3
29 import urllib.request 28 import urllib.request
30else: 29else:
31 # For python2 30 import urllib2
32 urllib = imp.new_module('urllib') 31 urllib = imp.new_module('urllib')
33 urllib.request = urllib2 32 urllib.request = urllib2
34 33
@@ -50,10 +49,10 @@ from pager import RunPager
50 49
51from subcmds import all_commands 50from subcmds import all_commands
52 51
53try: 52if not is_python3():
53 # pylint:disable=W0622
54 input = raw_input 54 input = raw_input
55except NameError: 55 # pylint:enable=W0622
56 pass
57 56
58global_options = optparse.OptionParser( 57global_options = optparse.OptionParser(
59 usage="repo [-p|--paginate|--no-pager] COMMAND [ARGS]" 58 usage="repo [-p|--paginate|--no-pager] COMMAND [ARGS]"