def kill_enqueue(paths): global kill_queue kill_format = config.get("kill").split() if len(kill_format) < 2: #complain() #TODO: create complain return recursive, pid = kill_format[:2] recursive = False if recursive == 'norecursive' else True #default is 'recursive' for path in paths: if path not in kill_queue and status.exists(path): pids = OrderedDict({}) kf_pids = kill_format[1:] for pid in kf_pids: val_pid = status.get_from_key(pid, "paths", path) if val_pid is not None: pids.update({pid: val_pid}) kill_queue.update({path: pids}) [kill_process(v.popitem(0)[1]) for k, v in kill_queue.items() if v] non_empty_kill_queue = {} #this queue filters empty items from kill_queue for k, v in kill_queue.items(): if not v: update_view_lst(path, underline=False) status.remove(k) continue non_empty_kill_queue.update({k: v}) kill_queue = non_empty_kill_queue
def get_paths(): provider_type = config.get("provider_type") if provider_type == "glob": program_paths = glob(config.get("glob")) elif provider_type == "script": provider_script = config.get("script") import importlib.util #https://stackoverflow.com/a/67692/6420136 spec = importlib.util.spec_from_file_location("*", provider_script) foo = importlib.util.module_from_spec(spec) try: spec.loader.exec_module(foo) except FileNotFoundError: return [ f"[Invalid provider script {provider_script}!", "Please make sure the path is correct.]" ] program_paths = foo.main() return program_paths
def main(stdscr): curs_set(0) stdscr.keypad(True) # initilize color start_color() init_pair(1, COLOR_BLACK, COLOR_CYAN) init_pair(2, COLOR_BLACK, COLOR_BLUE) init_pair(3, COLOR_CYAN, COLOR_BLUE) # Clear screen stdscr.clear() paths = provider.get_paths() inc_text = config.get("indicator_text") + " " lendinc = len(inc_text) view_list.init(stdscr, 0, 0, paths, inc_text)
def execute(path): command = generate_command(path) filedir = config.get("output_dir") if not os.path.exists(filedir): os.mkdir(filedir) filename = filedir + generate_stdout_file() fileobject = open(filename, 'w', 1) #TODO: if program crashes show it on view output not all over file (check by running a program which crashes) #proc = subprocess.Popen(shlex.split(command), stdout=fileobject, stderr=fileobject) proc = subprocess.Popen(command, shell=True, stdout=fileobject, stderr=fileobject) pid = proc.pid update_view_lst(path, underline=True) status.add(path, pid, filename) execute_dequeue([path])
def kill_enqueue_old(paths): global kill_queue kill_format = config.get("kill").split() if len(kill_format) < 2: #complain() #TODO: create complain return recursive, pid = kill_format[:2] recursive = False if recursive == 'norecursive' else True #default is 'recursive' for path in paths: if path not in kill_queue and status.exists(path): pids = OrderedDict({}) kf_pids = kill_format[1:] for pid in kf_pids: pf_pid = split('[:|-]', pid) pflen = len(pf_pid) pid, *pf_extra = pf_pid val_pid = status.get_from_key(pid, "paths", path) pf_recursive, *pf_remove = pf_extra val = (val_pid, True if pf_recursive == "norecursive" else False, True if pf_remove else False) if pf_extra else ( val_pid, recursive, False) if val_pid is not None: pids.update({pid: val}) # sys.stdout.write(f"kf_pids: {kf_pids}, kill_queue: {kill_queue}, pid: {pid}, path: {path}, val_pid: {val_pid}") kill_queue.update({path: pids}) non_empty_kill_queue = {} #this queue filters empty items from kill_queue for k, v in kill_queue.items(): pid, recursive, remove = v.popitem(0)[1] kill_process(pid, recursive) if any([remove, not v]): update_view_lst(path, underline=False) status.remove(k) continue non_empty_kill_queue.update({k: v}) kill_queue = non_empty_kill_queue
def generate_command(path): command = config.get("executor_path") + " " + path return command
import json import configurer as config SFILE = config.get("status") def write(status): with open(SFILE, 'w') as f: json.dump(status, f, indent=4) def clear(): write({}) return {} def read(): try: with open(SFILE, 'r') as f: return json.load(f) except json.JSONDecodeError: return {} except FileNotFoundError: return clear() def add(path, pid, stdout): status = read() status.update({path: {"pid": pid, "stdout": stdout}})