本文整理汇总了Python中API.API.fileList方法的典型用法代码示例。如果您正苦于以下问题:Python API.fileList方法的具体用法?Python API.fileList怎么用?Python API.fileList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类API.API
的用法示例。
在下文中一共展示了API.fileList方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GUI
# 需要导入模块: from API import API [as 别名]
# 或者: from API.API import fileList [as 别名]
#.........这里部分代码省略.........
return index
# Mark the active selection in the listbox for deletion
def deleteFile(self):
# Get the index of the current active selection
index = self.currentSelectionIndex()
# Get the filename of the current active selection
filename = self.area.get(index)
# Call the API function to mark file for deletion
self.api.delete(filename)
# Change the background color of the selection to denote it has been marked for deletion
self.area.itemconfig(index, {"bg": "salmon"})
# Append the filename to the toDelete list
self.toDelete.append(filename)
# Unmarks the active selection in the listbox for deletion
def undeleteFile(self):
# Get the index of the current active selection
index = self.currentSelectionIndex()
# Get the filename of the current active selection
filename = self.area.get(index)
# See if the file has been marked for deletion
if filename in self.toDelete:
# Call the API function to unmark file for deletion
self.api.undelete(filename)
# Change the background color of the selection to denote it is no longer marked for deletion
self.area.itemconfig(index, {"bg": "white"})
# Remove the filename from the toDelete list
self.toDelete.remove(filename)
# Upload a file from local machine to the distributed file system
def uploadFile(self):
# Get the file name and file path of the file the user wants to upload
fileinfo = self.openFile()
# Create a file with the filename provided
self.api.create(fileinfo[0])
# Append the file data from the file at the given file path
self.api.append(fileinfo[0], fileinfo[1], 1)
# Once that is complete, refresh the file list in the listbox
self.getFiles()
# Prompt the user to select a file
def openFile(self):
# Prompt the user to select a file, and store the returned file path
filepath = tkFileDialog.askopenfilename(**self.file_opt)
# Parse the filepath, and store the last element of the split as the file name
filename = filepath.split("/")[-1]
# Return a list containing the file name and file path
return [filename, filepath]
# Get the list of existing files from the master server
def getFiles(self):
try:
# Get the file data using the API's fileList() function
# At this stage, the data has lots of extra things in it, so it needs to be cleaned up
data = self.api.fileList()
# Split the string at every * character
data = re.split("\*", data)
# Declare an empty array which will hold the file names found from the parsing
fileNames = []
for item in data:
# Split the element at every ^ character
tempitem = re.split("\^", item)
for thing in tempitem:
# If the element has a | in it, but is not just a |, then it is the filename
if "|" in thing and not thing == "|":
# Append the filename (with the | stripped out) to the fileNames list
fileNames.append(thing.strip("|"))
# If the file is marked for deletion and still in the fileNames list
# keep the file in the toDelete list
temp = []
for item in self.toDelete:
if item in fileNames:
temp.append(item)
# Update the toDelete list
self.toDelete = temp
# Remove all entries in the listbox
self.area.delete(0, END)
# Populate the listbox with the file names returned from the master
for item in fileNames:
self.area.insert(END, item)
self.checkIfMarked(item)
except Exception as e:
raise e
# Check to see if the provided file name exists in the toDelete list
def checkIfMarked(self, fileName):
# If the file name is in the toDelete list
if fileName in self.toDelete:
# Change the background color of the element to denote that it has been marked for deletion
self.area.itemconfig(END, {"bg": "salmon"})
# An exit function that quits the UI (any additional clean up pre-close should go in here)
def exitProgram(self):
self.quit()