Exemple #1
0
 def update(self, lock):
     """ See if a file was modified or created. """
     self.error = False
     self.updated = False
     self.specto.mark_watch_busy(True, self.id)
     self.specto.logger.log(_("Updating watch: \"%s\"") % self.name, "info", self.__class__)
     
     try:
         self.get_cache_file()
         self.old_values = self.read_cache_file()
         mode = os.stat(self.file)[ST_MODE]
         self.new_files = []
         if S_ISDIR(mode):
             self.get_dir(self.file)
             self.update_cache_file()#write the new values to the cache file
             self.old_values = self.read_cache_file() #read the new valeus
             self.get_removed_files() #remove the files that were removed
             self.update_cache_file()#write the values (with the removed lines) to the cache file
         else:
             self.get_file(self.file)
             self.update_cache_file()
             
         #first time don't mark as updated
         if self.first_time == True:
             self.updated = False
             self.first_time = False            
     except:
         self.error = True
         self.specto.logger.log(_("Watch: \"%s\" has an error") % self.name, "error", self.__class__)
     
     self.specto.mark_watch_busy(False, self.id)
     self.actually_updated = self.updated
     Watch.update(self, lock)
Exemple #2
0
 def update(self, lock):
     """ Check for new mails on your gmail account. """
     self.error = False
     self.specto.mark_watch_busy(True, self.id)
     self.specto.logger.log(_("Updating watch: \"%s\"") % self.name, "info", self.__class__)
     
     try:
         s = GmailAtom(self.user, self.password)
         s.refreshInfo()
         self.oldMsg = s.getUnreadMsgCount()
         self.newMsg = 0
         if self.oldMsg == 0:#no unread messages, we need to clear the watch
             self.actually_updated=False
             self.specto.notifier.clear_watch("", self.id)
         else:
             i=0
             while i < self.oldMsg:
                 info = s.getMsgAuthorName(i) + s.getMsgTitle(i) + s.getMsgSummary(i) #create unique info
                 if info not in self.mail_info: #check if it is a new email or just unread
                     self.actually_updated=True
                     self.mail_info.append(info)
                     self.newMsg+=1
                 i+=1
     except:
         self.error = True
         self.specto.logger.log(_("Watch: \"%s\" has error: wrong username/password") % self.name, "error", self.__class__)
         
     self.specto.mark_watch_busy(False, self.id)
     Watch.update(self, lock)
Exemple #3
0
 def update(self, lock):
     """ Check for new mails on your gmail account. """
     self.error = False
     self.specto.mark_watch_busy(True, self.id)
     self.specto.logger.log(_("Updating watch: \"%s\"") % self.name, "info", self.__class__)
     
     try:
         self.oldMsg = self.newMsg
         self.newMsg = 0
         SID = self.get_SID()
         f = file(self.cache_file , "w")
         f.write(str(self.get_reading_list(SID)))
         f.close()
         doc = minidom.parse(self.cache_file)
         rootNode = doc.documentElement
         attributes =[] 
         self.walk(rootNode, False, attributes)
         
         if self.oldMsg == 0 and self.newMsg == 0:#no unread messages, we need to clear the watch
             self.actually_updated=False
             self.specto.notifier.clear_watch("", self.id)
         if self.newMsg > 0:
             self.actually_updated=True
             if self.oldMsg == 0:
                 self.oldMsg = self.newMsg
     except:
         self.error = True
         self.specto.logger.log(_("Watch: \"%s\" has error: Error in processing cache file") % self.name, "error", self.__class__)
         
     self.specto.mark_watch_busy(False, self.id)
     Watch.update(self, lock)
Exemple #4
0
 def update(self, lock):
     """ See if a http or rss page changed. """
     self.error = False
     self.specto.mark_watch_busy(True, self.id)
     self.specto.logger.log(_("Updating watch: \"%s\"") % self.name, "info", self.__class__)
     
     # Create a unique name for each url.
     digest = md5.new(self.url_).digest()
     cacheFileName = "".join(["%02x" % (ord(c),) for c in digest])
     self.cacheFullPath_ = os.path.join(cacheSubDir__, cacheFileName)
     request = urllib2.Request(self.url_, None, {"Accept-encoding" : "gzip"})
     
     if (self.cached == 1) or (os.path.exists(self.cacheFullPath_)):
         self.cached = 1
         f = file(self.cacheFullPath_, "r")# Load up the cached version
         self.infoB_ = HTTPMessage(f)
         if self.infoB_.has_key('last-modified'):
             request.add_header("If-Modified-Since", self.infoB_['last-modified'])
         if self.infoB_.has_key('ETag'):
             request.add_header("If-None-Match", self.infoB_['ETag'])
     try:
         response = urllib2.urlopen(request)
     except (urllib2.URLError, BadStatusLine), e:
         self.error = True
         self.specto.logger.log(_("Watch: \"%s\" has error: ") % self.name + str(e), "error", self.__class__)
Exemple #5
0
    def update(self, lock):
        """ See if a socket was opened or closed. """
        self.error = False
        self.specto.mark_watch_busy(True, self.id)
        self.specto.logger.log(
            _("Updating watch: \"%s\"") % self.name, "info", self.__class__)

        try:
            established = self.check_port()
            if self.running and established == False:
                self.running = False
                self.actually_updated = True
            elif self.running == False and established == True:
                self.running = True
                self.actually_updated = True
            else:
                self.actually_updated = False
        except:
            self.error = True
            self.specto.logger.log(
                _("Watch: \"%s\" has an error") % self.name, "error",
                self.__class__)

        self.specto.mark_watch_busy(False, self.id)
        Watch.update(self, lock)
