Exemplo n.º 1
0
def main():
    # Récupération des options de la ligne de commande
    optlist = dict(getopt.getopt(
        sys.argv[1:], "cdf:hn:",
        ['optname=', 'conf-dir=', 'debug', 'co', 'help', 'opengl'])[0])

    # L'aide
    if '-h' in optlist or '--help' in optlist:
        print HELP_STRING.encode(locale.getpreferredencoding())
        sys.exit(0)

    # Chargement des options
    import flrn_config
    if '--server' in optlist:
        server = optlist['--server']
    elif '-n' in optlist:
        server = optlist['-n']
    else: server = None
    if '--conf-dir' in optlist:
        conf_dir = optlist['--conf-dir']
    elif '-f' in optlist:
        conf_dir = optlist['-f']
    else: conf_dir = None

    # Messages de debug
    if ('-d' in optlist) or ('--debug' in optlist):
        data_types.debug_fd = sys.stderr
        data_types.debug_output(u"[Main] Activation des messages de déboguage")
    else:
        data_types.debug_fd = open(os.path.devnull, 'w')

    conf_source = flrn_config.FlrnConfig(conf_dir, server)

    # Dénombrement des messages non lus
    unreads = 0
    if ('-c' in optlist) or ('--co' in optlist):
        conf_source.update_unreads()
        for g in conf_source.subscribed:
            if (conf_source.unreads[g] > 0):
                print '  ' + g + ':',  conf_source.unreads[g], \
                      ('article non lu.' if conf_source.unreads[g] == 1
                       else 'articles non lus.')
            unreads += conf_source.unreads[g]
        if unreads == 0:
            print 'Rien de nouveau.'
        elif unreads == 1:
            print 'Il y a au total 1 article non lu.'
        else:
            print 'Il y a au total', unreads, 'articles non lus.'
        return 0

    # Est-ce l'heure ?
    if not(flrn_config.is_geek_time(
            conf_source.params['geek_start_time'],
            conf_source.params['geek_end_time'])):
        print "C'est pas l'heure de lire forum !"
        return 0

    # Chargement de l'interface avec OpenGL ou pas
    if '--opengl' in optlist:
        import gtkgl_gui as gui_module
    else:
        import gtk_gui as gui_module
    gui = gui_module.MainWindow(conf_source)
        
    import gtk
    gtk.main()
