def copy(src, tgt, mkdirs=False): try: if mkdirs: Directory.make(File.getDirectory(tgt)) copyfile(src, tgt) except IOError as e: Error.handleException(e, True, True)
def deleteSafe(): try: for path in [ "./", "./Core", "./Plugin", "./Plugin/Analyzer", "./Plugin/Demo", "./Plugin/IO", "./Plugin/Test", "./Plugin/Translator" ]: Directory.delete("{0}/__pycache__".format(path)) for path in glob.glob("./Test/Tmp/*"): File.delete(File.getCanonicalPath(path)) except Exception as e: Error.handleException(e, True)
def create(forceDeleteIfExists=False): if Database.exists(): if forceDeleteIfExists: Database.drop() else: return Directory.make(Database.directory) try: Database.ODB.bind("sqlite", Database.path, create_db=True) except TypeError: pass else: Database.ODB.generate_mapping(create_tables=True) Database.ODB.disconnect()
def setContent(path, content, asJson=False, asBytes=False, mkdirs=False): try: if mkdirs: Directory.make(File.getDirectory(path)) if asJson: with open(path, "w", encoding="utf-8") as fd: json.dump(content, fd) elif asBytes: with open(path, "wb") as fd: fd.write(content) else: with open(path, "w", encoding="utf-8") as fd: fd.write(content) except IOError as e: Error.handleException(e, True, True)
def __initializeFramework(self): self.frameworkParams["projectID"] = self.getProjectID() self.frameworkParams["dataDir"] = "{0}/Data/{1}".format( self.installDir, self.getProjectID()) Directory.make(self.frameworkParams["dataDir"]) self.frameworkParams["originalPath"] = "{0}/original.txt".format( self.frameworkParams["dataDir"]) self.frameworkParams["inputPath"] = "{0}/input.txt".format( self.frameworkParams["dataDir"]) self.frameworkParams["analyzerPath"] = "{0}/analyzer.txt".format( self.frameworkParams["dataDir"]) self.frameworkParams["translatorPath"] = "{0}/translator.txt".format( self.frameworkParams["dataDir"]) self.frameworkParams["outputPath"] = "{0}/output.txt".format( self.frameworkParams["dataDir"]) self.frameworkParams["dateTime"] = datetime.datetime.now().isoformat()
def getSubresourceIntegrityHashes(displayValues=False): sriHashes = {} webDir = Framework.getWebDir() for subDir in ["Css", "Js"]: for path in Directory.getFiles("{0}/{1}".format(webDir, subDir)): sriHashes[path] = Security.getSubresourceIntegrityHash(path) if displayValues: print("\n{0}\n{1}\n".format(path, sriHashes[path]))
def getInstallDir(): return Directory.getCanonicalPath(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))