2019-03-24 16:56:34 +03:00
|
|
|
import os
|
|
|
|
|
|
|
|
def instructions(keys):
|
|
|
|
|
2019-03-24 18:19:45 +03:00
|
|
|
html = "<table class='misc'>"
|
2019-03-24 16:56:34 +03:00
|
|
|
|
|
|
|
html += "<tr><th></th><th>Module</th><th>Author</th><th>Description</th></tr>"
|
|
|
|
|
2019-03-24 18:04:44 +03:00
|
|
|
|
|
|
|
validchars = "-_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
2019-03-24 16:56:34 +03:00
|
|
|
for f in os.listdir("rules/predefined"):
|
|
|
|
if f.endswith(".tsv"):
|
|
|
|
|
2019-03-24 18:04:44 +03:00
|
|
|
rawf = f.replace(".tsv","")
|
|
|
|
valid = True
|
|
|
|
for char in rawf:
|
|
|
|
if char not in validchars:
|
|
|
|
valid = False
|
|
|
|
break # don't even show up invalid filenames
|
|
|
|
|
|
|
|
if not valid: continue
|
|
|
|
if not "_" in rawf: continue
|
|
|
|
|
2019-03-24 16:56:34 +03:00
|
|
|
try:
|
|
|
|
with open("rules/predefined/" + f) as tsvfile:
|
|
|
|
line1 = tsvfile.readline()
|
|
|
|
line2 = tsvfile.readline()
|
|
|
|
|
|
|
|
if "# NAME: " in line1:
|
|
|
|
name = line1.replace("# NAME: ","")
|
2019-03-24 18:04:44 +03:00
|
|
|
else: name = rawf.split("_")[1]
|
2019-03-24 16:56:34 +03:00
|
|
|
if "# DESC: " in line2:
|
|
|
|
desc = line2.replace("# DESC: ","")
|
|
|
|
else: desc = ""
|
|
|
|
|
2019-03-24 18:04:44 +03:00
|
|
|
author = rawf.split("_")[0]
|
2019-03-24 16:56:34 +03:00
|
|
|
except:
|
|
|
|
continue
|
|
|
|
|
|
|
|
html += "<tr>"
|
|
|
|
|
|
|
|
if os.path.exists("rules/" + f):
|
2019-03-24 18:04:44 +03:00
|
|
|
html += "<td class='interaction' onclick=deactivateRuleModule(this,'" + rawf + "')><a class='textlink'>Remove:</a></td>"
|
2019-03-24 16:56:34 +03:00
|
|
|
else:
|
2019-03-24 18:04:44 +03:00
|
|
|
html += "<td class='interaction' onclick=activateRuleModule(this,'" + rawf + "')><a class='textlink'>Add:</a></td>"
|
2019-03-24 16:56:34 +03:00
|
|
|
html += "<td>" + name + "</td>"
|
|
|
|
html += "<td>" + author + "</td>"
|
|
|
|
html += "<td>" + desc + "</td>"
|
|
|
|
|
|
|
|
html += "</tr>"
|
|
|
|
html += "</table>"
|
|
|
|
|
|
|
|
|
|
|
|
pushresources = []
|
|
|
|
replace = {"KEY_PREDEFINED_RULESETS":html}
|
|
|
|
return (replace,pushresources)
|