def writedb(root): rough_string = ElementTree.tostring(root, 'utf-8').decode("utf-8").replace("\n", "").replace("\t", "").replace(" ", "").replace(" ", "").encode("utf-8") reparsed = minidom.parseString(rough_string) clean = reparsed.toprettyxml(indent="\t") f = open(getpath.core()+"module_database.xml", "w") f.write(clean) f.close()
def addtodb(modadd): xml = moddbparser.parsemoddb() root = xml[0] tree = xml[1] new = True newcat = True for category in root: if category.tag == "category": for item in category: if item.tag == "module" and item.attrib["name"] == modadd.conf[ "name"]: for info in item: if info.tag == "shortdesc": info.text = modadd.conf["shortdesc"] new = False tree.write(getpath.core() + "module_database.xml") printSuccess("database updated") return if new == True: printInfo(modadd.conf["name"] + " doesn't exist in database\n", start="\n") print("available categories keys:" + colors.yellow) for category in root: if category.tag == "category": print(category.attrib["key"]) print(colors.end, end="") catkey = input("\nGive new or exist key? ") for category in root: if category.tag == "category" and category.attrib["key"] == catkey: module = ElementTree.Element("module") shortdesc = ElementTree.Element("shortdesc") shortdesc.text = modadd.conf["shortdesc"] module.set("name", modadd.conf["name"]) module.append(shortdesc) category.append(module) writedb(root) newcat = False printSuccess("Module added to " + category.attrib["name"]) break if newcat == True: printInfo("Category not found!") printInfo("Going to add new category...") catname = input("Give new category name: ") newcat = ElementTree.Element("category") newcat.set("name", catname) newcat.set("key", catkey) module = ElementTree.Element("module") shortdesc = ElementTree.Element("shortdesc") shortdesc.text = modadd.conf["shortdesc"] module.set("name", modadd.conf["name"]) module.append(shortdesc) newcat.append(module) root.append(newcat) writedb(root) printSuccess("New category created!") printSuccess("Module added to " + newcat.attrib["name"])
def compile_core(): core = glob.glob(getpath.core()+"*.py") print(colors.green+'\ntesting core...\n'+colors.green) for item in core: print(colors.yellow+'compiling',item+colors.green) py_compile.compile(item)
def addtodb(modadd): xml = moddbparser.parsemoddb() root = xml[0] tree = xml[1] new = True newcat = True for category in root: if category.tag == "category": for item in category: if item.tag == "module" and item.attrib["name"] == modadd.conf["name"]: for info in item: if info.tag == "shortdesc": info.text = modadd.conf["shortdesc"] new = False tree.write(getpath.core()+"module_database.xml") printSuccess("database updated") return if new == True: printInfo(modadd.conf["name"]+" doesn't exist in database\n", start="\n") print("available categories keys:"+colors.yellow) for category in root: if category.tag == "category": print(category.attrib["key"]) print(colors.end, end="") catkey = input("\ngive new or exist key? ") for category in root: if category.tag == "category" and category.attrib["key"] == catkey: module = ElementTree.Element("module") shortdesc = ElementTree.Element("shortdesc") shortdesc.text = modadd.conf["shortdesc"] module.set("name", modadd.conf["name"]) module.append(shortdesc) category.append(module) writedb(root) newcat = False printSuccess("module added to "+category.attrib["name"]) break if newcat == True: printInfo("category not found") printInfo("going to add new category") catname = input("give new category name: ") newcat = ElementTree.Element("category") newcat.set("name", catname) newcat.set("key", catkey) module = ElementTree.Element("module") shortdesc = ElementTree.Element("shortdesc") shortdesc.text = modadd.conf["shortdesc"] module.set("name", modadd.conf["name"]) module.append(shortdesc) newcat.append(module) root.append(newcat) writedb(root) printSuccess("new category created") printSuccess("module added to "+newcat.attrib["name"])
def check_cmethods(): print(colors.green+"\ntesting cmethods...\n"+colors.end) fcm = open(getpath.core()+"cmethods.py", "r") linenum = 1 for line in fcm: if "self" not in line and "def " in line or "args" not in line and "def " in line: if "__init__" not in line and "mcu" not in line and "#" not in line: print("\033[1;31m[-]\033[0m error in line "+str(linenum)+":\n"+colors.end) print(colors.red+line+colors.end) testfailed() linenum += 1
def check_cmethods(): print(colors.green+"\ntesting cmethods...\n"+colors.end) fcm = open(getpath.core()+"cmethods.py", "r") linenum = 1 for line in fcm: if "self" not in line and "def " in line or "args" not in line and "def " in line: if "__init__" not in line and "mcu" not in line and "#" not in line: print(colors.red+"error in line "+str(linenum)+":\n"+colors.end) print(colors.red+line+colors.end) testfailed() linenum += 1
def parsemoddb(): tree = ET.parse(getpath.core() + "module_database.xml") root = tree.getroot() return root, tree
def addtodb(modadd): xml = moddbparser.parsemoddb() root = xml[0] tree = xml[1] new = True newcat = True for category in root: if category.tag == "category": for item in category: if item.tag == "module" and item.attrib["name"] == modadd.conf["name"]: for info in item: if info.tag == "shortdesc": info.text = modadd.conf["shortdesc"] new = False tree.write(getpath.core()+"module_database.xml") printSuccess("database updated") return if new == True: printInfo("Module "+modadd.conf["name"]+" doesn't exist in modules database!") printInfo("Going to add this module to modules database...") dome = input(colors.purple+"Add module to [old/new] "+colors.end) if dome == "old": pass if dome == "new": printInfo("Going to add new category...") catname = input(colors.purple+"Category: "+colors.end) newcat = ElementTree.Element("category") newcat.set("name", catname) newcat.set("key", catname) module = ElementTree.Element("module") shortdesc = ElementTree.Element("shortdesc") shortdesc.text = modadd.conf["shortdesc"] module.set("name", modadd.conf["name"]) module.append(shortdesc) newcat.append(module) root.append(newcat) writedb(root) printSuccess("New category created!") printSuccess("Module added to "+newcat.attrib["name"]) return print(colors.purple+"Categories:"+colors.yellow) for category in root: if category.tag == "category": print(category.attrib["key"]) print(colors.end, end="") catkey = input(colors.purple+"Category: "+colors.end) for category in root: if category.tag == "category" and category.attrib["key"] == catkey: module = ElementTree.Element("module") shortdesc = ElementTree.Element("shortdesc") shortdesc.text = modadd.conf["shortdesc"] module.set("name", modadd.conf["name"]) module.append(shortdesc) category.append(module) writedb(root) newcat = False printSuccess("Module added to "+category.attrib["name"]) break if newcat == True: printInfo("Category not found!") printInfo("Going to add new category...") catname = input(colors.purple+"Category: "+colors.end) newcat = ElementTree.Element("category") newcat.set("name", catname) newcat.set("key", catkey) module = ElementTree.Element("module") shortdesc = ElementTree.Element("shortdesc") shortdesc.text = modadd.conf["shortdesc"] module.set("name", modadd.conf["name"]) module.append(shortdesc) newcat.append(module) root.append(newcat) writedb(root) printSuccess("New category created!") printSuccess("Module added to "+newcat.attrib["name"])
def parsemoddb(): tree = ET.parse(getpath.core()+"module_database.xml") root = tree.getroot() return root, tree