Exemple #1
0
    def initialize(self):
        smart_dirs = None
        if USING_FIREFOX:
            smart_dirs = [
                get_firefox_home_file("searchplugins"),
                get_firefox_home_file("search"),
                expanduser("~/.mozilla/searchplugins"),
                "/usr/local/lib/firefox/searchplugins",
                "/usr/lib/mozilla-firefox/searchplugins",
                "/usr/local/lib/mozilla-firefox/searchplugins",
                "/usr/lib/iceweasel/searchplugins"] + \
                glob.glob("/usr/lib*/firefox*/searchplugins")
        else:
            smart_dirs = [
                get_mozilla_home_file("search"),
                expanduser("~/.mozilla/searchplugins"),
                "/usr/lib/mozilla/searchplugins",
                "/usr/local/lib/mozilla/searchplugins"
            ]

        if not hasattr(self, 'watcher'):
            self.watcher = DirWatcher()
            self.watcher.connect(
                'changed',
                lambda watcher, f: self._parse_search_engines(smart_dirs))

        self.watcher.add(smart_dirs)
        self._parse_search_engines(smart_dirs)
Exemple #2
0
 def initialize(self):
     smart_dirs = None
     if USING_FIREFOX:
         smart_dirs = [
             get_firefox_home_file("searchplugins"),
             get_firefox_home_file("search"),
             expanduser("~/.mozilla/searchplugins"),
             "/usr/local/lib/firefox/searchplugins",
             "/usr/lib/mozilla-firefox/searchplugins",
             "/usr/local/lib/mozilla-firefox/searchplugins",
             "/usr/lib/iceweasel/searchplugins"] + \
             glob.glob("/usr/lib*/firefox*/searchplugins")
     else:
         smart_dirs = [
             get_mozilla_home_file("search"),
             expanduser("~/.mozilla/searchplugins"),
             "/usr/lib/mozilla/searchplugins",
             "/usr/local/lib/mozilla/searchplugins"]
     
     if not hasattr(self, 'watcher'):
         self.watcher = DirWatcher()
         self.watcher.connect('changed', lambda watcher, f: self._parse_search_engines(smart_dirs))
     
     self.watcher.add(smart_dirs)
     self._parse_search_engines(smart_dirs)
Exemple #3
0
    def __init__(self, dirs, extension=".py"):
        """
        dirs: A list of directories to search. Relative pathnames and paths
              containing ~ will be expanded. If dirs is None the 
              ModuleLoader will not search for modules.
        extension: What extension should this ModuleLoader accept (string).
        """
        gobject.GObject.__init__(self)
        self.ext = extension
        self.watcher = DirWatcher()
        self.watch_id = self.watcher.connect('changed',
                                             self._on_handler_file_changed)

        if (dirs):
            self.dirs = [abspath(expanduser(s)) for s in dirs]
            self.build_filelist()
            self.watcher.add(self.dirs)
        else:
            self.dirs = None
            self.filelist = []
 def __init__ (self, dirs, extension=".py"):
     """
     dirs: A list of directories to search. Relative pathnames and paths
           containing ~ will be expanded. If dirs is None the 
           ModuleLoader will not search for modules.
     extension: What extension should this ModuleLoader accept (string).
     """
     gobject.GObject.__init__ (self)
     self.ext = extension
     self.watcher = DirWatcher()
     self.watch_id = self.watcher.connect('changed', self._on_handler_file_changed)
     
     if (dirs):
         self.dirs = [abspath(expanduser(s)) for s in dirs]
         self.build_filelist ()
         self.watcher.add(self.dirs)
     else:
         self.dirs = None
         self.filelist = []