Exemple #6
0
    def update(self, lock):
        """ Check for new mails on your gmail account. """
        self.error = False
        self.specto.mark_watch_busy(True, self.id)
        self.specto.logger.log(
            _("Updating watch: \"%s\"") % self.name, "info", self.__class__)

        try:
            s = GmailAtom(self.user, self.password)
            s.refreshInfo()
            self.oldMsg = s.getUnreadMsgCount()
            self.newMsg = 0
            if self.oldMsg == 0:  #no unread messages, we need to clear the watch
                self.actually_updated = False
                self.specto.notifier.clear_watch("", self.id)
            else:
                i = 0
                while i < self.oldMsg:
                    info = s.getMsgAuthorName(i) + s.getMsgTitle(
                        i) + s.getMsgSummary(i)  #create unique info
                    if info not in self.mail_info:  #check if it is a new email or just unread
                        self.actually_updated = True
                        self.mail_info.append(info)
                        self.newMsg += 1
                    i += 1
        except:
            self.error = True
            self.specto.logger.log(
                _("Watch: \"%s\" has error: wrong username/password") %
                self.name, "error", self.__class__)

        self.specto.mark_watch_busy(False, self.id)
        Watch.update(self, lock)
Exemple #7
0
    def toggle_notifier(self, *args):
        """
        Toggle the state of the notifier, hidden or shown.
        It will save the size, position, and the last state when you closed Specto.
        """
        #Creating the notifier window, but keeping it hidden
        if not self.notifier_initialized and self.notifier_keep_hidden:
            self.notifier = Notifier(self)
            #self.notifier.restore_size_and_position()#this is NOT needed here because it already does that on instanciation on the line above -kiddo
            self.notifier.notifier.hide()            
        #Creating the notifier window and displaying it
        elif not self.notifier_initialized and not self.notifier_keep_hidden:
            self.notifier = Notifier(self)
            #self.notifier.restore_size_and_position()#this is NOT needed here because it already does that on instanciation on the line above -kiddo
            self.notifier.notifier.show()

        elif self.notifier_initialized:
            if self.notifier.get_state()==True and self.notifier_keep_hidden:
                self.logger.log(_("notifier: reappear"), "debug", self.__class__)
                self.specto_gconf.set_entry("show_notifier", True)
                self.notifier.restore_size_and_position()#to make sure that the x and y positions don't jump around
                self.notifier.notifier.show()
            elif self.notifier.get_state()==True and not self.notifier_keep_hidden:
                self.logger.log(_("notifier: hide"), "debug", self.__class__)
                self.specto_gconf.set_entry("show_notifier", False)
                self.notifier.notifier.hide()
            else:
                self.logger.log(_("notifier: reappear"), "debug", self.__class__)
                self.specto_gconf.set_entry("show_notifier", True)
                self.notifier.restore_size_and_position()#to make sure that the x and y positions don't jump around
                self.notifier.notifier.show()
        self.notifier_initialized = True
Exemple #8
0
    def update(self, lock):
        """ See if a file was modified or created. """
        self.error = False
        self.specto.mark_watch_busy(True, self.id)
        self.specto.logger.log(
            _("Updating watch: \"%s\"") % self.name, "info", self.__class__)

        try:
            process = self.check_process()
            if self.running and process == False:
                self.running = False
                self.updated = True
                self.actually_updated = True
            elif self.running == False and process == True:
                self.running = True
                self.actually_updated = True
            else:
                self.actually_updated = False
        except:
            self.error = True
            self.specto.logger.log(
                _("Watch: \"%s\" has an error") % self.name, "error",
                self.__class__)

        self.specto.mark_watch_busy(False, self.id)
        Watch.update(self, lock)
Exemple #9
0
    def update(self, lock):
        """ See if a http or rss page changed. """
        self.error = False
        self.specto.mark_watch_busy(True, self.id)
        self.specto.logger.log(
            _("Updating watch: \"%s\"") % self.name, "info", self.__class__)

        # Create a unique name for each url.
        digest = md5.new(self.url_).digest()
        cacheFileName = "".join(["%02x" % (ord(c), ) for c in digest])
        self.cacheFullPath_ = os.path.join(cacheSubDir__, cacheFileName)
        request = urllib2.Request(self.url_, None, {"Accept-encoding": "gzip"})

        if (self.cached == 1) or (os.path.exists(self.cacheFullPath_)):
            self.cached = 1
            f = file(self.cacheFullPath_, "r")  # Load up the cached version
            self.infoB_ = HTTPMessage(f)
            if self.infoB_.has_key('last-modified'):
                request.add_header("If-Modified-Since",
                                   self.infoB_['last-modified'])
            if self.infoB_.has_key('ETag'):
                request.add_header("If-None-Match", self.infoB_['ETag'])
        try:
            response = urllib2.urlopen(request)
        except (urllib2.URLError, BadStatusLine), e:
            self.error = True
            self.specto.logger.log(
                _("Watch: \"%s\" has error: ") % self.name + str(e), "error",
                self.__class__)
Exemple #10
0
 def update(self, lock):
     """
     Check if an error sound has to be played or if a watch has to be flagged updated.
     """
     #play error sound
     if self.error == True and self.specto.specto_gconf.get_entry("use_problem_sound"):
         problem_sound = self.specto.specto_gconf.get_entry("problem_sound")
         gnome.sound_play(problem_sound)
         pop_toast = self.specto.specto_gconf.get_entry("pop_toast")  
         if (pop_toast == True) and (self.specto.GTK):
             NotificationToast(self.specto, _("The watch, <b>%s</b>, has a problem. You may need to check the error log.") % self.name, self.specto.icon_theme.load_icon("error", 64, 0), urgency="critical")#fixme: not sure if that's possible, but this has no self.tray_x, self.tray_y, because we cannot be sure that the tray icon is actually displayed already
     
     #call update function if watch was updated
     if self.actually_updated:#we want to notify, but ONLY if it has not been marked as updated already
         try:
             self.specto.toggle_updated(self.id) #call the main function to update the notifier entry. We need to use a try statement in case the watch was already toggled in the notifier entry.
         except: 
             if self.specto.DEBUG : self.specto.logger.log(_("Watch \"%s\" is already marked as updated in the notifier") % self.name, "info", self.__class__)
         else: pass
         self.specto.count_updated_watches()
         self.notify()
         self.updated = True
         self.actually_updated = False
     self.timer_id = gobject.timeout_add(self.refresh, self.thread_update)
     lock.release()
