Mercurial > cpython-lru_cache-weakref
annotate Lib/idlelib/PathBrowser.py @ 79691:05c8928362ee
Merge __next__ method link fixes with 3.3.
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Fri, 12 Oct 2012 13:46:37 +0300 |
| parents | b81ddaf0db47 |
| children | d369e50677a6 |
| rev | line source |
|---|---|
| 13975 | 1 import os |
| 2 import sys | |
| 3 import imp | |
|
76874
b81ddaf0db47
Issue #13959: Deprecate imp.get_suffixes() for new attributes on
Brett Cannon <brett@python.org>
parents:
42714
diff
changeset
|
4 import importlib.machinery |
| 13975 | 5 |
|
42714
2ec16b6b4d04
Switch to absolute imports to support direct execution of modules. Many
Kurt B. Kaiser <kbk@shore.net>
parents:
42324
diff
changeset
|
6 from idlelib.TreeWidget import TreeItem |
|
2ec16b6b4d04
Switch to absolute imports to support direct execution of modules. Many
Kurt B. Kaiser <kbk@shore.net>
parents:
42324
diff
changeset
|
7 from idlelib.ClassBrowser import ClassBrowser, ModuleBrowserTreeItem |
| 13975 | 8 |
| 9 class PathBrowser(ClassBrowser): | |
|
18553
29be871bd876
py-cvs-rel2_1 (Rev 1.6) merge - whitespace normalization
Kurt B. Kaiser <kbk@shore.net>
parents:
13975
diff
changeset
|
10 |
| 13975 | 11 def __init__(self, flist): |
| 12 self.init(flist) | |
| 13 | |
| 14 def settitle(self): | |
| 15 self.top.wm_title("Path Browser") | |
| 16 self.top.wm_iconname("Path Browser") | |
| 17 | |
| 18 def rootnode(self): | |
| 19 return PathBrowserTreeItem() | |
| 20 | |
| 21 class PathBrowserTreeItem(TreeItem): | |
| 22 | |
| 23 def GetText(self): | |
| 24 return "sys.path" | |
| 25 | |
| 26 def GetSubList(self): | |
| 27 sublist = [] | |
| 28 for dir in sys.path: | |
| 29 item = DirBrowserTreeItem(dir) | |
| 30 sublist.append(item) | |
| 31 return sublist | |
| 32 | |
| 33 class DirBrowserTreeItem(TreeItem): | |
| 34 | |
| 35 def __init__(self, dir, packages=[]): | |
| 36 self.dir = dir | |
| 37 self.packages = packages | |
| 38 | |
| 39 def GetText(self): | |
| 40 if not self.packages: | |
| 41 return self.dir | |
| 42 else: | |
| 43 return self.packages[-1] + ": package" | |
| 44 | |
| 45 def GetSubList(self): | |
| 46 try: | |
| 47 names = os.listdir(self.dir or os.curdir) | |
| 48 except os.error: | |
| 49 return [] | |
| 50 packages = [] | |
| 51 for name in names: | |
| 52 file = os.path.join(self.dir, name) | |
| 53 if self.ispackagedir(file): | |
| 54 nn = os.path.normcase(name) | |
| 55 packages.append((nn, name, file)) | |
| 56 packages.sort() | |
| 57 sublist = [] | |
| 58 for nn, name, file in packages: | |
| 59 item = DirBrowserTreeItem(file, self.packages + [name]) | |
| 60 sublist.append(item) | |
| 61 for nn, name in self.listmodules(names): | |
| 62 item = ModuleBrowserTreeItem(os.path.join(self.dir, name)) | |
| 63 sublist.append(item) | |
| 64 return sublist | |
| 65 | |
| 66 def ispackagedir(self, file): | |
| 67 if not os.path.isdir(file): | |
| 68 return 0 | |
| 69 init = os.path.join(file, "__init__.py") | |
| 70 return os.path.exists(init) | |
| 71 | |
| 72 def listmodules(self, allnames): | |
| 73 modules = {} | |
|
76874
b81ddaf0db47
Issue #13959: Deprecate imp.get_suffixes() for new attributes on
Brett Cannon <brett@python.org>
parents:
42714
diff
changeset
|
74 suffixes = importlib.machinery.EXTENSION_SUFFIXES[:] |
|
b81ddaf0db47
Issue #13959: Deprecate imp.get_suffixes() for new attributes on
Brett Cannon <brett@python.org>
parents:
42714
diff
changeset
|
75 suffixes += importlib.machinery.SOURCE_SUFFIXES[:] |
|
b81ddaf0db47
Issue #13959: Deprecate imp.get_suffixes() for new attributes on
Brett Cannon <brett@python.org>
parents:
42714
diff
changeset
|
76 suffixes += importlib.machinery.BYTECODE_SUFFIXES[:] |
| 13975 | 77 sorted = [] |
| 78 for suff, mode, flag in suffixes: | |
| 79 i = -len(suff) | |
| 80 for name in allnames[:]: | |
| 81 normed_name = os.path.normcase(name) | |
| 82 if normed_name[i:] == suff: | |
| 83 mod_name = name[:i] | |
|
39634
d91585b2cdc1
Remove has_key() references from idlelib. IDLE still doesn't run due
Guido van Rossum <guido@python.org>
parents:
18553
diff
changeset
|
84 if mod_name not in modules: |
| 13975 | 85 modules[mod_name] = None |
| 86 sorted.append((normed_name, name)) | |
| 87 allnames.remove(name) | |
| 88 sorted.sort() | |
| 89 return sorted | |
| 90 | |
| 91 def main(): | |
|
42714
2ec16b6b4d04
Switch to absolute imports to support direct execution of modules. Many
Kurt B. Kaiser <kbk@shore.net>
parents:
42324
diff
changeset
|
92 from idlelib import PyShell |
| 13975 | 93 PathBrowser(PyShell.flist) |
| 94 if sys.stdin is sys.__stdin__: | |
| 95 mainloop() | |
| 96 | |
| 97 if __name__ == "__main__": | |
| 98 main() |
