Пример #1
0
    def get_remote_base_url(cls):
        """Return the Gerrit Code Review server base URL

        :rtype: str
        """

        url = Config.get('gerrit.host')
        unsecure = Config.get('gerrit.unsecure', False)

        if url is None:
            fail('gerrit.host not set')

        # From Gerrit Code Review Documentation (section Authentication):
        # https://gerrit-review.googlesource.com/Documentation/rest-api.html
        #
        # Users (and programs) may authenticate using HTTP authentication by
        # supplying the HTTP password from the user's account settings page.
        # Gerrit by default uses HTTP digest authentication. To authenticate,
        # prefix the endpoint URL with /a/. For example to authenticate to
        # /projects/ request URL /a/projects/.

        if RequestFactory.require_auth():
            url = '{}/a'.format(url)

        if not url.startswith('http://') or not url.startswith('https://'):
            return '{}://{}'.format('http' if unsecure else 'https', url)

        return url
Пример #2
0
    def get_remote_base_url(cls):
        """Return the Gerrit Code Review server base URL

        :rtype: str
        """

        url = Config.get("gerrit.host")
        unsecure = Config.get("gerrit.unsecure", False)

        if url is None:
            fail("gerrit.host not set")

        # From Gerrit Code Review Documentation (section Authentication):
        # https://gerrit-review.googlesource.com/Documentation/rest-api.html
        #
        # Users (and programs) may authenticate using HTTP authentication by
        # supplying the HTTP password from the user's account settings page.
        # Gerrit by default uses HTTP digest authentication. To authenticate,
        # prefix the endpoint URL with /a/. For example to authenticate to
        # /projects/ request URL /a/projects/.

        if RequestFactory.require_auth():
            url = "{}/a".format(url)

        if not url.startswith("http://") or not url.startswith("https://"):
            return "{}://{}".format("http" if unsecure else "https", url)

        return url
Пример #3
0
    def get_remote_base_url(cls):
        """
        Return the Gerrit Code Review server base URL.

        RETURNS
            the Gerrit Code Review server base URL as a string
        """

        url = Config.get('gerrit.host')
        unsecure = Config.get('gerrit.unsecure', False)

        if url is None:
            fail('gerrit.host not set')

        # From Gerrit Code Review Documentation (section Authentication):
        # https://gerrit-review.googlesource.com/Documentation/rest-api.html
        #
        # Users (and programs) may authenticate using HTTP authentication by
        # supplying the HTTP password from the user's account settings page.
        # Gerrit by default uses HTTP digest authentication. To authenticate,
        # prefix the endpoint URL with /a/. For example to authenticate to
        # /projects/ request URL /a/projects/.

        if RequestFactory.require_auth():
            url = '%s/a' % url

        if not url.startswith('http://') or not url.startswith('https://'):
            return '%s://%s' % ('http' if unsecure else 'https', url)

        return url
Пример #4
0
    def __enter__(self):
        pager = Config.get('core.pager', get_pager())
        pager = Config.get('pager.%s' % self.command, pager)

        if pager:
            env = os.environ.copy()
            if 'LESS' not in env:
                env['LESS'] = 'FRSX'
            if 'LV' not in env:
                env['LV'] = '-c'
            self._pager_proc = Popen([pager], stdin=PIPE, env=env)
            sys.stdout = self._pager_proc.stdin
Пример #5
0
    def __enter__(self):
        pager = Config.get('core.pager', get_pager())
        pager = Config.get('pager.%s' % self.command, pager)

        if pager:
            env = os.environ.copy()
            if 'LESS' not in env:
                env['LESS'] = 'FRSX'
            if 'LV' not in env:
                env['LV'] = '-c'
            self._pager_proc = Popen([pager], stdin=PIPE, env=env)
            sys.stdout = self._pager_proc.stdin
Пример #6
0
    def get_http_digest_auth_token(cls):
        """Return the HTTPDigestAuth object to use for authentication

        Prompt the user if the password is unknown.

        :rtype: requests.auth.HTTPDigestAuth
        """

        username = Config.get('gerrit.username')
        password = Config.get('gerrit.password')

        if password is None:
            password = getpass.getpass()

        return HTTPDigestAuth(username, password)
