~vcs-imports/pyxdg/main

« back to all changes in this revision

Viewing changes to xdg/Menu.py

  • Committer: lanius
  • Date: 2005-08-09 10:58:04 UTC
  • Revision ID: Arch-1:pyxdg@products.ubuntu.com%pyxdg--MAIN--0--patch-309
another fix

Show diffs side-by-side

added added

removed removed

Lines of Context:
751
751
        if value:
752
752
                for item in os.listdir(value):
753
753
                        try:
754
 
                                item.decode(locale.getpreferredencoding()).encode('utf-8')
755
 
                        except:
 
754
                                if os.path.splitext(item)[1] == ".menu":
 
755
                                        __mergeFile(os.path.join(value, item), child, parent)
 
756
                        except UnicodeDecodeError:
756
757
                                continue
757
758
 
758
 
                        if os.path.splitext(item)[1] == ".menu":
759
 
                                __mergeFile(os.path.join(value, item), child, parent)
760
 
 
761
759
def __parseDefaultMergeDirs(child, filename, parent):
762
760
        basename = os.path.splitext(os.path.basename(filename))[0]
763
761
        for dir in reversed(xdg_config_dirs):
806
804
 
807
805
                for item in os.listdir(dir):
808
806
                        try:
809
 
                                item.decode(locale.getpreferredencoding()).encode('utf-8')
810
 
                        except:
 
807
                                if item == ".directory":
 
808
                                        m.Directories.append(item)
 
809
                                elif os.path.isdir(os.path.join(dir,item)):
 
810
                                        m.addSubmenu(__mergeLegacyDir(os.path.join(dir,item), prefix, filename, parent))
 
811
                        except UnicodeDecodeError:
811
812
                                continue
812
813
 
813
 
                        if item == ".directory":
814
 
                                m.Directories.append(item)
815
 
                        elif os.path.isdir(os.path.join(dir,item)):
816
 
                                m.addSubmenu(__mergeLegacyDir(os.path.join(dir,item), prefix, filename, parent))
817
 
 
818
814
                tmp["cache"].addMenuEntries([dir],prefix, True)
819
815
                menuentries = tmp["cache"].getMenuEntries([dir], False)
820
816
 
1005
1001
 
1006
1002
        def __addFiles(self, dir, subdir, prefix, legacy):
1007
1003
                for item in os.listdir(os.path.join(dir,subdir)):
1008
 
                        try:
1009
 
                                item.decode(locale.getpreferredencoding()).encode('utf-8')
1010
 
                        except:
1011
 
                                continue
1012
 
 
1013
1004
                        if os.path.splitext(item)[1] == ".desktop":
1014
1005
                                try:
1015
1006
                                        menuentry = MenuEntry(os.path.join(subdir,item), dir, prefix)
1037
1028
                        pass
1038
1029
                for dir in appdirs:
1039
1030
                        for menuentry in self.cacheEntries[dir]:
1040
 
                                if menuentry.DesktopFileID not in ids:
1041
 
                                        ids.append(menuentry.DesktopFileID)
1042
 
                                        list.append(menuentry)
1043
 
                                elif menuentry.getType() == "System":
1044
 
                                # FIXME: This is only 99% correct, but still...
1045
 
                                        i = list.index(menuentry)
1046
 
                                        e = list[i]
1047
 
                                        if e.getType() == "User":
1048
 
                                                e.Original = menuentry
 
1031
                                try:
 
1032
                                        if menuentry.DesktopFileID not in ids:
 
1033
                                                ids.append(menuentry.DesktopFileID)
 
1034
                                                list.append(menuentry)
 
1035
                                        elif menuentry.getType() == "System":
 
1036
                                        # FIXME: This is only 99% correct, but still...
 
1037
                                                i = list.index(menuentry)
 
1038
                                                e = list[i]
 
1039
                                                if e.getType() == "User":
 
1040
                                                        e.Original = menuentry
 
1041
                                except UnicodeDecodeError:
 
1042
                                        continue
1049
1043
                self.cache[key] = list
1050
1044
                return list