Exemple #11
0
    def restore_size_and_position(self):
        """
        Restore the size and the postition from the notifier window.
        """
        saved_window_width = self.specto.specto_gconf.get_entry(
            "window_notifier_width")
        saved_window_height = self.specto.specto_gconf.get_entry(
            "window_notifier_height")
        saved_window_x = self.specto.specto_gconf.get_entry(
            "window_notifier_x")
        saved_window_y = self.specto.specto_gconf.get_entry(
            "window_notifier_y")
        if self.specto.specto_gconf.get_entry("hide_from_windowlist") == True:
            self.notifier.set_skip_taskbar_hint(
                True)  #hide from the window list applet

        if saved_window_width != None and saved_window_height != None:  #check if the size is not 0
            self.wTree.get_widget("notifier").resize(saved_window_width,
                                                     saved_window_height)
            self.specto.logger.log(_("notifier: size set"), "debug",
                                   self.__class__)
        else:
            self.specto.logger.log(_("notifier: size not set"), "debug",
                                   self.__class__)

        if saved_window_x != None and saved_window_y != None:  #check if the position is not 0
            self.wTree.get_widget("notifier").move(saved_window_x,
                                                   saved_window_y)
            self.specto.logger.log(_("notifier: position set"), "debug",
                                   self.__class__)
        else:
            self.specto.logger.log(_("notifier: position not set"), "debug",
                                   self.__class__)
Exemple #12
0
    def replace_name(self, orig, new):
        """ Replace a watch name (rename). """
        #read the file
        try:
            f = open(self.file_name, "r")
            text = f.read()
        except IOError:
            self.specto.logger.log(
                _("There was an error writing to %s") % self.file_name,
                "critical", self.__class__)
        finally:
            f.close

        text = text.replace("[" + orig + "]", "[" + new + "]")

        #replace and write file
        try:
            f = open(self.file_name, "w")
            f.write(text)
        except IOError:
            self.specto.logger.log(
                _("There was an error writing to %s") % self.file_name,
                "critical", self.__class__)
        finally:
            f.close()
Exemple #13
0
 def show_preferences(self, *args):
     """ Show the preferences window. """
     if not self.preferences_initialized or self.preferences.get_state() == True:
         self.logger.log(_("preferences: create"), "debug", self.__class__)
         self.pref=Preferences(self)
     else:
         self.logger.log(_("preferences: reappear"), "debug", self.__class__)
         self.pref.show()
Exemple #14
0
 def show_error_log(self, *args):
     """ Show the error log. """
     if self.error_l == "":
         self.error_l= Log_dialog(self)
         self.logger.log(_("error log: create"), "debug", self.__class__)
     elif self.error_l.log_dialog.flags() & gtk.MAPPED:
         self.logger.log(_("error log: already visible"), "debug", self.__class__)
     else:
         self.error_l= Log_dialog(self)
         self.logger.log(_("error log: recreate"), "debug", self.__class__)
Exemple #15
0
 def show_add_watch(self, *args):
     """ Show the add watch window. """
     if self.add_w == "":
         self.add_w= Add_watch(self)
         self.logger.log(_("add watch: create"), "debug", self.__class__)
     elif self.add_w.add_watch.flags() & gtk.MAPPED:
         self.logger.log(_("add watch: already visible"), "debug", self.__class__)
     else:
         self.add_w= Add_watch(self)
         self.logger.log(_("add watch: recreate"), "debug", self.__class__)
Exemple #16
0
 def show_preferences(self, *args):
     """ Show the preferences window. """
     if not self.preferences_initialized or self.preferences.get_state(
     ) == True:
         self.logger.log(_("preferences: create"), "debug", self.__class__)
         self.pref = Preferences(self)
     else:
         self.logger.log(_("preferences: reappear"), "debug",
                         self.__class__)
         self.pref.show()
Exemple #17
0
 def show_error_log(self, *args):
     """ Show the error log. """
     if self.error_l == "":
         self.error_l = Log_dialog(self)
         self.logger.log(_("error log: create"), "debug", self.__class__)
     elif self.error_l.log_dialog.flags() & gtk.MAPPED:
         self.logger.log(_("error log: already visible"), "debug",
                         self.__class__)
     else:
         self.error_l = Log_dialog(self)
         self.logger.log(_("error log: recreate"), "debug", self.__class__)
Exemple #18
0
 def show_add_watch(self, *args):
     """ Show the add watch window. """
     if self.add_w == "":
         self.add_w = Add_watch(self)
         self.logger.log(_("add watch: create"), "debug", self.__class__)
     elif self.add_w.add_watch.flags() & gtk.MAPPED:
         self.logger.log(_("add watch: already visible"), "debug",
                         self.__class__)
     else:
         self.add_w = Add_watch(self)
         self.logger.log(_("add watch: recreate"), "debug", self.__class__)