Exemple #5
0
class ModuleLoader(gobject.GObject):
    """
    An auxilary class to L{deskbar.core.ModuleList.ModuleList}.
    
    Create an instance of ModuleLoader by
    specifying which directories to search and what extension to accept.
    The L{load_all} method will load all qualified modules and tell
    you when it's ready with the C{modules-loaded} signal.
    
    Most methods have a _async variant. These methods emits signals that is handled
    by the mainloop.
            
    Hint: If you pass None as the dirs argument the ModuleLoader will not search
    for modules at all. This is useful if you want to reload a single module for
    which you know the path.
    """

    __gsignals__ = {
        # Fired when the passed module module is loaded, that is the module's __init__ method has been called
        "module-loaded":
        (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [gobject.TYPE_PYOBJECT]),
        # Fired when load_all has loaded every available modules
        "modules-loaded": (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, []),
        # Fired when the passed module module has successfully run the initialize() method, and is thus ready to be queried
        "module-initialized":
        (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [gobject.TYPE_PYOBJECT]),
        # Fired when the passed module module has not run initialize() without errors. The module is no usable anymore
        "module-not-initialized":
        (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [gobject.TYPE_PYOBJECT]),
        # Fired when the passed module module has run the stop() method successfully. The module is not usable anymore
        "module-stopped":
        (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [gobject.TYPE_PYOBJECT]),
    }

    def __init__(self, dirs, extension=".py"):
        """
        dirs: A list of directories to search. Relative pathnames and paths
              containing ~ will be expanded. If dirs is None the 
              ModuleLoader will not search for modules.
        extension: What extension should this ModuleLoader accept (string).
        """
        gobject.GObject.__init__(self)
        self.ext = extension
        self.watcher = DirWatcher()
        self.watch_id = self.watcher.connect('changed',
                                             self._on_handler_file_changed)

        if (dirs):
            self.dirs = [abspath(expanduser(s)) for s in dirs]
            self.build_filelist()
            self.watcher.add(self.dirs)
        else:
            self.dirs = None
            self.filelist = []

    def _on_handler_file_changed(self, watcher, f):
        if f in self.filelist or not self.is_module(f):
            return

        self.load(f)
        self.filelist.append(f)

    def build_filelist(self):
        """Returns a list containing the filenames of all qualified modules.
        This method is automatically invoked by the constructor.
        """
        res = []
        for d in self.dirs:
            try:
                if not os.path.exists(d):
                    continue

                for i in [
                        join(d, m) for m in os.listdir(d) if self.is_module(m)
                ]:
                    if basename(i) not in [basename(j) for j in res]:
                        res.append(i)
            except OSError, err:
                LOGGER.error("Error reading directory %s, skipping.", d)
                LOGGER.exception(err)

        self.filelist = res
class ModuleLoader (gobject.GObject):
    """
    An auxilary class to L{deskbar.core.ModuleList.ModuleList}.
    
    Create an instance of ModuleLoader by
    specifying which directories to search and what extension to accept.
    The L{load_all} method will load all qualified modules and tell
    you when it's ready with the C{modules-loaded} signal.
    
    Most methods have a _async variant. These methods emits signals that is handled
    by the mainloop.
            
    Hint: If you pass None as the dirs argument the ModuleLoader will not search
    for modules at all. This is useful if you want to reload a single module for
    which you know the path.
    """
    
    __gsignals__ = {
        # Fired when the passed module module is loaded, that is the module's __init__ method has been called
        "module-loaded" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [gobject.TYPE_PYOBJECT]),
        # Fired when load_all has loaded every available modules
        "modules-loaded" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, []),
        # Fired when the passed module module has successfully run the initialize() method, and is thus ready to be queried
        "module-initialized" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [gobject.TYPE_PYOBJECT]),
        # Fired when the passed module module has not run initialize() without errors. The module is no usable anymore
        "module-not-initialized" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [gobject.TYPE_PYOBJECT]),
        # Fired when the passed module module has run the stop() method successfully. The module is not usable anymore
        "module-stopped" : (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, [gobject.TYPE_PYOBJECT]),
    }
    
    def __init__ (self, dirs, extension=".py"):
        """
        dirs: A list of directories to search. Relative pathnames and paths
              containing ~ will be expanded. If dirs is None the 
              ModuleLoader will not search for modules.
        extension: What extension should this ModuleLoader accept (string).
        """
        gobject.GObject.__init__ (self)
        self.ext = extension
        self.watcher = DirWatcher()
        self.watch_id = self.watcher.connect('changed', self._on_handler_file_changed)
        
        if (dirs):
            self.dirs = [abspath(expanduser(s)) for s in dirs]
            self.build_filelist ()
            self.watcher.add(self.dirs)
        else:
            self.dirs = None
            self.filelist = []

    def _on_handler_file_changed(self, watcher, f):
        if f in self.filelist or not self.is_module(f):
            return
        
        self.load(f)
        self.filelist.append(f)
        
    def build_filelist (self):
        """Returns a list containing the filenames of all qualified modules.
        This method is automatically invoked by the constructor.
        """
        res = []
        for d in self.dirs:
            try:
                if not os.path.exists(d):
                    continue

                for i in [join(d, m) for m in os.listdir (d) if self.is_module(m)]:
                    if basename(i) not in [basename(j) for j in res]:
                        res.append(i)
            except OSError, err:
                LOGGER.error("Error reading directory %s, skipping.", d)
                LOGGER.exception(err)
        
        self.filelist = res
