def google(self, menuItem, pid): try: webbrowser.open("https://google.com/search?q=Mac process '%s'" % process.get_name(pid)) log.log("Google process %d (%s)" % (pid, process.get_name(pid))) except: error.error("Error in menu callback") finally: self.handle_action()
def suspend_process(pid, manual=False): name = process.get_name(pid) if process.suspend_pid(pid): suspended_tasks.add((pid, name)) if manual: set_suspend_preference(name, True) else: set_suspend_preference(name, False)
def resume_process(pid, manual=False): name = process.get_name(pid) if manual or (pid,name) in suspended_tasks: if process.resume_pid(pid): for pid, suspended_name in list(suspended_tasks): if name == suspended_name: suspended_tasks.remove((pid, name)) if manual: set_suspend_preference(name, "")
def suspend_process(pid, manual=False, battery=False): name = process.get_name(pid) if manual: set_suspend_preference(name, SUSPEND_ON_BATTERY if battery else SUSPEND_ALWAYS) if battery and not process.on_battery(): return if process.suspend_pid(pid): suspended_tasks.add((pid, name)) else: set_suspend_preference(name, "")
def menu_item_for_process(self, p, resumable=False, suspendable=False): if not p: return None name = process.get_name(p.pid) cpu = process.cpu(p.pid) percent = max(0 if resumable else 1, int(100 * cpu)) if p.pid != utils.get_current_app_pid() and not resumable and percent < IDLE_PROCESS_PERCENT_CPU: return None item = rumps.MenuItem("%s - %d%%" % (name, percent)) item.icon = self.get_icon(percent) item.percent = percent item.pid = p.pid item.add(rumps.MenuItem(TITLE_GOOGLE, callback=functools.partial(self.google, pid=p.pid))) if resumable: item.add(rumps.MenuItem(TITLE_RESUME, callback=functools.partial(self.resume, pid=p.pid))) elif suspendable: item.add(rumps.MenuItem(TITLE_SUSPEND, callback=functools.partial(self.suspend, pid=p.pid))) item.add(rumps.MenuItem(TITLE_TERMINATE, callback=functools.partial(self.terminate, pid=p.pid))) return item
def get_suspend_preference(pid): return preferences.get("suspend - %s" % process.get_name(pid))
# similar_true_positive_count = {"PER": 0, "RAN": 0, "ORG": 0, "TIT": 0, "ROL": 0, "LOC": 0} # similar_false_positive_count = {"PER": 0, "RAN": 0, "ORG": 0, "TIT": 0, "ROL": 0, "LOC": 0} # similar_false_negative_count = {"PER": 0, "RAN": 0, "ORG": 0, "TIT": 0, "ROL": 0, "LOC": 0} for line in test_lines: sentence = line.strip() id, s_position = dataset_sentences[sentence] print('=================================================') print("From file with id: ", id) print("Sentence: ") pp.pprint(sentence) print('\n-------------- Ground truth --------------') ground_truth_names = [] ground_truth_tags = [] for label in dataset_labels[id][s_position]: gt_name = process.get_name(sentence, label) ground_truth_names.append(tokenizer(gt_name)) ground_truth_tags.append(label_mapping[label[1]]) print(ground_truth_names[-1], "||||", label[1], "||||", label[2]) # print(ground_truth_names) print('\n-------------- Predicted labels --------------') pred_names = [] pred_tags = [] for name_position in sentence_pred_tags[sentence].keys(): pred_name = sentence[name_position[0]:name_position[1]] pred_names.append(tokenizer(pred_name)) # pred_names.append(pred_name) pred_tags.append(sentence_pred_tags[sentence][name_position]) print(pred_names[-1], "||||", inv_label_mapping[pred_tags[-1]], "||||", name_position)