Example #1
0
def get_updated_css(stylepath, current_style, css_template):
    """
    Return the style json and the complete css if it is valid and has been
    changed since last update, otherwise return None.

    current_style - a dict with keys to format() the template
    css_template - a format()-ready string that matches current_style
    """
    # Copy in the default theme if a customized doesn't exist
    if not os.path.exists(stylepath):
        defaultcss = common.local_path('defaultstyle.json')
        shutil.copyfile(defaultcss, stylepath)
    try:
        style = common.read_json(stylepath)
    except:
        print('Invalid style config: unable to parse it as json')
        return
    # Only update if something's changed
    if style != current_style:
        try:
            css = css_template.format(**style)
        except KeyError:
            print('Invalid style config: key missing')
            return
        else:
            return style, common.parse_stylesheet(css)
    return
 def read_config(self):
     # config
     configfile = os.path.join(self.configpath, 'kalpana-chapters.conf')
     make_sure_config_exists(configfile, os.path.join(self.pluginpath, 'default_config.json'))
     self.sidebar.settings = read_json(configfile)
     # stylesheet
     cssfile = os.path.join(self.configpath, 'kalpana-chapters.css')
     make_sure_config_exists(cssfile, os.path.join(self.pluginpath, 'default_theme.css'))
     self.sidebar.setStyleSheet(parse_stylesheet(read_file(cssfile)))