Ejemplo n.º 1
0
def test_egg_info():
    egg_dir = os.path.join(os.path.dirname(__file__), 'fake_packages',
                           'FakePlugin.egg')
    found = pluginlib.find_egg_info_dir(os.path.join(egg_dir, 'fakeplugin'))
    assert found == os.path.join(egg_dir, 'FakePlugin.egg-info')
    found = pluginlib.find_egg_info_dir(os.path.dirname(__file__))
    assert found == os.path.join(os.path.dirname(os.path.dirname(__file__)),
                                 'PasteScript.egg-info')
Ejemplo n.º 2
0
def test_egg_info():
    egg_dir = os.path.join(os.path.dirname(__file__),
                           'fake_packages', 'FakePlugin.egg')
    found = pluginlib.find_egg_info_dir(os.path.join(egg_dir, 'fakeplugin'))
    assert found == os.path.join(egg_dir, 'FakePlugin.egg-info')
    found = pluginlib.find_egg_info_dir(os.path.dirname(__file__))
    assert found == os.path.join(
        os.path.dirname(os.path.dirname(__file__)),
        'PasteScript.egg-info')
Ejemplo n.º 3
0
 def find_dir(self, dirname, package=False):
     egg_info = pluginlib.find_egg_info_dir(os.getcwd())
     # @@: Should give error about egg_info when top_level.txt missing
     f = open(os.path.join(egg_info, 'top_level.txt'))
     packages = [l.strip() for l in f.readlines()
                 if l.strip() and not l.strip().startswith('#')]
     f.close()
     if not len(packages):
         raise BadCommand("No top level dir found for %s" % dirname)
     # @@: This doesn't support deeper servlet directories,
     # or packages not kept at the top level.
     base = os.path.dirname(egg_info)
     possible = []
     for pkg in packages:
         d = os.path.join(base, pkg, dirname)
         if os.path.exists(d):
             possible.append((pkg, d))
     if not possible:
         self.ensure_dir(os.path.join(base, packages[0], dirname),
                         package=package)
         return self.find_dir(dirname)
     if len(possible) > 1:
         raise BadCommand(
             "Multiple %s dirs found (%s)" % (dirname, possible))
     return possible[0]
Ejemplo n.º 4
0
 def find_dir(self, dirname, package=False):
     egg_info = pluginlib.find_egg_info_dir(os.getcwd())
     # @@: Should give error about egg_info when top_level.txt missing
     f = open(os.path.join(egg_info, 'top_level.txt'))
     packages = [
         l.strip() for l in f.readlines()
         if l.strip() and not l.strip().startswith('#')
     ]
     f.close()
     if not len(packages):
         raise BadCommand("No top level dir found for %s" % dirname)
     # @@: This doesn't support deeper servlet directories,
     # or packages not kept at the top level.
     base = os.path.dirname(egg_info)
     possible = []
     for pkg in packages:
         d = os.path.join(base, pkg, dirname)
         if os.path.exists(d):
             possible.append((pkg, d))
     if not possible:
         self.ensure_dir(os.path.join(base, packages[0], dirname),
                         package=package)
         return self.find_dir(dirname)
     if len(possible) > 1:
         raise BadCommand("Multiple %s dirs found (%s)" %
                          (dirname, possible))
     return possible[0]
Ejemplo n.º 5
0
    def command(self):
        self.modelname = self.options.modelname
        self.modelpackage = self.options.modelpackage
        self.modelform = self.options.modelform
        self.primary_key = self.options.primary_key

        try:
            try:
                # Determine the package name from the .egg-info top_level.txt.
                here_dir = os.getcwd()
                egg_info = find_egg_info_dir(here_dir)
                f = open(os.path.join(egg_info, 'top_level.txt'))
                packages = [l.strip() for l in f.readlines()
                        if l.strip() and not l.strip().startswith('#')]
                f.close()
                #upper 2 levels
                baselink = os.path.dirname(
                            os.path.dirname(os.path.abspath(__file__)))
                file_op = FileOp(
                            source_dir=os.path.join(baselink, 'templates'))
                self.base_package, directory = \
                            file_op.find_dir('controllers', True)
            except:
                raise command.BadCommand('No egg_info directory was found')

        except command.BadCommand, e:
            raise command.BadCommand('An error occurred. %s' % e)
