This repository was archived by the owner on Oct 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbin_launcher.py
More file actions
118 lines (91 loc) · 3.23 KB
/
bin_launcher.py
File metadata and controls
118 lines (91 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
from . import commands
import os
class BinaryRunner(commands.BaseCommand):
"""
Simple binary file manager.
The system is run around the env variable PATHS. All the bins used are read from that.
Format: bin <subcommand> <args>
Sub Commands:
bin ignore path <path>
Adds a PATH to ignores so it doesnt show up in the listing.
bin unignore path <path>
Undo's the above.
bin list paths
Shows all available directories in PATH.
Gives each path an ID number that is used for the command below.
bin list bins [arg]
If arg supplied is a number, lists all bins in the directory matching the ID number from the list.
If arg is a string, attempts to find a directory matching it, and then lists the bins in that directory.
If no arg is supplied, lists ALL bins in ALL paths.
bin run <arg>
Finds if the arg exists in the paths, and runs it.
"""
def __init__(self, host):
super().__init__(host)
#self.phrases = [self.message("bin"), self.message("brun")]
self.addListener("bin")
self.addListener("brun")
self.inter = True
def onStart(self):
self.paths_list = []
self.paths_raw = os.environ['PATH']
self.paths_list = self.paths_raw.split(":")
self.ignored = self.host.config._get('bin_ignored_paths')
if not self.ignored:
self.host.config._set('bin_ignored_paths', [])
for item in self.paths_list:
if item in self.ignored:
self.paths_list.remove(item)
def onTrigger(self, value=""):
if value.startswith("ignore path "):
value = value[12:]
for item in self.paths_list:
if value == item:
self.ignored.append(value)
self.host.config._set('bin_ignored_paths', self.ignored)
return self.message(f"Ignored path {value}")
return self.message(f"Failed to ignore path {value}")
elif value.startswith("unignore path "):
value = value[14:]
for item in self.ignored:
if value == item:
self.ignored.remove(value)
self.host.config._set('bin_ignored_paths', self.ignored)
return self.message(f"Unignored path {value}")
return self.message(f"Failed to unignore path {value}")
elif value == "list paths":
s = ""
for item in self.paths_list:
s += f" [ {self.host.colours.F_Yellow}{self.paths_list.index(item)}{self.host.reset_f} ] {item}\n"
return self.output(s[:-1])
elif value.startswith("list bins "):
target = value[10:]
if target.isdigit():
path = self.paths_list[int(target)]
s = f" - Files in {path} -\n"
for file in os.listdir(path):
filename = os.fsdecode(file)
s += f" {filename}\n"
return self.output(s[:-1])
else:
path = ""
for item in self.paths_list:
print(f"Does {item} start with {target}")
if item.startswith(target):
print("Yes!")
path = item
if path == "":
return self.message("Incorrect path.")
s = f" - Files in {path} -\n"
for file in os.listdir(path):
filename = os.fsdecode(file)
s += f" {filename}\n"
return self.output(s[:-1])
elif value.startswith("list bins"):
s = "Not ready yet\n"
return self.output(s[:-1])
elif value.startswith("run "):
print(value)
value = value[4:]
print(value)
os.system(f'{value}*&')