Exemple #19
0
    def quit(self, *args):
        """ Save the save and position from the notifier and quit Specto. """
        if self.notifier.get_state() == True and not self.notifier_keep_hidden:
            self.notifier.save_size_and_position(
            )  #when quitting specto abruptly, remember the notifier window properties
        try:
            gtk.main_quit()
        except:
            #create a close dialog
            dialog = gtk.Dialog(
                _("Cannot quit yet"), None, gtk.DIALOG_MODAL
                | gtk.DIALOG_NO_SEPARATOR | gtk.DIALOG_DESTROY_WITH_PARENT,
                None)
            #HIG tricks
            dialog.set_has_separator(False)

            dialog.add_button(_("Murder!"), 3)
            dialog.add_button(gtk.STOCK_CANCEL, -1)

            dialog.label_hbox = gtk.HBox(spacing=6)

            icon = gtk.Image()
            icon.set_from_icon_name("dialog-warning", 64)
            dialog.label_hbox.pack_start(icon, True, True, 6)
            icon.show()

            label = gtk.Label(
                _('<b><big>Specto is currently busy and cannot quit yet.</big></b>\n\nThis may be because it is checking for watch updates.\nHowever, you can try forcing it to quit by clicking the murder button.'
                  ))
            label.set_use_markup(True)
            dialog.label_hbox.pack_start(
                label, True, True, 6
            )  #here, pack means "cram the label right at the start of the vbox before the buttons"
            label.show()

            dialog.vbox.pack_start(dialog.label_hbox, True, True, 12)
            dialog.label_hbox.show()

            icon = gtk.gdk.pixbuf_new_from_file(self.PATH +
                                                'icons/specto_window_icon.svg')
            dialog.set_icon(icon)
            answer = dialog.run()
            if answer == 3:
                try:  #go figure, it never works!
                    self.notifier.stop_refresh = True
                    sys.exit(0)
                except:
                    #kill the specto process with killall
                    os.system('killall specto')
            else:
                dialog.destroy()
Exemple #20
0
 def update(self, lock):
     """ Check for new mails on your imap account. """
     self.error = False
     self.specto.mark_watch_busy(True, self.id)
     self.specto.logger.log(_("Updating watch: \"%s\"") % self.name, "info", self.__class__)
        
     try:
         if str(self.ssl) == 'True':
             server = imaplib.IMAP4_SSL(self.host)
         else:
             server = imaplib.IMAP4(self.host)
     except error, e:
         self.error = True
         self.specto.logger.log(_("Watch: \"%s\" has error: %s") % (self.name, str(e)), "error", self.__class__)
Exemple #21
0
 def get_quick_tip(
     self
 ):  #these are the tips of the day that are shown on startup. The code that displays them is further below.
     tips = [
         _("You can add all kinds of websites as watches. Static pages, RSS or Atom feeds, etc. Specto will automatically handle them."
           ),
         _("Website watches can use an error margin that allows you to set a minimum difference percentage. This allows you to adapt to websites that change constantly or have lots of advertising."
           ),
         _("Single-click an existing watch to display information, and double-click it to open the content."
           ),
         _("Please set a reasonable refresh interval in order to save bandwidth and prevent you from being blocked from content providers."
           )
     ]
     chosen_tip = tips[randrange(len(tips))]
     return chosen_tip
Exemple #22
0
 def open_watch(self, id):
     """ 
     Open the selected watch. 
     Returns False if the watch failed to open
     """
     res = True
     selected = self.specto.watch_db[id]
     self.specto.logger.log(
         _("watch \"%s\" opened") % self.specto.watch_db[id].name, "info",
         self.__class__)
     if selected.type == 0:
         uri_real = self.specto.watch_io.read_option(
             self.specto.watch_db[id].name, "uri_real"
         )  #this is just in case the uri_real parameter is present, i.e.: a web feed
         if uri_real:
             spectlib.util.show_webpage(uri_real)
         else:
             spectlib.util.show_webpage(selected.url_)
     elif selected.type == 1:
         if selected.prot == 2:  #gmail opens in a browser
             spectlib.util.show_webpage("https://gmail.google.com")
         else:
             spectlib.util.open_gconf_application(
                 "/desktop/gnome/url-handlers/mailto")
     elif selected.type == 2:
         spectlib.util.open_file_watch(selected.file)
     elif selected.type == 5:  #google reader
         spectlib.util.show_webpage("http://www.google.com/reader/view/")
     else:
         res = False
     return res
Exemple #23
0
    def write_options(self, values):
        """
        Write or change the watch options in a configuration file.
        Values has to be a dictionary with the name from the options and the value. example: { 'name':'value', 'option1':'value' }
        If the name is not found, a new watch will be added, else the existing watch will be changed.
        """
        self.cfg = ini_namespace(file(self.file_name))
        name = values['name']

        if not self.cfg._sections.has_key(name):
            self.cfg.new_namespace(name)  #add a new watch in the list

        del values[
            'name']  #now that we know the name of the watch, we only want to write its options
        for option, value in values.iteritems():
            self.cfg[name][option] = value

        try:
            f = open(self.file_name, "w")
            f.write(str(self.cfg).strip())  #write the new configuration file
        except IOError:
            self.specto.logger.log(
                _("There was an error writing to %s") % self.file_name,
                "critical", self.__class__)
        finally:
            f.close()
Exemple #24
0
 def remove_watch(self, name):
     """ Remove a watch from the configuration file. """
     try:
         cfgpr = ConfigParser()
         cfgpr.read(self.file_name)
         cfgpr.remove_section(name)
     except:
         self.specto.logger.log(_("There was an error writing to %s") % self.file_name, "critical", self.__class__)
         
     try:
         f = open(self.file_name, "w")
         cfgpr.write(f)
     except IOError:
         self.specto.logger.log(_("There was an error writing to %s") % self.file_name, "critical", self.__class__)
     finally:
         f.close()
Exemple #25
0
 def start_watch(self, id):
     """ Start a watch. """
     self.notifier.toggle_updating(True, id)
     self.watch_db[id].start_watch()
     self.logger.log(
         _("watch \"%s\" started") % self.watch_db[id].name, "info",
         self.__class__)
Exemple #26
0
 def thread_update(self):
     if not self.specto.connection_manager.connected():
         self.specto.logger.log(_("No network connection detected"),
                                "info", self.__class__)
         self.specto.connection_manager.add_callback(self._real_update)
     else :
         self._real_update()