Ejemplo n.º 6
0
    def add_hidden_tag(self, output_dir, vars, pmarker):
        add_hidden = True
        egg_info = pluginlib.find_egg_info_dir(output_dir)
        theme_vars_fp = os.path.join(egg_info, 'theme_vars.txt')

        if egg_info and os.path.exists(theme_vars_fp):
            config = SafeConfigParser()
            config.read(theme_vars_fp)

            sec, opt = 'qplone3_theme', 'used_subtemplates'
            used_subtemplates = filter(None,[st.strip() \
                         for st in config.get(sec,opt).split(',')])
            
            if self.name in used_subtemplates:
                sections = [self.name,]
                if config.has_section('multiple_templates') and \
                  config.has_option('multiple_templates',self.name):
                    ms_sections = config.get('multiple_templates',self.name)
                    sections = [s.strip() for s in ms_sections.split(',')]

                pmarkers = [config.get(sec, 'viewlet_profile_marker') \
                            for sec in sections]
                if pmarker in pmarkers:
                    add_hidden = False
        return add_hidden
Ejemplo n.º 7
0
    def _list_sub_templates(self, show_all=False):
        """
        lists available templates
        """
        templates = []
        parent_template = None

        egg_info_dir = pluginlib.find_egg_info_dir(os.getcwd())
        src_path = os.path.dirname(egg_info_dir)
        setup_path = os.path.sep.join(src_path.split(os.path.sep)[:-1])
        setup_cfg = os.path.join(setup_path, 'setup.cfg')

        parent_template = None
        if os.path.exists(setup_cfg):
            parser = ConfigParser.ConfigParser()
            parser.read(setup_cfg)
            try:
                parent_template =\
                    parser.get('templer.local', 'template') or None
            except:
                pass

        for entry in self._all_entry_points():
            try:
                entry_point = entry.load()
                t = entry_point(entry.name)
                if show_all or \
                   parent_template is None or \
                   parent_template in t.parent_templates:
                    templates.append(t)
            except Exception, e:
                # We will not be stopped!
                print 'Warning: could not load entry point %s (%s: %s)' % (
                    entry.name, e.__class__.__name__, e)
Ejemplo n.º 8
0
 def command(self):
     """Main command to create a modwsgi configuration files"""
     #Output directory is current folder unless specified vi output command.
     output_dir = os.path.join(self.options.output_dir, 'apache')
     #Input where the templates are at.
     input_dir= source_filename = os.path.join(os.path.dirname(__file__), 'templates/apache')
     #Finding directory that has egg info
     egg_info_dir = pluginlib.find_egg_info_dir(os.getcwd())
     #Name of the module
     plugins= os.path.splitext(os.path.basename(egg_info_dir))[0]
     #print os.path.splitext(os.path.basename(egg_info_dir))[0]
     dist_name= pluginlib.get_distro(plugins)
     vars={}
     #If PKG-INFO exists read it and add it to vars
     if dist_name.has_metadata('PKG-INFO'):
         data=dist_name.get_metadata('PKG-INFO')
         for add_info in pluginlib.parse_lines(data):
             (key,value) = add_info.split(':',1)
             vars[key]=value
     #Add package names
     vars['project']=plugins
     vars['package']=plugins
     vars['egg']=pluginlib.egg_name(str(dist_name))
     
     #Copy my template direcotry to destination.
     copy_dir(input_dir, output_dir, vars, verbosity=1, simulate=False, use_cheetah=True)
     print 'Thank you for using modwsgideploy!'
     print 'Please read README.txt in apache folder.'
     print 'http://lucasmanual.com/mywiki/modwsgideploy'
     print 'Made in Chicago,IL USA'
Ejemplo n.º 9
0
    def add_template_vars(self, output_dir, vars):

        egg_info = pluginlib.find_egg_info_dir(output_dir)
        theme_vars_fp = os.path.join(egg_info, 'theme_vars.txt')

        if egg_info and os.path.exists(theme_vars_fp):
            config = SafeConfigParser()
            config.read(theme_vars_fp)

            # Update qplone3_theme used_subtemplate option
            sec, opt = 'qplone3_theme', 'used_subtemplates'
            val = filter(None,[st.strip() \
                         for st in config.get(sec,opt).split(',')])
            val.append(self.name)
            config.set(sec, opt, ','.join(set(val)))

            # Add subtemplate vars
            if self.shared_vars:
                thesection = self.name
                if config.has_section(thesection):
                    msection = 'multiple_templates'
                    moption = self.name

                    if not config.has_section(msection):
                        config.add_section(msection)

                    val = []
                    if config.has_option(msection, moption):
                        val = config.get(msection, moption).split(',')
                    else:
                        val.append(moption)
                    thesection = "%s_%d"%(moption,len(val))
                    val.append(thesection)

                    config.set(msection, moption, ','.join(val))

                config.add_section(thesection)
                for k in self.shared_vars:
                    config.set(thesection, k, vars[k])

            # Save theme_vars.txt file
            theme_file = file(theme_vars_fp,'w')
            config.write(theme_file)
            theme_file.close()
