def write_options(self, file_name, 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', 'name':'value' } If the name is not found, a new watch will be added, else the excisting watch will be changed. """ watch_io = Watch_io(self.specto, file_name) watch_io.write_watch(values)
def __init__(self): self.DEBUG = DEBUG import gettext #this is for the glade files self.glade_gettext = gettext.textdomain("specto") self.logger = Logger(self) self.check_instance() #see if specto is already running self.util = util self.PATH = self.util.get_path() self.specto_gconf = specto_gconf self.check_default_settings( ) #if this is the first run of specto, set the default values for gconf. Whenever you add some gconf preference for specto, this function will also need to be updated. self.GTK = GTK if GTK: self.tray = Tray(self) self.icon_theme = gtk.icon_theme_get_default() self.watch_db = {} self.watch_io = Watch_io() watch_value_db = self.watch_io.read_options() self.preferences_initialized = False self.notifier_initialized = False #listen for gconf keys self.specto_gconf.notify_entry("debug_mode", self.key_changed, "debug") self.connection_manager = conmgr.get_net_listener() if GTK: if self.specto_gconf.get_entry("always_show_icon") == False: #if the user has not requested the tray icon to be shown at all times, it's impossible that the notifier is hidden on startup, so we must show it. self.notifier_keep_hidden = False self.toggle_notifier() elif self.specto_gconf.get_entry("show_notifier") == True: self.notifier_keep_hidden = False self.toggle_notifier() elif self.specto_gconf.get_entry("show_notifier") == False: self.notifier_keep_hidden = True self.toggle_notifier() self.notifier_keep_hidden = False else: #just in case the entry was never created in gconf self.notifier_keep_hidden = False self.toggle_notifier() self.create_all_watches(watch_value_db) if GTK: gtk.main() else: self.go = gobject.MainLoop() self.go.run()
def read_options(self, file_name): watch_io = Watch_io(self.specto, file_name) if watch_io.valid == False: return False values = watch_io.read_all_watches() for i in values: try: int(values[i]['type']) except: pass else: values[i]['open_command'] = "" values[i]['last_changed'] = "" # Import from Specto 0.2 # FIXME: wouldn't this code be more efficient with a case/switch? if values[i]['type'] == "0": values[i]['type'] = "Watch_web_static" elif values[i]['type'] == "1": if values[i]['prot'] == "0": values[i]['type'] = "Watch_mail_pop3" if values[i]['prot'] == "1": values[i]['type'] = "Watch_mail_imap" if values[i]['prot'] == "2": values[i]['type'] = "Watch_mail_gmail" del values[i]['prot'] elif values[i]['type'] == "2": if values[i]['mode'] == "file": values[i]['type'] = "Watch_system_file" else: values[i]['type'] = "Watch_system_folder" del values[i]['mode'] elif values[i]['type'] == "3": values[i]['type'] = "Watch_system_process" elif values[i]['type'] == "4": values[i]['type'] = "Watch_system_port" elif values[i]['type'] == "5": values[i]['type'] = "Watch_web_greader" watch_collection = Watch_collection(self.specto) watch_collection.create(values) self._import.set_new_watch_db(watch_collection) for watch in watch_collection: self._import.add_watch_entry(watch.id)
def __init__(self): self.DEBUG = DEBUG self.util = util self.PATH = self.util.get_path() self.LOGO_PATH = os.path.join(self.PATH, "icons/specto.svg") self.SRC_PATH = self.util.get_path("src") self.SPECTO_DIR = self.util.get_path("specto") self.CACHE_DIR = self.util.get_path("tmp") self.FILE = self.util.get_file() self.logger = Logger(self) self.VERSION = VERSION # The Specto version number self.GTK = GTK if not self.check_instance(): #see if specto is already running self.specto_gconf = specto_gconf self.check_default_settings() self.connection_manager = conmgr.get_net_listener() self.use_keyring = self.specto_gconf.get_entry("use_keyring") #create the watch collection and add the watches self.watch_db = Watch_collection(self) self.watch_io = Watch_io(self, self.FILE) if (sys.argv[1:] and "--console" in sys.argv[1:][0]) or not self.GTK: self.logger.log(_("Console mode enabled."), "debug", "specto") self.GTK = False self.CONSOLE = True try: args = sys.argv[1:][1] except: args = "" self.console = Console(self, args) elif self.GTK: self.GTK = True self.CONSOLE = False self.icon_theme = gtk.icon_theme_get_default() #allow users to hide the window on startup if sys.argv[1:] and "--no-window" in sys.argv[1:][0]: self.notifier_hide = True #always show if there's no icon and no indicator support elif self.specto_gconf.get_entry( "always_show_icon") == False and not INDICATOR: self.notifier_hide = False elif self.specto_gconf.get_entry("show_notifier") == True: self.notifier_hide = False elif self.specto_gconf.get_entry("show_notifier") == False: self.notifier_hide = True else: #just in case the entry was never created in gconf self.notifier_keep_hidden = False self.notifier = Notifier(self) else: sys.exit(0) #listen for gconf keys self.specto_gconf.notify_entry("debug_mode", self.key_changed, "debug") values = self.watch_io.read_all_watches(True) try: self.watch_db.create(values) except AttributeError as error_fields: self.logger.log(_("Could not create a watch, because it is corrupt."), \ "critical", "specto") if self.GTK: for watch in self.watch_db: self.notifier.add_notifier_entry(watch.id) # Listen for USR1. If received, answer and show the window def listen_for_USR1(signum, frame): f = open(self.SPECTO_DIR + "/" + "specto.pid.boot") pid = int(f.readline()) f.close() os.kill(pid, signal.SIGUSR1) # If window was not shown, make it appear if not self.notifier.get_state(): self.logger.log( "Showing window, the user ran another instance of specto", "debug", "specto") self.toggle_notifier() else: # Based on http://www.pygtk.org/docs/pygtk/class-gtkwindow.html#method-gtkwindow--present self.logger.log( "Window is already visible! Raising it to the front.", "debug", "specto") self.notifier.notifier.present() signal.signal(signal.SIGUSR1, listen_for_USR1) self.notifier.refresh_all_watches() else: self.console.start_watches() if self.GTK: gtk.main() else: try: self.go = gobject.MainLoop() self.go.run() except (KeyboardInterrupt, SystemExit): sys.exit(0)