def remove(self): if not os.path.isdir(self.enginePath): return Fail( FileSystemError("Engine \"%s\" does not exist." % self.name)) if self.isProvisioned(): return Fail( EngineProvisioned("Engine \"%s\" is provisioned." % self.name)) return Shell.nukeDirectory(self.enginePath)
def readSupportFile(filename): try: keyfile = getSupportFile(filename) with open(keyfile, "r") as fileh: keydata = fileh.read() return keydata except IOError as err: raise FileDoesNotExist("File not found: %s" % keyfile) except Exception as err: raise FileSystemError("Failed to read: %s" % keyfile)
def readYAML(filename): try: with open(filename, "r") as stream: contents = yaml.load(stream, Loader=yaml.SafeLoader) return contents except yaml.YAMLError as exc: msg = "Syntax error in file %s" if hasattr(exc, 'problem_mark'): mark = exc.problem_mark msg += " Error position: (%s:%s)" % (mark.line + 1, mark.column + 1) raise ConfigSyntaxError(msg) except Exception as err: raise FileSystemError("Failed to read configuration file %s : %s" % (filename, err))
def rmFile(path): if os.path.isdir(path): return Fail(FileSystemError("%s is a directory.") % path) return OK(os.remove(path))
def pathExists(path): return OK(path) if os.path.exists(path) else Fail( FileSystemError("Path %s does not exist." % path))
def writeYAML(filename, data): try: with open(filename, "w") as fileh: fileh.write(yaml.dump(data, default_flow_style=False)) except Exception as err: raise FileSystemError("Failed to write to %s : %s" % (filename, err))
def writeToFile(filename, data): try: with open(filename, "wb") as fh: fh.write(data) except Exception as err: raise FileSystemError("Failed to write to %s : %s" % (filename, err))
def readYAML(filename): try: stream = open(filename, "r") contents = yaml.load(stream) return contents except yaml.YAMLError, exc: msg = "Syntax error in file %s" if hasattr(exc, 'problem_mark'): mark = exc.problem_mark msg += " Error position: (%s:%s)" % (mark.line + 1, mark.column + 1) raise ConfigSyntaxError(msg) except Exception as err: raise FileSystemError( "Failed to read configuration file %s : %s" % (filename, err)) def getSupportFile(filename): return resource_filename(Requirement.parse('substance'), filename) def getPackageVersion(): return require('substance')[0].version def readSupportFile(filename): try: keyfile = getSupportFile(filename) with open(keyfile, "r") as fileh: keydata = fileh.read()