Exemplo n.º 1
0
 def exit(self, msg, clear_cache=True):
     if clear_cache:
         # 删除缓存
         alfred.cache.delete('tasks')
         #! 延迟时间换取缓存 避免对DS的部分操作为完成造成任务状态错误
         forkCacheProcess(10)
     alfred.exit(msg)
Exemplo n.º 2
0
 def exit(self, msg, clear_cache=True):
     if clear_cache:
         # 删除缓存
         self.cache.delete('tasks')
         #! 延迟时间换取缓存 避免对DS的部分操作为完成造成任务状态错误
         forkCacheProcess(10)
     alfred.exit(msg)
Exemplo n.º 3
0
    def pauseTask(self):
        success, data = self.ds.pauseTask(alfred.argv(2))
        self.judgeSingleTaskResult(success, data, 'Pause task')

    def resumeTask(self):
        success, data = self.ds.resumeTask(alfred.argv(2))
        self.judgeSingleTaskResult(success, data, 'Resume task')

    def deleteTask(self):
        success, data = self.ds.deleteTask(alfred.argv(2))
        self.judgeSingleTaskResult(success, data, 'Delete task')
            
    def judgeSingleTaskResult(self, success, data, action_str='Do action'):
        if not success:
            self.exit('{} failed: {}'.format(action_str, data))
        error_code = data[0]['error']
        if error_code == 0:
            self.exit('{} success.'.format(action_str))
        else:
            desc = self.getDSTaskErrorCodeDesc(error_code)
            self.exit('{} failed: {}'.format(action_str, desc))

    def getDSTaskErrorCodeDesc(self, code):
        global DSTaskCodeDesc
        return self.ds.getErrorDesc(code, extend_error_desc=DSTaskCodeDesc)

if __name__ == '__main__':
    #! 必须重新获取缓存 防止在这时缓存过期
    forkCacheProcess()
    DSAction().run()
        
Exemplo n.º 4
0
    def pauseTask(self):
        success, data = self.ds.pauseTask(alfred.argv(2))
        self.judgeSingleTaskResult(success, data, 'Pause task')

    def resumeTask(self):
        success, data = self.ds.resumeTask(alfred.argv(2))
        self.judgeSingleTaskResult(success, data, 'Resume task')

    def deleteTask(self):
        success, data = self.ds.deleteTask(alfred.argv(2))
        self.judgeSingleTaskResult(success, data, 'Delete task')
            
    def judgeSingleTaskResult(self, success, data, action_str='Do action'):
        if not success:
            self.exit('{} failed: {}'.format(action_str, data))
        error_code = data[0]['error']
        if error_code == 0:
            self.exit('{} success.'.format(action_str))
        else:
            desc = self.getDSTaskErrorCodeDesc(error_code)
            self.exit('{} failed: {}'.format(action_str, desc))

    def getDSTaskErrorCodeDesc(self, code):
        global DSTaskCodeDesc
        return self.ds.getErrorDesc(code, extend_error_desc=DSTaskCodeDesc)

if __name__ == '__main__':
    #! 必须重新获取缓存 防止在这时缓存过期
    forkCacheProcess()
    DSAction().run()