mirror of
https://github.com/facebook/sapling.git
synced 2024-12-26 06:21:48 +03:00
edenapi: remove python wrapper
Summary: Now that Mercurial itself can properly handle SIGINT, there isn't a need for a Python wrapper around the Rust EdenAPI client (since the main purpose of the wrapper was to ensure proper SIGINT handling--something that could only be done in Python). Note that while this does remove some code that prints out certificate warnings, that code was actually broken after the big refactor of the Rust bindings. (The exception types referenced no longer exist, so the code would simple result in a `NameError` if it actually tried to catch an exception from the Rust client.) Reviewed By: singhsrb Differential Revision: D23801363 fbshipit-source-id: 3359c181fd05dbec24d77fa1b7d9c8bd821b49a6
This commit is contained in:
parent
514f349132
commit
683520106e
@ -132,6 +132,7 @@ import time
|
||||
import traceback
|
||||
from contextlib import contextmanager
|
||||
|
||||
from bindings import edenapi
|
||||
from edenscm.mercurial import (
|
||||
archival,
|
||||
bundle2,
|
||||
@ -144,7 +145,6 @@ from edenscm.mercurial import (
|
||||
copies,
|
||||
dirstate,
|
||||
dispatch,
|
||||
edenapi,
|
||||
error,
|
||||
exchange,
|
||||
extensions,
|
||||
@ -388,7 +388,7 @@ def setupclient(ui, repo):
|
||||
|
||||
repo.edenapi = None
|
||||
if ui.config("edenapi", "url"):
|
||||
repo.edenapi = edenapi.pyclient(ui)
|
||||
repo.edenapi = edenapi.client(ui._rcfg._rcfg)
|
||||
|
||||
|
||||
clientonetime = False
|
||||
|
@ -1,60 +0,0 @@
|
||||
# Copyright (c) Facebook, Inc. and its affiliates.
|
||||
#
|
||||
# This software may be used and distributed according to the terms of the
|
||||
# GNU General Public License version 2.
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from bindings import edenapi
|
||||
|
||||
from .i18n import _
|
||||
|
||||
|
||||
class pyclient(object):
|
||||
"""Wrapper around an EdenAPI client from Mercurial's Rust bindings.
|
||||
|
||||
The primary purpose of this class is user-friendliness. It provides correct
|
||||
handling of SIGINT and prints out configurable user-friendly error messages.
|
||||
"""
|
||||
|
||||
def __init__(self, ui):
|
||||
self._ui = ui
|
||||
self._rustclient = _warnexceptions(ui)(edenapi.client)(ui._rcfg._rcfg)
|
||||
|
||||
def __getattr__(self, name):
|
||||
method = getattr(self._rustclient, name)
|
||||
method = _warnexceptions(self._ui)(method)
|
||||
return method
|
||||
|
||||
|
||||
def _warnexceptions(ui):
|
||||
"""Decorator that catches certain exceptions defined by the Rust bindings
|
||||
and emits a user-friendly message before re-raising the exception.
|
||||
|
||||
Although function is designed as a decorator, in practice it needs
|
||||
to be called manually rather than using decorator syntax, since it
|
||||
requires a ui object as an argument, which is typically not available
|
||||
outside of a function/method body.
|
||||
"""
|
||||
|
||||
def decorator(func):
|
||||
def wrapped(*args, **kwargs):
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
except edenapi.CertificateError as e:
|
||||
_printhelp(ui, "tlsauthhelp")
|
||||
raise e
|
||||
except edenapi.TlsError as e:
|
||||
_printhelp(ui, "tlshelp")
|
||||
raise e
|
||||
|
||||
return wrapped
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
def _printhelp(ui, msgname):
|
||||
"""Print a help message defined in the [help] config section."""
|
||||
msg = ui.config("help", msgname)
|
||||
if msg is not None:
|
||||
ui.warn(msg + "\n")
|
Loading…
Reference in New Issue
Block a user