def openOutputFile(self): if self.outputFileName == None: return theDir, name = g.os_path_split(self.outputFileName) if len(theDir) == 0: self.show("empty output directory") return if len(name) == 0: self.show("empty output file name") return if not g.os_path_exists(theDir): self.show("output directory not found: " + theDir) else: try: if self.appendOutput: self.show("appending to " + self.outputFileName) self.outputFile = open(self.outputFileName, "ab") else: self.show("writing to " + self.outputFileName) self.outputFile = open(self.outputFileName, "wb") except: self.outputFile = None self.show("exception opening output file") g.es_exception()
def __init__(self, emacs): self.emacs = emacs path, file = g.os_path_split(g.app.loadDir) path = g.os_path_join(path, "swingmacs_exts", "lib_locations.txt") self.path = path llfile = java.io.File(path) data = [] if llfile.exists(): fos = java.io.FileInputStream(llfile) isr = java.io.InputStreamReader(fos) brd = java.io.BufferedReader(isr) while 1: line = brd.readLine() if line == None: break else: data.append(line) else: llfile.createNewFile() self.libraries = {} for z in data: nl = z.split('=') if len(nl) == 2: name, location = nl self.libraries[name] = location self.jd = None
def __init__( self, emacs ): self.emacs = emacs path,file = g.os_path_split(g.app.loadDir) path = g.os_path_join(path,"swingmacs_exts","lib_locations.txt") self.path = path llfile = java.io.File( path ) data = [] if llfile.exists(): fos = java.io.FileInputStream( llfile ) isr = java.io.InputStreamReader( fos ) brd = java.io.BufferedReader( isr ) while 1: line = brd.readLine() if line == None: break else: data.append( line ) else: llfile.createNewFile() self.libraries = {} for z in data: nl = z.split( '=' ) if len( nl ) == 2: name, location = nl self.libraries[ name ] = location self.jd = None
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 openOutputFile (self): if self.outputFileName == None: return theDir,name = g.os_path_split(self.outputFileName) if len(theDir) == 0: self.show("empty output directory") return if len(name) == 0: self.show("empty output file name") return if not g.os_path_exists(theDir): self.show("output directory not found: " + theDir) else: try: if self.appendOutput: self.show("appending to " + self.outputFileName) self.outputFile = open(self.outputFileName,"ab") else: self.show("writing to " + self.outputFileName) self.outputFile = open(self.outputFileName,"wb") except: self.outputFile = None self.show("exception opening output file") g.es_exception()
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 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 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 __init__ (self,c): """Ctor for the leoTkinterPrefs class.""" g.trace('tkinterPrefs') # Init the base class leoPrefs.leoPrefs.__init__(self,c) head,tail = g.os_path_split(c.frame.title) leoTkinterDialog.leoTkinterDialog.__init__(self,"Prefs for " + tail,resizeable=False) self.createTopFrame() # Create the outer tkinter dialog frame. self.createFrame() self.setWidgets()
def __init__(self, c): """Ctor for the leoTkinterPrefs class.""" g.trace('tkinterPrefs') # Init the base class leoPrefs.leoPrefs.__init__(self, c) head, tail = g.os_path_split(c.frame.title) leoTkinterDialog.leoTkinterDialog.__init__(self, "Prefs for " + tail, resizeable=False) self.createTopFrame() # Create the outer tkinter dialog frame. self.createFrame() self.setWidgets()
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 createFrame (self): """Create the tkinter Prefs panel.""" c = self.c ; gui = g.app.gui ; top = self.top c.frame.prefsPanel = self head,tail = g.os_path_split(c.frame.title) # Create the outer frame outer = Tk.Frame(top,bd=2,relief="groove") outer.pack(fill="both",expand=1,padx=2,pady=2) #@ << Create the Tk.IntVars >> #@+node:ekr.20031218072017.4126:<< Create the Tk.IntVars >> self.replace_tabs_var = Tk.IntVar() self.tangle_batch_var = Tk.IntVar() self.untangle_batch_var = Tk.IntVar() self.use_header_var = Tk.IntVar() self.output_doc_var = Tk.IntVar() self.lang_var = Tk.StringVar() #@nonl #@-node:ekr.20031218072017.4126:<< Create the Tk.IntVars >> #@nl #@ << Create the Global Options frame >> #@+node:ekr.20031218072017.4127:<< Create the Global Options frame >> # Frame and title w,glob = gui.create_labeled_frame (outer,caption="Global Options") w.pack(padx=2,pady=2,expand=1,fill="x") # Page width & page width f = Tk.Frame(glob) f.pack(anchor="w", pady="1m", expand=1, fill="x") lab = Tk.Label(f, anchor="w", padx="1m", text="Page width:") self.pageWidthText = txt = Tk.Text(f, height=1, width=4) lab.pack(side="left") txt.pack(side="left") txt.bind("<Key>", self.idle_set_ivars) lab2 = Tk.Label(f, padx="1m", text="Tab width:") self.tabWidthText = txt2 = Tk.Text(f, height=1, width=4) lab2.pack(side="left") txt2.pack(side="left") txt2.bind("<Key>", self.idle_set_ivars) # Batch Checkbuttons... self.replaceTabsBox = replaceBox = Tk.Checkbutton(glob,anchor="w", text="Replace tabs with spaces", variable=self.replace_tabs_var,command=self.idle_set_ivars) self.doneBox = doneBox = Tk.Checkbutton(glob,anchor="w", text="Run tangle_done.py after Tangle", variable=self.tangle_batch_var,command=self.idle_set_ivars) self.unBox = unBox = Tk.Checkbutton(glob,anchor="w", text="Run untangle_done.py after Untangle", variable=self.untangle_batch_var,command=self.idle_set_ivars) for box in (replaceBox, doneBox, unBox): box.pack(fill="x") #@nonl #@-node:ekr.20031218072017.4127:<< Create the Global Options frame >> #@nl #@ << Create the Tangle Options frame >> #@+node:ekr.20031218072017.4128:<< Create the Tangle Options frame >> # Frame and title w,tangle = gui.create_labeled_frame (outer,caption="Default Options") w.pack(padx=2,pady=2,expand=1,fill="x") # Label and text lab3 = Tk.Label(tangle, anchor="w", text="Default tangle directory") self.tangleDirectoryText = txt3 = Tk.Text(tangle, height=1, width=30) txt3.bind("<Key>", self.idle_set_ivars) # Capture the change immediately lab3.pack( padx="1m", pady="1m", fill="x") txt3.pack(anchor="w", padx="1m", pady="1m", fill="x") # Checkbuttons self.headerBox = header = Tk.Checkbutton(tangle,anchor="w", text="Tangle outputs header line", variable=self.use_header_var,command=self.idle_set_ivars) self.docBox = doc = Tk.Checkbutton(tangle,anchor="w", text="Tangle outputs document chunks", variable=self.output_doc_var,command=self.idle_set_ivars) header.pack(fill="x") doc.pack(fill="x") #@nonl #@-node:ekr.20031218072017.4128:<< Create the Tangle Options frame >> #@nl #@ << Create the Target Language frame >> #@+node:ekr.20031218072017.369:<< Create the Target Language frame >> frame # Frame and title w,target = gui.create_labeled_frame (outer,caption="Default Target Language") w.pack(padx=2,pady=2,expand=1,fill="x") # Frames for two columns of radio buttons lt = Tk.Frame(target) rt = Tk.Frame(target) lt.pack(side="left") rt.pack(side="right") # Left column of radio buttons. left_data = [ ("ActionScript", "actionscript"), ("Ada", "ada"), ("C#", "csharp"), ("C/C++", "c"), ("CSS", "css"), ("CWEB", "cweb"), ("elisp", "elisp"), ("Forth", "forth"), ("HTML", "html"), ("Java", "java"), ("LaTeX", "latex") ] for text,value in left_data: button = Tk.Radiobutton(lt,anchor="w",text=text, variable=self.lang_var,value=value,command=self.set_lang) button.pack(fill="x") # Right column of radio buttons. right_data = [ ("Pascal","pascal"), ("Perl", "perl"), ("Perl+POD", "perlpod"), ("PHP", "php"), ("Plain Text", "plain"), ("Python", "python"), ("RapidQ", "rapidq"), ("Rebol", "rebol"), ("Shell", "shell"), ("tcl/tk", "tcltk")] for text,value in right_data: button = Tk.Radiobutton(rt,anchor="w",text=text, variable=self.lang_var,value=value,command=self.set_lang) button.pack(fill="x") #@nonl #@-node:ekr.20031218072017.369:<< Create the Target Language frame >> frame #@nl #@ << Create the Ok, Cancel & Revert buttons >> #@+node:ekr.20031218072017.4129:<< Create the Ok, Cancel & Revert buttons >> buttons = Tk.Frame(outer) buttons.pack(padx=2,pady=2,expand=1,fill="x") okButton = Tk.Button(buttons,text="OK",width=7,command=self.onOK) cancelButton = Tk.Button(buttons,text="Cancel",width=7,command=self.onCancel) revertButton = Tk.Button(buttons,text="Revert",width=7,command=self.onRevert) okButton.pack(side="left",pady=7,expand=1) cancelButton.pack(side="left",pady=7,expand=0) revertButton.pack(side="left",pady=7,expand=1) #@nonl #@-node:ekr.20031218072017.4129:<< Create the Ok, Cancel & Revert buttons >> #@nl gui.center_dialog(top) # Do this _after_ building the dialog! self.top.protocol("WM_DELETE_WINDOW", self.onCancel)
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 __init__(self, c, title=None): self.c = c # Spell checkers use this class, so we can't always compute a title. if title: self.title = title else: #@ << compute self.title >> #@+node:ekr.20041121145452:<< compute self.title >> if not c.mFileName: s = "untitled" else: path, s = g.os_path_split(c.mFileName) self.title = "Find/Change for %s" % s #@nonl #@-node:ekr.20041121145452:<< compute self.title >> #@nl #@ << init the gui-independent ivars >> #@+node:ekr.20031218072017.3054:<< init the gui-independent ivars >> self.wrapVnode = None self.onlyVnode = None self.find_text = "" self.change_text = "" #@+at # New in 4.3: # - These are the names of leoFind ivars. (no more _flag hack). # - There are no corresponding commander ivars to keep in synch # (hurray!) # - These ivars are inited (in the subclass by init) when this class # is created. # - These ivars are updated (in the subclass by update_ivars) just # before doing any find. #@-at #@@c #@<< do dummy initialization to keep Pychecker happy >> #@+node:ekr.20050123164539:<< do dummy initialization to keep Pychecker happy >> self.batch = None self.ignore_case = None self.node_only = None self.pattern_match = None self.search_headline = None self.search_body = None self.suboutline_only = None self.mark_changes = None self.mark_finds = None self.reverse = None self.script_search = None self.script_change = None self.selection_only = None self.wrap = None self.whole_word = None #@nonl #@-node:ekr.20050123164539:<< do dummy initialization to keep Pychecker happy >> #@nl self.intKeys = [ "batch", "ignore_case", "node_only", "pattern_match", "search_headline", "search_body", "suboutline_only", "mark_changes", "mark_finds", "reverse", "script_search", "script_change", "selection_only", "wrap", "whole_word", ] self.newStringKeys = ["radio-find-type", "radio-search-scope"] # Ivars containing internal state... self.c = None # The commander for this search. self.v = None # The vnode being searched. Never saved between searches! self.in_headline = False # True: searching headline text. self.s_ctrl = None # The search text for this search. self.wrapping = False # True: wrapping is enabled. # This is _not_ the same as self.wrap for batch searches. #@+at #@nonl # Initializing a wrapped search is tricky. The search() method will # fail if v==wrapVnode and pos >= wrapPos. selectNextVnode() will # fail if v == wrapVnode. We set wrapPos on entry, before the first # search. We set wrapVnode in selectNextVnode after the first search # fails. We also set wrapVnode on exit if the first search suceeds. #@-at #@@c self.wrapVnode = None # The start of wrapped searches: persists between calls. self.onlyVnode = None # The starting node for suboutline-only searches. self.wrapPos = None # The starting position of the wrapped search: persists between calls. self.errors = 0 self.selStart = self.selEnd = None # For selection-only searches.
def createFrame(self): """Create the tkinter Prefs panel.""" c = self.c gui = g.app.gui top = self.top c.frame.prefsPanel = self head, tail = g.os_path_split(c.frame.title) # Create the outer frame outer = Tk.Frame(top, bd=2, relief="groove") outer.pack(fill="both", expand=1, padx=2, pady=2) #@ << Create the Tk.IntVars >> #@+node:ekr.20031218072017.4126:<< Create the Tk.IntVars >> self.replace_tabs_var = Tk.IntVar() self.tangle_batch_var = Tk.IntVar() self.untangle_batch_var = Tk.IntVar() self.use_header_var = Tk.IntVar() self.output_doc_var = Tk.IntVar() self.lang_var = Tk.StringVar() #@nonl #@-node:ekr.20031218072017.4126:<< Create the Tk.IntVars >> #@nl #@ << Create the Global Options frame >> #@+node:ekr.20031218072017.4127:<< Create the Global Options frame >> # Frame and title w, glob = gui.create_labeled_frame(outer, caption="Global Options") w.pack(padx=2, pady=2, expand=1, fill="x") # Page width & page width f = Tk.Frame(glob) f.pack(anchor="w", pady="1m", expand=1, fill="x") lab = Tk.Label(f, anchor="w", padx="1m", text="Page width:") self.pageWidthText = txt = Tk.Text(f, height=1, width=4) lab.pack(side="left") txt.pack(side="left") txt.bind("<Key>", self.idle_set_ivars) lab2 = Tk.Label(f, padx="1m", text="Tab width:") self.tabWidthText = txt2 = Tk.Text(f, height=1, width=4) lab2.pack(side="left") txt2.pack(side="left") txt2.bind("<Key>", self.idle_set_ivars) # Batch Checkbuttons... self.replaceTabsBox = replaceBox = Tk.Checkbutton( glob, anchor="w", text="Replace tabs with spaces", variable=self.replace_tabs_var, command=self.idle_set_ivars) self.doneBox = doneBox = Tk.Checkbutton( glob, anchor="w", text="Run tangle_done.py after Tangle", variable=self.tangle_batch_var, command=self.idle_set_ivars) self.unBox = unBox = Tk.Checkbutton( glob, anchor="w", text="Run untangle_done.py after Untangle", variable=self.untangle_batch_var, command=self.idle_set_ivars) for box in (replaceBox, doneBox, unBox): box.pack(fill="x") #@nonl #@-node:ekr.20031218072017.4127:<< Create the Global Options frame >> #@nl #@ << Create the Tangle Options frame >> #@+node:ekr.20031218072017.4128:<< Create the Tangle Options frame >> # Frame and title w, tangle = gui.create_labeled_frame(outer, caption="Default Options") w.pack(padx=2, pady=2, expand=1, fill="x") # Label and text lab3 = Tk.Label(tangle, anchor="w", text="Default tangle directory") self.tangleDirectoryText = txt3 = Tk.Text(tangle, height=1, width=30) txt3.bind("<Key>", self.idle_set_ivars) # Capture the change immediately lab3.pack(padx="1m", pady="1m", fill="x") txt3.pack(anchor="w", padx="1m", pady="1m", fill="x") # Checkbuttons self.headerBox = header = Tk.Checkbutton( tangle, anchor="w", text="Tangle outputs header line", variable=self.use_header_var, command=self.idle_set_ivars) self.docBox = doc = Tk.Checkbutton( tangle, anchor="w", text="Tangle outputs document chunks", variable=self.output_doc_var, command=self.idle_set_ivars) header.pack(fill="x") doc.pack(fill="x") #@nonl #@-node:ekr.20031218072017.4128:<< Create the Tangle Options frame >> #@nl #@ << Create the Target Language frame >> #@+node:ekr.20031218072017.369:<< Create the Target Language frame >> frame # Frame and title w, target = gui.create_labeled_frame(outer, caption="Default Target Language") w.pack(padx=2, pady=2, expand=1, fill="x") # Frames for two columns of radio buttons lt = Tk.Frame(target) rt = Tk.Frame(target) lt.pack(side="left") rt.pack(side="right") # Left column of radio buttons. left_data = [("ActionScript", "actionscript"), ("Ada", "ada"), ("C#", "csharp"), ("C/C++", "c"), ("CSS", "css"), ("CWEB", "cweb"), ("elisp", "elisp"), ("Forth", "forth"), ("HTML", "html"), ("Java", "java"), ("LaTeX", "latex")] for text, value in left_data: button = Tk.Radiobutton(lt, anchor="w", text=text, variable=self.lang_var, value=value, command=self.set_lang) button.pack(fill="x") # Right column of radio buttons. right_data = [("Pascal", "pascal"), ("Perl", "perl"), ("Perl+POD", "perlpod"), ("PHP", "php"), ("Plain Text", "plain"), ("Python", "python"), ("RapidQ", "rapidq"), ("Rebol", "rebol"), ("Shell", "shell"), ("tcl/tk", "tcltk")] for text, value in right_data: button = Tk.Radiobutton(rt, anchor="w", text=text, variable=self.lang_var, value=value, command=self.set_lang) button.pack(fill="x") #@nonl #@-node:ekr.20031218072017.369:<< Create the Target Language frame >> frame #@nl #@ << Create the Ok, Cancel & Revert buttons >> #@+node:ekr.20031218072017.4129:<< Create the Ok, Cancel & Revert buttons >> buttons = Tk.Frame(outer) buttons.pack(padx=2, pady=2, expand=1, fill="x") okButton = Tk.Button(buttons, text="OK", width=7, command=self.onOK) cancelButton = Tk.Button(buttons, text="Cancel", width=7, command=self.onCancel) revertButton = Tk.Button(buttons, text="Revert", width=7, command=self.onRevert) okButton.pack(side="left", pady=7, expand=1) cancelButton.pack(side="left", pady=7, expand=0) revertButton.pack(side="left", pady=7, expand=1) #@nonl #@-node:ekr.20031218072017.4129:<< Create the Ok, Cancel & Revert buttons >> #@nl gui.center_dialog(top) # Do this _after_ building the dialog! self.top.protocol("WM_DELETE_WINDOW", self.onCancel)
#@-others #depandance on sanitize_ and leoID #@<< set filenames >> #@+node:ekr.20050421093045.132:<< set filenames >> #note, these changes are at the time the button or menu is created #to effect these changes you have to #write the plugin and start a new python and leo. maybe reload #execute script on the dynaclick node for the dynabutton #they will take effect in dynatester imediatly #preserve the space after to allow for parameters #those that will be joined to pypath start with seperator \ or / #any other scripts should have their own full path, #pypath = r'C:\c\py\Python233' #nospace pypath = g.os_path_split(sys.executable)[0] #py = pypath + '/python.exe -tOO ' #_space_ py = g.os_path_join(pypath, 'python') + ' -tO ' #leosrc = r'c:\c\leo\leo4CVS233\src' leosrc = g.app.loadDir #reindent = g.os_path_join(pypath, '/Tools/Scripts/reindent.py ') #space reindent = pypath + '/Tools/Scripts/reindent.py ' #space #print pypath, py, leosrc #classic pychecker pycheck = pypath + '/Lib/site-packages/pychecker/checker.py ' #space #pychecker2, doesnt import, is alot slower and less details.
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,c,title=None): self.c = c # Spell checkers use this class, so we can't always compute a title. if title: self.title = title else: #@ << compute self.title >> #@+node:ekr.20041121145452:<< compute self.title >> if not c.mFileName: s = "untitled" else: path,s = g.os_path_split(c.mFileName) self.title = "Find/Change for %s" % s #@nonl #@-node:ekr.20041121145452:<< compute self.title >> #@nl #@ << init the gui-independent ivars >> #@+node:ekr.20031218072017.3054:<< init the gui-independent ivars >> self.wrapPosition = None self.onlyPosition = None self.find_text = "" self.change_text = "" self.unstick = False #@+at # New in 4.3: # - These are the names of leoFind ivars. (no more _flag hack). # - There are no corresponding commander ivars to keep in synch # (hurray!) # - These ivars are inited (in the subclass by init) when this class # is created. # - These ivars are updated (in the subclass by update_ivars) just # before doing any find. #@-at #@@c #@<< do dummy initialization to keep Pychecker happy >> #@+node:ekr.20050123164539:<< do dummy initialization to keep Pychecker happy >> if 1: self.batch = None self.clone_find_all = None self.ignore_case = None self.node_only = None self.pattern_match = None self.search_headline = None self.search_body = None self.suboutline_only = None self.mark_changes = None self.mark_finds = None self.reverse = None self.script_search = None self.script_change = None self.selection_only = None self.wrap = None self.whole_word = None #@nonl #@-node:ekr.20050123164539:<< do dummy initialization to keep Pychecker happy >> #@nl self.intKeys = [ "batch","ignore_case", "node_only", "pattern_match", "search_headline", "search_body", "suboutline_only", "mark_changes", "mark_finds", "reverse", "script_search","script_change","selection_only", "wrap", "whole_word", ] self.newStringKeys = ["radio-find-type", "radio-search-scope"] # Ivars containing internal state... self.c = None # The commander for this search. self.clone_find_all = False self.p = None # The position being searched. Never saved between searches! self.in_headline = False # True: searching headline text. self.s_ctrl = None # The search text for this search. self.wrapping = False # True: wrapping is enabled. # This is _not_ the same as self.wrap for batch searches. #@+at #@nonl # Initializing a wrapped search is tricky. The search() method will # fail if p==wrapPosition and pos >= wrapPos. selectNextPosition() # will fail if p == wrapPosition. We set wrapPos on entry, before the # first search. We set wrapPosition in selectNextPosition after the # first search fails. We also set wrapPosition on exit if the first # search suceeds. #@-at #@@c self.wrapPosition = None # The start of wrapped searches: persists between calls. self.onlyPosition = None # The starting node for suboutline-only searches. self.wrapPos = None # The starting position of the wrapped search: persists between calls. self.errors = 0 self.selStart = self.selEnd = None # For selection-only searches.
def importDir (self,dir,compteur,compteurglobal): """ La routine récursive de lecture des fichiers """ if not g.os_path_exists(dir): if language == 'french': g.es("Ce répertoire n'existe pas: %s" + dir) else: g.es("No such Directory: %s" + dir) return compteur, compteurglobal # EKR head,tail = g.os_path_split(dir) c = self.c ; v = c.currentVnode() try: #ici, on liste le contenu du répertoire body="" #@ << listdir >> #@+node:ekr.20050301083306.11:<< listdir >> try: fichiers = os.listdir(dir) dossiers = [] for f in fichiers: if compteur == 25: self.esfm("\n") compteur = 0 # mettre ici le code de création des noeuds path = g.os_path_join(dir,f) # est-ce un fichier ? if g.os_path_isfile(path): body += (f+"\n") else: # c'est alors un répertoire dossiers.append(path) self.esfm(".") compteur += 1 compteurglobal += 1 except Exception: if language == 'french': g.es("erreur dans listage fichiers...") else: g.es("os.listdir error...") g.es_exception() #@-node:ekr.20050301083306.11:<< listdir >> #@nl retour = c.importCommands.createHeadline(v,body,tail) #sélectionne le noeud nouvellement créé c.selectVnode(retour) if len(dossiers) > 0: for d in dossiers: compteur,compteurglobal = self.importDir(d,compteur,compteurglobal) c.setChanged(True) #sélectionne le noeud parent c.selectVnode(v) except: if language == 'french': g.es("erreur d'insertion de noeud...") else: g.es("error while creating vnode...") g.es_exception() return compteur, compteurglobal