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 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 project_files(self, name, force_all=False): '''Return a list of all files in the named project.''' # Ignore everything after the first space. i = name.find(' ') if i > -1: name = name[: i].strip() leo_path, junk = g.os_path_split(__file__) d = { # Change these paths as required for your system. 'coverage': ( r'C:\Python26\Lib\site-packages\coverage-3.5b1-py2.6-win32.egg\coverage', ['.py'], ['.bzr', 'htmlfiles']), 'leo': ( r'C:\leo.repo\leo-editor\leo\core', ['.py'], ['.git']), # ['.bzr'] 'lib2to3': ( r'C:\Python26\Lib\lib2to3', ['.py'], ['tests']), 'pylint': ( r'C:\Python26\Lib\site-packages\pylint', ['.py'], ['.bzr', 'test']), 'rope': ( r'C:\Python26\Lib\site-packages\rope-0.9.4-py2.6.egg\rope\base', ['.py'], ['.bzr']), # 'test': ( # g.os_path_finalize_join(leo_path,'test-proj'), # ['.py'],['.bzr']), } data = d.get(name.lower()) if not data: g.trace('bad project name: %s' % (name)) return [] theDir, extList, excludeDirs = data files = self.files_in_dir(theDir, recursive=True, extList=extList, excludeDirs=excludeDirs) if files: if name.lower() == 'leo': for exclude in ['__init__.py', 'format-code.py']: files = [z for z in files if not z.endswith(exclude)] table = ( r'C:\leo.repo\leo-editor\leo\commands', # r'C:\leo.repo\leo-editor\leo\plugins\importers', # r'C:\leo.repo\leo-editor\leo\plugins\writers', ) for dir_ in table: files2 = self.files_in_dir(dir_, recursive=True, extList=['.py',], excludeDirs=[]) files2 = [z for z in files2 if not z.endswith('__init__.py')] # g.trace(g.os_path_exists(dir_), dir_, '\n'.join(files2)) files.extend(files2) files.extend(glob.glob(r'C:\leo.repo\leo-editor\leo\plugins\qt_*.py')) fn = g.os_path_finalize_join(theDir, '..', 'plugins', 'qtGui.py') if fn and g.os_path_exists(fn): files.append(fn) if g.app.runningAllUnitTests and len(files) > 1 and not force_all: return [files[0]] if not files: g.trace(theDir) if g.app.runningAllUnitTests and len(files) > 1 and not force_all: return [files[0]] else: return files
def callback(event, c=c, p=p): path, name = g.os_path_split(p.filename) name, ext = g.os_path_splitext(name) pc = g.app.pluginsController if pc and pc.isLoaded(name): p.hastoplevel(c) else: p.about()
def callback (event,c=c,p=p): path, name = g.os_path_split(p.filename) name, ext = g.os_path_splitext(name) pc = g.app.pluginsController if pc and pc.isLoaded(name): p.hastoplevel(c) else: p.about()
def project_files(self, name, force_all=False): """Return a list of all files in the named project.""" # Ignore everything after the first space. i = name.find(" ") if i > -1: name = name[:i].strip() leo_path, junk = g.os_path_split(__file__) d = { # Change these paths as required for your system. "coverage": ( r"C:\Python26\Lib\site-packages\coverage-3.5b1-py2.6-win32.egg\coverage", [".py"], [".bzr", "htmlfiles"], ), "leo": (r"C:\leo.repo\leo-editor\leo\core", [".py"], [".git"]), # ['.bzr'] "lib2to3": (r"C:\Python26\Lib\lib2to3", [".py"], ["tests"]), "pylint": (r"C:\Python26\Lib\site-packages\pylint", [".py"], [".bzr", "test"]), "rope": (r"C:\Python26\Lib\site-packages\rope-0.9.4-py2.6.egg\rope\base", [".py"], [".bzr"]), # 'test': ( # g.os_path_finalize_join(leo_path,'test-proj'), # ['.py'],['.bzr']), } data = d.get(name.lower()) if not data: g.trace("bad project name: %s" % (name)) return [] theDir, extList, excludeDirs = data files = self.files_in_dir(theDir, recursive=True, extList=extList, excludeDirs=excludeDirs) if files: if name.lower() == "leo": for exclude in ["__init__.py", "format-code.py"]: files = [z for z in files if not z.endswith(exclude)] table = ( r"C:\leo.repo\leo-editor\leo\commands", # r'C:\leo.repo\leo-editor\leo\plugins\importers', # r'C:\leo.repo\leo-editor\leo\plugins\writers', ) for dir_ in table: files2 = self.files_in_dir(dir_, recursive=True, extList=[".py"], excludeDirs=[]) files2 = [z for z in files2 if not z.endswith("__init__.py")] # g.trace(g.os_path_exists(dir_), dir_, '\n'.join(files2)) files.extend(files2) files.extend(glob.glob(r"C:\leo.repo\leo-editor\leo\plugins\qt_*.py")) fn = g.os_path_finalize_join(theDir, "..", "plugins", "qtGui.py") if fn and g.os_path_exists(fn): files.append(fn) if g.app.runningAllUnitTests and len(files) > 1 and not force_all: return [files[0]] if not files: g.trace(theDir) if g.app.runningAllUnitTests and len(files) > 1 and not force_all: return [files[0]] else: return files
def importDir (self,dir,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 compteurglobal head,tail = g.os_path_split(dir) c = self.c ; current = c.p try: #ici, on liste le contenu du répertoire body="" #@+<< listdir >> #@+node:ekr.20050301083306.11: *4* << listdir >> try: fichiers = os.listdir(dir) dossiers = [] for f in fichiers: # 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) compteurglobal += 1 except Exception: if language == 'french': g.es("erreur dans listage fichiers...") else: g.es("os.listdir error...") g.es_exception() #@-<< listdir >> p = c.importCommands.createHeadline(current,body,tail) c.selectPosition(p) if dossiers: for d in dossiers: compteurglobal = self.importDir(d,compteurglobal) c.setChanged(True) #sélectionne le noeud parent c.selectPosition(current) except Exception: if language == 'french': g.es("erreur d'insertion de noeud...") else: g.es("error while creating node...") g.es_exception() return compteurglobal
def importDir(self, dir, 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 compteurglobal head, tail = g.os_path_split(dir) c = self.c current = c.p try: #ici, on liste le contenu du répertoire body = "" #@+<< listdir >> #@+node:ekr.20050301083306.11: *4* << listdir >> try: fichiers = os.listdir(dir) dossiers = [] for f in fichiers: # 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) compteurglobal += 1 except Exception: if language == 'french': g.es("erreur dans listage fichiers...") else: g.es("os.listdir error...") g.es_exception() #@-<< listdir >> p = c.importCommands.createHeadline(current, body, tail) c.selectPosition(p) if dossiers: for d in dossiers: compteurglobal = self.importDir(d, compteurglobal) c.setChanged() #sélectionne le noeud parent c.selectPosition(current) except Exception: if language == 'french': g.es("erreur d'insertion de noeud...") else: g.es("error while creating node...") g.es_exception() return compteurglobal
def create_directory(self, fn): ''' Create the directory for fn if a) it doesn't exist and b) the user options allow it. Return True if the directory existed or was made. ''' c = self.c theDir, junk = g.os_path_split(fn) theDir = c.os_path_finalize(theDir) if g.os_path_exists(theDir): return True ok = g.makeAllNonExistentDirectories(theDir, c=c, force=False) if not ok: g.error('did not create:', theDir) return ok
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: *4* << Get plugin manager module >> # Get the manager try: self.plugin_manager = __import__("plugin_manager") except ImportError as err: g.es("Autotrees did not load plugin manager: %s" % (err, ), color="red") self.plugin_manager = None #@-<< Get plugin manager module >> #@+<< Find all handlers >> #@+node:ekr.20050329082101.136: *4* << 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 as err: g.es("... unable to load '%s' handler: %s" % (handler_name, err), color="red") #@-<< Find all handlers >> # Restore sys.path = old_path
def createDirectoryForFile(self, fn): """ Create the directory for fn if a) it doesn't exist and b) the user options allow it. Return True if the directory existed or was made. """ c, ok = self.c, False # 1815. # Create the directory if it doesn't exist. theDir, junk = g.os_path_split(fn) theDir = g.os_path_finalize(theDir) # 1341 if g.os_path_exists(theDir): return True if c and c.config and c.config.create_nonexistent_directories: theDir = c.expand_path_expression(theDir) ok = g.makeAllNonExistentDirectories(theDir) if not ok: g.error('did not create:', theDir) return ok
def get_project_directory(self, name): # Ignore everything after the first space. i = name.find(" ") if i > -1: name = name[:i].strip() leo_path, junk = g.os_path_split(__file__) d = { # Change these paths as required for your system. "coverage": r"C:\Python26\Lib\site-packages\coverage-3.5b1-py2.6-win32.egg\coverage", "leo": r"C:\leo.repo\leo-editor\leo\core", "lib2to3": r"C:\Python26\Lib\lib2to3", "pylint": r"C:\Python26\Lib\site-packages\pylint", "rope": r"C:\Python26\Lib\site-packages\rope-0.9.4-py2.6.egg\rope\base", "test": g.os_path_finalize_join(g.app.loadDir, "..", "test-proj"), } dir_ = d.get(name.lower()) # g.trace(name,dir_) if not dir_: g.trace("bad project name: %s" % (name)) if not g.os_path_exists(dir_): g.trace("directory not found:" % (dir_)) return dir_ or ""
def get_project_directory(self, name): # Ignore everything after the first space. i = name.find(' ') if i > -1: name = name[: i].strip() leo_path, junk = g.os_path_split(__file__) d = { # Change these paths as required for your system. 'coverage': r'C:\Python26\Lib\site-packages\coverage-3.5b1-py2.6-win32.egg\coverage', 'leo': r'C:\leo.repo\leo-editor\leo\core', 'lib2to3': r'C:\Python26\Lib\lib2to3', 'pylint': r'C:\Python26\Lib\site-packages\pylint', 'rope': r'C:\Python26\Lib\site-packages\rope-0.9.4-py2.6.egg\rope\base', 'test': g.os_path_finalize_join(g.app.loadDir, '..', 'test-proj'), } dir_ = d.get(name.lower()) # g.trace(name,dir_) if not dir_: g.trace('bad project name: %s' % (name)) if not g.os_path_exists(dir_): g.trace('directory not found:' % (dir_)) return dir_ or ''
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: *4* << Get plugin manager module >> # Get the manager try: self.plugin_manager = __import__("plugin_manager") except ImportError as err: g.es("Autotrees did not load plugin manager: %s" % (err,), color="red") self.plugin_manager = None #@-<< Get plugin manager module >> #@+<< Find all handlers >> #@+node:ekr.20050329082101.136: *4* << 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 as err: g.es("... unable to load '%s' handler: %s" % (handler_name, err), color="red") #@-<< Find all handlers >> # Restore sys.path = old_path
def set_expected_imported_headlines(self, root): '''Set v._imported_headline for every vnode.''' trace = False and not g.unitTesting cc = self c = cc.c ic = cc.c.importCommands language = g.scanForAtLanguage(c, root) ext = '.' + g.app.language_extension_dict.get(language) aClass = ic.classDispatchDict.get(ext) scanner = aClass(importCommands=ic, atAuto=True) # Duplicate the fn logic from ic.createOutline. theDir = g.setDefaultDirectory(c, root, importing=True) fn = c.os_path_finalize_join(theDir, root.h) fn = root.h.replace('\\', '/') junk, fn = g.os_path_split(fn) fn, junk = g.os_path_splitext(fn) if aClass and hasattr(scanner, 'headlineForNode'): for p in root.subtree(): if not hasattr(p.v, '_imported_headline'): h = scanner.headlineForNode(fn, p) setattr(p.v, '_imported_headline', h) if trace and h != p.h: g.trace('==>', h) # p.h,'==>',h
def set_expected_imported_headlines(self,root): '''Set v._imported_headline for every vnode.''' trace = False and not g.unitTesting cc = self c = cc.c ic = cc.c.importCommands language = g.scanForAtLanguage(c,root) ext = '.'+g.app.language_extension_dict.get(language) aClass = ic.classDispatchDict.get(ext) scanner = aClass(importCommands=ic,atAuto=True) # Duplicate the fn logic from ic.createOutline. theDir = g.setDefaultDirectory(c,root,importing=True) fn = c.os_path_finalize_join(theDir,root.h) fn = root.h.replace('\\','/') junk,fn = g.os_path_split(fn) fn,junk = g.os_path_splitext(fn) if aClass and hasattr(scanner,'headlineForNode'): for p in root.subtree(): if not hasattr(p.v,'_imported_headline'): h = scanner.headlineForNode(fn,p) setattr(p.v,'_imported_headline',h) if trace and h != p.h: g.trace('==>',h) # p.h,'==>',h
def get_project_directory(self, name): # Ignore everything after the first space. i = name.find(' ') if i > -1: name = name[:i].strip() leo_path, junk = g.os_path_split(__file__) d = { # Change these paths as required for your system. 'coverage': r'C:\Python26\Lib\site-packages\coverage-3.5b1-py2.6-win32.egg\coverage', 'leo': r'C:\leo.repo\leo-editor\leo\core', 'lib2to3': r'C:\Python26\Lib\lib2to3', 'pylint': r'C:\Python26\Lib\site-packages\pylint', 'rope': r'C:\Python26\Lib\site-packages\rope-0.9.4-py2.6.egg\rope\base', 'test': g.os_path_finalize_join(g.app.loadDir, '..', 'test-proj'), } dir_ = d.get(name.lower()) # g.trace(name,dir_) if not dir_: g.trace('bad project name: %s' % (name)) if not g.os_path_exists(dir_): g.trace('directory not found:' % (dir_)) return dir_ or ''
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: return self.show("Please pick distinct directories.") try: list1 = os.listdir(dir1) except Exception: return self.show("invalid directory:" + dir1) try: list2 = os.listdir(dir2) except Exception: return self.show("invalid directory:" + dir2) if self.outputFileName: self.openOutputFile() ok = self.outputFileName is None or self.outputFile if not ok: return None # 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 missing lists. yes = []; no = []; missing1 = []; missing2 = [] 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 Exception: self.show("exception in filecmp.cmp") g.es_exception() missing1.append(f1) else: missing1.append(f1) for f2 in files2: head, f1 = g.os_path_split(f2) if f1 not in files1: missing2.append(f1) # Print the results. for kind, files in ( ("----- matches --------", yes), ("----- mismatches -----", no), ("----- not found 1 ------", missing1), ("----- not found 2 ------", missing2), ): self.show(kind) for f in files: self.show(f) if self.outputFile: self.outputFile.close() self.outputFile = None return None # To keep pychecker happy.
def run_diff_on_vcs(self, event=None): """run_diff_on_vcs - try and check out the previous version of the Leo file and compare a node with the same gnx in that file with the current node :Parameters: - `event`: Leo event """ c = self.c dir_, filename = g.os_path_split(c.fileName()) relative_path = [] # path from top of repo. to .leo file mode = None # mode is which VCS to use # given A=/a/b/c/d/e, B=file.leo adjust to A=/a/b/c, B=d/e/file.leo # so that A is the path to the repo. and B the path in the repo. to # the .leo file path = dir_ while not mode: for vcs in 'git', 'bzr': if g.os_path_exists(g.os_path_join(path, '.' + vcs)): mode = vcs break else: path, subpath = g.os_path_split(path) if not subpath: break relative_path[0:0] = [subpath] if not mode: g.es("No supported VCS found in '%s'" % dir_) return gnx = c.p.gnx if mode == 'git': cmd = [ 'git', '--work-tree=%s' % path, 'show', 'HEAD:%s' % g.os_path_join(*(relative_path + [filename])), ] if mode == 'bzr': cmd = [ 'bzr', 'cat', '--revision=revno:-1', c.fileName(), # path, # g.os_path_join( *(relative_path + [filename]) ), ] cmd = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE) data, err = cmd.communicate() aFile = StringIO(data) tree = leosax.get_leo_data(aFile) for node in tree.flat(): if node.gnx == gnx: node.b = ''.join(node.b) self.run_appropriate_diff([node, c.p]) return g.es("Node (gnx) not found in previous version")
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: return self.show("Please pick distinct directories.") try: list1 = os.listdir(dir1) except: return self.show("invalid directory:" + dir1) try: list2 = os.listdir(dir2) except: return self.show("invalid directory:" + dir2) if self.outputFileName: self.openOutputFile() ok = self.outputFileName == None or self.outputFile if not ok: return None # 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 missing lists. yes = [] no = [] missing1 = [] missing2 = [] 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() missing1.append(f1) else: missing1.append(f1) for f2 in files2: head, f1 = g.os_path_split(f2) if f1 not in files1: missing2.append(f1) # Print the results. for kind, files in ( ("----- matches --------", yes), ("----- mismatches -----", no), ("----- not found 1 ------", missing1), ("----- not found 2 ------", missing2), ): self.show(kind) for f in files: self.show(f) if self.outputFile: self.outputFile.close() self.outputFile = None return None # To keep pychecker happy.
def project_files(self, name, force_all=False): '''Return a list of all files in the named project.''' # Ignore everything after the first space. i = name.find(' ') if i > -1: name = name[:i].strip() leo_path, junk = g.os_path_split(__file__) d = { # Change these paths as required for your system. 'coverage': (r'C:\Python26\Lib\site-packages\coverage-3.5b1-py2.6-win32.egg\coverage', ['.py'], ['.bzr', 'htmlfiles']), 'leo': (r'C:\leo.repo\leo-editor\leo\core', ['.py'], ['.git']), # ['.bzr'] 'lib2to3': (r'C:\Python26\Lib\lib2to3', ['.py'], ['tests']), 'pylint': (r'C:\Python26\Lib\site-packages\pylint', ['.py'], ['.bzr', 'test']), 'rope': (r'C:\Python26\Lib\site-packages\rope-0.9.4-py2.6.egg\rope\base', ['.py'], ['.bzr']), # 'test': ( # g.os_path_finalize_join(leo_path,'test-proj'), # ['.py'],['.bzr']), } data = d.get(name.lower()) if not data: g.trace('bad project name: %s' % (name)) return [] theDir, extList, excludeDirs = data files = self.files_in_dir(theDir, recursive=True, extList=extList, excludeDirs=excludeDirs) if files: if name.lower() == 'leo': for exclude in ['__init__.py', 'format-code.py']: files = [z for z in files if not z.endswith(exclude)] table = ( r'C:\leo.repo\leo-editor\leo\commands', # r'C:\leo.repo\leo-editor\leo\plugins\importers', # r'C:\leo.repo\leo-editor\leo\plugins\writers', ) for dir_ in table: files2 = self.files_in_dir(dir_, recursive=True, extList=[ '.py', ], excludeDirs=[]) files2 = [ z for z in files2 if not z.endswith('__init__.py') ] # g.trace(g.os_path_exists(dir_), dir_, '\n'.join(files2)) files.extend(files2) files.extend( glob.glob(r'C:\leo.repo\leo-editor\leo\plugins\qt_*.py')) fn = g.os_path_finalize_join(theDir, '..', 'plugins', 'qtGui.py') if fn and g.os_path_exists(fn): files.append(fn) if g.app.runningAllUnitTests and len(files) > 1 and not force_all: return [files[0]] if not files: g.trace(theDir) if g.app.runningAllUnitTests and len(files) > 1 and not force_all: return [files[0]] else: return files
def run_diff_on_vcs(self, event=None): """run_diff_on_vcs - try and check out the previous version of the Leo file and compare a node with the same gnx in that file with the current node :Parameters: - `event`: Leo event """ c = self.c dir_, filename = g.os_path_split(c.fileName()) relative_path = [] # path from top of repo. to .leo file mode = None # mode is which VCS to use # given A=/a/b/c/d/e, B=file.leo adjust to A=/a/b/c, B=d/e/file.leo # so that A is the path to the repo. and B the path in the repo. to # the .leo file path = dir_ while not mode: for vcs in 'git', 'bzr': if g.os_path_exists(g.os_path_join(path, '.'+vcs)): mode = vcs break else: path, subpath = g.os_path_split(path) if not subpath: break relative_path[0:0] = [subpath] if not mode: g.es("No supported VCS found in '%s'"%dir_) return gnx = c.p.gnx if mode == 'git': cmd = [ 'git', '--work-tree=%s' % path, 'show', 'HEAD:%s' % g.os_path_join( *(relative_path + [filename]) ), ] if mode == 'bzr': cmd = [ 'bzr', 'cat', '--revision=revno:-1', c.fileName(), # path, # g.os_path_join( *(relative_path + [filename]) ), ] cmd = subprocess.Popen( cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE) data, err = cmd.communicate() aFile = StringIO(data) tree = leosax.get_leo_data(aFile) for node in tree.flat(): if node.gnx == gnx: break else: g.es("Node (gnx) not found in previous version") return node.b = ''.join(node.b) self.run_appropriate_diff([node, c.p])