示例#1
0
    def first_pass(self, parser, node, children):
          print "initial!!!!!!"
          
          env = Environment(loader=FileSystemLoader('templates'))
          env_web = Environment(loader=FileSystemLoader('templates/web'))
          env_dao = Environment(loader=FileSystemLoader('templates/dao'))
          env_hibernate = Environment(loader=FileSystemLoader('templates/hibernate'))
          env_project = Environment(loader=FileSystemLoader('templates/project'))
          
          if not os.path.exists("WebApp/web"):
            os.makedirs("WebApp/web")
          if not os.path.exists("WebApp/src/dao/generic"):
            os.makedirs("WebApp/src/dao/generic")

          if not os.path.exists("WebApp/src/META-INF"):
            os.makedirs("WebApp/src/META-INF")

          if not os.path.exists("WebApp/src/util"):
            os.makedirs("WebApp/src/util")

          generate_text_file_project(env_dao.get_template('abstract_hibernate_dao.txt'),"WebApp/src/dao/generic/AbstractHibernateDao.java")  
          generate_text_file_project(env_dao.get_template('generic_dao.txt'),"WebApp/src/dao/generic/IGenericDao.java")  
          generate_text_file_project(env_web.get_template('error.txt'),"WebApp/web/error.jsp")
          generate_text_file_project(env_web.get_template('404.txt'),"WebApp/web/404.jsp")
          generate_text_file_project(env_project.get_template('application.txt'),"WebApp/src/META-INF/application.xml")
          generate_text_file_project(env_hibernate.get_template('hibernate_util.txt'),"WebApp/src/util/HibernateUtil.java")
          generate_text_file_project(env_hibernate.get_template('hibernate_listener.txt'),"WebApp/src/util/HibernateListener.java")
          generate_text_file_project(env_project.get_template('classpath.txt'),"WebApp/.classpath")
          generate_text_file_project(env_project.get_template('project.txt'),"WebApp/.project")
          generate_text_file_project(env_project.get_template('build_properties.txt'),"WebApp/build.properties")
          generate_text_file_project(env_project.get_template('jndi_properties.txt'),"WebApp/src/jndi.properties")
          generate_text_file_project(env_project.get_template('build.txt'),"WebApp/build.xml")
          generate_text_file_project(env_web.get_template('css.txt'),"WebApp/web/style.css")
          generate_text_file_project(env_web.get_template('home.txt'),"WebApp/web/home.jsp")
示例#2
0
    def execute(self, container, args):
        l = self.logger

        try:
            jira = container.getJIRA()

            try:
                op = generate_wbs(l)
                param_wbsentry = op.execute(container, args)

                env = Environment()

                templatepath = "%s/../data/%s" % (os.path.dirname(
                    os.path.realpath(__file__)), "generate_wbs")
                l.msg("Loading template from path %s" % templatepath)
                loader = FileSystemLoader(templatepath)

                template = loader.load(env, 'wbs.jinja2')
                return template.render(
                    param_wbsentry=param_wbsentry,
                    param_serverbase=container.connectionConfig.server)

            except Exception as e:
                l.error("Exception happened boards search " + str(e), e)

        except Exception as e:
            l.error(
                "Exception happened during connection establishment " + str(e),
                e)
示例#3
0
    def __init__(self, searchpath, files, prefix=None, **kwargs):
        FileSystemLoader.__init__(self, searchpath, **kwargs)
        self.files = files

        if prefix is not None and not prefix.endswith("/"):
            prefix += "/"
        self.prefix = prefix
示例#4
0
    def test_get_hierarchy_loader(self):
        expected_hierarchy = OrderedDict((
            ("eurogamer_net",
             FileSystemLoader(self.get_template_dir("eurogamer_net"))),
            ("eurogamer",
             FileSystemLoader(self.get_template_dir("eurogamer"))),
            ("core", FileSystemLoader(self.get_template_dir("core"))),
        ))
        loader = get_hierarchy_loader((
            ('eurogamer_net', self.get_template_dir('eurogamer_net')),
            ('eurogamer', self.get_template_dir('eurogamer')),
            ('core', self.get_template_dir('core')),
        ))
        expected_hierarchy_chain = list(expected_hierarchy.keys())
        expected_hierarchy_len = len(expected_hierarchy_chain)
        actual_hierarchy_chain = list(loader.hierarchy.keys())
        for i in range(expected_hierarchy_len):
            # Make sure the hierarchy is in the expected order
            loader_name = actual_hierarchy_chain[i]
            self.assertEquals(expected_hierarchy_chain[i],
                              actual_hierarchy_chain[i])
            # Make sure the templates contained within the built loader is
            # identical to what we are expecting
            expected_templates = expected_hierarchy[
                loader_name].list_templates()
            actual_templates = loader.hierarchy[loader_name].list_templates()
            self.assertEquals(expected_templates, actual_templates)

        self.assertEquals(len(file_system_loaders), 3)