Ejemplo n.º 10
0
    def get_template_vars(self, output_dir, vars):

        res = {}
        egg_info = pluginlib.find_egg_info_dir(output_dir)
        theme_vars_fp = os.path.join(egg_info, 'theme_vars.txt')

        if egg_info and os.path.exists(theme_vars_fp):
            config = SafeConfigParser()
            config.read(theme_vars_fp)
            
            for section in config.sections():
                for option in config.options(section):
                    key = section + '_' + option
                    val = config.get(section, option)
                    if section == 'multiple_templates':
                        val = val.split(',')
                    res[key] = val

        return res
Ejemplo n.º 11
0
    def command(self):
        """Main command to create a new shell"""
        self.verbose = 3
        if len(self.args) == 0:
            # Assume the .ini file is ./development.ini
            config_file = 'development.ini'
            if not os.path.isfile(config_file):
                raise BadCommand('%sError: CONFIG_FILE not found at: .%s%s\n'
                                 'Please specify a CONFIG_FILE' % \
                                 (self.parser.get_usage(), os.path.sep,
                                  config_file))
        else:
            config_file = self.args[0]

        config_name = 'config:%s' % config_file
        here_dir = os.getcwd()
        locs = dict(__name__="pylons-admin")

        # XXX: Note, initializing CONFIG here is Legacy support. pylons.config
        # will automatically be initialized and restored via the registry
        # restorer along with the other StackedObjectProxys
        # Load app config into paste.deploy to simulate request config
        # Setup the Paste CONFIG object, adding app_conf/global_conf for legacy
        # code
        conf = appconfig(config_name, relative_to=here_dir)
        conf.update(dict(app_conf=conf.local_conf,
                         global_conf=conf.global_conf))
        paste.deploy.config.CONFIG.push_thread_config(conf)

        # Load locals and populate with objects for use in shell
        sys.path.insert(0, here_dir)

        # Load the wsgi app first so that everything is initialized right
        wsgiapp = loadapp(config_name, relative_to=here_dir)
        test_app = paste.fixture.TestApp(wsgiapp)

        # Query the test app to setup the environment
        tresponse = test_app.get('/_test_vars')
        request_id = int(tresponse.body)

        # Disable restoration during test_app requests
        test_app.pre_request_hook = lambda self: \
            paste.registry.restorer.restoration_end()
        test_app.post_request_hook = lambda self: \
            paste.registry.restorer.restoration_begin(request_id)

        # Restore the state of the Pylons special objects
        # (StackedObjectProxies)
        paste.registry.restorer.restoration_begin(request_id)

        # Determine the package name from the .egg-info top_level.txt.
        egg_info = find_egg_info_dir(here_dir)
        f = open(os.path.join(egg_info, 'top_level.txt'))
        packages = [l.strip() for l in f.readlines()
                    if l.strip() and not l.strip().startswith('#')]
        f.close()

        # Start the rest of our imports now that the app is loaded
        found_base = False
        for pkg_name in packages:
            # Import all objects from the base module
            base_module = pkg_name + '.lib.base'
            found_base = can_import(base_module)
            if not found_base:
                # Minimal template
                base_module = pkg_name + '.controllers'
                found_base = can_import(base_module)

            if found_base:
                break

        if not found_base:
            raise ImportError("Could not import base module. Are you sure "
                              "this is a Pylons app?")

        base = sys.modules[base_module]
        base_public = [__name for __name in dir(base) if not \
                       __name.startswith('_') or __name == '_']
        for name in base_public:
            locs[name] = getattr(base, name)
        locs.update(dict(wsgiapp=wsgiapp, app=test_app))

        mapper = tresponse.config.get('routes.map')
        if mapper:
            locs['mapper'] = mapper

        banner = "  All objects from %s are available\n" % base_module
        banner += "  Additional Objects:\n"
        if mapper:
            banner += "  %-10s -  %s\n" % ('mapper', 'Routes mapper object')
        banner += "  %-10s -  %s\n" % ('wsgiapp',
            "This project's WSGI App instance")
        banner += "  %-10s -  %s\n" % ('app',
            'paste.fixture wrapped around wsgiapp')

        if not self.options.quiet:
            # Configure logging from the config file
            self.logging_file_config(config_file)
        
        try:
            if self.options.disable_ipython:
                raise ImportError()

            # try to use IPython if possible
            from IPython.Shell import IPShellEmbed

            shell = IPShellEmbed(argv=self.args)
            shell.set_banner(shell.IP.BANNER + '\n\n' + banner)
            try:
                shell(local_ns=locs, global_ns={})
            finally:
                paste.registry.restorer.restoration_end()
        except ImportError:
            import code
            newbanner = "Pylons Interactive Shell\nPython %s\n\n" % sys.version
            banner = newbanner + banner
            shell = code.InteractiveConsole(locals=locs)
            try:
                import readline
            except ImportError:
                pass
            try:
                shell.interact(banner)
            finally:
                paste.registry.restorer.restoration_end()
