Exemple #1
0
def test_slugify():
    text = u'a slug to b\xeb!' # compose "e
    assert slugify(text) == 'a-slug-to-be'
Exemple #2
0
 def get_slug(self):
     return slugify(self.name)
Exemple #3
0
    def validate(self, workspace=None):
        errors = []

        # can we just assume this is ascii/utf8?
        name = self.name_entry.get_text().decode("utf8")
        dirpath = self.dir_entry.get_text().decode("utf8")
        slug = slugify(name)

        if not name:
            errors.append("Name is required.")
        elif workspace and slug != workspace.slug:
            if any((w.slug == slug for w in self.editor.workspaces)):
                errors.append("Name must be unique.")

        if not dirpath:
            errors.append("Root Directory is required.")
        elif not (os.path.exists(dirpath) and os.path.isdir(dirpath)):
            errors.append("Root Directory is not a valid directory.")

        m = self.glob_exclude_liststore
        i = m.get_iter_first()
        while i:
            next = m.iter_next(i)
            pattern = m.get_value(i, 0)
            if not pattern:
                m.remove(i)  # just delete empty ones
            i = next

        m = self.regex_exclude_liststore
        i = m.get_iter_first()
        while i:
            next = m.iter_next(i)
            pattern = m.get_value(i, 0)
            if not pattern:
                m.remove(i)  # just delete empty ones
            try:
                re.compile(pattern)
            except:
                err = "'%s' is not a valid regular expression." % (pattern,)
                errors.append(err)
            i = next

        filter_names = {}

        m = self.glob_filter_liststore
        i = m.get_iter_first()
        while i:
            next = m.iter_next(i)
            name = m.get_value(i, 0)
            pattern = m.get_value(i, 1)
            if not (name and pattern):
                m.remove(i)  # just delete empty ones
            filter_names[name] = filter_names.get(name, 0) + 1
            i = next

        m = self.regex_filter_liststore
        i = m.get_iter_first()
        while i:
            next = m.iter_next(i)
            name = m.get_value(i, 0)
            pattern = m.get_value(i, 1)
            if not (name and pattern):
                m.remove(i)  # just delete empty ones
            try:
                re.compile(pattern)
            except:
                err = "'%s' is not a valid regular expression." % (pattern,)
                errors.append(err)
            filter_names[name] = filter_names.get(name, 0) + 1
            i = next

        for name, count in filter_names.iteritems():
            if count > 1:
                err = "'%s' is used as a filter name multiple times." % (name,)
                errors.append(err)

        if errors:
            dialog = gtk.MessageDialog(
                self.editor.window,
                gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
                gtk.MESSAGE_ERROR,
                gtk.BUTTONS_OK,
                "\n".join(errors),
            )
            response = dialog.run()
            try:
                dialog.destroy()
            except AttributeError:
                pass

            return False

        else:
            return True