On Tue, 2010-07-20 at 14:10 +0200, Antonio Valentino wrote:

> > --------------------------
> > Then at runtime the unpackMetadata.py was the key:
> > import carchive
> > import sys
> > import os
> > 
> > this = carchive.CArchive(sys.executable)
> > archives = os.environ['_MEIPASS2']
> > pkgs = ['wx', 'traits', 'traitswx', 'chaco', 'enthought', 'enable',
> > 'traitsgui'] for pkg in pkgs:
> >     mp = this.openEmbedded('%s.pkg' % pkg)
> >     targetdir = os.path.join(archives,pkg)
> >     os.mkdir(targetdir)
> >     print "Extracting %s ..." % pkg,
> >     for fnm in mp.contents():
> >         try:
> >             stuff = mp.extract(fnm)[1]
> >             outnm = os.path.join(targetdir, fnm)
> >             dirnm = os.path.dirname(outnm)
> >             if not os.path.exists(dirnm):
> >                 os.makedirs(dirnm)
> >             open(outnm, 'wb').write(stuff)
> >         except Exception, mex:
> >             print mex
> >     mp = None
> >     sys.path.insert(0, targetdir)
> >     if pkg == 'traitsgui':
> >         imagepath = os.path.join(targetdir, 'enthought', 'traits',
> > 'ui', 'image', 'library')
> >         os.environ['TRAITS_IMAGES'] = imagepath
> >         os.putenv('TRAITS_IMAGES', imagepath)
> >     print "ok"
> > 
> > from resource_path_override import ResourcePathOverride
> > resource_override = ResourcePathOverride(archives)
> > 
> > -------------------------------------
> > And then the custom ResourcePathOverride:
> > import sys
> > import os
> > """This class will extend the original resource_path function so that
> > it will always point to the archive_path instead of whatever was
> > frozen into it. WARNING: Do not create an instance of this class
> > before the archives have been extracted!
> > """
> > class ResourcePathOverride(object):
> >     resource_path_orig = None
> >     archive_path = None
> > 
> >     def __init__(self, archive_path):
> >         import enthought.resource.resource_path #here, so that you can
> > import the module freely (at least in theory)
> >         self.resource_path_orig =
> > enthought.resource.resource_path.resource_path self.archive_path =
> > archive_path enthought.resource.resource_path.resource_path =
> > self.resource_path
> > 
> >     def resource_path(self, level = 2):
> >         path = self.resource_path_orig(level+1)
> >         path = path.rsplit(''.join((os.path.sep, 'enthought',
> > os.path.sep)), 1) root = path[0].rsplit(os.path.sep, 1)
> >         path = os.path.join(self.archive_path,
> > self.get_pkg_name(root[1]), 'enthought', path[1])
> >         return path
> > 
> >     def get_pkg_name(self, path):
> >         """This function must mirror the list in yasso.spec
> >         """
> >         if path.lower().startswith('traits-'):
> >             return 'traits'
> >         if path.lower().startswith('traitsgui'):
> >             return 'traitsgui'
> >         if path.lower().startswith('traitsbackendwx'):
> >             return 'traitswx'
> >         if path.lower().startswith('enable'):
> >             return 'enable'
> >         if path.lower().startswith('enthought'):
> >             return 'enthought'
> >         if path.lower().startswith('chaco'):
> >             return 'chaco'
> 
> This part is black magic.
> I wonder what Giovanni thinks about this solution and, most of all, if
> there are plans for an official pkg_resources support in pyinstaller.

The solution looks like it is on the right track, though it should be
generalized before being acceptable for PyInstaller.

The generic plan for pkg_resources I had in mind was to leverage its
hook mechanism to install a plugin into it to be able to dynamically
extract files from PyInstaller's pkg archive. This is just a generic
idea, and I don't know if it would really work.
-- 
Giovanni Bajo   ::  [email protected]
Develer S.r.l.  ::  http://www.develer.com

My Blog: http://giovanni.bajo.it
Last post: Compile-time Function Execution in D

-- 
You received this message because you are subscribed to the Google Groups 
"PyInstaller" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pyinstaller?hl=en.

Reply via email to