示例#5
0
    def get_source(self, environment, template):
        # keep legacy asset: prefix checking that bypasses
        # source path checking altogether
        if template.startswith('asset:'):
            template = template[6:]

        # split the template into the chain of relative-imports
        rel_chain = template.split(PARENT_RELATIVE_DELIM)
        template, rel_chain = rel_chain[0], rel_chain[1:]

        # load the template directly if it's an absolute path or asset spec
        if os.path.isabs(template) or ':' in template:
            src = self._get_absolute_source(template)
            if src is not None:
                return src
            else:
                # fallback to the search path just incase
                return FileSystemLoader.get_source(self, environment, template)

        # try to import the template as an asset spec or absolute path
        # relative to its parents
        rel_searchpath = self._relative_searchpath(rel_chain)
        for parent in rel_searchpath:
            if os.path.isabs(parent):
                uri = os.path.join(parent, template)
                # avoid recursive includes
                if uri not in rel_chain:
                    src = self._get_absolute_source(uri)
                    if src is not None:
                        return src
            # avoid doing "':' in" and then redundant "split"
            parts = parent.split(':', 1)
            if len(parts) > 1:
                # parent is an asset spec
                ppkg, ppath = parts
                ppath = posixpath.join(ppath, template)
                uri = '{0}:{1}'.format(ppkg, ppath)
                # avoid recursive includes
                if uri not in rel_chain:
                    src = self._get_absolute_source(uri)
                    if src is not None:
                        return src

        # try to load the template from the default search path
        for parent in rel_searchpath:
            try:
                uri = os.path.join(parent, template)
                # avoid recursive includes
                if uri not in rel_chain:
                    return FileSystemLoader.get_source(self, environment, uri)
            except TemplateNotFound:
                pass

        # we're here because of an exception during the last step so extend
        # the message and raise an appropriate error
        # there should always be an exception because the rel_searchpath is
        # guaranteed to contain at least one element ('')
        searchpath = [p for p in rel_searchpath if p] + self.searchpath
        message = '{0}; searchpath={1}'.format(template, searchpath)
        raise TemplateNotFound(name=template, message=message)
示例#6
0
	def __init__(self, searchpath, files, prefix=None, **kwargs):
		FileSystemLoader.__init__(self, searchpath, **kwargs)
		self.files = files

		if prefix is not None and not prefix.endswith("/"):
			prefix += "/"
		self.prefix = prefix
示例#7
0
    def __init__(self):
        """Load Templates Jinja2 Templates

        Initialize loading for Jinja2 Templates.
        """
        override_path = g.app.app_root + '/templates'
        self._fsl = FileSystemLoader(override_path)
        self._pkgloaders = {}
示例#8
0
 def test_init_name_has_parent_but_its_valid(self):
     hierarchy = OrderedDict((
         ("eurogamer_net",
          FileSystemLoader(self.get_template_dir("eurogamer_net"))),
         ("eurogamer",
          FileSystemLoader(self.get_template_dir("eurogamer"))),
         ("core", FileSystemLoader(self.get_template_dir("core"))),
         ("parent_parent_net",
          FileSystemLoader(self.get_template_dir("eurogamer_net"))),
     ))
     loader = HierarchyLoader(hierarchy)
示例#9
0
 def test_init_name_has_custom_delimiter(self):
     hierarchy = OrderedDict((
         ("eurogamer_net",
          FileSystemLoader(self.get_template_dir("eurogamer_net"))),
         ("eurogamer",
          FileSystemLoader(self.get_template_dir("eurogamer"))),
         ("core", FileSystemLoader(self.get_template_dir("core"))),
         ("eurogamer-net",
          FileSystemLoader(self.get_template_dir("eurogamer_net"))),
     ))
     with self.assertRaises(Exception):
         loader = HierarchyLoader(hierarchy, '-')
