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 /subcmds/sync.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 'subcmds/sync.py')
-rw-r--r-- | subcmds/sync.py | 17 |
1 files changed, 6 insertions, 11 deletions
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 | |||
24 | import subprocess | 24 | import subprocess |
25 | import sys | 25 | import sys |
26 | import time | 26 | import time |
27 | try: | 27 | |
28 | # For python3 | 28 | from pyversion import is_python3 |
29 | if is_python3(): | ||
29 | import urllib.parse | 30 | import urllib.parse |
30 | except ImportError: | 31 | import xmlrpc.client |
31 | # For python2 | 32 | else: |
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 |
36 | try: | ||
37 | # For python3 | ||
38 | import xmlrpc.client | ||
39 | except 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 | ||