Merge commits up to v2.11.1
* tag 'v2.11.1':
launcher: bump version for new release
Fix bug in git trace2 event Write() function when no config present.
drop pyversion & is_python3 checking
strip python2-only coding:utf-8 & print_function settings
Change-Id: Ib769ae4b5f827166bb09c2635d46cb95237eb73f
diff --git a/color.py b/color.py
index 7df2022..fdd7253 100644
--- a/color.py
+++ b/color.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2008 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/command.py b/command.py
index b1fa0ef..ef2554d 100644
--- a/command.py
+++ b/command.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2008 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/editor.py b/editor.py
index 4306836..b84a42d 100644
--- a/editor.py
+++ b/editor.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2008 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import print_function
import os
import re
import sys
diff --git a/error.py b/error.py
index f5496cb..9d92e47 100644
--- a/error.py
+++ b/error.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2008 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/event_log.py b/event_log.py
index 5dd9db6..c77c564 100644
--- a/event_log.py
+++ b/event_log.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2017 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import print_function
-
import json
import multiprocessing
diff --git a/git_command.py b/git_command.py
index 1cb8f1a..b29d240 100644
--- a/git_command.py
+++ b/git_command.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2008 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import print_function
import os
import re
import sys
diff --git a/git_config.py b/git_config.py
index 9af90df..2fa43a1 100644
--- a/git_config.py
+++ b/git_config.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2008 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,10 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import print_function
-
import contextlib
import errno
+from http.client import HTTPException
import json
import os
import re
@@ -30,25 +27,12 @@
except ImportError:
import dummy_threading as _threading
import time
-
-from pyversion import is_python3
-if is_python3():
- import urllib.request
- import urllib.error
-else:
- import urllib2
- import imp
- urllib = imp.new_module('urllib')
- urllib.request = urllib2
- urllib.error = urllib2
+import urllib.error
+import urllib.request
from error import GitError, UploadError
import platform_utils
from repo_trace import Trace
-if is_python3():
- from http.client import HTTPException
-else:
- from httplib import HTTPException
from git_command import GitCommand
from git_command import ssh_sock
@@ -345,8 +329,6 @@
d = self._do('--null', '--list')
if d is None:
return c
- if not is_python3():
- d = d.decode('utf-8')
for line in d.rstrip('\0').split('\0'):
if '\n' in line:
key, val = line.split('\n', 1)
diff --git a/git_refs.py b/git_refs.py
index e2b62ab..3c8a986 100644
--- a/git_refs.py
+++ b/git_refs.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2009 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/git_trace2_event_log.py b/git_trace2_event_log.py
index 4a8e034..dfbded1 100644
--- a/git_trace2_event_log.py
+++ b/git_trace2_event_log.py
@@ -132,6 +132,30 @@
exit_event['code'] = result
self._log.append(exit_event)
+ def _GetEventTargetPath(self):
+ """Get the 'trace2.eventtarget' path from git configuration.
+
+ Returns:
+ path: git config's 'trace2.eventtarget' path if it exists, or None
+ """
+ path = None
+ cmd = ['config', '--get', 'trace2.eventtarget']
+ # TODO(https://crbug.com/gerrit/13706): Use GitConfig when it supports
+ # system git config variables.
+ p = GitCommand(None, cmd, capture_stdout=True, capture_stderr=True,
+ bare=True)
+ retval = p.Wait()
+ if retval == 0:
+ # Strip trailing carriage-return in path.
+ path = p.stdout.rstrip('\n')
+ elif retval != 1:
+ # `git config --get` is documented to produce an exit status of `1` if
+ # the requested variable is not present in the configuration. Report any
+ # other return value as an error.
+ print("repo: error: 'git config --get' call failed with return code: %r, stderr: %r" % (
+ retval, p.stderr), file=sys.stderr)
+ return path
+
def Write(self, path=None):
"""Writes the log out to a file.
@@ -150,21 +174,11 @@
log_path = None
# If no logging path is specified, get the path from 'trace2.eventtarget'.
if path is None:
- cmd = ['config', '--get', 'trace2.eventtarget']
- # TODO(https://crbug.com/gerrit/13706): Use GitConfig when it supports
- # system git config variables.
- p = GitCommand(None, cmd, capture_stdout=True, capture_stderr=True,
- bare=True)
- retval = p.Wait()
- if retval == 0:
- # Strip trailing carriage-return in path.
- path = p.stdout.rstrip('\n')
- elif retval != 1:
- # `git config --get` is documented to produce an exit status of `1` if
- # the requested variable is not present in the configuration. Report any
- # other return value as an error.
- print("repo: error: 'git config --get' call failed with return code: %r, stderr: %r" % (
- retval, p.stderr), file=sys.stderr)
+ path = self._GetEventTargetPath()
+
+ # If no logging path is specified, exit.
+ if path is None:
+ return None
if isinstance(path, str):
# Get absolute path.
diff --git a/gitc_utils.py b/gitc_utils.py
index 6354702..89cfbec 100644
--- a/gitc_utils.py
+++ b/gitc_utils.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2015 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import print_function
import os
import platform
import re
diff --git a/hooks.py b/hooks.py
index 1abba0c..67c21a2 100644
--- a/hooks.py
+++ b/hooks.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2008 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,20 +19,11 @@
import subprocess
import sys
import traceback
+import urllib.parse
from error import HookError
from git_refs import HEAD
-from pyversion import is_python3
-if is_python3():
- import urllib.parse
-else:
- import imp
- import urlparse
- urllib = imp.new_module('urllib')
- urllib.parse = urlparse
- input = raw_input # noqa: F821
-
class RepoHook(object):
"""A RepoHook contains information about a script to run as a hook.
diff --git a/main.py b/main.py
index ebfa652..f638a67 100755
--- a/main.py
+++ b/main.py
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
-# -*- coding:utf-8 -*-
#
# Copyright (C) 2008 The Android Open Source Project
#
@@ -21,7 +20,6 @@
which takes care of execing this entry point.
"""
-from __future__ import print_function
import getpass
import netrc
import optparse
@@ -30,15 +28,7 @@
import sys
import textwrap
import time
-
-from pyversion import is_python3
-if is_python3():
- import urllib.request
-else:
- import imp
- import urllib2
- urllib = imp.new_module('urllib')
- urllib.request = urllib2
+import urllib.request
try:
import kerberos
@@ -70,8 +60,6 @@
from subcmds import all_commands
-if not is_python3():
- input = raw_input # noqa: F821
# NB: These do not need to be kept in sync with the repo launcher script.
# These may be much newer as it allows the repo launcher to roll between
diff --git a/manifest_xml.py b/manifest_xml.py
index 0065931..9b7a81b 100644
--- a/manifest_xml.py
+++ b/manifest_xml.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2008 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,21 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import print_function
import itertools
import os
import re
import sys
import xml.dom.minidom
-
-from pyversion import is_python3
-if is_python3():
- import urllib.parse
-else:
- import imp
- import urlparse
- urllib = imp.new_module('urllib')
- urllib.parse = urlparse
+import urllib.parse
import gitc_utils
from git_config import GitConfig, IsId
diff --git a/pager.py b/pager.py
index 167f003..352923d 100644
--- a/pager.py
+++ b/pager.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2008 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import print_function
import os
import select
import subprocess
diff --git a/platform_utils.py b/platform_utils.py
index d10e888..a280982 100644
--- a/platform_utils.py
+++ b/platform_utils.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2016 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,16 +15,10 @@
import errno
import os
import platform
+from queue import Queue
import select
import shutil
import stat
-
-from pyversion import is_python3
-if is_python3():
- from queue import Queue
-else:
- from Queue import Queue
-
from threading import Thread
diff --git a/platform_utils_win32.py b/platform_utils_win32.py
index a628637..bf916d4 100644
--- a/platform_utils_win32.py
+++ b/platform_utils_win32.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2016 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,18 +14,10 @@
import errno
-from pyversion import is_python3
from ctypes import WinDLL, get_last_error, FormatError, WinError, addressof
-from ctypes import c_buffer
+from ctypes import c_buffer, c_ubyte, Structure, Union, byref
from ctypes.wintypes import BOOL, BOOLEAN, LPCWSTR, DWORD, HANDLE
-from ctypes.wintypes import WCHAR, USHORT, LPVOID, ULONG
-if is_python3():
- from ctypes import c_ubyte, Structure, Union, byref
- from ctypes.wintypes import LPDWORD
-else:
- # For legacy Python2 different imports are needed.
- from ctypes.wintypes import POINTER, c_ubyte, Structure, Union, byref
- LPDWORD = POINTER(DWORD)
+from ctypes.wintypes import WCHAR, USHORT, LPVOID, ULONG, LPDWORD
kernel32 = WinDLL('kernel32', use_last_error=True)
@@ -204,26 +194,15 @@
'Error reading symbolic link \"%s\"'.format(path))
rdb = REPARSE_DATA_BUFFER.from_buffer(target_buffer)
if rdb.ReparseTag == IO_REPARSE_TAG_SYMLINK:
- return _preserve_encoding(path, rdb.SymbolicLinkReparseBuffer.PrintName)
+ return rdb.SymbolicLinkReparseBuffer.PrintName
elif rdb.ReparseTag == IO_REPARSE_TAG_MOUNT_POINT:
- return _preserve_encoding(path, rdb.MountPointReparseBuffer.PrintName)
+ return rdb.MountPointReparseBuffer.PrintName
# Unsupported reparse point type
_raise_winerror(
ERROR_NOT_SUPPORTED,
'Error reading symbolic link \"%s\"'.format(path))
-def _preserve_encoding(source, target):
- """Ensures target is the same string type (i.e. unicode or str) as source."""
-
- if is_python3():
- return target
-
- if isinstance(source, unicode): # noqa: F821
- return unicode(target) # noqa: F821
- return str(target)
-
-
def _raise_winerror(code, error_desc):
win_error_desc = FormatError(code).strip()
error_desc = "%s: %s".format(error_desc, win_error_desc)
diff --git a/progress.py b/progress.py
index ff62798..9222fcf 100644
--- a/progress.py
+++ b/progress.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2009 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/project.py b/project.py
index 3bf5969..370328d 100644
--- a/project.py
+++ b/project.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2008 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import print_function
import errno
import filecmp
import glob
@@ -28,6 +25,7 @@
import tarfile
import tempfile
import time
+import urllib.parse
from color import Coloring
from git_command import GitCommand, git_require
@@ -43,16 +41,6 @@
from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB, R_M, R_WORKTREE_M
-from pyversion import is_python3
-if is_python3():
- import urllib.parse
-else:
- import imp
- import urlparse
- urllib = imp.new_module('urllib')
- urllib.parse = urlparse
- input = raw_input # noqa: F821
-
# Maximum sleep time allowed during retries.
MAXIMUM_RETRY_SLEEP_SEC = 3600.0
diff --git a/pyversion.py b/pyversion.py
deleted file mode 100644
index 8dbf909..0000000
--- a/pyversion.py
+++ /dev/null
@@ -1,21 +0,0 @@
-# -*- coding:utf-8 -*-
-#
-# Copyright (C) 2013 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-import sys
-
-
-def is_python3():
- return sys.version_info[0] == 3
diff --git a/repo b/repo
index 427c6d7..0162f0e 100755
--- a/repo
+++ b/repo
@@ -147,7 +147,7 @@
REPO_REV = 'stable'
# increment this whenever we make important changes to this script
-VERSION = (2, 8)
+VERSION = (2, 11)
# increment this if the MAINTAINER_KEYS block is modified
KEYRING_VERSION = (2, 3)
diff --git a/repo_trace.py b/repo_trace.py
index cd571f4..7be0c04 100644
--- a/repo_trace.py
+++ b/repo_trace.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2008 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,7 +17,6 @@
Activated via `repo --trace ...` or `REPO_TRACE=1 repo ...`.
"""
-from __future__ import print_function
import sys
import os
diff --git a/run_tests b/run_tests
index 30e7b55..9f19e2e 100755
--- a/run_tests
+++ b/run_tests
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
-# -*- coding:utf-8 -*-
# Copyright 2019 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,8 +15,6 @@
"""Wrapper to run pytest with the right settings."""
-from __future__ import print_function
-
import errno
import os
import shutil
diff --git a/setup.py b/setup.py
index 5aa15fe..77b1435 100755
--- a/setup.py
+++ b/setup.py
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
-# -*- coding:utf-8 -*-
# Copyright 2019 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the 'License");
@@ -16,8 +15,6 @@
"""Python packaging for repo."""
-from __future__ import print_function
-
import os
import setuptools
diff --git a/subcmds/__init__.py b/subcmds/__init__.py
index c3de9d1..051dda0 100644
--- a/subcmds/__init__.py
+++ b/subcmds/__init__.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2008 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/subcmds/abandon.py b/subcmds/abandon.py
index 3301121..359c431 100644
--- a/subcmds/abandon.py
+++ b/subcmds/abandon.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2008 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import print_function
-
from collections import defaultdict
import sys
diff --git a/subcmds/branches.py b/subcmds/branches.py
index 2b1f807..20f5169 100644
--- a/subcmds/branches.py
+++ b/subcmds/branches.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2009 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import print_function
import itertools
import multiprocessing
import sys
diff --git a/subcmds/checkout.py b/subcmds/checkout.py
index efa31d2..fbb1365 100644
--- a/subcmds/checkout.py
+++ b/subcmds/checkout.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2009 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import print_function
import sys
from command import Command
from progress import Progress
diff --git a/subcmds/cherry_pick.py b/subcmds/cherry_pick.py
index 3ad8210..c333fcf 100644
--- a/subcmds/cherry_pick.py
+++ b/subcmds/cherry_pick.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2010 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import print_function
import re
import sys
from command import Command
diff --git a/subcmds/diff.py b/subcmds/diff.py
index 190b18f..c987bf2 100644
--- a/subcmds/diff.py
+++ b/subcmds/diff.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2008 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/subcmds/diffmanifests.py b/subcmds/diffmanifests.py
index 409bbda..8ff212e 100644
--- a/subcmds/diffmanifests.py
+++ b/subcmds/diffmanifests.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2014 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/subcmds/download.py b/subcmds/download.py
index 723124f..c0c47dd 100644
--- a/subcmds/download.py
+++ b/subcmds/download.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2008 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import print_function
import re
import sys
diff --git a/subcmds/forall.py b/subcmds/forall.py
index 55d61ec..c586433 100644
--- a/subcmds/forall.py
+++ b/subcmds/forall.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2008 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import print_function
import errno
import multiprocessing
import re
diff --git a/subcmds/gitc_delete.py b/subcmds/gitc_delete.py
index 24d355a..56e0eab 100644
--- a/subcmds/gitc_delete.py
+++ b/subcmds/gitc_delete.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2015 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,16 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import print_function
import sys
from command import Command, GitcClientCommand
import platform_utils
-from pyversion import is_python3
-if not is_python3():
- input = raw_input # noqa: F821
-
class GitcDelete(Command, GitcClientCommand):
common = True
diff --git a/subcmds/gitc_init.py b/subcmds/gitc_init.py
index 30a9f7a..7ecfdca 100644
--- a/subcmds/gitc_init.py
+++ b/subcmds/gitc_init.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2015 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import print_function
import os
import sys
diff --git a/subcmds/grep.py b/subcmds/grep.py
index 89611cd..e3628c6 100644
--- a/subcmds/grep.py
+++ b/subcmds/grep.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2009 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import print_function
-
import sys
from color import Coloring
diff --git a/subcmds/help.py b/subcmds/help.py
index c219a76..9ba9e70 100644
--- a/subcmds/help.py
+++ b/subcmds/help.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2008 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import print_function
import re
import sys
from formatter import AbstractFormatter, DumbWriter
diff --git a/subcmds/info.py b/subcmds/info.py
index 6014997..6381fa8 100644
--- a/subcmds/info.py
+++ b/subcmds/info.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2012 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/subcmds/init.py b/subcmds/init.py
index af3685a..1bcf546 100644
--- a/subcmds/init.py
+++ b/subcmds/init.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2008 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,22 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import print_function
-
import optparse
import os
import platform
import re
import sys
-
-from pyversion import is_python3
-if is_python3():
- import urllib.parse
-else:
- import imp
- import urlparse
- urllib = imp.new_module('urllib')
- urllib.parse = urlparse
+import urllib.parse
from color import Coloring
from command import InteractiveCommand, MirrorSafeCommand
diff --git a/subcmds/list.py b/subcmds/list.py
index 13cae5f..a1247b7 100644
--- a/subcmds/list.py
+++ b/subcmds/list.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2011 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import print_function
-
from command import Command, MirrorSafeCommand
diff --git a/subcmds/manifest.py b/subcmds/manifest.py
index 0052d7a..e33e683 100644
--- a/subcmds/manifest.py
+++ b/subcmds/manifest.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2009 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import print_function
-
import json
import os
import sys
diff --git a/subcmds/overview.py b/subcmds/overview.py
index 08b58a6..004a847 100644
--- a/subcmds/overview.py
+++ b/subcmds/overview.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2012 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import print_function
from color import Coloring
from command import PagedCommand
diff --git a/subcmds/prune.py b/subcmds/prune.py
index e90ff21..8cad812 100644
--- a/subcmds/prune.py
+++ b/subcmds/prune.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2008 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import print_function
from color import Coloring
from command import PagedCommand
diff --git a/subcmds/rebase.py b/subcmds/rebase.py
index 24d80bf..cf536e9 100644
--- a/subcmds/rebase.py
+++ b/subcmds/rebase.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2010 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import print_function
import sys
from color import Coloring
diff --git a/subcmds/selfupdate.py b/subcmds/selfupdate.py
index bf6256a..388881d 100644
--- a/subcmds/selfupdate.py
+++ b/subcmds/selfupdate.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2009 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import print_function
from optparse import SUPPRESS_HELP
import sys
diff --git a/subcmds/smartsync.py b/subcmds/smartsync.py
index 6037e5a..c7d1d4d 100644
--- a/subcmds/smartsync.py
+++ b/subcmds/smartsync.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2010 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/subcmds/stage.py b/subcmds/stage.py
index 4dce5ce..98b3022 100644
--- a/subcmds/stage.py
+++ b/subcmds/stage.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2008 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import print_function
import sys
from color import Coloring
diff --git a/subcmds/start.py b/subcmds/start.py
index adc6d29..7684b6d 100644
--- a/subcmds/start.py
+++ b/subcmds/start.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2008 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import print_function
import os
import sys
diff --git a/subcmds/status.py b/subcmds/status.py
index dfa974e..e293d75 100644
--- a/subcmds/status.py
+++ b/subcmds/status.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2008 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import print_function
-
import functools
import glob
import multiprocessing
diff --git a/subcmds/sync.py b/subcmds/sync.py
index fe20dd2..034c07c 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2008 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,9 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import print_function
-
import glob
+import http.cookiejar as cookielib
import json
import netrc
from optparse import SUPPRESS_HELP
@@ -27,26 +24,10 @@
import sys
import tempfile
import time
-
-from pyversion import is_python3
-if is_python3():
- import http.cookiejar as cookielib
- import urllib.error
- import urllib.parse
- import urllib.request
- import xmlrpc.client
-else:
- import cookielib
- import imp
- import urllib2
- import urlparse
- import xmlrpclib
- urllib = imp.new_module('urllib')
- urllib.error = urllib2
- urllib.parse = urlparse
- urllib.request = urllib2
- xmlrpc = imp.new_module('xmlrpc')
- xmlrpc.client = xmlrpclib
+import urllib.error
+import urllib.parse
+import urllib.request
+import xmlrpc.client
try:
import threading as _threading
diff --git a/subcmds/upload.py b/subcmds/upload.py
index 6196fe4..50dccc5 100644
--- a/subcmds/upload.py
+++ b/subcmds/upload.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2008 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import print_function
import copy
import re
import sys
@@ -26,11 +23,6 @@
from git_refs import R_HEADS
from hooks import RepoHook
-from pyversion import is_python3
-if not is_python3():
- input = raw_input # noqa: F821
-else:
- unicode = str
UNUSUAL_COMMIT_THRESHOLD = 5
diff --git a/subcmds/version.py b/subcmds/version.py
index 6a7921d..000abf0 100644
--- a/subcmds/version.py
+++ b/subcmds/version.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2009 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import print_function
-
import platform
import sys
diff --git a/tests/test_editor.py b/tests/test_editor.py
index fbcfcdb..cfd4f5e 100644
--- a/tests/test_editor.py
+++ b/tests/test_editor.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2019 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,8 +14,6 @@
"""Unittests for the editor.py module."""
-from __future__ import print_function
-
import unittest
from editor import Editor
diff --git a/tests/test_git_command.py b/tests/test_git_command.py
index 2c22b25..912a9db 100644
--- a/tests/test_git_command.py
+++ b/tests/test_git_command.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright 2019 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,8 +14,6 @@
"""Unittests for the git_command.py module."""
-from __future__ import print_function
-
import re
import unittest
diff --git a/tests/test_git_config.py b/tests/test_git_config.py
index 4541b35..964bc32 100644
--- a/tests/test_git_config.py
+++ b/tests/test_git_config.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2009 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,8 +14,6 @@
"""Unittests for the git_config.py module."""
-from __future__ import print_function
-
import os
import unittest
diff --git a/tests/test_git_trace2_event_log.py b/tests/test_git_trace2_event_log.py
index 3905630..686802e 100644
--- a/tests/test_git_trace2_event_log.py
+++ b/tests/test_git_trace2_event_log.py
@@ -15,8 +15,10 @@
"""Unittests for the git_trace2_event_log.py module."""
import json
+import os
import tempfile
import unittest
+from unittest import mock
import git_trace2_event_log
@@ -157,12 +159,27 @@
self.assertIn('code', exit_event)
self.assertEqual(exit_event['code'], 2)
- # TODO(https://crbug.com/gerrit/13706): Add additional test coverage for
- # Write() where:
- # - path=None (using git config call)
- # - path=<Non-String type> (raises TypeError)
- # - path=<Non-Directory> (should return None)
- # - tempfile.NamedTemporaryFile errors with FileExistsError (should return None)
+ def test_write_with_filename(self):
+ """Test Write() with a path to a file exits with None."""
+ self.assertIsNone(self._event_log_module.Write(path='path/to/file'))
+
+ def test_write_with_git_config(self):
+ """Test Write() uses the git config path when 'git config' call succeeds."""
+ with tempfile.TemporaryDirectory(prefix='event_log_tests') as tempdir:
+ with mock.patch.object(self._event_log_module,
+ '_GetEventTargetPath', return_value=tempdir):
+ self.assertEqual(os.path.dirname(self._event_log_module.Write()), tempdir)
+
+ def test_write_no_git_config(self):
+ """Test Write() with no git config variable present exits with None."""
+ with mock.patch.object(self._event_log_module,
+ '_GetEventTargetPath', return_value=None):
+ self.assertIsNone(self._event_log_module.Write())
+
+ def test_write_non_string(self):
+ """Test Write() with non-string type for |path| throws TypeError."""
+ with self.assertRaises(TypeError):
+ self._event_log_module.Write(path=1234)
if __name__ == '__main__':
diff --git a/tests/test_hooks.py b/tests/test_hooks.py
index ed8268d..6632b3e 100644
--- a/tests/test_hooks.py
+++ b/tests/test_hooks.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2019 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,8 +14,6 @@
"""Unittests for the hooks.py module."""
-from __future__ import print_function
-
import hooks
import unittest
@@ -28,7 +24,6 @@
"""Lines w/out shebangs should be rejected."""
DATA = (
'',
- '# -*- coding:utf-8 -*-\n',
'#\n# foo\n',
'# Bad shebang in script\n#!/foo\n'
)
diff --git a/tests/test_manifest_xml.py b/tests/test_manifest_xml.py
index 2a8c3f6..d53ea56 100644
--- a/tests/test_manifest_xml.py
+++ b/tests/test_manifest_xml.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2019 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,8 +14,6 @@
"""Unittests for the manifest_xml.py module."""
-from __future__ import print_function
-
import os
import shutil
import tempfile
diff --git a/tests/test_project.py b/tests/test_project.py
index 02285e2..7dfbabb 100644
--- a/tests/test_project.py
+++ b/tests/test_project.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2019 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,8 +14,6 @@
"""Unittests for the project.py module."""
-from __future__ import print_function
-
import contextlib
import os
import shutil
diff --git a/tests/test_wrapper.py b/tests/test_wrapper.py
index d7e5800..d871373 100644
--- a/tests/test_wrapper.py
+++ b/tests/test_wrapper.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2015 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,30 +14,21 @@
"""Unittests for the wrapper.py module."""
-from __future__ import print_function
-
import contextlib
+from io import StringIO
import os
import re
import shutil
import tempfile
import unittest
+from unittest import mock
import git_command
import main
import platform_utils
-from pyversion import is_python3
import wrapper
-if is_python3():
- from unittest import mock
- from io import StringIO
-else:
- import mock
- from StringIO import StringIO
-
-
@contextlib.contextmanager
def TemporaryDirectory():
"""Create a new empty git checkout for testing."""
@@ -66,9 +55,6 @@
wrapper._wrapper_module = None
self.wrapper = wrapper.Wrapper()
- if not is_python3():
- self.assertRegex = self.assertRegexpMatches
-
class RepoWrapperUnitTest(RepoWrapperTestCase):
"""Tests helper functions in the repo wrapper
diff --git a/wrapper.py b/wrapper.py
index 8130298..b1aa4c5 100644
--- a/wrapper.py
+++ b/wrapper.py
@@ -1,5 +1,3 @@
-# -*- coding:utf-8 -*-
-#
# Copyright (C) 2014 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from __future__ import print_function
try:
from importlib.machinery import SourceFileLoader
_loader = lambda *args: SourceFileLoader(*args).load_module()