Exemplo n.º 1
0
def computeLoadDir():
    """Returns the directory containing leo.py."""

    import leoGlobals as g

    # g.trace(g.app.tkEncoding)

    try:
        import leo
        path = g.os_path_abspath(leo.__file__)

        if sys.platform == "win32":  # "mbcs" exists only on Windows.
            path = g.toUnicode(path, "mbcs")
        elif sys.platform == "dawwin":
            path = g.toUnicode(path, "utf-8")
        else:
            path = g.toUnicode(path, g.app.tkEncoding)

        if path:
            loadDir = g.os_path_dirname(path)
        else:
            loadDir = None
        if not loadDir:
            loadDir = g.os_path_abspath(os.getcwd())
            print "Using emergency loadDir:", repr(loadDir)

        encoding = g.choose(sys.platform == "dawwin", "utf-8",
                            g.app.tkEncoding)  # 11/18/03
        loadDir = g.toUnicode(loadDir, encoding)  # 10/20/03
        return loadDir
    except:
        print "Exception getting load directory"
        import traceback
        traceback.print_exc()
        return None
Exemplo n.º 2
0
def computeLoadDir():
    
    """Returns the directory containing leo.py."""
    
    import leoGlobals as g

    try:
        import leo
        encoding = startupEncoding()
        path = g.os_path_abspath(leo.__file__,encoding)
        #path = g.os_path_abspath( leoGlobals.__file__, encoding )
        
        if path:
            loadDir = g.os_path_dirname(path,encoding)
        else: loadDir = None
            
        if (
            not loadDir or
            not g.os_path_exists(loadDir,encoding) or
            not g.os_path_isdir(loadDir,encoding)
        ):
            loadDir = os.getcwd()
            print "Using emergency loadDir:",repr(loadDir)
        
        loadDir = g.os_path_abspath(loadDir,encoding)
        # g.es("load dir: %s" % (loadDir),color="blue")
        return loadDir
    except:
        print "Exception getting load directory"
        import traceback ; traceback.print_exc()
        return None
Exemplo n.º 3
0
 def _getpath (self,p):
 
     c = self.c
     dict = g.scanDirectives(c,p=p)
     d = dict.get("path")
 
     if p.isAnyAtFileNode():
         filename = p.anyAtFileNodeName()
         filename = g.os_path_join(d,filename)
         if filename:
             d = g.os_path_dirname(filename)
 
     if d is None:
         return ""
     else:
         return g.os_path_normpath(d)
Exemplo n.º 4
0
    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