Really, I'm not trying to be funny... but where are the missing
modules? are they on the machine somewhere? or do they need to be
fetched from the net somewhere?

This does seem like a great idea! Do we mean to load "unknown" modules
or install missing software? or both? this is what I do for
"unknown" (like missing) modules ... they only get loaded at build
time, this way I don't need to care what the build system is doing...

hoep it helps, and apologies if you mean something else :)

    '''
    blueCmdHandler extends cmdBaseClass
    '''
    def loadBuildCmd(self,
                     builtins=None):

        '''--- Use dictFunctionObject (DFO), to step through main sets
---'''
        '''--- * 1) retrieve _main_ sets DFO from objInit table
---'''
        rows = self.db(self.db.buildData.id>0).select()
        last_row = rows.last()
        dfo_main = cPickle.loads(last_row.get('dfo_main'))

        '''--- * 2) retrieve cmd_Init DFO from cmdObjects table
---'''
        rows = self.db(self.db.cmdObjects.id>0).select()

        '''--- * 3) retrieve cmd_Init DFO from cmdObjects table
                    retrieve all cmds/pyModules specified in build
file ---'''
        for row in rows:
            '''--- load serialized (pickled) data from data ---'''
            cmdInit =
cPickle.loads(row.get('dfo_objCmd'))
            '''--- iter through ---'''
            if 'Cmd' in cmdInit.keys():
                '''---
                pyModule (i.e. blueLite.pyModules.cmdInit) is the path
to
                the module to be invoked. Pass pyModule to blueCmd
 
---'''
                pyModule =
cmdInit.Cmd.pyModule
                try:
                    self.blueCmd(pyModule,row.name)
                except  Exception as
errObj:
                    err = cmdException.cmdPlugin(self.db,row.name)
 
err.blueCmd(errObj,pyModule,all)


    def blueCmd(self,
                chloe,
                rowName,
                builtIn_CmdName=None):
        '''---
             chloe is the module to be __imported__
 
---'''
        if chloe is not None:
            print("{0} will be processed by blueLite".format(chloe))
            '''---
                miaZoe is the named py class going to sys.modules
                                                                ---'''
            try:
                miaZoe = __import__(chloe)
                components = chloe.split('.')
                '''---
                    split the path to named module, and collect
attributes
 
---'''

                for comp in components[1:]:
                    miaZoe = getattr(miaZoe,
                                     comp)

                '''---
                caraAnne is now the object reference to class Chloe,
no need to
                worry about __imported__ class since they inherit from
base class
                call cmdPlugin, then blueCmd()
                                                         ---'''

                caraAnne = miaZoe.cmdPlugin(self.db,
                                            rowName)
                '''---
                step logic is in <pyModule>.cmd().
                                            ---'''
                caraAnne.blueCmd()
                '''---
                step is done, chuck object and class reference
                                                          ---'''
                if caraAnne is not None:
                    del caraAnne
                del miaZoe


On Dec 29, 11:47 pm, mdipierro <[email protected]> wrote:
> How about some code that is you try o timport a module that is not
> installed, trys to ez_install it?
>
> import sys, imp
> from ez_setup import use_setuptools
> use_setuptools()
> from setuptools.command.easy_install import main
>
> class SmartImporter(object):
>     tried_modules=set()
>     domain_modules = set()
>
>     def find_module(self, fullname, path=None):
>         if fullname in self.domain_modules:
>             return self
>         if fullname in self.tried_modules:
>             return None
>         else:
>             self.tried_modules.add(fullname)
>             try:
>                 main([fullname])
>                 return self
>             except:
>                 return None
>
>     def load_module(self, fullname):
>         if fullname in sys.modules:
>             return sys.modules[fullname]
>         mod = imp.new_module(fullname)
>         mod.__loader__ = self
>         sys.modules[fullname] = mod
>         if fullname not in self.domain_modules:
>             self.domain_modules.add(fullname)
>         return mod
>
> sys.meta_path = [SmartImporter()]
>
> import tornado # is not installed should install it!
> print tornado
>
> This does not quite works. I could use some help.
>
> Massimo

Reply via email to