示例#10
0
 def test_init_name_has_parent_at_end(self):
     hierarchy = OrderedDict((
         ("eurogamer_net",
          FileSystemLoader(self.get_template_dir("eurogamer_net"))),
         ("eurogamer",
          FileSystemLoader(self.get_template_dir("eurogamer"))),
         ("core", FileSystemLoader(self.get_template_dir("core"))),
         ("eurogamer_net_parent",
          FileSystemLoader(self.get_template_dir("eurogamer_net"))),
     ))
     with self.assertRaises(Exception):
         loader = HierarchyLoader(hierarchy)
示例#11
0
    def first_pass(self, parser, node, children):
          print "NClass!!!!!!!!!"
          abstract = False
          if node[0] == "abstract":
            node.pop(0)
            children.pop(0)
            abstract = True
           
      
          env_model = Environment(loader=FileSystemLoader('templates/model'))
          env_dao = Environment(loader=FileSystemLoader('templates/dao'))
          env_controller = Environment(loader=FileSystemLoader('templates/controller'))
          
          if not os.path.exists("WebApp/src/model"):
            os.makedirs("WebApp/src/model")
          if not os.path.exists("WebApp/src/dao"):
            os.makedirs("WebApp/src/dao") 
          if not os.path.exists("WebApp/src/controller/show"):
            os.makedirs("WebApp/src/controller/show")
          if not os.path.exists("WebApp/src/controller/delete"):
            os.makedirs("WebApp/src/controller/delete")
          if not os.path.exists("WebApp/src/controller/prepareUpdate"):
            os.makedirs("WebApp/src/controller/prepareUpdate")
            
          length = len(node)
          if length > 3 :
              if node[2] == ":" :
                 parentClass = node[3]
                 superClass = True
              else: 
                  superClass = False
                  parentClass = "" 
          else: 
              superClass = False
              parentClass = ""
              
          
          generate_text_file_class_model(env_model.get_template('model.txt'), "WebApp/src/model/"+str(node[1])+".java", str(node[1]), superClass, parentClass, children, abstract) 
        
          if abstract == False :
              generate_text_file_class(env_controller.get_template('controller_show.txt'),"WebApp/src/controller/show/"+str(node[1])+"ControllerShow.java",str(node[1]))
              generate_text_file_class(env_controller.get_template('controller_delete.txt'),"WebApp/src/controller/delete/"+str(node[1])+"DeleteController.java",str(node[1]))
              generate_text_file_class(env_dao.get_template('dao.txt'),"WebApp/src/dao/I"+str(node[1])+"Dao.java",str(node[1]))
              generate_text_file_class(env_dao.get_template('hibernate_dao.txt'),"WebApp/src/dao/"+str(node[1])+"HibernateDao.java",str(node[1]))
              generate_text_file_class_attribute(env_controller.get_template('controller_prepare_update.txt'), "WebApp/src/controller/prepareUpdate/"+str(node[1])+"PrepareUpdateController.java", str(node[1]), children)
            

          return [str(node[1]),superClass,parentClass,children,abstract]
示例#12
0
文件: jinja.py 项目: TurboGears/tg2
    def get_source(self, environment, template):
        # Check if dottedname
        if not template.endswith(self.template_extension):
            # Get the actual filename from dotted finder
            finder = self.dotted_finder
            template = finder.get_dotted_filename(template_name=template,
                                                  template_extension=self.template_extension)
        else:
            return FileSystemLoader.get_source(self, environment, template)

        # Check if the template exists
        if not exists(template):
            raise TemplateNotFound(template)

        # Get modification time
        mtime = getmtime(template)

        # Read the source
        fd = open(template, 'rb')
        try:
            source = fd.read().decode('utf-8')
        finally:
            fd.close()

        return source, template, lambda: mtime == getmtime(template)
示例#13
0
文件: jinja.py 项目: ByReaL/OctoPrint
	def list_templates(self):
		result = FileSystemLoader.list_templates(self)

		if callable(self.path_filter):
			result = sorted(filter(self._combined_filter, result))

		return result
示例#14
0
文件: jinja.py 项目: ByReaL/OctoPrint
	def get_source(self, environment, template):
		if callable(self.path_filter):
			pieces = split_template_path(template)
			if not self._combined_filter(os.path.join(*pieces)):
				raise TemplateNotFound(template)

		return FileSystemLoader.get_source(self, environment, template)
示例#15
0
	def get_source(self, environment, template):
		if not template.startswith(self.prefix):
			raise TemplateNotFound(template)

		template = template[len(self.prefix):]
		if not template in self.files:
			raise TemplateNotFound(template)

		return FileSystemLoader.get_source(self, environment, template)
