Clone of official tools
Diff: export/exporters.py
- Revision:
- 35:da9c89f8be7d
- Parent:
- 31:8ea194f6145b
- Child:
- 36:96847d42f010
--- a/export/exporters.py Mon Feb 13 09:29:13 2017 -0600 +++ b/export/exporters.py Wed Feb 15 13:53:18 2017 -0600 @@ -2,9 +2,9 @@ import os from abc import abstractmethod, ABCMeta import logging -from os.path import join, dirname, relpath, basename, realpath +from os.path import join, dirname, relpath, basename, realpath, normpath from itertools import groupby -from jinja2 import FileSystemLoader +from jinja2 import FileSystemLoader, StrictUndefined from jinja2.environment import Environment import copy @@ -111,11 +111,12 @@ source_files.extend(getattr(self.resources, key)) return list(set([os.path.dirname(src) for src in source_files])) - def gen_file(self, template_file, data, target_file): + def gen_file(self, template_file, data, target_file, **kwargs): """Generates a project file from a template using jinja""" jinja_loader = FileSystemLoader( os.path.dirname(os.path.abspath(__file__))) - jinja_environment = Environment(loader=jinja_loader) + jinja_environment = Environment(loader=jinja_loader, + undefined=StrictUndefined, **kwargs) template = jinja_environment.get_template(template_file) target_text = template.render(data) @@ -130,9 +131,13 @@ Positional Arguments: src - the src's location """ - key = basename(dirname(src)) - if key == ".": - key = basename(realpath(self.export_dir)) + rel_path = relpath(src, self.resources.file_basepath[src]) + path_list = os.path.normpath(rel_path).split(os.sep) + assert len(path_list) >= 1 + if len(path_list) == 1: + key = self.project_name + else: + key = path_list[0] return key def group_project_files(self, sources):