示例#1
0
 def is_in_executelist(self, device_id, data_id):
     epd_task = EpdTask()
     if epd_task.image_data_id != device_id:
         return False
     if not epd_task.is_in_executelist(device_id):
         return False
     return True
示例#2
0
 def is_in_executelist(self, device_id, data_id):
     epd_task = EpdTask(self.task_url)
     if self.__taskStatus not in ('1', '2'):
         return False
     if epd_task.image_data_id == data_id:
         return False
     if not epd_task.is_in_executelist(device_id):
         return False
     return True
示例#3
0
 def set_task_status(self, task_id, task_status):
     if self.__taskId != task_id:
         return False
     epd_task = EpdTask()
     epd_task.set_item('task_status', task_status)
     epd_task.set_item('task_id', '0')
     epd_task.save()
     self.__taskId, self.__taskStatus = self.get_task_status()  # 更新任务状态
     return True
示例#4
0
 def set_task_status(self, task_id, task_status):
     if self.__taskId != task_id:
         return False
     epd_task = EpdTask(self.task_url)
     epd_task.set_item('task_status', str(task_status))
     epd_task.set_item('task_id', str(task_id))
     epd_task.save()
     self.__taskId = self.get_task_id()
     self.__taskStatus = self.get_task_status()  # 更新任务状态
     return True
示例#5
0
    def check_task_integrity(self, image_data_md5, iot_dev_list_md5):
        hash_obj = hashlib.md5()
        epd_task = EpdTask(self.task_url)
        with open("%s.tmp" % epd_task.data_url, "rb") as datafile:
            hash_obj.update(datafile.read())
            hash_code = hash_obj.hexdigest()
        if image_data_md5 != hash_code:
            LOG.info("image data md5 check failed")
            return False

        hash_obj = hashlib.md5()
        with open("%s.tmp" % epd_task.execute_url, "rb") as devfile:
            hash_obj.update(devfile.read())
            hash_code = hash_obj.hexdigest()
        if iot_dev_list_md5 != hash_code:
            LOG.info("iot dev list md5 check failed")
            return False
        return True
示例#6
0
 def get_data_id(self):
     epd_task = EpdTask(self.task_url)
     return epd_task.image_data_id
示例#7
0
 def get_task_time(self):
     epd_task = EpdTask(self.task_url)
     return epd_task.start_time, epd_task.end_time
示例#8
0
 def get_task_status(self):
     epd_task = EpdTask(self.task_url)
     return epd_task.task_status
示例#9
0
 def get_task_id(self):
     epd_task = EpdTask(self.task_url)
     return int(epd_task.task_id)
示例#10
0
    def create_task(self, task_id, image_data_id, image_data_url,\
            image_data_md5, iot_dev_list_md5, iot_dev_list_url, start_time, end_time):
        epd_task = EpdTask(self.task_url)

        # 0-none 1-sleep 2-ready 3-run 4-finish 5-suspend
        if self.__taskId == 0 or (self.__taskStatus in ('', '0', '4', '5')):
            # 下载任务
            os.system("wget %s -O %s.tmp" %
                      (image_data_url, epd_task.data_url))
            os.system("wget %s -O %s.tmp" %
                      (iot_dev_list_url, epd_task.execute_url))
            ret = self.check_task_integrity(image_data_md5, iot_dev_list_md5)
            if not ret:
                return False
            # 保存任务状态
            epd_task.set_item('task_id', str(task_id))
            epd_task.set_item('image_data_id', str(image_data_id))
            epd_task.set_item('image_data_url', image_data_url)
            epd_task.set_item('start_time', start_time)
            epd_task.set_item('end_time', end_time)
            epd_task.set_item('task_status', '1')
            epd_task.save()
            # 保存待更新列表
            os.system("mv %s.tmp %s" % (epd_task.data_url, epd_task.data_url))
            os.system("mv %s.tmp %s" %
                      (epd_task.execute_url, epd_task.execute_url))
            self.__taskId = self.get_task_id()
            self.__taskStatus = self.get_task_status()  # 更新任务状态
            self.set_task_monitor()
            return True
        else:
            LOG.info("task status not allowed, status:%s", self.__taskStatus)
            return False
示例#11
0
    def create_task(self, task_id, image_data_id, image_data_url,\
            image_data_md5, iot_dev_list_md5, iot_dev_list_url, start_time, end_time):
        os.system("wget -c %s -O %s.tmp" % (image_data_url, self.data_url))
        os.system("wget -c %s -O %s.tmp" %
                  (iot_dev_list_url, self.execute_url))
        ret = self.check_task_integrity(image_data_md5, iot_dev_list_md5)
        if not ret:
            return False

        # 0-none 1-sleep 2-ready 3-run 4-finish 5-suspend
        if self.__taskId == 0 or (task_id != self.__taskId
                                  and self.__taskStatus in
                                  ('', 'none', 'sleep', 'finish', 'suspend')):
            # 保存任务状态
            epd_task = EpdTask()
            epd_task.set_item('task_id', str(task_id))
            epd_task.set_item('image_data_id', str(image_data_id))
            epd_task.set_item('image_data_url', image_data_url)
            epd_task.set_item('start_time', start_time)
            epd_task.set_item('end_time', end_time)
            epd_task.set_item('task_status', 'sleep')
            epd_task.save()
            # 保存待更新列表
            os.system("mv %s.tmp %s" % (self.data_url, self.data_url))
            os.system("mv %s.tmp %s" % (self.execute_url, self.execute_url))
            self.__taskId, self.__taskStatus = self.get_task_status()  # 更新任务状态
            return True
        else:
            return False
示例#12
0
 def get_task_status(self):
     epd_task = EpdTask()
     return int(epd_task.task_id), epd_task.task_status