def getName(self, location): """Determine the plugin name from the location""" # return os.path.split(os.path.splitext(location)[0])[1] head, ext = g.os_path_splitext(location) path, name = g.os_path_split(head) return name
def callback(p=p): path, name = g.os_path_split(p.filename) name, ext = g.os_path_splitext(name) # g.trace(name,g.app.loadedPlugins) if name in g.app.loadedPlugins: p.hastoplevel() else: p.about()
def callback(p=p): path,name = g.os_path_split(p.filename) name,ext = g.os_path_splitext(name) # g.trace(name,g.app.loadedPlugins) if name in g.app.loadedPlugins: p.hastoplevel() else: p.about()
def getName(self, location): """Determine the plugin name from the location""" # return os.path.split(os.path.splitext(location)[0])[1] head,ext = g.os_path_splitext(location) path,name = g.os_path_split(head) return name
def getFiles (dir): from leoGlobals import os_path_join,os_path_split,os_path_splitext # Generate the list of modules. allFiles = os.listdir(dir) files = [] for f in allFiles: head,tail = g.os_path_split(f) root,ext = g.os_path_splitext(tail) if ext==".py": files.append(g.os_path_join(dir,f)) return files
def getFiles(dir): from leoGlobals import os_path_join, os_path_split, os_path_splitext # Generate the list of modules. allFiles = os.listdir(dir) files = [] for f in allFiles: head, tail = g.os_path_split(f) root, ext = g.os_path_splitext(tail) if ext == ".py": files.append(g.os_path_join(dir, f)) return files
def completeFileName (fileName): import leoGlobals as g if not fileName: return None # This does not depend on config settings. fileName = g.os_path_join(os.getcwd(),fileName) head,ext = g.os_path_splitext(fileName) if not ext: fileName = fileName + ".leo" return fileName
def getModules (dir): """Return the list of Python files in dir.""" from leoGlobals import os_path_split,os_path_splitext files = [] try: allFiles = os.listdir(dir) for f in allFiles: head,tail = g.os_path_split(f) fn,ext = g.os_path_splitext(tail) if ext==".py": files.append(fn) except: pass return files
def getModules(dir): """Return the list of Python files in dir.""" from leoGlobals import os_path_split, os_path_splitext files = [] try: allFiles = os.listdir(dir) for f in allFiles: head, tail = g.os_path_split(f) fn, ext = g.os_path_splitext(tail) if ext == ".py": files.append(fn) except: pass return files
def convertRSTfilesToHTML(root_list): """This routine creates .html files from all .rst files in root_list, the list of files that have just been tangled.""" for root in root_list: base,fullname = g.os_path_split(root) name,ext = g.os_path_splitext(fullname) if ext == ".rst": file = g.os_path_join(base,name+".html") #@ << Convert root to corresponding .html file >> #@+node:EKR.20040502194930.3:<< Convert root to corresponding .html file >> # Leo will report the execption if docutils is not installed. from docutils.core import Publisher from docutils.io import FileInput,StringOutput,StringInput # Read .rst file into s. f = open(root,"r") s = f.read() f.close() # Restucture s into output. pub = Publisher() pub.source = StringInput(pub.settings,source=s) pub.destination = StringOutput(pub.settings,encoding="utf-8") pub.set_reader('standalone',None,'restructuredtext') pub.set_writer('html') output = pub.publish() # EKR: 3/7/03: convert output using the present encoding. dict = g.scanDirectives(self.c,p=root) encoding = dict.get("encoding",None) if encoding == None: encoding = g.app.config.default_derived_file_encoding output = g.toEncodedString(output,encoding,reportErrors=True) # Write the corresponding html file. f = open(file,"w") f.write(output) f.close()
def loadTreeHandlers(self): """Load all the handler for tree items""" # # Paths for key folders plugin_path = g.os_path_join(g.app.loadDir, "..", "plugins") self.handler_path = handler_path = g.os_path_join(g.app.loadDir, "..", "plugins", "trees") # if not g.os_path_isdir(handler_path): g.es("No tree handler folder found", color="red") else: g.es("Scanning for tree handlers", color="blue") # # Add folder locations to path old_path = sys.path[:] sys.path.insert(0, plugin_path) sys.path.insert(0, handler_path) #@ << Get plugin manager module >> #@+node:ekr.20050329082101.135:<< Get plugin manager module >> # Get the manager try: self.plugin_manager = __import__("plugin_manager") except ImportError, err: g.es("Autotrees did not load plugin manager: %s" % (err,), color="red") self.plugin_manager = None #@-node:ekr.20050329082101.135:<< Get plugin manager module >> #@nl #@ << Find all handlers >> #@+node:ekr.20050329082101.136:<< Find all handlers >> # Find all handlers for filename in glob.glob(g.os_path_join(handler_path, "*.py")): handler_name = g.os_path_splitext(g.os_path_split(filename)[1])[0] g.es("... looking in %s" % handler_name, color="blue") try: self.loadHandlersFrom(handler_name) except BadHandler, err: g.es("... unable to load '%s' handler: %s" % (handler_name, err), color="red")
def completeFileName (fileName): import leoGlobals as g if not (fileName and fileName.strip()): return None,None # This does not depend on config settings. try: if sys.platform.lower().startswith('win'): fileName = g.toUnicode(fileName,'mbcs') else: fileName = g.toUnicode(fileName,'utf-8') except Exception: pass relativeFileName = fileName fileName = g.os_path_join(os.getcwd(),fileName) junk,ext = g.os_path_splitext(fileName) if not ext: fileName = fileName + ".leo" relativeFileName = relativeFileName + ".leo" return fileName,relativeFileName
def storeAllPlugins(self, files): """Store all the plugins for later reference if we need to enable them""" self.all_plugins = dict( [(g.os_path_splitext(g.os_path_basename(f))[0], f) for f in files])
def compare_directories(self, path1, path2): # Ignore everything except the directory name. dir1 = g.os_path_dirname(path1) dir2 = g.os_path_dirname(path2) dir1 = g.os_path_normpath(dir1) dir2 = g.os_path_normpath(dir2) if dir1 == dir2: self.show( "Directory names are identical.\nPlease pick distinct directories." ) return try: list1 = os.listdir(dir1) except: self.show("invalid directory:" + dir1) return try: list2 = os.listdir(dir2) except: self.show("invalid directory:" + dir2) return if self.outputFileName: self.openOutputFile() ok = self.outputFileName == None or self.outputFile if not ok: return # Create files and files2, the lists of files to be compared. files1 = [] files2 = [] for f in list1: junk, ext = g.os_path_splitext(f) if self.limitToExtension: if ext == self.limitToExtension: files1.append(f) else: files1.append(f) for f in list2: junk, ext = g.os_path_splitext(f) if self.limitToExtension: if ext == self.limitToExtension: files2.append(f) else: files2.append(f) # Compare the files and set the yes, no and fail lists. yes = [] no = [] fail = [] for f1 in files1: head, f2 = g.os_path_split(f1) if f2 in files2: try: name1 = g.os_path_join(dir1, f1) name2 = g.os_path_join(dir2, f2) val = filecmp.cmp(name1, name2, 0) if val: yes.append(f1) else: no.append(f1) except: self.show("exception in filecmp.cmp") g.es_exception() fail.append(f1) else: fail.append(f1) # Print the results. for kind, files in (("----- matches --------", yes), ("----- mismatches -----", no), ("----- not found ------", fail)): self.show(kind) for f in files: self.show(f) if self.outputFile: self.outputFile.close() self.outputFile = None
def compare_directories (self,path1,path2): # Ignore everything except the directory name. dir1 = g.os_path_dirname(path1) dir2 = g.os_path_dirname(path2) dir1 = g.os_path_normpath(dir1) dir2 = g.os_path_normpath(dir2) if dir1 == dir2: self.show("Directory names are identical.\nPlease pick distinct directories.") return try: list1 = os.listdir(dir1) except: self.show("invalid directory:" + dir1) return try: list2 = os.listdir(dir2) except: self.show("invalid directory:" + dir2) return if self.outputFileName: self.openOutputFile() ok = self.outputFileName == None or self.outputFile if not ok: return # Create files and files2, the lists of files to be compared. files1 = [] files2 = [] for f in list1: junk, ext = g.os_path_splitext(f) if self.limitToExtension: if ext == self.limitToExtension: files1.append(f) else: files1.append(f) for f in list2: junk, ext = g.os_path_splitext(f) if self.limitToExtension: if ext == self.limitToExtension: files2.append(f) else: files2.append(f) # Compare the files and set the yes, no and fail lists. yes = [] ; no = [] ; fail = [] for f1 in files1: head,f2 = g.os_path_split(f1) if f2 in files2: try: name1 = g.os_path_join(dir1,f1) name2 = g.os_path_join(dir2,f2) _file1 = java.io.File( name1 ) _file2 = java.io.File( name2 ) if _file1.length() == _file2.length(): val = self._filecmp( name1, name2 ) else: val = False #val = filecmp.cmp(name1,name2,0) if val: yes.append(f1) else: no.append(f1) except: self.show("exception in filecmp.cmp") g.es_exception() fail.append(f1) else: fail.append(f1) # Print the results. for kind, files in ( ("----- matches --------",yes), ("----- mismatches -----",no), ("----- not found ------",fail)): self.show(kind) for f in files: self.show(f) if self.outputFile: self.outputFile.close() self.outputFile = None
def __init__(self, filename): """Initialize the plug-in""" # Import the file to find out some interesting stuff # Do not use the imp module: we only want to import these files once! self.mod = self.doc = self.version = None self.filename = g.os_path_abspath(filename) try: self.mod = __import__( g.os_path_splitext(g.os_path_basename(filename))[0]) if not self.mod: return # self.group = getattr(self.mod, "__plugin_group__", None) if self.group: PluginDatabase.addPlugin(self, self.group) # g.trace('Plugin',self.mod) try: name = self.mod.__plugin_name__ except AttributeError: name = self.mod.__name__ self.name = self.getNiceName(name) try: self.priority = self.mod.__plugin_priority__ except AttributeError: self.priority = 200 - ord(self.name[0]) # self.doc = self.mod.__doc__ self.version = self.mod.__dict__.get("__version__", "<unknown>") # EKR: 3/17/05 # if self.version: print self.version,g.shortFileName(filename) except ImportError: # s = 'Can not import %s in plugins_menu plugin' % g.shortFileName(filename) # print s ; g.es(s,color='blue') return except Exception: s = 'Unexpected exception in plugins_menu plugin importing %s' % filename print s g.es(s, color='red') return #@ << Check if this can be configured >> #@+node:EKR.20040517080555.5:<< Check if this can be configured >> # Look for a configuration file self.configfilename = "%s.ini" % os.path.splitext(filename)[0] self.hasconfig = os.path.isfile(self.configfilename) #@-node:EKR.20040517080555.5:<< Check if this can be configured >> #@nl #@ << Check if this has an apply >> #@+node:EKR.20040517080555.6:<< Check if this has an apply >> #@+at #@nonl # Look for an apply function ("applyConfiguration") in the module. # # This is used to apply changes in configuration from the properties # window #@-at #@@c self.hasapply = hasattr(self.mod, "applyConfiguration") #@-node:EKR.20040517080555.6:<< Check if this has an apply >> #@nl #@ << Look for additional commands >> #@+node:EKR.20040517080555.7:<< Look for additional commands >> #@+at #@nonl # Additional commands can be added to the plugin menu by having # functions in the module called "cmd_whatever". These are added to # the main menu and will be called when clicked #@-at #@@c self.othercmds = {} for item in self.mod.__dict__.keys(): if item.startswith("cmd_"): self.othercmds[item[4:]] = self.mod.__dict__[item] #@-node:EKR.20040517080555.7:<< Look for additional commands >> #@nl #@ << Look for toplevel menu item >> #@+node:pap.20041009131822:<< Look for toplevel menu item >> #@+at #@nonl # Check to see if there is a toplevel menu item - this will be used # instead of the default About #@-at #@@c try: self.hastoplevel = self.mod.__dict__["topLevelMenu"] except KeyError: self.hastoplevel = False
def __init__(self, filename): """Initialize the plug-in""" # Import the file to find out some interesting stuff # Do not use the imp module: we only want to import these files once! self.mod = self.doc = self.version = None self.filename = g.os_path_abspath(filename) try: self.mod = __import__(g.os_path_splitext(g.os_path_basename(filename))[0]) if not self.mod: return # self.group = getattr(self.mod, "__plugin_group__", None) if self.group: PluginDatabase.addPlugin(self, self.group) # g.trace('Plugin',self.mod) try: name = self.mod.__plugin_name__ except AttributeError: name = self.mod.__name__ self.name = self.getNiceName(name) try: self.priority = self.mod.__plugin_priority__ except AttributeError: self.priority = 200 - ord(self.name[0]) # self.doc = self.mod.__doc__ self.version = self.mod.__dict__.get("__version__","<unknown>") # EKR: 3/17/05 # if self.version: print self.version,g.shortFileName(filename) except ImportError: # s = 'Can not import %s in plugins_menu plugin' % g.shortFileName(filename) # print s ; g.es(s,color='blue') return except Exception: s = 'Unexpected exception in plugins_menu plugin importing %s' % filename print s ; g.es(s,color='red') return #@ << Check if this can be configured >> #@+node:EKR.20040517080555.5:<< Check if this can be configured >> # Look for a configuration file self.configfilename = "%s.ini" % os.path.splitext(filename)[0] self.hasconfig = os.path.isfile(self.configfilename) #@-node:EKR.20040517080555.5:<< Check if this can be configured >> #@nl #@ << Check if this has an apply >> #@+node:EKR.20040517080555.6:<< Check if this has an apply >> #@+at #@nonl # Look for an apply function ("applyConfiguration") in the module. # # This is used to apply changes in configuration from the properties # window #@-at #@@c self.hasapply = hasattr(self.mod, "applyConfiguration") #@-node:EKR.20040517080555.6:<< Check if this has an apply >> #@nl #@ << Look for additional commands >> #@+node:EKR.20040517080555.7:<< Look for additional commands >> #@+at #@nonl # Additional commands can be added to the plugin menu by having # functions in the module called "cmd_whatever". These are added to # the main menu and will be called when clicked #@-at #@@c self.othercmds = {} for item in self.mod.__dict__.keys(): if item.startswith("cmd_"): self.othercmds[item[4:]] = self.mod.__dict__[item] #@-node:EKR.20040517080555.7:<< Look for additional commands >> #@nl #@ << Look for toplevel menu item >> #@+node:pap.20041009131822:<< Look for toplevel menu item >> #@+at #@nonl # Check to see if there is a toplevel menu item - this will be used # instead of the default About #@-at #@@c try: self.hastoplevel = self.mod.__dict__["topLevelMenu"] except KeyError: self.hastoplevel = False