Python controller.Controller() Examples

The following are 30 code examples of controller.Controller(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module controller , or try the search function .
Example #1
Source File: tasks.py    From stack with MIT License 7 votes vote down vote up
def restart_daemon(process, project, collector_id=None, network=None):
    """
    Calls a Controller to restart a daemonized STACK process
    """
    if process == 'collect':
        c = Controller(
            process=process,
            project=project,
            collector_id=collector_id
        )
    else:
        c = Controller(
            process=process,
            project=project,
            network=network
        )

    t = threading.Thread(name='test-thread', target=c.process_command, args=('restart',))
    t.start()

    # c.process_command('restart') 
Example #2
Source File: trainer.py    From hands-detection with MIT License 7 votes vote down vote up
def get_controller(self):
    """Get controller."""
    cls = controller.Controller
    return cls(self.env, self.env_spec, self.internal_dim,
               use_online_batch=self.use_online_batch,
               batch_by_steps=self.batch_by_steps,
               unify_episodes=self.unify_episodes,
               replay_batch_size=self.replay_batch_size,
               max_step=self.max_step,
               cutoff_agent=self.cutoff_agent,
               save_trajectories_file=self.save_trajectories_file,
               use_trust_region=self.trust_region_p,
               use_value_opt=self.value_opt is not None,
               update_eps_lambda=self.update_eps_lambda,
               prioritize_by=self.prioritize_by,
               get_model=self.get_model,
               get_replay_buffer=self.get_replay_buffer,
               get_buffer_seeds=self.get_buffer_seeds) 
Example #3
Source File: __init__.py    From addon with GNU General Public License v3.0 7 votes vote down vote up
def load_controllers():
    controllers = []
    path = os.path.join(config.get_runtime_path(),"platformcode", "controllers")
    for fname in os.listdir(path):
        mod, ext = os.path.splitext(fname)
        fname = os.path.join(path, fname)
        if os.path.isfile(fname) and ext == '.py' and not mod.startswith('_'):
            try:
                exec "import " + mod + " as controller"
            except:
                import traceback
                logger.error(traceback.format_exc())

            for c in dir(controller):
                cls = getattr(controller, c)

                if not c.startswith('_') and isclass(cls) and issubclass(cls, Controller) and Controller != cls:
                    controllers.append(cls)
    return controllers 
Example #4
Source File: trainer.py    From Gun-Detector with Apache License 2.0 7 votes vote down vote up
def get_controller(self, env):
    """Get controller."""
    cls = controller.Controller
    return cls(env, self.env_spec, self.internal_dim,
               use_online_batch=self.use_online_batch,
               batch_by_steps=self.batch_by_steps,
               unify_episodes=self.unify_episodes,
               replay_batch_size=self.replay_batch_size,
               max_step=self.max_step,
               cutoff_agent=self.cutoff_agent,
               save_trajectories_file=self.save_trajectories_file,
               use_trust_region=self.trust_region_p,
               use_value_opt=self.value_opt not in [None, 'None'],
               update_eps_lambda=self.update_eps_lambda,
               prioritize_by=self.prioritize_by,
               get_model=self.get_model,
               get_replay_buffer=self.get_replay_buffer,
               get_buffer_seeds=self.get_buffer_seeds) 
Example #5
Source File: tasks.py    From stack with MIT License 7 votes vote down vote up
def stop_daemon(process, project, collector_id=None, network=None):
    """
    Calls a Controller to stop a daemonized STACK process
    """
    if process == 'collect':
        c = Controller(
            process=process,
            project=project,
            collector_id=collector_id
        )
    else:
        c = Controller(
            process=process,
            project=project,
            network=network
        )

    t = threading.Thread(name='test-thread', target=c.process_command, args=('stop',))
    t.start()
    t.join()

    # c.process_command('stop') 
Example #6
Source File: tasks.py    From stack with MIT License 7 votes vote down vote up
def start_daemon(process, project, collector_id=None, network=None):
    """
    Calls a Controller to daemonize and start a STACK process
    """
    if process == 'collect':
        c = Controller(
            process=process,
            project=project,
            collector_id=collector_id
        )
    else:
        c = Controller(
            process=process,
            project=project,
            network=network
        )

    t = threading.Thread(name='test-thread', target=c.process_command, args=('start',))
    t.start()

    # c.process_command('start') 
Example #7
Source File: trainer.py    From yolo_v2 with Apache License 2.0 7 votes vote down vote up
def get_controller(self):
    """Get controller."""
    cls = controller.Controller
    return cls(self.env, self.env_spec, self.internal_dim,
               use_online_batch=self.use_online_batch,
               batch_by_steps=self.batch_by_steps,
               unify_episodes=self.unify_episodes,
               replay_batch_size=self.replay_batch_size,
               max_step=self.max_step,
               cutoff_agent=self.cutoff_agent,
               save_trajectories_file=self.save_trajectories_file,
               use_trust_region=self.trust_region_p,
               use_value_opt=self.value_opt is not None,
               update_eps_lambda=self.update_eps_lambda,
               prioritize_by=self.prioritize_by,
               get_model=self.get_model,
               get_replay_buffer=self.get_replay_buffer,
               get_buffer_seeds=self.get_buffer_seeds) 
Example #8
Source File: controller_esp.py    From SX127x_driver_for_MicroPython_on_ESP8266 with GNU General Public License v3.0 7 votes vote down vote up
def prepare_spi(self, spi): 
        if spi:
            new_spi = Controller.Mock()  

            def transfer(pin_ss, address, value = 0x00):        
                response = bytearray(1)

                pin_ss.low()
                 
                spi.write(bytes([address]))
                spi.write_readinto(bytes([value]), response)

                pin_ss.high()

                return response
                
            new_spi.transfer = transfer
            new_spi.close = spi.deinit            
            return new_spi 
Example #9
Source File: controller_rpi.py    From SX127x_driver_for_MicroPython_on_ESP8266 with GNU General Public License v3.0 7 votes vote down vote up
def prepare_spi(self, spi): 
        if spi:            
            new_spi = Controller.Mock()

            def transfer(pin_ss, address, value = 0x00):        
                response = bytearray(1)
                
                pin_ss.low()
                response.append(spi.xfer2([address, value])[1])                
                pin_ss.high()
                
                return response
                
            new_spi.transfer = transfer
            new_spi.close = spi.close         
            return new_spi 
Example #10
Source File: controller_esp.py    From SX127x_driver_for_MicroPython_on_ESP8266 with GNU General Public License v3.0 7 votes vote down vote up
def prepare_spi(self, spi):
        if spi:
            new_spi = Controller.Mock()


            def transfer(pin_ss, address, value = 0x00):
                response = bytearray(1)

                pin_ss.low()

                spi.write(bytes([address]))
                spi.write_readinto(bytes([value]), response)

                pin_ss.high()

                return response


            new_spi.transfer = transfer
            new_spi.close = spi.deinit
            return new_spi 
Example #11
Source File: trainer.py    From multilabel-image-classification-tensorflow with MIT License 6 votes vote down vote up
def get_controller(self, env):
    """Get controller."""
    cls = controller.Controller
    return cls(env, self.env_spec, self.internal_dim,
               use_online_batch=self.use_online_batch,
               batch_by_steps=self.batch_by_steps,
               unify_episodes=self.unify_episodes,
               replay_batch_size=self.replay_batch_size,
               max_step=self.max_step,
               cutoff_agent=self.cutoff_agent,
               save_trajectories_file=self.save_trajectories_file,
               use_trust_region=self.trust_region_p,
               use_value_opt=self.value_opt not in [None, 'None'],
               update_eps_lambda=self.update_eps_lambda,
               prioritize_by=self.prioritize_by,
               get_model=self.get_model,
               get_replay_buffer=self.get_replay_buffer,
               get_buffer_seeds=self.get_buffer_seeds) 
Example #12
Source File: view.py    From BitTorrent with GNU General Public License v3.0 6 votes vote down vote up
def render(self, request, doneCallback=None):
        if not getattr(request, 'currentId', 0):
            request.currentId = 0
        request.currentPage = self
        if self.controller is None:
            self.controller = controller.Controller(self.model)
        if doneCallback is not None:
            self.doneCallback = doneCallback
        else:
            self.doneCallback = doSendPage
        self.setupAllStacks()
        template = self.getTemplate(request)
        if template:
            self.d = microdom.parseString(template, caseInsensitive=0, preserveCase=0)
        else:
            if not self.templateFile:
                raise AttributeError, "%s does not define self.templateFile to operate on" % self.__class__
            self.d = self.lookupTemplate(request)
        request.d = self.d
        self.handleDocument(request, self.d)
        return NOT_DONE_YET 
Example #13
Source File: trainer.py    From g-tensorflow-models with Apache License 2.0 6 votes vote down vote up
def get_controller(self, env):
    """Get controller."""
    cls = controller.Controller
    return cls(env, self.env_spec, self.internal_dim,
               use_online_batch=self.use_online_batch,
               batch_by_steps=self.batch_by_steps,
               unify_episodes=self.unify_episodes,
               replay_batch_size=self.replay_batch_size,
               max_step=self.max_step,
               cutoff_agent=self.cutoff_agent,
               save_trajectories_file=self.save_trajectories_file,
               use_trust_region=self.trust_region_p,
               use_value_opt=self.value_opt not in [None, 'None'],
               update_eps_lambda=self.update_eps_lambda,
               prioritize_by=self.prioritize_by,
               get_model=self.get_model,
               get_replay_buffer=self.get_replay_buffer,
               get_buffer_seeds=self.get_buffer_seeds) 
Example #14
Source File: trainer.py    From models with Apache License 2.0 6 votes vote down vote up
def get_controller(self, env):
    """Get controller."""
    cls = controller.Controller
    return cls(env, self.env_spec, self.internal_dim,
               use_online_batch=self.use_online_batch,
               batch_by_steps=self.batch_by_steps,
               unify_episodes=self.unify_episodes,
               replay_batch_size=self.replay_batch_size,
               max_step=self.max_step,
               cutoff_agent=self.cutoff_agent,
               save_trajectories_file=self.save_trajectories_file,
               use_trust_region=self.trust_region_p,
               use_value_opt=self.value_opt not in [None, 'None'],
               update_eps_lambda=self.update_eps_lambda,
               prioritize_by=self.prioritize_by,
               get_model=self.get_model,
               get_replay_buffer=self.get_replay_buffer,
               get_buffer_seeds=self.get_buffer_seeds) 
Example #15
Source File: trainer.py    From object_detection_kitti with Apache License 2.0 6 votes vote down vote up
def get_controller(self):
    """Get controller."""
    cls = controller.Controller
    return cls(self.env, self.env_spec, self.internal_dim,
               use_online_batch=self.use_online_batch,
               batch_by_steps=self.batch_by_steps,
               unify_episodes=self.unify_episodes,
               replay_batch_size=self.replay_batch_size,
               max_step=self.max_step,
               cutoff_agent=self.cutoff_agent,
               save_trajectories_file=self.save_trajectories_file,
               use_trust_region=self.trust_region_p,
               use_value_opt=self.value_opt is not None,
               update_eps_lambda=self.update_eps_lambda,
               prioritize_by=self.prioritize_by,
               get_model=self.get_model,
               get_replay_buffer=self.get_replay_buffer,
               get_buffer_seeds=self.get_buffer_seeds) 
Example #16
Source File: trainer.py    From object_detection_with_tensorflow with MIT License 6 votes vote down vote up
def get_controller(self):
    """Get controller."""
    cls = controller.Controller
    return cls(self.env, self.env_spec, self.internal_dim,
               use_online_batch=self.use_online_batch,
               batch_by_steps=self.batch_by_steps,
               unify_episodes=self.unify_episodes,
               replay_batch_size=self.replay_batch_size,
               max_step=self.max_step,
               cutoff_agent=self.cutoff_agent,
               save_trajectories_file=self.save_trajectories_file,
               use_trust_region=self.trust_region_p,
               use_value_opt=self.value_opt is not None,
               update_eps_lambda=self.update_eps_lambda,
               prioritize_by=self.prioritize_by,
               get_model=self.get_model,
               get_replay_buffer=self.get_replay_buffer,
               get_buffer_seeds=self.get_buffer_seeds) 
Example #17
Source File: __init__.py    From pelisalacarta-ce with GNU General Public License v3.0 6 votes vote down vote up
def load_controllers():
    controllers=[]
    path=os.path.split(__file__)[0]
    for fname in os.listdir(path):
        mod,ext=os.path.splitext(fname)
        fname=os.path.join(path,fname)
        if os.path.isfile(fname) and ext=='.py' and not mod.startswith('_'):
            try:
              exec "import "+ mod + " as controller"
            except:
              import traceback
              logger.error(traceback.format_exc())
              
            for c in dir(controller):
                cls=getattr(controller, c);

                if not c.startswith('_') and isclass(cls) and issubclass(cls, Controller) and Controller != cls:
                    controllers.append(cls)
    return controllers 
Example #18
Source File: button_and_led.py    From EInk-Calendar with MIT License 6 votes vote down vote up
def __init__(self,
                 controller: Controller,
                 button_gpio: int = 26,
                 led_gpio: int = 21) -> None:
        self.button_gpio = button_gpio
        self.controller = controller
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(button_gpio, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        GPIO.setup(led_gpio, GPIO.OUT)
        self.led_gpio = led_gpio

        def call_back(channel: int) -> None:
            def new_thread():
                self.controller.update_and_redraw()
                logger.info('Update of the screen due to button event')

            thread = threading.Thread(target=new_thread)
            thread.start()

        GPIO.add_event_detect(button_gpio,
                              GPIO.FALLING,
                              callback=call_back,
                              bouncetime=500)
        self.led_off() 
Example #19
Source File: analyzer.py    From anchore with Apache License 2.0 5 votes vote down vote up
def run(self):
        self._logger.debug("main image analysis on images: " + str(self.images) + ": begin")
        # analyze image and all of its family members
        success = True
        toanalyze = OrderedDict()

        # calculate all images to be analyzed
        for imageId in self.images:
            coreimage = self.allimages[imageId]
            toanalyze.update(self.selection_strategy.evaluate_familytree(coreimage.anchore_familytree, self.allimages))

        # execute analyzers
        self._logger.debug("images to be analyzed: " + str(toanalyze.keys()))
        for imageId in toanalyze.keys():
            image = toanalyze[imageId]
            success = self.run_analyzers(image)

            if not success:
                self._logger.error("analyzer failed to run on image " + str(image.meta['imagename']) + ", skipping the rest")
                break

        if not success:
            self._logger.error("analyzers failed to run on one or more images.")
            return (False)

        #if not self.skipgates:
        #    # execute gates
        #    self._logger.debug("running gates post-analysis: begin")
        #    for imageId in toanalyze.keys():
        #        c = controller.Controller(anchore_config=self.config, imagelist=[imageId], allimages=self.allimages).run_gates(refresh=True)
        #    self._logger.debug("running gates post-analysis: end")

        self._logger.debug("main image analysis on images: " + str(self.images) + ": end")
        return (success) 
Example #20
Source File: mock.py    From EInk-Calendar with MIT License 5 votes vote down vote up
def __init__(self, controller: Controller):
        pass 
Example #21
Source File: stream_model.py    From seedsync with Apache License 2.0 5 votes vote down vote up
def __init__(self, controller: Controller):
        self.controller = controller
        self.serialize = SerializeModel()
        self.model_listener = WebResponseModelListener()
        self.initial_model_files = None
        self.first_run = True 
Example #22
Source File: controller_rpi.py    From SX127x_driver_for_MicroPython_on_ESP8266 with GNU General Public License v3.0 5 votes vote down vote up
def prepare_pin(self, pin_id, in_out = GPIO.OUT):
        if pin_id is not None:
            GPIO.setup(pin_id, in_out) 
            new_pin = Controller.Mock()
            new_pin.pin_id = pin_id
            
            if in_out == GPIO.OUT:
                new_pin.low = lambda : GPIO.output(pin_id, GPIO.LOW)
                new_pin.high = lambda : GPIO.output(pin_id, GPIO.HIGH)
            else:
                new_pin.value = lambda : GPIO.input(pin_id)
                
            return new_pin 
Example #23
Source File: web_app.py    From seedsync with Apache License 2.0 5 votes vote down vote up
def __init__(self, context: Context, controller: Controller):
        super().__init__()
        self.logger = context.logger.getChild("WebApp")
        self.__controller = controller
        self.__html_path = context.args.html_path
        self.__status = context.status
        self.logger.info("Html path set to: {}".format(self.__html_path))
        self.__stop = False
        self.__streaming_handlers = []  # list of (handler, kwargs) pairs 
Example #24
Source File: web_app_builder.py    From seedsync with Apache License 2.0 5 votes vote down vote up
def __init__(self,
                 context: Context,
                 controller: Controller,
                 auto_queue_persist: AutoQueuePersist):
        self.__context = context
        self.__controller = controller

        self.controller_handler = ControllerHandler(controller)
        self.server_handler = ServerHandler(context)
        self.config_handler = ConfigHandler(context.config)
        self.auto_queue_handler = AutoQueueHandler(auto_queue_persist)
        self.status_handler = StatusHandler(context.status) 
Example #25
Source File: tests.py    From pyNMS with GNU General Public License v3.0 5 votes vote down vote up
def start_pyNMS(function):
    def wrapper(self):
        self.app = QApplication(sys.argv)
        self.ct = controller.Controller(path_app, test=True)
        self.pj = self.ct.current_project
        self.vw = self.pj.current_view
        self.nk = self.vw.network
        function(self)
    return wrapper
    
# @start_pyNMS_and_import_project(name of the file to be imported)
# starting a project and importing a file: used for tests 
Example #26
Source File: view.py    From Tkinter-GUI-Application-Development-Blueprints-Second-Edition with MIT License 5 votes vote down vote up
def init_new_game():
    game_controller = controller.Controller()
    main(game_controller) 
Example #27
Source File: view.py    From Tkinter-GUI-Application-Development-Blueprints-Second-Edition with MIT License 5 votes vote down vote up
def init_new_game():
    game_controller = controller.Controller()
    main(game_controller) 
Example #28
Source File: pymdht.py    From p2ptv-pi with MIT License 5 votes vote down vote up
def __init__(self, dht_addr, conf_path, routing_m_mod, lookup_m_mod, private_dht_name, debug_level):
        logging_conf.setup(conf_path, debug_level)
        self.controller = controller.Controller(dht_addr, conf_path, routing_m_mod, lookup_m_mod, private_dht_name)
        self.controller.start() 
Example #29
Source File: controller_esp.py    From SX127x_driver_for_MicroPython_on_ESP8266 with GNU General Public License v3.0 5 votes vote down vote up
def prepare_pin(self, pin_id, in_out = Pin.OUT):
        if pin_id is not None:
            pin = Pin(pin_id, in_out)
            new_pin = Controller.Mock()
            new_pin.pin_id = pin_id
            new_pin.value = pin.value

            if in_out == Pin.OUT:
                new_pin.low = lambda: pin.value(0)
                new_pin.high = lambda: pin.value(1)
            else:
                new_pin.irq = pin.irq

            return new_pin 
Example #30
Source File: controller_rpi.py    From SX127x_driver_for_MicroPython_on_ESP8266 with GNU General Public License v3.0 5 votes vote down vote up
def prepare_pin(self, pin_id, in_out = GPIO.OUT):
        if pin_id is not None:
            GPIO.setup(pin_id, in_out)
            new_pin = Controller.Mock()
            new_pin.pin_id = pin_id

            if in_out == GPIO.OUT:
                new_pin.low = lambda: GPIO.output(pin_id, GPIO.LOW)
                new_pin.high = lambda: GPIO.output(pin_id, GPIO.HIGH)
            else:
                new_pin.value = lambda: GPIO.input(pin_id)

            return new_pin