Exemple #7
0
class MozillaSearchHandler(deskbar.interfaces.Module):
    
    INFOS = {'icon': deskbar.core.Utils.load_icon("web-search.png"),
             "name": _("Web Searches (Mozilla)"),
             "description": _("Search the web via your browser's search settings"),
             "version": VERSION}
    
    def __init__(self):
        deskbar.interfaces.Module.__init__(self)
        self._smart_bookmarks = None
    
    def initialize(self):
        smart_dirs = None
        if USING_FIREFOX:
            smart_dirs = [
                get_firefox_home_file("searchplugins"),
                get_firefox_home_file("search"),
                expanduser("~/.mozilla/searchplugins"),
                "/usr/local/lib/firefox/searchplugins",
                "/usr/lib/mozilla-firefox/searchplugins",
                "/usr/local/lib/mozilla-firefox/searchplugins",
                "/usr/lib/iceweasel/searchplugins"] + \
                glob.glob("/usr/lib*/firefox*/searchplugins")
        else:
            smart_dirs = [
                get_mozilla_home_file("search"),
                expanduser("~/.mozilla/searchplugins"),
                "/usr/lib/mozilla/searchplugins",
                "/usr/local/lib/mozilla/searchplugins"]
        
        if not hasattr(self, 'watcher'):
            self.watcher = DirWatcher()
            self.watcher.connect('changed', lambda watcher, f: self._parse_search_engines(smart_dirs))
        
        self.watcher.add(smart_dirs)
        self._parse_search_engines(smart_dirs)
        
    def _parse_search_engines(self, smart_dirs):
        self._smart_bookmarks = MozillaSmartBookmarksDirParser(smart_dirs).get_smart_bookmarks()
        self.set_priority_for_matches(self._smart_bookmarks)

    def stop(self):
        self.watcher.remove_all()
        
    def query(self, query):
        self.set_priority_for_matches (self._smart_bookmarks)
        if SHOW_ONLY_PRIMARY and PRIMARY_SEARCH_ENGINE != None:
            for s in self._smart_bookmarks:
                if s.get_name() == PRIMARY_SEARCH_ENGINE:
                    self._emit_query_ready(query, [s] )
                    return
            self._emit_query_ready(query, self._smart_bookmarks )
        else:
            self._emit_query_ready(query, self._smart_bookmarks )
    
    def has_config(self):
        return True
    
    def show_config(self, parent):
        _on_handler_preferences(parent)
    
    @staticmethod
    def has_requirements():
        if is_preferred_browser("firefox") or is_preferred_browser("iceweasel"):
            if is_preferred_browser("firefox") and not MozillaBookmarksHandler.has_firefox_version():
                
                MozillaSearchHandler.INSTRUCTIONS = \
                    _("Firefox version must be at least %s and less than %s") % (MIN_FF_VERSION_STRING, MAX_FF_VERSION_STRING)
                return False
            
            # Correct firefox version or iceweasel
            MozillaSearchHandler.INSTRUCTIONS = _("You can customize which search engines are offered.")
            return True
        elif is_preferred_browser("mozilla"):
            # TODO - similar functionality for old-school mozilla (not firefox)
            return True
        else:
            MozillaSearchHandler.INSTRUCTIONS = _("Mozilla/Firefox is not your preferred browser.")
            return False
