def dump_memory(user=None): """ Returns memory in BTree structure { file_1 : [process_1, process_2, ..., process_n], ... } Which describes that processes 1 to `n` is using file_1 """ memory = {} for process in Processes.all().owned_by(user).unique(): try: for file in process.files: if file in memory: memory[file].append(process) else: memory[file] = [process] except psutil.NoSuchProcess: pass except psutil.AccessDenied: pass return memory
def test_children(self): process = Processes.all()[0] children = process.children() self.assertIsInstance(children, ProcessesCollection) for child in children: self.assertIsInstance(child, Process)
def render_processes(self): view = ProcessesView() view.assign('processes', Processes.all()) view.render()
def test_processes_none_user(self): collection = Processes.all().owned_by(None) self.assertGreater(len(collection), 0)
def test_processes_types(self): collection = Processes.all() self.assertIsInstance(collection, ProcessesCollection) self.assertIsInstance(collection.owned_by('user'), ProcessesCollection) self.assertIsInstance(collection.newer_than(1414006430.1), ProcessesCollection)