本文整理汇总了Python中FileSystem.FileSystem.getFileContent方法的典型用法代码示例。如果您正苦于以下问题:Python FileSystem.getFileContent方法的具体用法?Python FileSystem.getFileContent怎么用?Python FileSystem.getFileContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileSystem.FileSystem
的用法示例。
在下文中一共展示了FileSystem.getFileContent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: UserSettings
# 需要导入模块: from FileSystem import FileSystem [as 别名]
# 或者: from FileSystem.FileSystem import getFileContent [as 别名]
class UserSettings():
def __init__(self, fileName=None, fileSystem=None):
if fileSystem is not None:
self.fileSystem = FileSystem()
self._settingsVariables = dict()
if fileName is not None:
self.setFile(fileName)
def set(self, variable, value):
self._settingsVariables[variable] = value
settingsNewContent = json.dumps(self._settingsVariables)
return self.fileSystem.replaceFile(self.fileName, settingsNewContent)
def get(self, variableName):
return self._settingsVariables[variableName]
def deleteAll(self):
self.fileSystem.remove(self.fileName)
def setFile(self, fileName):
self.fileName = fileName
userSettingsExist = self.fileSystem.isfile(fileName)
if userSettingsExist != True:
settingsContent = "{\n}"
created = self.fileSystem.createFile(fileName, settingsContent)
else:
settingsContent = self.fileSystem.getFileContent(self.fileName)
self._settingsVariables = json.loads(settingsContent)
示例2: __init__
# 需要导入模块: from FileSystem import FileSystem [as 别名]
# 或者: from FileSystem.FileSystem import getFileContent [as 别名]
class TemplateFileCreator:
def __init__(self, fileName = "", defaultFileExtension = ""):
self._settings = None
self.fileSystem = FileSystem()
self._fileComponents = MirroredDirectory()
self.importer = Importer()
self._templateDir = None
self.set(fileName, defaultFileExtension)
def set(self, fileName, defaultFileExtension = ""):
if DEBUG: print("TemplateFileCreator: setting dir to: '" + fileName + "'")
self._fileComponents.set(fileName)
if DEBUG: print("TemplateFileCreator: dir set to: '" + str(self._fileComponents.getOriginalFileName()) + "'")
self._cursors = []
def createFromTemplate(self):
templatePath = os.path.join(self.getTemplateDir(), self._fileComponents.getExtension(), self.classifyKind() + ".template")
variablePath = os.path.join(self.getTemplateDir(), self._fileComponents.getExtension(), self.classifyKind() + ".variables")
functionPath = os.path.join(self.getTemplateDir(), self._fileComponents.getExtension(), "functions.py")
templateContent = self.fileSystem.getFileContent(templatePath)
variableContent = self.fileSystem.getFileContent(variablePath)
functionCollectionObject = self.importer.getObjectInstance(functionPath, "FunctionCollection")()
content = self.getReplacementContent(templateContent, variableContent,
functionCollectionObject)
if DEBUG: print("TemplateFileCreator: creating file: " + self._fileComponents.getOriginalFileName())
return self.fileSystem.createFile(self._fileComponents.getOriginalFileName(), content)
def setBasePath(self, basePath):
self._fileComponents.setBasePath(basePath)
def setSettings(self, settings):
self._settings = settings
def setTemplateDir(self, templateDir):
self._templateDir = templateDir
def getCursors(self):
return self._cursors
def getFileName(self):
return self._fileComponents.getOriginalFileName()
def setDefaultExtension(self, fileExtension):
self._fileComponents.setDefaultExtension(fileExtension)
def getArgsDictFromVarContent(self, VarContent):
result = dict()
try:
varDictionary = ast.literal_eval(VarContent)
except:
raise TypeError("the content of VarContent could not be converted to a dict.")
for templateVar in varDictionary:
variableName = templateVar["variable"]
settingsValues = dict()
if "fromSettings" in templateVar:
for settingsVariable in templateVar["fromSettings"]:
settingsValues[settingsVariable] = self._settings.get(settingsVariable)
args = dict()
args["settings"] = str(settingsValues)
args["name"] = variableName
args["dir"] = self._fileComponents.getFileName()
#args["basePath"] = ""
args["command"] = templateVar["command"]
result[variableName] = args
return result
"""def getReplacements(self, args, functionCollectionObject):
# TODO: this check has loopholes...
if isinstance(functionCollectionObject, (int, float, complex, str)) or functionCollectionObject is None:
raise Exception("The functionCollectionObject argument must be an instance of an object, " + str(type(functionCollectionObject)) + " passed instead.")
result = dict()
for name, arg in Std.getIterItems(args):
function = getattr(functionCollectionObject, arg["command"])
result["/* @" + name + " */"] = function(arg)
return result"""
def getReplacements(self, args, functionCollectionObject):
# TODO: this check has loopholes...
if isinstance(functionCollectionObject, (int, float, complex, str)) or functionCollectionObject is None:
raise Exception("The functionCollectionObject argument must be an instance of an object, " + str(type(functionCollectionObject)) + " passed instead.")
result = dict()
for name, arg in Std.getIterItems(args):
function = getattr(functionCollectionObject, arg["command"])
result["/* @" + name + " */"] = function(arg)
return result
def getCursorsFromContent(self, templateContent):
lines = templateContent.splitlines()
cursorString = "/* @cursor */"
lineNbr = 0
cursors = []
for line in lines:
while cursorString in line:
#.........这里部分代码省略.........
示例3: LiveUnitTesting
# 需要导入模块: from FileSystem import FileSystem [as 别名]
# 或者: from FileSystem.FileSystem import getFileContent [as 别名]
class LiveUnitTesting():
def __init__(self, commandFolders):
if not isinstance(commandFolders, dict):
raise Exception("CommandFolders is a dictionary")
self._commandFolders = commandFolders
self._lastModTempFile = None
self.fileSystem = FileSystem()
def updateTempFiles(self, currentView):
self._setActiveFile(currentView)
if self._activeFile.getExtension() in self._commandFolders:
lastModTempFile = os.stat(self._activeFile.getTestFileName()).st_mtime
if lastModTempFile != self._lastModTempFile:
currentTestFileContent = self.fileSystem.getFileContent(self._activeFile.getTestFileName())
self._saveToTempTestFile(currentTestFileContent)
self._lastModTempFile = lastModTempFile
if self._activeFile.getKind() == self._activeFile.KIND_IS_CLASS:
curentViewContent = SublimeFunctions.getViewContent(currentView)
self._saveToTempClassFile(curentViewContent)
def getCommand(self):
extension = self._activeFile.getExtension()
if extension == "php":
result = os.path.join(os.path.normpath(self._commandFolders["php"]), "phpunit")
elif extension == "py":
result = os.path.join(os.path.normpath(self._commandFolders["py"]), "python")
elif extension == "js":
result = UnitTestFunctions.getCommand(extension)
else:
result = None
return result
def getArgument(self):
return self._getTempTestFileDir()
def getActiveFile(self):
return self._activeFile
def _setActiveFile(self, currentView):
md = MirroredDirectory()
md.fileSystem = self.fileSystem
md.set(currentView.file_name())
self._activeFile = md
def _getTempFileDir(self):
folderName, completeFileName = os.path.split(self._activeFile.getFileName())
fileName, extension = os.path.splitext(completeFileName)
return os.path.join(folderName, "____liveUnitTesting_" + fileName + extension)
def _getTempTestFileDir(self):
folderName, completeFileName = os.path.split(self._activeFile.getTestFileName())
fileName, extension = os.path.splitext(completeFileName)
return os.path.join(folderName, "____liveUnitTesting_" + fileName + extension)
def _saveToTempClassFile(self, curentViewContent):
extension = self._activeFile.getExtension()
self.fileSystem.replaceFile(self._getTempFileDir(), curentViewContent)
def _saveToTempTestFile(self, testFileContent):
self.fileSystem.replaceFile(self._getTempTestFileDir(), testFileContent)
extension = self._activeFile.getExtension()
if extension == "php":
self._replacePhpTestFileLoadingStatements()
elif extension == "py":
self._replacePyTestFileLoadingStatements()
else:
pass
def _replacePhpTestFileLoadingStatements(self):
injected = False
for line in fileinput.input(self._getTempTestFileDir(), inplace=True):
sys.stdout.write(line)
if not injected:
if "require_once" in line:
sys.stdout.write("\trequire_once \"" + self._getTempFileDir() + "\";")
injected = True
def _replacePyTestFileLoadingStatements(self):
folderName, completeFileName = os.path.split(self._activeFile.getFileName())
fileName, extension = os.path.splitext(completeFileName)
newModule = "____liveUnitTesting_" + fileName
replacementMade = False
for line in fileinput.input(self._getTempTestFileDir(), inplace=True):
if replacementMade == False and "import "in line:
if fileName in line:
pos = line.find(fileName)
partialString = line[:pos]
regexString = "\\S+$"
match = re.search(regexString, partialString)
if match:
parentPackages = match.group()
else:
parentPackages = ""
if len(parentPackages) > 0 and parentPackages[-1] == ".":
newModule = parentPackages + newModule
line = "from " + newModule + " import *\n"
#.........这里部分代码省略.........