Exemple #8
0
class MozillaSearchHandler(deskbar.interfaces.Module):

    INFOS = {
        'icon': deskbar.core.Utils.load_icon("web-search.png"),
        "name": _("Web Searches (Mozilla)"),
        "description": _("Search the web via your browser's search settings"),
        "version": VERSION
    }

    def __init__(self):
        deskbar.interfaces.Module.__init__(self)
        self._smart_bookmarks = None

    def initialize(self):
        smart_dirs = None
        if USING_FIREFOX:
            smart_dirs = [
                get_firefox_home_file("searchplugins"),
                get_firefox_home_file("search"),
                expanduser("~/.mozilla/searchplugins"),
                "/usr/local/lib/firefox/searchplugins",
                "/usr/lib/mozilla-firefox/searchplugins",
                "/usr/local/lib/mozilla-firefox/searchplugins",
                "/usr/lib/iceweasel/searchplugins"] + \
                glob.glob("/usr/lib*/firefox*/searchplugins")
        else:
            smart_dirs = [
                get_mozilla_home_file("search"),
                expanduser("~/.mozilla/searchplugins"),
                "/usr/lib/mozilla/searchplugins",
                "/usr/local/lib/mozilla/searchplugins"
            ]

        if not hasattr(self, 'watcher'):
            self.watcher = DirWatcher()
            self.watcher.connect(
                'changed',
                lambda watcher, f: self._parse_search_engines(smart_dirs))

        self.watcher.add(smart_dirs)
        self._parse_search_engines(smart_dirs)

    def _parse_search_engines(self, smart_dirs):
        self._smart_bookmarks = MozillaSmartBookmarksDirParser(
            smart_dirs).get_smart_bookmarks()
        self.set_priority_for_matches(self._smart_bookmarks)

    def stop(self):
        self.watcher.remove_all()

    def query(self, query):
        self.set_priority_for_matches(self._smart_bookmarks)
        if SHOW_ONLY_PRIMARY and PRIMARY_SEARCH_ENGINE != None:
            for s in self._smart_bookmarks:
                if s.get_name() == PRIMARY_SEARCH_ENGINE:
                    self._emit_query_ready(query, [s])
                    return
            self._emit_query_ready(query, self._smart_bookmarks)
        else:
            self._emit_query_ready(query, self._smart_bookmarks)

    def has_config(self):
        return True

    def show_config(self, parent):
        _on_handler_preferences(parent)

    @staticmethod
    def has_requirements():
        if is_preferred_browser("firefox") or is_preferred_browser(
                "iceweasel"):
            if is_preferred_browser(
                    "firefox"
            ) and not MozillaBookmarksHandler.has_firefox_version():

                MozillaSearchHandler.INSTRUCTIONS = \
                    _("Firefox version must be at least %s and less than %s") % (MIN_FF_VERSION_STRING, MAX_FF_VERSION_STRING)
                return False

            # Correct firefox version or iceweasel
            MozillaSearchHandler.INSTRUCTIONS = _(
                "You can customize which search engines are offered.")
            return True
        elif is_preferred_browser("mozilla"):
            # TODO - similar functionality for old-school mozilla (not firefox)
            return True
        else:
            MozillaSearchHandler.INSTRUCTIONS = _(
                "Mozilla/Firefox is not your preferred browser.")
            return False