def __init__(self, **kwargs): super(Task, self).__init__(**kwargs) self.id = utils.intval(kwargs.get('id')) self.type = kwargs['type'] if isinstance(self.type, (int, long)): self.type = enums.Task.Type.find(self.type) self.type_id = kwargs.get('type_id', 0) self.time_created = kwargs.get('time_created', int(utils.timestamp())) self.time_created_text = utils.timestamp2datefmt(self.time_created) self.active_time = kwargs.get('active_time', self.time_created) self.active_time_text = utils.timestamp2datefmt(self.active_time) self.last_time = kwargs.get('last_time', 0) self.tail_num = kwargs.get( 'tail_num', utils.make_tail_num(utils.randint(0, 999999999))) # 状态 self.status = kwargs.get('status', enums.Task.Status.Waiting) if isinstance(self.status, (int, long)): self.status = enums.Task.Status.find(self.status) self.statsu_text = kwargs.get('status_text') self.exec_times = utils.intval(kwargs.get('exec_times', 0)) self.content = kwargs.get('content', {}) if self.content and isinstance(self.content, (str, unicode)): self.content = utils.json_loads(self.content) # 任务的处理程序,默认为None self._handler = None # 是否被执行过 self._executed = False
def POST(self): role_id = utils.intval(web.input().get('role_id')) if role_id <= 0: return messages.ArgumentInvalid if web.ctx.admin.auth.delete_role(role_id): return messages.Success return messages.NoOperation
def get(self, name): value = self[name] if value: expire = utils.intval(value.get('time')) if expire and expire <= time.time(): return None return self[name]['data'] return None
async def check(self, domain): """ 检查给定域名 :param domain: :return: """ result = utils.intval( os.popen(f'{settings.APP_ROOT}/bin/dnscheck {domain}').readline(). strip()) return {'domain': domain, 'polluted': result == 0}
def all(self, values): """ 查找所有给定值的枚举项 :param values: list或str, [1,2,3]或'1,2,3'都支持 :return: """ if isinstance(values, (str, unicode)): values = [utils.intval(v) for v in values.split(',')] result = [] for v in values: item = self.find(v) if item != self.Unknown: result.append(item) return result
def between(self, name, value, comparer=Comparer.LeftClosedInterval): """ 获取范围匹配值 """ # 用于在范围中匹配的值 value = utils.floatval(value) # 获取对应的配置值 v = self.get(name) if v: v = v.replace('\r', '\n').replace('@', '\n') for vs in v.split('\n'): vs = vs.strip().split('$') if len(vs) >= 2: if comparer(vs, value): if len(vs) == 3: return [ utils.intval(val) for val in vs[2].split(',') ] elif len(vs) == 2: return True return None
def int(self, name, default=0): "获取给定配置的整数值" return utils.intval(self.get(name), default)
def bool(self, name): "获取给定配置的布尔型值" return bool(utils.intval(self.get(name)))