Commits

anatoly techtonik committed f15f8d0

add reinject.py to insert subversion bindings inside mercurial library.zip

Comments (0)

Files changed (1)

+"""
+Feel free to send patches as I didn't really had time to polish this thing.
+"""
+
+import os,sys,shutil
+
+def get_loader(dllname):
+  # Loader from py2exe
+  #
+  # This loader locates extension modules relative to the library.zip
+  # file when an archive is used (i.e., skip_archive is not used), otherwise
+  # it locates extension modules relative to sys.prefix.
+  LOADER = """
+def __load():
+    import imp, os, sys
+    try:
+        dirname = os.path.dirname(__loader__.archive)
+    except NameError:
+        dirname = sys.prefix
+    path = os.path.join(dirname, '%s')
+    #print "py2exe extension module", __name__, "->", path
+    mod = imp.load_dynamic(__name__, path)
+##    mod.frozen = 1
+__load()
+del __load
+  """
+  return LOADER % dllname
+
+if len(sys.argv) < 2 or not os.path.isdir(sys.argv[1]):
+  sys.exit("supply path to 'libsvn' dir")
+
+libdir = sys.argv[1]
+_dlls = [name for name in os.listdir(libdir) if name.startswith("_") and name.endswith(".dll")]
+#print _dlls
+
+for name in _dlls:
+  shutil.copy(libdir+"/"+name, "libsvn."+name)
+  open(name.split('.')[0]+".py", "w").write(get_loader("libsvn."+name))
+
+print
+print "copy libsvn._*.dll files and libsvn_swig_py-1.dll into mercurial directory"
+print "put generated *.py files into library.zip:/libsvn"
+print "copy other (lib)svn/*.py files into library.zip:/(lib)svn"