本文整理汇总了Python中FileSystem.FileSystem.isfile方法的典型用法代码示例。如果您正苦于以下问题:Python FileSystem.isfile方法的具体用法?Python FileSystem.isfile怎么用?Python FileSystem.isfile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileSystem.FileSystem
的用法示例。
在下文中一共展示了FileSystem.isfile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: UserSettings
# 需要导入模块: from FileSystem import FileSystem [as 别名]
# 或者: from FileSystem.FileSystem import isfile [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: UserSettingsSetter
# 需要导入模块: from FileSystem import FileSystem [as 别名]
# 或者: from FileSystem.FileSystem import isfile [as 别名]
class UserSettingsSetter():
def __init__(self, window, fileName, userInput, userInputCaption):
self.window = window
self.fileSystem = FileSystem()
self.fileName = fileName
self.userInput = userInput
self.userInputCaption = userInputCaption
self.callback = None
self.setUserSettings()
def setCallbackWhenFinished(self, callback):
self.callback = callback
def setUserSettings(self):
self.userSettings = UserSettings(self.fileName, self.fileSystem)
userSettingsExist = self.fileSystem.isfile(self.fileName)
self.userInputResponse = []
self.currentInput = 0
if userSettingsExist == True:
self.captureInput(self.userInputCaption[self.currentInput], "")
else:
print("Error trying to write to " + self.fileName)
def captureInput(self, caption, initial):
if self.currentInput != None:
self.inputPanelView = self.window.show_input_panel(
caption, initial,
self.settingEntered, self.settingEnteringChange, self.settingEnteringAbort
)
self.inputPanelView.set_name("InputPanel")
self.inputPanelView.settings().set("caret_style", "solid")
pass
def settingEntered(self, command_string):
self.userInputResponse.append(command_string)
self.currentInput += 1
if self.currentInput < len(self.userInput):
self.captureInput(self.userInputCaption[self.currentInput], "")
else:
for x in range(0,len(self.userInput)):
if len(self.userInputResponse[x]) > 0:
self.userSettings.set(self.userInput[x], self.userInputResponse[x])
view = self.window.active_view()
view.erase_status("InputPanel")
if self.callback is not None:
sublime.set_timeout(lambda: self.callback(), 100)
def settingEnteringChange(self, command_string):
view = self.window.active_view()
view.set_status("InputPanel", command_string)
def settingEnteringAbort(self):
self.userSettings.deleteAll()
view = self.window.active_view()
view.erase_status("InputPanel")