Exemple #27
0
 def get_file(self, file_):
     """ Get the info from a file and compair it with the previous info. """
     size = int(os.stat(file_)[6]) #mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime = info
     old_size = re.search('%s:\s(.+)' % file_, self.old_values)
     if old_size and size: 
         old_size = int(old_size.group(1))
         if size != old_size:
             #replace filesize
             self.old_values = self.old_values.replace(file_ + ": " + str(old_size), file_ + ": " + str(size))
             self.specto.logger.log(_("update: %s was modified") % file_, "info", self.__class__)
             self.updated = True
     elif (size or size ==0) and not old_size:
         #add the file to the list
         self.old_values += file_ + ": " + str(size) + "\n"
         self.specto.logger.log(_("update: %s was created") % file_, "info", self.__class__)
         self.updated = True
Exemple #28
0
 def thread_update(self):
     if not self.specto.connection_manager.connected():
         self.specto.logger.log(_("No network connection detected"), "info",
                                self.__class__)
         self.specto.connection_manager.add_callback(self._real_update)
     else:
         self._real_update()
Exemple #29
0
 def open_watch(self, id):
     """ 
     Open the selected watch. 
     Returns False if the watch failed to open
     """
     res = True
     selected = self.specto.watch_db[id]
     self.specto.logger.log(_('watch "%s" opened') % self.specto.watch_db[id].name, "info", self.__class__)
     if selected.type == 0:
         uri_real = self.specto.watch_io.read_option(
             self.specto.watch_db[id].name, "uri_real"
         )  # this is just in case the uri_real parameter is present, i.e.: a web feed
         if uri_real:
             spectlib.util.show_webpage(uri_real)
         else:
             spectlib.util.show_webpage(selected.url_)
     elif selected.type == 1:
         if selected.prot == 2:  # gmail opens in a browser
             spectlib.util.show_webpage("https://gmail.google.com")
         else:
             spectlib.util.open_gconf_application("/desktop/gnome/url-handlers/mailto")
     elif selected.type == 2:
         spectlib.util.open_file_watch(selected.file)
     elif selected.type == 5:  # google reader
         spectlib.util.show_webpage("http://www.google.com/reader/view/")
     else:
         res = False
     return res
Exemple #30
0
 def connected_message(self, connected):
     if not connected:
         self.wTree.get_widget("statusbar1").push(
             0, _("The network connection seems to be down, watches will not update until then.")
         )
         self.wTree.get_widget("statusbar1").show()
     else:
         self.wTree.get_widget("statusbar1").hide()
Exemple #31
0
 def get_quick_tip(
     self
 ):  # these are the tips of the day that are shown on startup. The code that displays them is further below.
     tips = [
         _(
             "You can add all kinds of websites as watches. Static pages, RSS or Atom feeds, etc. Specto will automatically handle them."
         ),
         _(
             "Website watches can use an error margin that allows you to set a minimum difference percentage. This allows you to adapt to websites that change constantly or have lots of advertising."
         ),
         _("Single-click an existing watch to display information, and double-click it to open the content."),
         _(
             "Please set a reasonable refresh interval in order to save bandwidth and prevent you from being blocked from content providers."
         ),
     ]
     chosen_tip = tips[randrange(len(tips))]
     return chosen_tip
Exemple #32
0
    def update(self, lock):
        """ Check for new mails on your pop3 account. """
        self.error = False
        self.specto.mark_watch_busy(True, self.id)
        self.specto.logger.log(
            _("Updating watch: \"%s\"") % self.name, "info", self.__class__)

        try:
            if str(self.ssl) == 'True':
                s = poplib.POP3_SSL(self.host)
            else:
                s = poplib.POP3(self.host)
        except error, e:
            self.error = True
            self.specto.logger.log(
                _("Watch: \"%s\" has error: ") % self.name + str(e), "error",
                self.__class__)
Exemple #33
0
 def clear_clicked(self, widget):
     """ Clear the log window. """
     self.specto.logger.remove_watch_log(self.watch.name)
     self.specto.logger.log(
         _("removed logs from watch: \"%s\"") % self.watch.name, "info",
         self.__class__)
     self.log = self.specto.logger.watch_log(self.watch.name)
     self.logwindow.set_text(self.log)
Exemple #34
0
 def thread_update(self):
     if not self.specto.connection_manager.connected():
         self.specto.logger.log(_("No network connection detected"),
                                "info", self.__class__)
         self.specto.notifier.connected_message(False) #show the network error message
         self.specto.connection_manager.add_callback(self._real_update)
         self.specto.mark_watch_busy(False, self.id)
     else :
         self._real_update()
Exemple #35
0
 def __init__(self, refresh, port, specto, id,  name = _("Unknown Process Watch")):
     Watch.__init__(self, specto)
     self.name = name
     self.refresh = refresh
     self.port = port
     self.id = id
     self.error = False
     self.actually_updated=False
     self.running = self.check_port()
Exemple #36
0
 def connected_message(self, connected):
     if not connected:
         self.wTree.get_widget("statusbar1").push(
             0,
             _("The network connection seems to be down, watches will not update until then."
               ))
         self.wTree.get_widget("statusbar1").show()
     else:
         self.wTree.get_widget("statusbar1").hide()
Exemple #37
0
    def show_edit_watch(self, id, *args):
        """ Show the edit watch window. """
        selected = ""
        if not id == -1:
            selected = self.watch_db[id]
        else:
            for i in self.watch_db:
                if self.watch_db[i].name == args[0]:
                    selected = self.watch_db[i]

        if self.edit_w == "":
            self.edit_w= Edit_watch(self, selected)
            self.logger.log(_("edit watch: create"), "debug", self.__class__)
        elif self.edit_w.edit_watch.flags() & gtk.MAPPED:
            self.logger.log(_("edit watch: already visible"), "debug", self.__class__)
        else:
            self.edit_w= Edit_watch(self, selected)
            self.logger.log(_("edit watch: recreate"), "debug", self.__class__)
