Exemplo n.º 1
0
    def setUp(self):
        """Load the wrapper module every time."""
        wrapper._wrapper_module = None
        self.wrapper = wrapper.Wrapper()

        if not is_python3():
            self.assertRegex = self.assertRegexpMatches
Exemplo n.º 2
0
    def _ReadGit(self):
        """
    Read configuration data from git.

    This internal method populates the GitConfig cache.

    """
        c = {}
        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)
            else:
                key = line
                val = None

            if key in c:
                c[key].append(val)
            else:
                c[key] = [val]

        return c
Exemplo n.º 3
0
  def Add(self, name, task_name, start, finish=None, success=None,
          try_count=1, kind='RepoOp'):
    """Add an event to the log.

    Args:
      name: Name of the object being operated upon.
      task_name: A sub-task that was performed for name.
      start: Timestamp of when the operation started.
      finish: Timestamp of when the operation finished.
      success: Boolean indicating if the operation was successful.
      try_count: A counter indicating the try count of this task.
      kind: The kind of the object for the unique identifier.

    Returns:
      A dictionary of the event added to the log.
    """
    event = {
        'id': (kind, self._next_id.__next__() if is_python3() else self._next_id.next()),
        'name': name,
        'task_name': task_name,
        'start_time': start,
        'try': try_count,
    }

    if self._parent:
      event['parent'] = self._parent['id']

    if success is not None or finish is not None:
        self.FinishEvent(event, finish, success)

    self._log.append(event)
    return event
Exemplo n.º 4
0
  def _ReadGit(self):
    """
    Read configuration data from git.

    This internal method populates the GitConfig cache.

    """
    c = {}
    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)
      else:
        key = line
        val = None

      if key in c:
        c[key].append(val)
      else:
        c[key] = [val]

    return c
Exemplo n.º 5
0
    def _ReadGit(self):
        """
    Read configuration data from git.

    This internal method populates the GitConfig cache.

    """
        c = {}
        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)
            else:
                key = line
                val = None

            if key in c:
                c[key].append(val)
            else:
                c[key] = [val]

        return c
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
from __future__ import print_function

import json
import os
import re
import subprocess
import sys
try:
  import threading as _threading
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

from signal import SIGTERM
from error import GitError, UploadError
from trace import Trace
if is_python3():
  from http.client import HTTPException
else:
Exemplo n.º 8
0
from __future__ import print_function

import contextlib
import os
import re
import shutil
import tempfile
import unittest

import git_command
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."""
    # TODO(vapier): Convert this to tempfile.TemporaryDirectory once we drop
    # Python 2 support entirely.
    try:
        tempdir = tempfile.mkdtemp(prefix='repo-tests')
        yield tempdir
Exemplo n.º 9
0
# 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

from command import InteractiveCommand
from editor import Editor
from error import HookError, UploadError
from git_command import GitCommand
from project import RepoHook

from pyversion import is_python3
if not is_python3():
    input = raw_input  # noqa: F821
else:
    unicode = str

UNUSUAL_COMMIT_THRESHOLD = 5


def _ConfirmManyUploads(multiple_branches=False):
    if multiple_branches:
        print('ATTENTION: One or more branches has an unusually high number '
              'of commits.')
    else:
        print(
            'ATTENTION: You are uploading an unusually high number of commits.'
        )
Exemplo n.º 10
0
# 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.

from __future__ import print_function
import getpass
import imp
import netrc
import optparse
import os
import sys
import time

from pyversion import is_python3
if is_python3():
  import urllib.request
else:
  import urllib2
  urllib = imp.new_module('urllib')
  urllib.request = urllib2

try:
  import kerberos
except ImportError:
  kerberos = None

from color import SetDefaultColoring
from trace import SetTrace
from git_command import git, GitCommand
from git_config import init_ssh, close_ssh
Exemplo n.º 11
0
#!/usr/bin/env python## Copyright (C) 2008 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.
from __future__ import print_function import getpass import imp import netrc import optparse import os import sys import time
from pyversion import is_python3
if is_python3(): import urllib.request
else: import urllib2 urllib = imp.new_module('urllib') urllib.request = urllib2
try: import kerberos except ImportError: kerberos = None
from color import SetDefaultColoring from trace import SetTrace from git_command import git, GitCommand from git_config import init_ssh, close_ssh from command import InteractiveCommand from command import MirrorSafeCommand from command import RequiresGitcCommand from subcmds.version import Version from editor import Editor from error import DownloadError from error import InvalidProjectGroupsError from error import ManifestInvalidRevisionError from error import ManifestParseError from error import NoManifestException from error import NoSuchProjectError from error import RepoChangedException import gitc_utils from manifest_xml import GitcManifest, XmlManifest from pager import RunPager from wrapper import WrapperPath, Wrapper from subcmds import all_commands
if not is_python3():input = raw_input # pylint:disable=W0622 # pylint:enable=W0622
global_options = optparse.OptionParser( usage="re po [-p|--paginate|--no-pager] COMMAND [ARGS]" )
global_options.add_option('-p', '--paginate', dest='pager', action='store_true', help='display command output in the pager')
global_options.add_option('--no-pager', dest='no_pager', action='store_true', help='disable the pager')
global_options.add_option('--color', choices=('auto', 'always', 'never'), default=None, help='control color usage: auto, always, never')
global_options.add_option('--trace', dest='trace', action='store_true', help='trace git command execution')
global_options.add_option('--time', dest='time', action='store_true', help='time re po command execution')
global_options.add_option('--version', dest='show_version', action='store_true', help='display this version of re po')
class _Repo(object):
  def __init__(self, repodir): self.repodir = repodir
    self.commands = all_commands# add 'branch' as an alias for 'branches'
    all_commands['branch'] = all_commands['branches']
  def _Run(self, argv): result = 0    name = None     glob = []
    for i in range(len(argv)):
      if not argv[i].startswith('-'): name = argv[i]
        if i > 0: glob = argv[:i]
        argv = argv[i + 1:]
        break
    if not name: glob = argv
      name = 'help'
      argv = []
    gopts, _gargs = global_options.parse_args(glob)
    if gopts.trace: SetTrace()
    if gopts.show_version: