Exemplo n.º 1
0
    def init_network(self):

        timeout = int(self.options['nonetwork'])
        if timeout == 0:
            self.network_connected = False
            self.unit = ''
            self.ip = ''
            self.interface = ''
            return

        self.network = Network()
        self.network_connected = False

        # try to connect to network
        self.mon.log(self,
                     'Waiting up to ' + str(timeout) + ' seconds for network')
        success = self.network.wait_for_network(timeout)
        if success is False:
            self.mon.warn(
                self, 'Failed to connect to network after ' + str(timeout) +
                ' seconds')
            # tkMessageBox.showwarning("Pi Presents","Failed to connect to network so using fake-hwclock")
            return

        self.network_connected = True
        self.mon.sched(
            self, None, 'Time after network check is ' +
            time.strftime("%Y-%m-%d %H:%M.%S"))
        self.mon.log(
            self, 'Time after network check is ' +
            time.strftime("%Y-%m-%d %H:%M.%S"))

        # Get web configuration
        self.network_details = False
        network_options_file_path = self.pp_dir + os.sep + 'pp_config' + os.sep + 'pp_web.cfg'
        if not os.path.exists(network_options_file_path):
            self.mon.warn(
                self, "pp_web.cfg not found at " + network_options_file_path)
            return
        self.mon.log(self, 'Found pp_web.cfg in ' + network_options_file_path)

        self.network.read_config(network_options_file_path)
        self.unit = self.network.unit

        # get interface and IP details of preferred interface
        self.interface, self.ip = self.network.get_preferred_ip()
        if self.interface == '':
            self.network_connected = False
            return
        self.network_details = True
        self.mon.log(
            self, 'Network details ' + self.unit + ' ' + self.interface + ' ' +
            self.ip)
Exemplo n.º 2
0
# ***************************************
# MAIN
# ***************************************


if __name__  ==  "__main__":

    # get directory holding the code
    editor_dir=sys.path[0]
    # print editor_dir
    if not os.path.exists(editor_dir+os.sep+"pp_web_editor.py"):
        print "Bad Application Directory"
        exit()

    # wait for network to be available
    network=Network()
    print 'Waiting for Network'
    success=network.wait_for_network(10)
    if success is False:
        print 'Failed to connect to network after 10 seconds'     
        exit()   


    # check pp_web.cfg
    editor_options_file_path=editor_dir+os.sep+'pp_config'+os.sep+'pp_web.cfg'
    if not os.path.exists(editor_options_file_path):
        print 'pp_web.cfg not found at ' + editor_options_file_path
        # tkMessageBox.showwarning("Pi Presents Web Editor",'pp_web.cfg not found at ' + editor_options_file_path)
        exit()

    print 'Found pp_web.cfg in ', editor_options_file_path