Exemple #38
0
    def set_preferences(self):
        """ Save the preferences in gconf. """
        self.specto.logger.log(_("Preferences saved."), "info", self.__class__)

        #save the path from the update sound
        if self.wTree.get_widget("soundUpdate").get_property('sensitive') == 1:
            self.specto.specto_gconf.set_entry(
                "update_sound",
                self.wTree.get_widget("soundUpdate").get_filename())
            self.specto.specto_gconf.set_entry("use_update_sound", True)
        else:
            self.specto.specto_gconf.unset_entry("use_update_sound")

        #save the path from the problem sound
        if self.wTree.get_widget("soundProblem").get_property(
                'sensitive') == 1:
            self.specto.specto_gconf.set_entry(
                "problem_sound",
                self.wTree.get_widget("soundProblem").get_filename())
            self.specto.specto_gconf.set_entry("use_problem_sound", True)
        else:
            self.specto.specto_gconf.unset_entry("use_problem_sound")

        #see if pop toast has to be saved
        if self.wTree.get_widget("chk_libnotify").get_active():
            self.specto.specto_gconf.set_entry("pop_toast", True)
            self.specto.specto_gconf.set_entry(
                "pop_toast_duration",
                int(
                    self.wTree.get_widget("hscale_libnotify_duration").
                    get_value()))  #save the pop toast duration
        else:
            self.specto.specto_gconf.set_entry("pop_toast", False)

        #see if windowlist has to be saved
        if self.wTree.get_widget("chk_windowlist").get_active():
            self.specto.specto_gconf.set_entry("show_in_windowlist", True)
            self.specto.notifier.notifier.set_skip_taskbar_hint(True)
        else:
            self.specto.specto_gconf.set_entry("show_in_windowlist", True)
            self.specto.notifier.notifier.set_skip_taskbar_hint(
                False
            )  #note, this is set_SKIP! this explains why it's False to skip.

        #see if tray has to be saved
        if self.wTree.get_widget("chk_tray").get_active():
            self.specto.specto_gconf.set_entry("always_show_icon", True)
        else:
            self.specto.specto_gconf.set_entry("always_show_icon", False)
        self.specto.recreate_tray()

        #see if debug mode has to be saved
        if self.wTree.get_widget("chk_debug").get_active():
            self.specto.specto_gconf.set_entry("debug_mode", True)
        else:
            self.specto.specto_gconf.set_entry("debug_mode", False)
Exemple #39
0
    def show_edit_watch(self, id, *args):
        """ Show the edit watch window. """
        selected = ""
        if not id == -1:
            selected = self.watch_db[id]
        else:
            for i in self.watch_db:
                if self.watch_db[i].name == args[0]:
                    selected = self.watch_db[i]

        if self.edit_w == "":
            self.edit_w = Edit_watch(self, selected)
            self.logger.log(_("edit watch: create"), "debug", self.__class__)
        elif self.edit_w.edit_watch.flags() & gtk.MAPPED:
            self.logger.log(_("edit watch: already visible"), "debug",
                            self.__class__)
        else:
            self.edit_w = Edit_watch(self, selected)
            self.logger.log(_("edit watch: recreate"), "debug", self.__class__)
Exemple #40
0
    def quit(self, *args):
        """ Save the save and position from the notifier and quit Specto. """
        if self.notifier.get_state()==True and not self.notifier_keep_hidden:
            self.notifier.save_size_and_position()#when quitting specto abruptly, remember the notifier window properties
        try:
            gtk.main_quit()
        except:
            #create a close dialog
            dialog = gtk.Dialog(_("Cannot quit yet"), None, gtk.DIALOG_MODAL | gtk.DIALOG_NO_SEPARATOR | gtk.DIALOG_DESTROY_WITH_PARENT, None)
            #HIG tricks
            dialog.set_has_separator(False)
            
            dialog.add_button(_("Murder!"), 3)
            dialog.add_button(gtk.STOCK_CANCEL, -1)

            dialog.label_hbox = gtk.HBox(spacing=6)
            
            
            icon = gtk.Image()
            icon.set_from_icon_name("dialog-warning", 64)
            dialog.label_hbox.pack_start(icon, True, True, 6)
            icon.show()

            label = gtk.Label(_('<b><big>Specto is currently busy and cannot quit yet.</big></b>\n\nThis may be because it is checking for watch updates.\nHowever, you can try forcing it to quit by clicking the murder button.'))
            label.set_use_markup(True)
            dialog.label_hbox.pack_start(label, True, True, 6)#here, pack means "cram the label right at the start of the vbox before the buttons"
            label.show()
            
            dialog.vbox.pack_start(dialog.label_hbox, True, True, 12)
            dialog.label_hbox.show()
            
            icon = gtk.gdk.pixbuf_new_from_file(self.PATH + 'icons/specto_window_icon.svg' )
            dialog.set_icon(icon)
            answer = dialog.run()
            if answer == 3:
                try:#go figure, it never works!
                    self.notifier.stop_refresh = True
                    sys.exit(0)
                except:
                    #kill the specto process with killall
                    os.system('killall specto')
            else:
                dialog.destroy()
Exemple #41
0
 def __init__(self, refresh, file, mode, specto, id,  name = _("Unknown File Watch")):
     Watch.__init__(self, specto)
     self.name = name
     self.refresh = refresh
     self.file = file
     self.mode = mode
     self.id = id
     self.error = False
     self.first_time = False
     self.actually_updated = False
Exemple #42
0
 def __init__(self, specto, name, refresh, url, id, error_margin):
     Watch.__init__(self, specto) #init superclass
     self.refresh = refresh
     self.id = id
     self.url_ = url
     if self.url_ == "":
         self.specto.logger.log(_("Watch: \"%s\" has error: empty url") % self.error, "error", self.__class__)
     self.name = name
     self.error_margin = error_margin#the amount in percent (as a float) of what the filesize must change to consider the page changed
     self.error = False
