1. Yuya Nishihara
  2. hgext-fixfrozenexts

Commits

Yuya Nishihara  committed 3f4a9c3

at least, it can list up some extensions

  • Participants
  • Branches default

Comments (0)

Files changed (1)

File hgext/fixfrozenexts.py

View file
+# fixfrozenexts - fix extensions.disabled() to work on frozen package
+#
+# Copyright 2010 Yuya Nishihara <yuya@tcha.org>
+#
+# This software may be used and distributed according to the terms of the
+# GNU General Public License version 2 or any later version.
+
+"""fix extensions.disabled() to work on frozen package"""
+
+import sys, os, zipfile
+from mercurial import util, extensions, help
+from mercurial.i18n import _, gettext
+
+def _libpath():
+    return os.path.join(os.path.dirname(sys.executable), 'library.zip')
+
+def _disabledpaths(orig, strip_init=False):
+    exts = {}
+    zf = zipfile.ZipFile(_libpath())
+    try:
+        for e in zf.namelist():
+            if not e.startswith('hgext/'):
+                continue
+            if e.endswith('.pyo'):
+                name = e[6:].rsplit('.', 1)[0]
+                path = e
+                exts[name] = path
+            else:
+                pass  # FIXME
+        return exts
+    finally:
+        zf.close()
+
+def _disabledhelp(orig, path):
+    # FIXME: not work for *.pyo
+    zf = zipfile.ZipFile(_libpath())
+    try:
+        try:
+            file = zf.open(path)
+        except IOError:
+            return
+        else:
+            doc = help.moduledoc(file)
+            file.close()
+
+        if doc: # extracting localized synopsis
+            return gettext(doc).splitlines()[0]
+        else:
+            return _('(no help text available)')
+    finally:
+        zf.close()
+
+def extsetup():
+    if not util.main_is_frozen():
+        return
+
+    for e in ('_disabledpaths', '_disabledhelp'):
+        extensions.wrapfunction(extensions, e, globals()[e])