Exemplo n.º 1
0
    def start(self):
        logger.debug('client pid:%s' % os.getpid())
        import argparse
        from apps.openport_api import open_port
        from common.session import Session

        parser = argparse.ArgumentParser()
        self.add_default_arguments(parser)
        args = parser.parse_args()
        if args.verbose:
            from logging import DEBUG
            set_log_level(DEBUG)

        if args.no_gui:
            args.hide_message = True
            args.no_clipboard = True
        self.args = args

        if not args.hide_message:
            import wx
            self.app = wx.App(redirect=False)

        def show_message_box(session):
            wx.MessageBox('Your local port %s is now reachable on %s' % ( session.local_port, session.get_link()), 'Info',
                wx.OK | wx.ICON_INFORMATION)

        self.first_time = True

        def callback(ignore):
            if not self.first_time:
                return
            self.first_time = False

            session.restart_command = self.get_restart_command(session)
            if args.tray_port > 0:
                self.inform_tray_app_new(session, args.tray_port, start_tray=(not args.no_tray))

            session.error_observers.append(self.error_callback)
            session.success_observers.append(self.success_callback)

            if not args.no_clipboard:
                self.copy_share_to_clipboard(session)
            if not args.hide_message:
                show_message_box(session)

        session = Session()
        session.local_port = int(args.local_port)
        session.server_port = args.request_port
        session.server_session_token = args.request_token

#        app.MainLoop()

        def show_error(error_msg):
            import wx
            wx.MessageBox(error_msg, 'Error', wx.OK | wx.ICON_ERROR)
        self.session = session

        open_port(session, callback, show_error)
Exemplo n.º 2
0
    def open_port_file(self, share, callback=None):
        import threading

        if share.local_port == -1:
            share.local_port = get_open_port()
        thr = threading.Thread(target=serve_file_on_port, args=(share.filePath, share.local_port, share.token))
        thr.setDaemon(True)
        thr.start()
        open_port(share, callback=callback)