def processCommandLineArgs(args): """Checks what is in the command line""" # I cannot import it at the top because the fileutils want # to use the pixmap cache which needs the application to be # created, so the import is deferred from utils.fileutils import (isFileOpenable, getFileProperties, isCDMProjectMime) if not args: return None # Check that all the files exist for fName in args: if not os.path.exists(fName): raise Exception("Cannot open file: " + fName) if not os.path.isfile(fName): raise Exception("The " + fName + " is not a file") if not isFileOpenable(fName): raise Exception("The file " + fName + " could not be opened") if len(args) == 1: mime, _, _ = getFileProperties(args[0]) if isCDMProjectMime(mime): return args[0] return None # There are many files, check that they are python only for fName in args: mime, _, _ = getFileProperties(fName) if isCDMProjectMime(mime): raise Exception("Codimension project file (" + fName + ") must not come " "together with other files") return None
def processCommandLineArgs(self): """Checks what is in the command line""" # I cannot import it at the top because the fileutils want # to use the pixmap cache which needs the application to be # created, so the import is deferred from utils.fileutils import getFileProperties, isCDMProjectMime if self.__args: totalArgs = len(self.__args) goodArgs = [] for fName in self.__args: if self.isOpenable(fName): goodArgs.append(fName) self.__args = goodArgs if totalArgs == 1 and len(self.__args) == 1: mime, _, _ = getFileProperties(self.__args[0]) if isCDMProjectMime(mime): return self.__args[0] # Check that the is no project file because it can only come alone for fName in self.__args: mime, _, _ = getFileProperties(fName) if isCDMProjectMime(mime): raise Exception('A Codimension project file (' + fName + ') must not come ' 'together with other files') return None
def onFileUpdated(self, fileName, uuid): """Triggered when the file is updated""" del uuid # unused argument mime, icon, _ = getFileProperties(fileName) if isPythonMime(mime): path = os.path.realpath(fileName) info = GlobalData().briefModinfoCache.get(path) if info.isOK: icon = getIcon('filepython.png') else: icon = getIcon('filepythonbroken.png') # For all root items for treeItem in self.model().sourceModel().rootItem.childItems: self.__walkTreeAndUpdate(treeItem, path, mime, icon, info) elif isCDMProjectMime(mime): path = os.path.realpath(fileName) # For all root items for treeItem in self.model().sourceModel().rootItem.childItems: self.__walkTreeAndUpdate(treeItem, path, mime, None, None) elif fileName.endswith(".cgi"): path = os.path.realpath(fileName) # For all root items for treeItem in self.model().sourceModel().rootItem.childItems: self.__walkTreeAndUpdate(treeItem, path, mime, icon, None)
def __walkTreeAndUpdate(self, treeItem, path, mime, icon, info): """Recursively walks the tree items and updates the icon""" if treeItem.itemType in [DirectoryItemType, SysPathItemType]: for i in treeItem.childItems: if i.itemType in [ DirectoryItemType, SysPathItemType, FileItemType ]: self.__walkTreeAndUpdate(i, path, mime, icon, info) if treeItem.itemType == FileItemType: if path == os.path.realpath(treeItem.getPath()): if isPythonMime(mime) and info: # Update icon treeItem.setIcon(icon) if info.docstring is None: treeItem.toolTip = "" else: treeItem.toolTip = info.docstring.text treeItem.parsingErrors = not info.isOK self._signalItemUpdated(treeItem) # Update content if populated self.updateFileItem(treeItem, info) elif isCDMProjectMime(mime): # Tooltip update only treeItem.toolTip = getProjectFileTooltip(path) self._signalItemUpdated(treeItem) elif path.endswith(".cgi"): # It can only happened when python CGI is not a python any # more. So display it as a general file. # The case when a cgi became a python file is covered in # the first branch of this if statement. treeItem.setIcon(icon) treeItem.toolTip = "" self._signalItemUpdated(treeItem) # Remove child items if so while treeItem.childItems: self.__removeTreeItem(treeItem.childItems[0]) else: treeItem.setIcon(icon) treeItem.toolTip = "" self._signalItemUpdated(treeItem)
def __init__(self, parent, path): path = str(path) TreeViewItem.__init__(self, parent, os.path.basename(path)) self.itemType = FileItemType self.parsingErrors = False # Used for python files only self.isLink = False self.fileType, self.icon, _ = getFileProperties(path) if self.fileType is None: if self.icon is None: self.icon = getIcon('filemisc.png') return if 'broken-symlink' in self.fileType: self.isLink = True self.toolTip = self.__brokenLinkTooltip(path) return if os.path.islink(path): self.isLink = True self.toolTip = self.__linkTooltip(path) self.icon = getIcon('filelink.png') self.fileType, _, _ = getFileProperties(os.path.realpath(path)) return # Fine corrections for some file types if isPythonMime(self.fileType): self.populated = False self.lazyPopulation = True return if isCDMProjectMime(self.fileType): # Get the project properties try: self.toolTip = getProjectFileTooltip(path) except: # cannot get project properties self.toolTip = 'Broken project file' return
def __markOK(self): """Mark the file as OK""" self.__isValid = True fileName = self.getFilename() mime, icon, _ = getFileProperties(fileName) if isPythonMime(mime): # The tooltip could be the file docstring info = GlobalData().briefModinfoCache.get(fileName) if info.docstring and Settings()['recentTooltips']: self.setToolTip(1, info.docstring.text) else: self.setToolTip(1, "") if info.isOK: self.setIcon(0, getIcon('filepython.png')) else: self.setIcon(0, getIcon('filepythonbroken.png')) self.setToolTip(0, "") elif isCDMProjectMime(mime): # Get the project properties try: self.setToolTip(0, "") tooltip = getProjectFileTooltip(fileName) if Settings()['recentTooltips']: self.setToolTip(1, tooltip) else: self.setToolTip(1, "") self.setText(0, "") except: # cannot get project properties. Mark broken. self.__isValid = False self.setToolTip(0, 'Broken project file') self.setToolTip(1, 'Broken project file') self.setIcon(0, icon) else: # Get the other file type icon self.setIcon(0, icon) self.setToolTip(2, self.getFilename())