def _get_catalog_dirs(): catalog_error = "" _parse_gazpacho_path() catalogs = [] for dirname in environ.get_resource_paths('catalog'): try: dir_list = os.listdir(dirname) except OSError, e: if e.errno == 2: catalog_error = ("The catalog directory %s does not exist" % dirname) elif e.errno == 13: catalog_error = ("You do not have read permissions in the " "catalog directory %s" % dirname) else: catalog_error = e.strerror if catalog_error: raise EnvironmentError(catalog_error) for filename in dir_list: if not filename.endswith('.xml'): continue name = filename[:-4] item = name, os.path.join(dirname, filename) # Make sure the base catalog is always loaded first, see #343283 # We should introduce proper dependencies in the future. if name == 'base': catalogs.insert(0, item) else: catalogs.append(item)
def _get_latest_schema(): schema_pattern = "schema-??.sql" schemas = [] for resource in environ.get_resource_paths("sql"): for filename in glob.glob(os.path.join(resource, schema_pattern)): schemas.append(filename) assert schemas schemas.sort() return schemas[-1]
def render_template(filename, **ns): """Renders a template giving a filename and a keyword dictionary @filename: a template filename to render @kwargs: keyword arguments to send to the template @return: the rendered template """ lookup = TemplateLookup(directories=environ.get_resource_paths('template'), output_encoding='utf8', input_encoding='utf8', default_filters=['h']) tmpl = lookup.get_template(filename) return tmpl.render(**ns)
def get_custom_ui_filename(): """Return the name of the file with custom UI definitions if it exists First it look in the user home directory (in the .gazpacho subdirectory), then it looks in every directory where there are catalogs. """ # First we look in the user home directory app_dir = get_app_data_dir('gazpacho') custom_ui_filename = os.path.join(app_dir, CUSTOM_UI_FILENAME) if os.path.exists(custom_ui_filename): return custom_ui_filename # Then, look at standard catalog places for dirname in environ.get_resource_paths('catalog'): custom_ui_filename = os.path.join(dirname, CUSTOM_UI_FILENAME) if os.path.exists(custom_ui_filename): return custom_ui_filename
def render(self, stylesheet=None): template_dirs = environ.get_resource_paths('template') html = weasyprint.HTML(string=self.get_html(), base_url=template_dirs[0]) return html.render(stylesheets=[weasyprint.CSS(string=stylesheet)])
def __init__(self): Resource.__init__(self) path = environ.get_resource_paths('html')[0] self.putChild('static', File(path)) self.putChild('calendar-events.json', CalendarEvents())
except EnvironmentError, e: dialogs.error("<b>There were errors while loading Gazpacho</b>", str(e)) raise SystemExit problems = [] for name, filename in catalogs: # Skip external catalogs, for the testsuite. if not external and name != 'base': continue if filename.endswith('gtk+.xml'): warnings.warn("gtk+.xml found, it has been replaced by " + "base.xml. Please remove it.", stacklevel=2) continue resources_path = environ.get_resource_paths('resource') try: catalog = Catalog(filename, resources_path) _catalogs.append(catalog) except IOError, e: problems.append(str(e)) except BadCatalogSyntax, e: problems.append(str(e)) except CatalogError, e: print 'Error while loading catalog %s: %s' % (name, e) if problems: dialogs.error('\n'.join(problems)) _catalogs.sort(lambda c1, c2: cmp(c1.priority, c2.priority))