Exemple #43
0
 def __init__(self, refresh, host, username, password, ssl, specto, id, name = _("Unknown Mail Watch")):
     Watch.__init__(self, specto)
     self.name = name
     self.refresh = refresh
     self.host = host
     self.user = username
     self.password = password
     self.id = id
     self.error = False
     self.ssl = ssl
Exemple #44
0
 def thread_update(self):
     if not self.specto.connection_manager.connected():
         self.specto.logger.log(_("No network connection detected"), "info",
                                self.__class__)
         self.specto.notifier.connected_message(
             False)  #show the network error message
         self.specto.connection_manager.add_callback(self._real_update)
         self.specto.mark_watch_busy(False, self.id)
     else:
         self._real_update()
Exemple #45
0
    def remove_watch(self, name):
        """ Remove a watch from the configuration file. """
        try:
            cfgpr = ConfigParser()
            cfgpr.read(self.file_name)
            cfgpr.remove_section(name)
        except:
            self.specto.logger.log(
                _("There was an error writing to %s") % self.file_name,
                "critical", self.__class__)

        try:
            f = open(self.file_name, "w")
            cfgpr.write(f)
        except IOError:
            self.specto.logger.log(
                _("There was an error writing to %s") % self.file_name,
                "critical", self.__class__)
        finally:
            f.close()
Exemple #46
0
    def __init__(self, specto):
        self.specto = specto
        version_file_path = (spectlib.util.get_path(category="doc") +
                             'VERSION')
        version_file = open(version_file_path, 'r')
        version = str(
            version_file.readline()
            [:-1])  # "[:-1]" means we omit the last character, which is "\n".
        version_file.close
        license_file_path = (spectlib.util.get_path(category="doc") +
                             'COPYING')
        license_file = open(license_file_path, "r")
        license = license_file.read()
        license_file.close()
        license = str(license)
        authors = [
            "Jean-Francois 'Kiddo' Fortin Tam\n\t<nekohayo AT gmail DOT com>\n",
            "Pascal Potvin\n\t<pascal.potvin AT gmail DOT com>\n",
            "Wout Clymans\n\t<woutclymans AT pi DOT be>\n",
            "Giulio 'Dullboy' lotti\n\t<dullgiulio AT gmail DOT com>\n",
            "Thomas McColgan\n\t<thomas DOT mccolgan AT gmx DOT de>\n",
            "Conor 'majikstreet' Callahan\n\t<majikstreet AT gmail DOT com>\n",
            "Chris 'RAOF' Halse Rogers\n\t<chalserogers AT gmail DOT com>\n"
        ]
        logo = gtk.gdk.pixbuf_new_from_file(self.specto.PATH +
                                            'icons/specto_about.png')

        translator_credits = _("translator-credits")

        #create tree
        self.about = gtk.AboutDialog()

        self.about.set_name("Specto")
        self.about.set_version(version)
        self.about.set_copyright("Jean-Francois Fortin Tam")
        #self.wTree.set_comments(comments)
        self.about.set_license(license)
        #self.wTree.set_wrap_license(license)
        self.about.set_website("http://specto.sourceforge.net")
        self.about.set_website_label("Specto's Website")
        self.about.set_authors(authors)
        #self.about.set_documenters(documenters)
        #self.about.set_artists(artists)
        self.about.set_translator_credits(translator_credits)
        self.about.set_logo(logo)

        icon = gtk.gdk.pixbuf_new_from_file(self.specto.PATH +
                                            'icons/specto_window_icon.png')
        self.about.set_icon(icon)
        #self.wTree.set_logo_icon_name(icon_name)

        self.about.connect("response", lambda d, r: self.close())

        self.about.show_all()
Exemple #47
0
 def __init__(self, refresh, username, password, specto, id,  name = _("Unknown Mail Watch")):
     Watch.__init__(self, specto)
     self.name = name
     self.refresh = refresh
     if "@" not in username:
         self.user = username + "@gmail.com"
     else:
         self.user = username
     self.password = password
     self.id = id
     self.error = False
Exemple #48
0
 def replace_name(self, orig, new):
     """ Replace a watch name (rename). """
     #read the file
     try:
         f = open(self.file_name, "r")
         text = f.read()
     except IOError:
         self.specto.logger.log(_("There was an error writing to %s") % self.file_name, "critical", self.__class__)
     finally:
         f.close
                    
     text = text.replace("[" + orig + "]", "[" + new + "]")
     
     #replace and write file
     try:
         f = open(self.file_name, "w")
         f.write(text)
     except IOError:
         self.specto.logger.log(_("There was an error writing to %s") % self.file_name, "critical", self.__class__)
     finally:
         f.close()
Exemple #49
0
 def __init__(self, specto, name, refresh, url, id, error_margin):
     Watch.__init__(self, specto)  #init superclass
     self.refresh = refresh
     self.id = id
     self.url_ = url
     if self.url_ == "":
         self.specto.logger.log(
             _("Watch: \"%s\" has error: empty url") % self.error, "error",
             self.__class__)
     self.name = name
     self.error_margin = error_margin  #the amount in percent (as a float) of what the filesize must change to consider the page changed
     self.error = False
Exemple #50
0
 def update(self, lock):
     """ See if a socket was opened or closed. """
     self.error = False
     self.specto.mark_watch_busy(True, self.id)
     self.specto.logger.log(_("Updating watch: \"%s\"") % self.name, "info", self.__class__)
     
     try:
         established = self.check_port()
         if self.running and established == False:
             self.running = False
             self.actually_updated = True
         elif self.running == False and established == True:
             self.running = True 
             self.actually_updated = True
         else: self.actually_updated=False
     except:
         self.error = True
         self.specto.logger.log(_("Watch: \"%s\" has an error") % self.name, "error", self.__class__)
     
     self.specto.mark_watch_busy(False, self.id)
     Watch.update(self, lock)
