diff options
author | David Pursehouse <david.pursehouse@sonymobile.com> | 2013-05-17 10:49:33 +0900 |
---|---|---|
committer | David Pursehouse <david.pursehouse@sonymobile.com> | 2013-05-23 07:28:53 +0000 |
commit | 59bbb580e34bbc5dce76dacaad9ff94f21fa396f (patch) | |
tree | 4d19216215edc174851baa10a00a3bccba9d4e45 /main.py | |
parent | da45e5d8848246cddbce80ff56786bd7330ba5af (diff) | |
download | git-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-x | main.py | 15 |
1 files changed, 7 insertions, 8 deletions
@@ -22,13 +22,12 @@ import optparse | |||
22 | import os | 22 | import os |
23 | import sys | 23 | import sys |
24 | import time | 24 | import time |
25 | try: | 25 | |
26 | import urllib2 | 26 | from pyversion import is_python3 |
27 | except ImportError: | 27 | if is_python3(): |
28 | # For python3 | ||
29 | import urllib.request | 28 | import urllib.request |
30 | else: | 29 | else: |
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 | ||
51 | from subcmds import all_commands | 50 | from subcmds import all_commands |
52 | 51 | ||
53 | try: | 52 | if not is_python3(): |
53 | # pylint:disable=W0622 | ||
54 | input = raw_input | 54 | input = raw_input |
55 | except NameError: | 55 | # pylint:enable=W0622 |
56 | pass | ||
57 | 56 | ||
58 | global_options = optparse.OptionParser( | 57 | global_options = optparse.OptionParser( |
59 | usage="repo [-p|--paginate|--no-pager] COMMAND [ARGS]" | 58 | usage="repo [-p|--paginate|--no-pager] COMMAND [ARGS]" |