summaryrefslogtreecommitdiffstats
path: root/pygtk.py
diff options
context:
space:
mode:
authorJohan Dahlin <zilch@src.gnome.org>2003-01-07 23:16:01 +0000
committerJohan Dahlin <zilch@src.gnome.org>2003-01-07 23:16:01 +0000
commit91a638791a09285e052415194c3a35f9ce231bdc (patch)
tree690f7689319fd5cd113a21ad3d38271fcad31487 /pygtk.py
parentc7719c39095334785d6a7b88617e23ef487142b1 (diff)
downloadpygobject-91a638791a09285e052415194c3a35f9ce231bdc.tar.gz
pygobject-91a638791a09285e052415194c3a35f9ce231bdc.tar.xz
pygobject-91a638791a09285e052415194c3a35f9ce231bdc.zip
Rewrite using glob.glob, with python2.2 glob uses fnmatch.filter with is
* pygtk.py (_get_available_versions): Rewrite using glob.glob, with python2.2 glob uses fnmatch.filter with is an optimized version of what we did before. _get_available_versions is now roughly 5 times faster.
Diffstat (limited to 'pygtk.py')
-rw-r--r--pygtk.py25
1 files changed, 15 insertions, 10 deletions
diff --git a/pygtk.py b/pygtk.py
index 821f567..77c6862 100644
--- a/pygtk.py
+++ b/pygtk.py
@@ -19,28 +19,33 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA
-import sys, os, re
+import fnmatch
+import glob
+import os
+import sys
__all__ = ['require']
-_pygtk_dir_pat = re.compile(r'^gtk-([\d]+[\d\.]+)$')
_pygtk_required_version = None
def _get_available_versions():
- global _pygtk_dir_pat
versions = {}
for dir in sys.path:
- if not dir: dir = os.getcwd()
- if not os.path.isdir(dir): continue
- if _pygtk_dir_pat.match(os.path.basename(dir)):
+ if not dir:
+ dir = os.getcwd()
+ if not os.path.isdir(dir):
+ continue
+
+ if fnmatch.fnmatchcase(os.path.basename(dir), DIR_PAT):
continue # if the dir is a pygtk dir, skip it
- for filename in os.listdir(dir):
+
+ for filename in glob.glob(os.path.join(dir, DIR_PAT)):
pathname = os.path.join(dir, filename)
if not os.path.isdir(pathname):
continue # skip non directories
- match = _pygtk_dir_pat.match(filename)
- if match and not versions.has_key(match.group(1)):
- versions[match.group(1)] = pathname
+
+ if not versions.has_key(filename[-3:]):
+ versions[filename[-3:]] = pathname
return versions
def require(version):