Ejemplo n.º 12
0
    def command(self):
        """Main command to create a new shell"""
        self.verbose = 3
        if len(self.args) == 0:
            # Assume the .ini file is ./development.ini
            config_file = 'development.ini'
            if not os.path.isfile(config_file):
                raise BadCommand('%sError: CONFIG_FILE not found at: .%s%s\n'
                                 'Please specify a CONFIG_FILE' % \
                                 (self.parser.get_usage(), os.path.sep,
                                  config_file))
        else:
            config_file = self.args[0]

        config_name = 'config:%s' % config_file
        here_dir = os.getcwd()
        locs = dict(__name__="pylons-admin")

        # XXX: Note, initializing CONFIG here is Legacy support. pylons.config
        # will automatically be initialized and restored via the registry
        # restorer along with the other StackedObjectProxys
        # Load app config into paste.deploy to simulate request config
        # Setup the Paste CONFIG object, adding app_conf/global_conf for legacy
        # code
        conf = appconfig(config_name, relative_to=here_dir)
        conf.update(
            dict(app_conf=conf.local_conf, global_conf=conf.global_conf))
        paste.deploy.config.CONFIG.push_thread_config(conf)

        # Load locals and populate with objects for use in shell
        sys.path.insert(0, here_dir)

        # Load the wsgi app first so that everything is initialized right
        wsgiapp = loadapp(config_name, relative_to=here_dir)
        test_app = paste.fixture.TestApp(wsgiapp)

        # Query the test app to setup the environment
        tresponse = test_app.get('/_test_vars')
        request_id = int(tresponse.body)

        # Disable restoration during test_app requests
        test_app.pre_request_hook = lambda self: \
            paste.registry.restorer.restoration_end()
        test_app.post_request_hook = lambda self: \
            paste.registry.restorer.restoration_begin(request_id)

        # Restore the state of the Pylons special objects
        # (StackedObjectProxies)
        paste.registry.restorer.restoration_begin(request_id)

        # Determine the package name from the .egg-info top_level.txt.
        egg_info = find_egg_info_dir(here_dir)
        f = open(os.path.join(egg_info, 'top_level.txt'))
        packages = [
            l.strip() for l in f.readlines()
            if l.strip() and not l.strip().startswith('#')
        ]
        f.close()

        # Start the rest of our imports now that the app is loaded
        found_base = False
        for pkg_name in packages:
            # Import all objects from the base module
            base_module = pkg_name + '.lib.base'
            found_base = can_import(base_module)
            if not found_base:
                # Minimal template
                base_module = pkg_name + '.controllers'
                found_base = can_import(base_module)

            if found_base:
                break

        if not found_base:
            raise ImportError("Could not import base module. Are you sure "
                              "this is a Pylons app?")

        base = sys.modules[base_module]
        base_public = [__name for __name in dir(base) if not \
                       __name.startswith('_') or __name == '_']
        for name in base_public:
            locs[name] = getattr(base, name)
        locs.update(dict(wsgiapp=wsgiapp, app=test_app))

        mapper = tresponse.config.get('routes.map')
        if mapper:
            locs['mapper'] = mapper

        banner = "  All objects from %s are available\n" % base_module
        banner += "  Additional Objects:\n"
        if mapper:
            banner += "  %-10s -  %s\n" % ('mapper', 'Routes mapper object')
        banner += "  %-10s -  %s\n" % ('wsgiapp',
                                       "This project's WSGI App instance")
        banner += "  %-10s -  %s\n" % ('app',
                                       'paste.fixture wrapped around wsgiapp')

        if not self.options.quiet:
            # Configure logging from the config file
            self.logging_file_config(config_file)

        try:
            if self.options.disable_ipython:
                raise ImportError()

            # try to use IPython if possible
            from IPython.Shell import IPShellEmbed

            shell = IPShellEmbed(argv=self.args)
            shell.set_banner(shell.IP.BANNER + '\n\n' + banner)
            try:
                shell(local_ns=locs, global_ns={})
            finally:
                paste.registry.restorer.restoration_end()
        except ImportError:
            import code
            newbanner = "Pylons Interactive Shell\nPython %s\n\n" % sys.version
            banner = newbanner + banner
            shell = code.InteractiveConsole(locals=locs)
            try:
                import readline
            except ImportError:
                pass
            try:
                shell.interact(banner)
            finally:
                paste.registry.restorer.restoration_end()
Ejemplo n.º 13
0
 def get_egg_info_dir(self):
     return pluginlib.find_egg_info_dir(os.getcwd())
Ejemplo n.º 14
0
 def dest_dir(self):
     ns_pkg, ns_pkg2, pkg = self.get_parent_namespace_packages()
     dest_dir = os.path.join(
         os.path.dirname(pluginlib.find_egg_info_dir(os.getcwd())),
         ns_pkg, ns_pkg2, pkg)
     return dest_dir