def deploy(self, f, autostart=False):
        """

        :param f:
        :param autostart:
        :return: a tuple with 3 elements. 1. status as string, 2. error message as string, 3. list of uuids of added wrapper
        """
        L.i("Deploying", f)
        sensordescriptions = []
        try:
            zFile = zipfile.ZipFile(f)
            if "deploy.json" in zFile.namelist():
                deployDescription = JOb(zFile.open("deploy.json", "r"))
                sys.path.insert(0, f)
                if deployDescription.isList():
                    for dd in deployDescription:
                        module = __import__(dd.module)
                        wrapper = getattr(module, dd["class"])()
                        self.addWrapper(wrapper)
                        sensordescriptions.append(wrapper.getSensorDescription())
                        if autostart:
                            self.startWrapper(wrapper)
                else:
                    module = __import__(deployDescription.module)
                    wrapper = getattr(module, deployDescription["class"])()
                    self.addWrapper(wrapper)
                    sensordescriptions.append(wrapper.getSensorDescription())
                    if autostart:
                        self.startWrapper(wrapper)
            return "OK", "", sensordescriptions
        except Exception as e:
            L.w("Deployment of wrapper", f, "failed.", e.message)
            return "Fail", e.message, []
 def setTimeframe(self, startdate, enddate):
     if not isinstance(self.data, list):
         Log.i("Searching start date in historic data for", self.wrapper.getSensorDescription().sensorID, "...")
         if self.data.scrollTo(startdate):
             Log.i("done")
         else:
             Log.w("no historic data beginning at", startdate, "found")
     super(CSVHistoryReader, self).setTimeframe(startdate, enddate)
    def start_messagebus(self, args):
        L.i("Connecting to the message bus")
        self.messageBusQueue = QueueThread(handler=self.sendMessageHandler)
        try:

            # prepare RabbitMQ configuration
            rmq_host = str(self.config.rabbitmq.host)
            rmq_port = self.config.rabbitmq.port
            rmq_username = self.config.rabbitmq.username if "username" in self.config.rabbitmq else None
            rmq_password = self.config.rabbitmq.username if "password" in self.config.rabbitmq else None
            if rmq_username:
                if rmq_password:
                    RabbitMQ.establishConnection(rmq_host, rmq_port, rmq_username, rmq_password)
                else:
                    RabbitMQ.establishConnection(rmq_host, rmq_port, rmq_username)
            else:
                RabbitMQ.establishConnection(rmq_host, rmq_port)
            L.i("Connected to the message bus")
            self.messageBusQueue.start()
        except MessageBusConnectionError:
            self.args.messagebus = False
            args.messagebus = False
            L.w("Could not connect to MessageBus server. Disabling MessageBus feature.")
    def startReplay(self):
        # cherrypy.tree.mount(dowser.Root(), '/dowser')
        self._startQueues()
        method = self.replayEnd
        args = None

        start_time = datetime.datetime.now()

        # if continuelive enabled set "start" as method to set the system to live mode if historic replay is finished
        if ResourceManagement.args.continuelive:
            method = self.start
            args = True

        if ResourceManagement.args.speed:
            self.clock = ReplayClock(ResourceManagement.args.speed, endCallback=method, endCallbackArgs=args)
        else:
            self.clock = ReplayClock(endCallback=method)

        if ResourceManagement.args.end and ResourceManagement.args.start:
            try:
                startDate = datetime.datetime.strptime(ResourceManagement.args.start, ReplayClock.parserformat)
                endDate = datetime.datetime.strptime(ResourceManagement.args.end, ReplayClock.parserformat)
                # for w in self.wrappers:
                #     w.setTimeframe(startDate, endDate)
                if startDate > endDate:
                    L.w("start date after end date. Changing both")
                    tmp = endDate
                    endDate = startDate
                    startDate = tmp
                self.clock.setTimeframe(startDate, endDate)
            except Exception as e:
                L.e("Problem parsing start- or end date:", str(e))
                raise e

        else:
            raise Exception("start- and enddate required for replay mode")

        if ResourceManagement.args.pt:
            from virtualisation.resourcemanagement.performancetestreceiver import PerformanceMeterMinutes

            performancetest = PerformanceMeterMinutes()  # PerformanceMeterSeconds()

        for w in self.wrappers:
            w.setReplayMode(True)
            w.setClock(self.clock)
            w.setTimeframe(startDate, endDate)
            w.addReceiver(self)
            if ResourceManagement.args.pt:
                w.addReceiver(performancetest)
            w.start()
            w.runReplay()

        if not self.args.noQuality:
            if not self.averageStreamQuality:
                self.averageStreamQuality = AverageStreamQuality(self, self.clock)
            else:
                self.averageStreamQuality.setClock(self.clock)
        self.clock.runAsync()
        self.startMonitor()

        if not ResourceManagement.args.continuelive:
            raw_input("press Enter to end.\n")
            self.clock.stop()
            L.i("Runtime", datetime.datetime.now() - start_time)