当前位置: 首页>>代码示例>>Python>>正文


Python FileSystem.createFile方法代码示例

本文整理汇总了Python中FileSystem.FileSystem.createFile方法的典型用法代码示例。如果您正苦于以下问题:Python FileSystem.createFile方法的具体用法?Python FileSystem.createFile怎么用?Python FileSystem.createFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileSystem.FileSystem的用法示例。


在下文中一共展示了FileSystem.createFile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: UserSettings

# 需要导入模块: from FileSystem import FileSystem [as 别名]
# 或者: from FileSystem.FileSystem import createFile [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)
开发者ID:anconaesselmann,项目名称:LiveUnit,代码行数:31,代码来源:UserSettings.py

示例2: __init__

# 需要导入模块: from FileSystem import FileSystem [as 别名]
# 或者: from FileSystem.FileSystem import createFile [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:
#.........这里部分代码省略.........
开发者ID:anconaesselmann,项目名称:LiveUnit,代码行数:103,代码来源:TemplateFileCreator.py


注:本文中的FileSystem.FileSystem.createFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。