Exemple #51
0
 def get_removed_files(self):
     """ Get the removed files. """
     old_values_ = self.old_values.split("\n")
     self.old_values = ""
     y = 0
     for i in self.old_files:
         if i not in self.new_files:#see if a old file still exists in the new files list
             self.specto.logger.log(_("update: %s removed") % i, "info", self.__class__)
             self.updated = True
         else:
             self.old_values += old_values_[y] + "\n"
         y+=1
Exemple #52
0
 def get_dir(self, dir_):
     """ Recursively walk a directory. """
     for f in os.listdir(dir_):
         pathname = os.path.join(dir_, f)
         mode = os.stat(pathname)[ST_MODE]
         if S_ISDIR(mode): # It's a directory, recurse into it
             self.get_dir(pathname)
         elif S_ISREG(mode): # It's a file, get the info
             self.new_files.append(pathname)
             self.get_file(pathname)
         else: # Unknown file type
             self.specto.logger.log(_("Skipping %s") % pathname, "debug", self.__class__)
Exemple #53
0
 def get_SID(self):
     header = {'User-agent' : self.source}
     post_data = urllib.urlencode({ 'Email': self.user, 'Passwd': self.password, 'service': 'reader', 'source': self.source, 'continue': self.google_url, })
     request = urllib2.Request(self.login_url, post_data, header)
     
     try :
         f = urllib2.urlopen( request )
         result = f.read()
     
     except:
         self.specto.logger.log(_("Watch: \"%s\" has error: wrong username/password") % self.name, "error", self.__class__)
         
     return re.search('SID=(\S*)', result).group(1)
Exemple #54
0
 def get_removed_files(self):
     """ Get the removed files. """
     old_values_ = self.old_values.split("\n")
     self.old_values = ""
     y = 0
     for i in self.old_files:
         if i not in self.new_files:  #see if a old file still exists in the new files list
             self.specto.logger.log(
                 _("update: %s removed") % i, "info", self.__class__)
             self.updated = True
         else:
             self.old_values += old_values_[y] + "\n"
         y += 1
Exemple #55
0
 def get_dir(self, dir_):
     """ Recursively walk a directory. """
     for f in os.listdir(dir_):
         pathname = os.path.join(dir_, f)
         mode = os.stat(pathname)[ST_MODE]
         if S_ISDIR(mode):  # It's a directory, recurse into it
             self.get_dir(pathname)
         elif S_ISREG(mode):  # It's a file, get the info
             self.new_files.append(pathname)
             self.get_file(pathname)
         else:  # Unknown file type
             self.specto.logger.log(
                 _("Skipping %s") % pathname, "debug", self.__class__)
Exemple #56
0
    def restore_size_and_position(self):
        """
        Restore the size and the postition from the notifier window.
        """
        saved_window_width = self.specto.specto_gconf.get_entry("window_notifier_width")
        saved_window_height = self.specto.specto_gconf.get_entry("window_notifier_height")
        saved_window_x = self.specto.specto_gconf.get_entry("window_notifier_x")
        saved_window_y = self.specto.specto_gconf.get_entry("window_notifier_y")
        if self.specto.specto_gconf.get_entry("hide_from_windowlist") == True:
            self.notifier.set_skip_taskbar_hint(True)  # hide from the window list applet

        if saved_window_width != None and saved_window_height != None:  # check if the size is not 0
            self.wTree.get_widget("notifier").resize(saved_window_width, saved_window_height)
            self.specto.logger.log(_("notifier: size set"), "debug", self.__class__)
        else:
            self.specto.logger.log(_("notifier: size not set"), "debug", self.__class__)

        if saved_window_x != None and saved_window_y != None:  # check if the position is not 0
            self.wTree.get_widget("notifier").move(saved_window_x, saved_window_y)
            self.specto.logger.log(_("notifier: position set"), "debug", self.__class__)
        else:
            self.specto.logger.log(_("notifier: position not set"), "debug", self.__class__)
Exemple #57
0
 def get_file(self, file_):
     """ Get the info from a file and compair it with the previous info. """
     size = int(
         os.stat(file_)[6]
     )  #mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime = info
     old_size = re.search('%s:\s(.+)' % file_, self.old_values)
     if old_size and size:
         old_size = int(old_size.group(1))
         if size != old_size:
             #replace filesize
             self.old_values = self.old_values.replace(
                 file_ + ": " + str(old_size), file_ + ": " + str(size))
             self.specto.logger.log(
                 _("update: %s was modified") % file_, "info",
                 self.__class__)
             self.updated = True
     elif (size or size == 0) and not old_size:
         #add the file to the list
         self.old_values += file_ + ": " + str(size) + "\n"
         self.specto.logger.log(
             _("update: %s was created") % file_, "info", self.__class__)
         self.updated = True
Exemple #58
0
    def update(self, lock):
        """ See if a file was modified or created. """
        self.error = False
        self.updated = False
        self.specto.mark_watch_busy(True, self.id)
        self.specto.logger.log(
            _("Updating watch: \"%s\"") % self.name, "info", self.__class__)

        try:
            self.get_cache_file()
            self.old_values = self.read_cache_file()
            mode = os.stat(self.file)[ST_MODE]
            self.new_files = []
            if S_ISDIR(mode):
                self.get_dir(self.file)
                self.update_cache_file(
                )  #write the new values to the cache file
                self.old_values = self.read_cache_file()  #read the new valeus
                self.get_removed_files()  #remove the files that were removed
                self.update_cache_file(
                )  #write the values (with the removed lines) to the cache file
            else:
                self.get_file(self.file)
                self.update_cache_file()

            #first time don't mark as updated
            if self.first_time == True:
                self.updated = False
                self.first_time = False
        except:
            self.error = True
            self.specto.logger.log(
                _("Watch: \"%s\" has an error") % self.name, "error",
                self.__class__)

        self.specto.mark_watch_busy(False, self.id)
        self.actually_updated = self.updated
        Watch.update(self, lock)