示例#16
0
class CustomizationLoader(BaseLoader):
    def __init__(self, fallback_loader, customization_dir, customization_debug=False):
        from indico.core.logger import Logger
        self.logger = Logger.get('customization')
        self.debug = customization_debug
        self.fallback_loader = fallback_loader
        self.fs_loader = FileSystemLoader(customization_dir, followlinks=True)

    def _get_fallback(self, environment, template, path, customization_ignored=False):
        rv = self.fallback_loader.get_source(environment, template)
        if not customization_ignored and self.debug:
            try:
                orig_path = rv[1]
            except TemplateNotFound:
                orig_path = None
            self.logger.debug('Customizable: %s (original: %s, reference: ~%s)', path, orig_path, template)
        return rv

    def get_source(self, environment, template):
        path = posixpath.join(*split_template_path(template))
        if template[0] == '~':
            return self._get_fallback(environment, template[1:], path[1:], customization_ignored=True)
        try:
            plugin, path = path.split(':', 1)
        except ValueError:
            plugin = None
        prefix = posixpath.join('plugins', plugin) if plugin else 'core'
        path = posixpath.join(prefix, path)
        try:
            rv = self.fs_loader.get_source(environment, path)
            if self.debug:
                self.logger.debug('Customized: %s', path)
            return rv
        except TemplateNotFound:
            return self._get_fallback(environment, template, path)

    @internalcode
    def load(self, environment, name, globals=None):
        tpl = super(CustomizationLoader, self).load(environment, name, globals)
        if ':' not in name:
            return tpl
        # This is almost exactly what PluginPrefixLoader.load() does, but we have
        # to replicate it here since we need to handle `~` and use our custom
        # `get_source` to get the overridden template
        plugin_name, tpl_name = name.split(':', 1)
        if plugin_name[0] == '~':
            plugin_name = plugin_name[1:]
        plugin = get_state(current_app).plugin_engine.get_plugin(plugin_name)
        if plugin is None:
            # that should never happen
            raise RuntimeError('Plugin template {} has no plugin'.format(name))
        tpl.plugin = plugin
        return tpl
示例#17
0
    def get_source(self, environment, template):
        # keep legacy asset: prefix checking that bypasses
        # source path checking altogether
        if template.startswith('asset:'):
            newtemplate = template.split(':', 1)[1]
            fi = self._get_asset_source_fileinfo(environment, newtemplate)
            return fi.contents, fi.filename, fi.uptodate

        fi = self._get_asset_source_fileinfo(environment, template)
        if os.path.isfile(fi.filename):
            return fi.contents, fi.filename, fi.uptodate

        try:
            return FileSystemLoader.get_source(self, environment, template)
        except TemplateNotFound, ex:
            message = ex.message
            message += ('; asset=%s; searchpath=%r'
                        % (fi.filename, self.searchpath))
            raise TemplateNotFound(name=ex.name, message=message)
示例#18
0
    def get_source(self, environment, template):
        # keep legacy asset: prefix checking that bypasses
        # source path checking altogether
        if template.startswith('asset:'):
            template = template[6:]

        # load template directly from the filesystem
        filename = abspath_from_asset_spec(template)
        fi = FileInfo(filename, self.encoding)
        if os.path.isfile(fi.filename):
            return fi.contents, fi.filename, fi.uptodate

        # fallback to search-path lookup
        try:
            return FileSystemLoader.get_source(self, environment, template)
        except TemplateNotFound as ex:
            message = ex.message
            message += ('; asset=%s; searchpath=%r'
                        % (template, self.searchpath))
            raise TemplateNotFound(name=ex.name, message=message)
示例#19
0
 def __init__(self, searchpath=(), encoding='utf-8', debug=False):
     FileSystemLoader.__init__(self, searchpath, encoding)
     self.debug = debug
示例#20
0
 def __init__(self, fallback_loader, customization_dir, customization_debug=False):
     from indico.core.logger import Logger
     self.logger = Logger.get('customization')
     self.debug = customization_debug
     self.fallback_loader = fallback_loader
     self.fs_loader = FileSystemLoader(customization_dir, followlinks=True)
示例#21
0
文件: jinja.py 项目: ByReaL/OctoPrint
	def __init__(self, searchpath, path_filter=None, **kwargs):
		FileSystemLoader.__init__(self, searchpath, **kwargs)
		self.path_filter = path_filter