Пример #7
0
    def get_http_digest_auth_token(cls):
        """Return the HTTPDigestAuth object to use for authentication

        Prompt the user if the password is unknown.

        :rtype: requests.auth.HTTPDigestAuth
        """

        username = Config.get("gerrit.username")
        password = Config.get("gerrit.password")

        if password is None:
            password = getpass.getpass()

        return HTTPDigestAuth(username, password)
Пример #8
0
def raw_input_editor(default=None):
    """Request user input by firing an editor

    Like the built-in raw_input(), except that it uses a visual text editor for
    ease of editing.

    :param editor: the editor to use
    :type editor: str
    :param default: the initital content of the editor
    :type default: str | None
    """

    editor = Config.get('core.editor', get_editor())

    with tempfile.NamedTemporaryFile(mode='r+', delete=False) as tmpfile:
        if default:
            tmpfile.write(default)
            tmpfile.flush()

        # NOTE: We need to close then re-open the file after edition to ensure
        # that buffers are correctly emptied on all platforms.
        tmpfile.close()

        subprocess.check_call([editor, tmpfile.name])

        with open(tmpfile.name) as comment_file:
            comment = comment_file.read().strip()

        os.unlink(tmpfile.name)

    return comment
Пример #9
0
def raw_input_editor(default=None):
    """Request user input by firing an editor

    Like the built-in raw_input(), except that it uses a visual text editor for
    ease of editing.

    :param editor: the editor to use
    :type editor: str
    :param default: the initital content of the editor
    :type default: str | None
    """

    editor = Config.get("core.editor", get_editor())

    with tempfile.NamedTemporaryFile(mode="r+", delete=False) as tmpfile:
        if default:
            tmpfile.write(default)
            tmpfile.flush()

        # NOTE: We need to close then re-open the file after edition to ensure
        # that buffers are correctly emptied on all platforms.
        tmpfile.close()

        subprocess.check_call([editor, tmpfile.name])

        with open(tmpfile.name) as comment_file:
            comment = comment_file.read().strip()

        os.unlink(tmpfile.name)

    return comment
Пример #10
0
def raw_input_editor(default=None):
    """
    Like the built-in raw_input(), except that it uses a visual
    text editor for ease of editing.

    PARAMETERS
        editor: the editor to use
        default: the initital content of the editor

    RETURNS
        the final content after edition
    """

    editor = Config.get('core.editor', get_editor())

    with tempfile.NamedTemporaryFile(mode='r+', delete=False) as tmpfile:
        if default:
            tmpfile.write(default)
            tmpfile.flush()

        # NOTE: We need to close then re-open the file after edition to ensure
        # that buffers are correctly emptied on all platforms.
        tmpfile.close()

        subprocess.check_call([editor, tmpfile.name])

        with open(tmpfile.name) as comment_file:
            comment = comment_file.read().strip()

        os.unlink(tmpfile.name)

    return comment
Пример #11
0
    def require_auth(cls):
        """Whether authentication is required

        Return True if authentication is required.

        :rtype: bool
        """

        return Config.get('gerrit.username') is not None
Пример #12
0
    def require_auth(cls):
        """Whether authentication is required

        Return True if authentication is required.

        :rtype: bool
        """

        return Config.get("gerrit.username") is not None
Пример #13
0
    def __initialize(cls):
        """Initialize the object if needed"""

        if cls.formatter is None:
            name = Config.get("core.color", Formatter.NO_COLOR)

            if name == "auto":
                name = "terminal256"

            cls.formatter = get_formatter_by_name(name, style=OutputStyle, encoding=Formatter.ENCODING)
Пример #14
0
    def require_auth(cls):
        """
        Return True if authentication is required.
        Check whether cls.username is None.

        RETURNS
            True if auth required, False otherwise
        """

        return Config.get('gerrit.username') is not None
Пример #15
0
    def __initialize(cls):
        """Initialize the object if needed"""

        if cls.formatter is None:
            name = Config.get('core.color', Formatter.NO_COLOR)

            if name == 'auto':
                name = 'terminal256'

            cls.formatter = get_formatter_by_name(name,
                                                  style=OutputStyle,
                                                  encoding=Formatter.ENCODING)