type hint for new small update

This commit is contained in:
Huy Pham 2020-01-15 10:55:29 -08:00
commit c1c580cdc4
5 changed files with 21 additions and 9 deletions

View file

@ -137,7 +137,7 @@ class CoreGrpcClient:
Provides convenience methods for interfacing with the CORE grpc server. Provides convenience methods for interfacing with the CORE grpc server.
""" """
def __init__(self, address="localhost:50051"): def __init__(self, address="localhost:50051", proxy=False):
""" """
Creates a CoreGrpcClient instance. Creates a CoreGrpcClient instance.
@ -146,6 +146,7 @@ class CoreGrpcClient:
self.address = address self.address = address
self.stub = None self.stub = None
self.channel = None self.channel = None
self.proxy = proxy
def start_session( def start_session(
self, self,
@ -1035,7 +1036,9 @@ class CoreGrpcClient:
:return: nothing :return: nothing
""" """
self.channel = grpc.insecure_channel(self.address) self.channel = grpc.insecure_channel(
self.address, options=[("grpc.enable_http_proxy", self.proxy)]
)
self.stub = core_pb2_grpc.CoreApiStub(self.channel) self.stub = core_pb2_grpc.CoreApiStub(self.channel)
def close(self): def close(self):

View file

@ -17,8 +17,8 @@ HEIGHT = 800
class Application(tk.Frame): class Application(tk.Frame):
def __init__(self, master: tk.Widget = None): def __init__(self, proxy: bool):
super().__init__(master) super().__init__(master=None)
# load node icons # load node icons
NodeUtils.setup() NodeUtils.setup()
@ -33,7 +33,7 @@ class Application(tk.Frame):
self.guiconfig = appconfig.read() self.guiconfig = appconfig.read()
self.style = ttk.Style() self.style = ttk.Style()
self.setup_theme() self.setup_theme()
self.core = CoreClient(self) self.core = CoreClient(self, proxy)
self.setup_app() self.setup_app()
self.draw() self.draw()
self.core.set_up() self.core.set_up()

View file

@ -53,11 +53,11 @@ class Observer:
class CoreClient: class CoreClient:
def __init__(self, app: "Application"): def __init__(self, app: "Application", proxy: bool):
""" """
Create a CoreGrpc instance Create a CoreGrpc instance
""" """
self.client = client.CoreGrpcClient() self.client = client.CoreGrpcClient(proxy=proxy)
self.session_id = None self.session_id = None
self.node_ids = [] self.node_ids = []
self.app = app self.app = app

View file

@ -1,4 +1,5 @@
#!/usr/bin/env python #!/usr/bin/env python
import argparse
import logging import logging
from core.gui import appconfig from core.gui import appconfig
@ -6,10 +7,18 @@ from core.gui.app import Application
from core.gui.images import Images from core.gui.images import Images
if __name__ == "__main__": if __name__ == "__main__":
# parse flags
parser = argparse.ArgumentParser(description=f"CORE Python Tk GUI")
parser.add_argument("-p", "--proxy", action="store_true", help="enable proxy")
args = parser.parse_args()
# setup logging
log_format = "%(asctime)s - %(levelname)s - %(module)s:%(funcName)s - %(message)s" log_format = "%(asctime)s - %(levelname)s - %(module)s:%(funcName)s - %(message)s"
logging.basicConfig(level=logging.DEBUG, format=log_format) logging.basicConfig(level=logging.DEBUG, format=log_format)
logging.getLogger("PIL").setLevel(logging.ERROR) logging.getLogger("PIL").setLevel(logging.ERROR)
# start app
Images.load_all() Images.load_all()
appconfig.check_directory() appconfig.check_directory()
app = Application() app = Application(args.proxy)
app.mainloop() app.mainloop()

View file

@ -8,7 +8,7 @@ function install_python_depencencies() {
} }
function install_python_dev_dependencies() { function install_python_dev_dependencies() {
sudo pip install pipenv grpcio-tools sudo python3 -m pip install pipenv grpcio-tools
} }
function install_ospf_mdr() { function install_ospf_mdr() {