Esempio n. 1
0
 def setup_theme(self):
     if self.document.settings.theme:
         self.copy_theme()
     elif self.document.settings.theme_url:
         self.theme_file_path = self.document.settings.theme_url
     else:
         raise docutils.ApplicationError(
             'No theme specified for S5/HTML writer.')
Esempio n. 2
0
def find_theme(name):
    # Where else to look for a theme?
    # Check working dir?  Destination dir?  Config dir?  Plugins dir?
    path = os.path.join(themes_dir_path, name)
    if not os.path.isdir(path):
        raise docutils.ApplicationError(
            'Theme directory not found: %r (path: %r)' % (name, path))
    return path
    def copy_theme(self):
        """
        Locate & copy theme files.

        A theme may be explicitly based on another theme via a '__base__'
        file.  The default base theme is 'default'.  Files are accumulated
        from the specified theme, any base themes, and 'default'.
        """

        settings = self.document.settings
        # path = find_theme(settings.theme)
        path = os.path.join(os.path.dirname(__file__), 'slidy')
        theme_paths = [path]
        self.theme_files_copied = {}
        required_files_copied = {}
        # This is a link (URL) in HTML, so we use "/", not os.sep:
        # self.theme_file_path = '%s/%s' % ('ui', settings.theme)
        if settings._destination:
            settings._destination = os.path.abspath(settings._destination)

            dest_dir = os.path.dirname(settings._destination)

            if not os.path.isdir(dest_dir):
                os.makedirs(dest_dir)

        else:
            # no destination, so we can't copy the theme
            return
        # default = 0
        while path:
            for f in os.listdir(path):  # copy all files from each theme
                if (self.copy_file(f, path, dest_dir)
                        and f in self.required_theme_files):
                    required_files_copied[f] = 1

            # XXX no theme support yet
            path = None

            #if default:
            #    break                   # "default" theme has no base theme
            #    path = find_theme(self.default_theme)
            #    theme_paths.append(path)
            #    default = 1

        if len(required_files_copied) != len(self.required_theme_files):
            # Some required files weren't found & couldn't be copied.
            required = list(self.required_theme_files)
            for f in required_files_copied.keys():
                required.remove(f)
            raise docutils.ApplicationError(
                'Theme files not found: %s' %
                ', '.join(['%r' % f for f in required]))
Esempio n. 4
0
    def copy_theme(self):
        """
        Locate & copy theme files.

        A theme may be explicitly based on another theme via a '__base__'
        file.  The default base theme is 'default'.  Files are accumulated
        from the specified theme, any base themes, and 'default'.
        """
        settings = self.document.settings
        path = find_theme(settings.theme)
        theme_paths = [path]
        self.theme_files_copied = {}
        required_files_copied = {}
        # This is a link (URL) in HTML, so we use "/", not os.sep:
        self.theme_file_path = '%s/%s' % ('ui', settings.theme)
        if settings._destination:
            dest = os.path.join(os.path.dirname(settings._destination), 'ui',
                                settings.theme)
            if not os.path.isdir(dest):
                os.makedirs(dest)
        else:
            # no destination, so we can't copy the theme
            return
        default = 0
        while path:
            for f in os.listdir(path):  # copy all files from each theme
                if f == self.base_theme_file:
                    continue  # ... except the "__base__" file
                if (self.copy_file(f, path, dest)
                        and f in self.required_theme_files):
                    required_files_copied[f] = 1
            if default:
                break  # "default" theme has no base theme
            # Find the "__base__" file in theme directory:
            base_theme_file = os.path.join(path, self.base_theme_file)
            # If it exists, read it and record the theme path:
            if os.path.isfile(base_theme_file):
                lines = open(base_theme_file).readlines()
                for line in lines:
                    line = line.strip()
                    if line and not line.startswith('#'):
                        path = find_theme(line)
                        if path in theme_paths:  # check for duplicates (cycles)
                            path = None  # if found, use default base
                        else:
                            theme_paths.append(path)
                        break
                else:  # no theme name found
                    path = None  # use default base
            else:  # no base theme file found
                path = None  # use default base
            if not path:
                path = find_theme(self.default_theme)
                theme_paths.append(path)
                default = 1
        if len(required_files_copied) != len(self.required_theme_files):
            # Some required files weren't found & couldn't be copied.
            required = list(self.required_theme_files)
            for f in required_files_copied.keys():
                required.remove(f)
            raise docutils.ApplicationError(
                'Theme files not found: %s' %
                ', '.join(['%r' % f for f in required]))
Esempio n. 5
0
 def test_non_ASCII_message(self):
     err = docutils.ApplicationError(u'\u0169')
     self.assertEqual(unicode(err), u'\u0169')
Esempio n. 6
0
 def test_message(self):
     err = docutils.ApplicationError('the message')
     self.assertEqual(unicode(err), u'the message')
Esempio n. 7
0
 def test_non_ASCII_message(self):
     err = docutils.ApplicationError('\u0169')
     self.assertEqual(str(err), '\u0169')