Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def ListFill():
- # Find the maximum length among the lists in data
- max_length = max(len(data[key]) for key in data)
- # Fill lists to the maximum length with empty strings
- for key in data:
- data[key] += [''] * (max_length - len(data[key]))
- def SelectionChecker(Selection):
- if os.path.isfile(Selection): return "File"
- elif os.path.islink(Selection): return "Link"
- elif os.path.isdir(Selection): return "Dir"
- else:
- try:
- # Use os.stat to access file metadata
- stat_info = os.stat(path)
- if stat_info.st_mode & 0o170000 == 0o020000: return "Character Device"
- elif stat_info.st_mode & 0o170000 == 0o060000: return "Block Device"
- else: return "Unknown"
- except Exception as e:
- return "Unknown"
- def SelectionFormat(SelectionName, SelectionType):
- if SelectionName in RestrictedDir: FormatOutput = SelectionName + "*Locked*"; return FormatOutput
- if SelectionType == "File": FormatOutput = SelectionName + ""; return FormatOutput
- if SelectionType == "Link": FormatOutput = "~" + SelectionName + "/"; return FormatOutput
- if SelectionType == "Dir": FormatOutput = SelectionName + "/"; return FormatOutput
- if SelectionType == "Character Device": FormatOutput = SelectionName + "CDCD"; return FormatOutput
- if SelectionType == "Block Device": FormatOutput = SelectionName + "BDBD"; return FormatOutput
- if SelectionType == "Unknown": FormatOutput = SelectionName + "/"; return FormatOutput
- def FileOpen(FileName):
- if FileName == 0:
- FileOutput = "~"
- #return FileOutput
- else:
- os.chdir("..")
- FileOutput = []
- encodings_to_try = ["utf-8", "latin-1", "iso-8859-1", "windows-1252"] # Add more encodings as needed
- for encoding in encodings_to_try:
- try:
- with open(FileName, "r", encoding=encoding) as file:
- for line in file:
- FileOutput.append(line)
- break # Stop trying encodings if successful
- except UnicodeDecodeError as e:
- # Handle the decoding error, for example, by skipping the problematic line
- FileOutput.append(f"Error decoding with {encoding}: {str(e)}")
- return FileOutput
- def SelectionOpen(Selection):
- SelectionName = Selection
- if SelectionName == 0:
- Output = "~"
- elif SelectionChecker(SelectionName) == "File" or SelectionChecker(SelectionName) == "None":
- Output = "Open Me"
- FileOpen(SelectionName)
- else:
- try:
- SelectionDir = os.listdir(SelectionName)
- SelectionType = SelectionChecker(SelectionName)
- Output = []
- for SelectionName in SelectionDir:
- SelectionType = SelectionChecker(SelectionName)
- SelectionOut = SelectionFormat(SelectionName, SelectionType)
- Output.append(SelectionOut)
- except Exception as e:
- SelectionName = SelectionName[:-1]
- FileOpen(SelectionName)
- Output = "Open Me!"
- if not Output: Output = "Empty"
- return Output
- "Functions"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement