def scan_commands(self): self._commands = [] if self.mod == None: return dic = self.mod.__dict__ if '__root__' in dic: root = dic['__root__'] else: root = [] for k in dic: if k.startswith('_') or k in root: continue item = dic[k] if type(item) == types.FunctionType: bisect.insort(self._commands, method.Method(item, k, self)) elif type(item) == types.ModuleType and utils.is_commander_module(item): mod = Module(k, item, self) bisect.insort(self._commands, mod) # Insert root functions into this module for r in mod.roots(): bisect.insert(self._commands, r)
def add_interval(arr, interval, d): days_num = interval[1] - interval[0] if days_num < d: return 0 if not len(arr): arr.append(interval) return days_num pos, possible_positions = find(arr, interval), [] if pos: possible_positions.append(arr[pos - 1]) if pos < len(arr): possible_positions.append(arr[pos]) if len(possible_positions) == 1: if not pos: if arr[0][0] < interval[1]: return 0 elif arr[0][0] == interval[1]: arr[0][0] = interval[0] return days_num else: insert(arr, interval) return days_num if arr[-1][1] > interval[0]: return 0 elif arr[-1][1] == interval[0]: arr[-1][1] = interval[1] return days_num else: insert(arr, interval) return days_num p1, p2 = possible_positions[0], possible_positions[1] if p1[1] > interval[0] or p2[0] < interval[1]: return 0 elif p1[1] == interval[0] and p2[0] == interval[1]: p1[1] = p2[1] del arr[pos] return days_num elif p1[1] == interval[0]: p1[1] = interval[1] return days_num elif p2[0] == interval[1]: p2[0] = interval[0] return days_num else: insert(arr, interval) return days_num