def get_leo_data(source): """Return the root node for the specificed .leo file (path or file)""" parser = LeoReader() if g.os_path_isfile(source): source = g.readFileIntoEncodedString(source) parseString(source, parser) return parser.root
def isSignificantPublicFile(self, fn): """ This tells the AtFile.read logic whether to import a public file or use an existing public file. """ return (g.os_path_exists(fn) and g.os_path_isfile(fn) and g.os_path_getsize(fn) > 10)
def isSignificantPublicFile(self, fn): '''This tells the AtFile.read logic whether to import a public file or use an existing public file.''' return ( g.os_path_exists(fn) and g.os_path_isfile(fn) and g.os_path_getsize(fn) > 10 )
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 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
if self.in_ == 't': self.idx[self.in_attrs['tx']].b.append(content) #@-others #@+node:ekr.20120519121124.9931: ** get_leo_data def get_leo_data(source): """Return the root node for the specificed .leo file (path or file)""" parser = LeoReader() if g.os_path_isfile(source): source = g.readFileIntoEncodedString(source) parseString(source, parser) return parser.root #@-others #@@language python #@@tabwidth -4 #@@pagewidth 70 if __name__ == '__main__': import sys if len(sys.argv) > 1 and g.os_path_isfile(sys.argv[1]): wb = sys.argv[1] else: wb = g.os_path_expanduser(g.os_path_join('~', '.leo', 'workbook.leo')) leo_data = get_leo_data(g.readFileIntoUnicodeString(wb)) print(leo_data) #@-leo
if self.in_ == 't': self.idx[self.in_attrs['tx']].b.append(content) #@-others #@+node:ekr.20120519121124.9931: ** get_leo_data def get_leo_data(source): """Return the root node for the specificed .leo file (path or file)""" parser = LeoReader() if g.os_path_isfile(source): source = g.readFileIntoEncodedString(source) parseString(source, parser) return parser.root #@-others #@@language python #@@tabwidth -4 #@@pagewidth 70 if __name__ == '__main__': import sys if len(sys.argv) > 1 and g.os_path_isfile(sys.argv[1]): wb = sys.argv[1] else: wb = g.os_path_expanduser( g.os_path_join('~', '.leo', 'workbook.leo') ) leo_data = get_leo_data(g.readFileIntoUnicodeString(wb)) print(leo_data) #@-leo