class VMCClient(object): def __init__(self, device, config): self.device = device self.config = config self.wrapper = None self.connsm = None def start_it(self): if self.config['connect']: statemachine_callbacks = { 'ImDoneEnter': self.connect_to_internet, } else: # Nothing to do statemachine_callbacks = {} statemachine_errbacks = { 'AlreadyConnecting': None, 'AlreadyConnected': None, 'IllegalOperationError': None, } from vmc.cli.wrapper import CLIWrapper self.wrapper = CLIWrapper(self.device, {}, statemachine_callbacks, statemachine_errbacks) # we pass the config so CLICollaborator can send PIN if needed self.wrapper.start_behaviour(self.config) def connect_to_internet(self): reactor.callLater(1, self.__connect_to_internet) def __connect_to_internet(self): self.connsm = self.wrapper.behaviour.current_sm # generate the configuration dialconf = DialerConf.from_config_dict(self.config) # configure dialer self.connsm.dialer.configure(dialconf, self.wrapper.device) # connect to Internet d = self.connsm.connect() def connect_eb(failure): log.err(failure) reactor.stop() def run_and_disconnect(result): executable = self.config['executable'] if executable: log.msg("Running '%s'" % executable) returnVal = system(executable) log.msg("Executable end with status %d" % returnVal) d = self.connsm.close() def stop(*results): reactor.callLater(2, reactor.stop) d.addCallback(stop) d.addCallback(run_and_disconnect) d.addErrback(connect_eb)
class VMCClient(object): def __init__(self, device, config): self.device = device self.config = config self.wrapper = None self.connsm = None def start_it(self): if self.config['connect']: statemachine_callbacks = { 'ImDoneEnter' : self.connect_to_internet, } else: # we just wanna run standalone ok? statemachine_callbacks = {} statemachine_errbacks = { 'AlreadyConnecting' : None, 'AlreadyConnected' : None, 'IllegalOperationError' : None, } from vmc.cli.wrapper import CLIWrapper self.wrapper = CLIWrapper(self.device, {}, statemachine_callbacks, statemachine_errbacks) # we pass the config so CLICollaborator can send PIN if needed self.wrapper.start_behaviour(self.config) def connect_to_internet(self): reactor.callLater(1, self.__connect_to_internet) def __connect_to_internet(self): self.connsm = self.wrapper.behaviour.current_sm # generate the configuration dialconf = DialerConf.from_config_dict(self.config) # configure dialer self.connsm.dialer.configure(dialconf, self.wrapper.device) # connect to Internet d = self.connsm.connect() def connect_eb(failure): log.err(failure) reactor.stop() d.addCallback(lambda _: log.msg("Connected to Internet!")) d.addErrback(connect_eb)
class VMCClient(object): def __init__(self, device, config): self.device = device self.config = config self.wrapper = None self.connsm = None def start_it(self): if self.config['connect']: statemachine_callbacks = { 'ImDoneEnter': self.connect_to_internet, } else: # we just wanna run standalone ok? statemachine_callbacks = {} statemachine_errbacks = { 'AlreadyConnecting': None, 'AlreadyConnected': None, 'IllegalOperationError': None, } from vmc.cli.wrapper import CLIWrapper self.wrapper = CLIWrapper(self.device, {}, statemachine_callbacks, statemachine_errbacks) # we pass the config so CLICollaborator can send PIN if needed self.wrapper.start_behaviour(self.config) def connect_to_internet(self): reactor.callLater(1, self.__connect_to_internet) def __connect_to_internet(self): self.connsm = self.wrapper.behaviour.current_sm # generate the configuration dialconf = DialerConf.from_config_dict(self.config) # configure dialer self.connsm.dialer.configure(dialconf, self.wrapper.device) # connect to Internet d = self.connsm.connect() def connect_eb(failure): log.err(failure) reactor.stop() d.addCallback(lambda _: log.msg("Connected to Internet!")) d.addErrback(connect_eb)
class VMCClient(object): def __init__(self, device, config): self.device = device self.config = config self.wrapper = None self.connsm = None def start_it(self): if self.config['connect']: statemachine_callbacks = { 'ImDoneEnter' : self.connect_to_internet, } else: # we just wanna run standalone ok? statemachine_callbacks = {} statemachine_errbacks = { 'AlreadyConnecting' : None, 'AlreadyConnected' : None, 'IllegalOperationError' : None, } from vmc.cli.wrapper import CLIWrapper self.wrapper = CLIWrapper(self.device, {}, statemachine_callbacks, statemachine_errbacks) # we pass the config so CLICollaborator can send PIN if needed self.wrapper.start_behaviour(self.config) def connect_to_internet(self): reactor.callLater(1, self.__connect_to_internet) def __connect_to_internet(self): self.connsm = self.wrapper.behaviour.current_sm # generate the configuration dialconf = DialerConf.from_config_dict(self.config) # configure dialer self.connsm.dialer.configure(dialconf, self.wrapper.device) # connect to Internet d = self.connsm.connect() def connect_eb(failure): log.err(failure) reactor.stop() def run_and_disconnect(result): executable = self.config['executable'] if executable: log.msg("Running '%s'" % executable) returnVal = system(executable) log.msg("Executable end with status %d" % returnVal) d = self.connsm.close() def stop(*results): reactor.callLater(2, reactor.stop) d.addCallback(stop) d.addCallback(run_and_disconnect) d.addErrback(connect_eb)