Exemple #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
Exemple #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
Exemple #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
Exemple #4
0
    def set_host(cls, host):
        """Set the Gerrit Code Review server host name.

        PARAMETERS
            host: the server's host
        """

        Config.set('gerrit.host', host)
Exemple #5
0
    def set_formatter(cls, formatter_name="terminal256"):
        """Set the formatter to use for the output

        :param formatter_name: the name of the Pygments formatter
        :type formatter_name: str
        """

        Config.set("core.formatter", formatter_name)
Exemple #6
0
    def set_host(cls, host):
        """Set the Gerrit Code Review server host name

        :param host: the server's host
        :type host: str
        """

        Config.set("gerrit.host", host)
Exemple #7
0
    def set_host(cls, host):
        """Set the Gerrit Code Review server host name

        :param host: the server's host
        :type host: str
        """

        Config.set('gerrit.host', host)
Exemple #8
0
    def set_formatter(cls, formatter_name='terminal256'):
        """Set the formatter to use for the output

        :param formatter_name: the name of the Pygments formatter
        :type formatter_name: str
        """

        Config.set('core.formatter', formatter_name)
Exemple #9
0
    def set_formatter(cls, formatter_name='terminal256'):
        """
        Set the formatter to use for the output.

        PARAMETERS
            formatter_name: the name of the Pygments formatter
        """

        Config.set('core.formatter', formatter_name)
Exemple #10
0
    def set_unsecure_connection(cls, unsecure):
        """If True, requests will be made over HTTP instead of HTTPS.

        Always use HTTPS by default.

        PARAMETERS
            unsecure: True to use HTTP
        """

        Config.set('gerrit.unsecure', unsecure)
Exemple #11
0
    def set_unsecure_connection(cls, unsecure):
        """If True, requests will be made over HTTP instead of HTTPS

        Always use HTTPS by default.

        :param unsecure: True to use HTTP
        :type unsecure: bool
        """

        Config.set('gerrit.unsecure', unsecure)
Exemple #12
0
    def set_unsecure_connection(cls, unsecure):
        """If True, requests will be made over HTTP instead of HTTPS

        Always use HTTPS by default.

        :param unsecure: True to use HTTP
        :type unsecure: bool
        """

        Config.set("gerrit.unsecure", unsecure)
Exemple #13
0
    def set_auth_token(cls, username, password=None):
        """
        Set the authentication pair to use for HTTP requests.

        PARAMETERS
            username: the account username
            password: the account HTTP password
        """

        Config.set('gerrit.username', username)
        Config.set('gerrit.password', password)
Exemple #14
0
    def set_auth_token(cls, username, password=None):
        """Set the authentication pair to use for HTTP requests

        :param username: the account username
        :type username: str
        :param password: the account HTTP password
        :type password: str
        """

        Config.set("gerrit.username", username)
        Config.set("gerrit.password", password)
Exemple #15
0
    def set_auth_token(cls, username, password=None):
        """Set the authentication pair to use for HTTP requests

        :param username: the account username
        :type username: str
        :param password: the account HTTP password
        :type password: str
        """

        Config.set('gerrit.username', username)
        Config.set('gerrit.password', password)
Exemple #16
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
Exemple #17
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
Exemple #18
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)
Exemple #19
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)
Exemple #20
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
Exemple #21
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
Exemple #22
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
Exemple #23
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
Exemple #24
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
Exemple #25
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)
Exemple #26
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
Exemple #27
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)
Exemple #28
0
def builtin_main(builtin_type):
    """Generic main function

    :param builtin_type: the type of Builtin to look for
    :type builtin_type: Builtin
    """

    try:
        # Load various input configurations
        Config.load_all()

        # Fetch the result of the command-line parsing
        command, arguments = parse_command_line(builtin_type)

        # Execute the requested command
        command.run(arguments)

    except PyCRError as why:
        sys.exit(format_message(str(why), prefix='fatal'))

    except KeyboardInterrupt:
        sys.exit(os.linesep + 'Interruption caught...')

    sys.exit()