Exemplo n.º 2
0
    def display_tree(self, group, nb_start, nb_end,
                     time_format = "%d %b %Y %H:%M"):
        """Crée un arbre de threads à partir d'une overview
           Renvoie un dictionnaire indexé par Msg-Id"""
        # On ne lit pas forum à des heures indues
        if not(flrn_config.is_geek_time(
                self.parent.conf.params['geek_start_time'],
            self.parent.conf.params['geek_end_time'])):
            print "C'est pas l'heure de lire forum !"
            self.parent.action_quit_callback()
            return False

        data_source = self.parent.conf.overview_cache[group]
        # On prend d'avance ce qui nous intéresse
        data_source.get_overview(
            nb_start - self.parent.conf.params['max_backtrack'],
            nb_end   + self.parent.conf.params['max_foretrack'])
        overview, vanished = data_source.get_overview(nb_start, nb_end)
        ids = set([i[4] for i in overview])
        xover = []
        lowest = nb_start

        # On cherche les parents
        for i in xrange(-1, -1 - len(overview), -1):
            for t in xrange(-1, -1 - len(overview[i][5]), -1):
                ref_id = overview[i][5][t]
                # Déja traité ?
                if ref_id in ids: continue
                art = self.parent.conf.server.get_article_by_msgid(ref_id)
                if not(art): continue
                # Sorti du conti et numéro ?
                sorti = True
                for xref in art.headers['Xref'].strip().split():
                    if xref.split(':')[0] == group:
                        sorti = False
                        art_no = int(xref.split(':')[1])
                        if art_no < lowest: lowest = art_no
                        break
                if not(sorti):
                    ids.add(ref_id)
                    truc = data_source.get_item(art_no)
                    if truc: xover[0:0] = [truc]
        
        if self.parent.conf.params['with_cousins']:
            overview2, vanished2 = data_source.get_overview(
                max(lowest, nb_start -
                    int(self.parent.conf.params['max_backtrack'])), 
                nb_start - 1)
            vanished.extend(vanished2)

            # On vérifie quand même qu'ils font partie des bons threads
            for i in overview2:
                for t in xrange(-1, -1 - len(i[5]), -1):
                    ref_id = i[5][t]
                    if ref_id in ids:
                        ids.add(i[4])
                        xover[0:0] = [i]
                        break
        xover.extend(overview)
        # On ajoute les enfants
        overview3, vanished3 = data_source.get_overview(
            nb_end + 1, nb_end 
            + int(self.parent.conf.params['max_foretrack']))
        vanished.extend(vanished3)
        for i in overview3:
            for t in xrange(-1, -1-len(i[5]), -1):
                ref_id = i[5][t]
                if ref_id in ids:
                    ids.add(i[4])
                    xover.append(i)
                    break
        # On trie
        i = 0
        while i < len(xover):
            j = i + 1
            while j < len(xover):
                while xover[j][0] == xover[i][0]: 
                    del xover[j]
                    if j == len(xover): break
                if xover[j][4] in xover[i][5]:
                    xover[i], xover[j] = xover[j], xover[i]
                j += 1
            i += 1

        model = self.data
        model.clear()
        self.current_node = None
        if hasattr(self, 'nodes'): del self.nodes
        self.nodes = {}

        # Les articles inexistants sont marqués comme lus dans le newsrc
        for i in vanished:
            self.parent.conf.register_read(self.parent.current_group, int(i))
        # Sélection des règles
        To_Apply = []
        for K in self.parent.conf.killrules:
            if K.group_match(group): To_Apply.append(K)
        
        for i in xover:
            number = int(i[0])
            # Lu ?
            read = self.parent.conf.groups[self.parent.current_group].owns(number)
            subject = nntp_io.translate_header(i[1])
            # Application des règles
            for K in To_Apply:
                if read == K.read_before:
                    heads = {
                        'Newsgroups': group,
                        'Subject': i[1],
                        'From': i[2],
                        'Date': i[3],
                        'Message-ID': i[4],
                        'References': ' '.join(i[5]) }
                    if K.article_match(heads):
                        read = K.read_after
                        if K.read_after:
                            debug_output(
                                u'[SumBuffer] Marqué ' 
                                + str(number) + ' comme lu ')
                            self.parent.conf.register_read(
                                self.parent.current_group, number)
                        else:
                            debug_output(
                                u'[SumBuffer] Marqué ' 
                                + str(number) + ' comme non lu ')
                            self.parent.conf.register_unread(
                                self.parent.current_group, number)

            # Auteur ?
            real_name, addr = email.Utils.parseaddr(
                nntp_io.translate_header(i[2]))
            if len(real_name) == 0: author = addr
            else: author = real_name
            # Affichage du sujet
            caption = subject
            if (len(i[5]) > 0) and (i[5][-1] in self.nodes):
                if (model.get_value(self.nodes[i[5][-1]], 2) == subject):
                    # C'est le même sujet, on l'indique
                    caption = "..."
            # Autres données
            date = time.strftime(time_format, email.Utils.parsedate(i[3]))
            msgid = i[4]
            color = "black" 
            font = "bold" if not read else "normal"
            if not(nb_start <= number <= nb_end):
                color = "grey"
                font = "italic"
            choses_affichees = [msgid, number, subject, author,
                                date, read, caption, color, font]
            if len(i[5]) > 0 and self.nodes.has_key(i[5][-1]):
                self.nodes[msgid] = model.append(
                    self.nodes[i[5][-1]], choses_affichees)
            else:
                self.nodes[msgid] = model.append(
                    None, choses_affichees)
                
        self.widget.set_model(model)
        self.widget.expand_all()
        
        # Informations
        self.parent.group_tab.refresh_tree()