diff options
-rwxr-xr-x | examples/data/uzbl/scripts/cookie_daemon.py | 30 | ||||
-rwxr-xr-x | examples/data/uzbl/scripts/uzbl_tabbed.py | 60 |
2 files changed, 64 insertions, 26 deletions
diff --git a/examples/data/uzbl/scripts/cookie_daemon.py b/examples/data/uzbl/scripts/cookie_daemon.py index af53e73..4850802 100755 --- a/examples/data/uzbl/scripts/cookie_daemon.py +++ b/examples/data/uzbl/scripts/cookie_daemon.py @@ -127,12 +127,19 @@ if 'XDG_DATA_HOME' in os.environ.keys() and os.environ['XDG_DATA_HOME']: else: DATA_DIR = os.path.join(os.environ['HOME'], '.local/share/uzbl/') +# Location of the uzbl configuration directory. +if 'XDG_CONFIG_HOME' in os.environ.keys() and os.environ['XDG_DATA_HOME']: + CONFIG_DIR = os.path.join(os.environ['XDG_CONFIG_HOME'], 'uzbl/') +else: + CONFIG_DIR = os.path.join(os.environ['HOME'], '.config/uzbl/') + # Default config config = { - # Default cookie jar and daemon socket locations. - 'cookie_socket': os.path.join(CACHE_DIR, 'cookie_daemon_socket'), + # Default cookie jar, whitelist, and daemon socket locations. 'cookie_jar': os.path.join(DATA_DIR, 'cookies.txt'), + 'cookie_whitelist': os.path.join(CONFIG_DIR, 'cookie_whitelist'), + 'cookie_socket': os.path.join(CACHE_DIR, 'cookie_daemon_socket'), # Time out after x seconds of inactivity (set to 0 for never time out). # WARNING: Do not use this option if you are manually launching the daemon. @@ -314,12 +321,29 @@ class CookieMonster: '''Open the cookie jar.''' cookie_jar = config['cookie_jar'] + cookie_whitelist = config['cookie_whitelist'] + if cookie_jar: mkbasedir(cookie_jar) + if cookie_whitelist: + mkbasedir(cookie_whitelist) + + # Create cookie whitelist file if it does not exist. + if not os.path.exists(cookie_whitelist): + open(cookie_whitelist, 'w').close() + + # Read cookie whitelist file into list. + file = open(cookie_whitelist,'r') + domain_list = [line.rstrip('\n') for line in file] + file.close() # Create cookie jar object from file. self.jar = cookielib.MozillaCookieJar(cookie_jar) + # Define policy of allowed domains. + policy = cookielib.DefaultCookiePolicy(allowed_domains=domain_list) + self.jar.set_policy(policy) + if cookie_jar: try: # Attempt to load cookies from the cookie jar. @@ -531,7 +555,7 @@ def main(): error("expected int argument for -t, --daemon-timeout") # Expand $VAR's in config keys that relate to paths. - for key in ['cookie_socket', 'cookie_jar']: + for key in ['cookie_socket', 'cookie_jar', 'cookie_whitelist']: if config[key]: config[key] = os.path.expandvars(config[key]) diff --git a/examples/data/uzbl/scripts/uzbl_tabbed.py b/examples/data/uzbl/scripts/uzbl_tabbed.py index 9ffa97d..827f8ab 100755 --- a/examples/data/uzbl/scripts/uzbl_tabbed.py +++ b/examples/data/uzbl/scripts/uzbl_tabbed.py @@ -97,12 +97,13 @@ # bind_goto_first = g< # bind_goto_last = g> # bind_clean_slate = gQ +# bind_exit = gZ # # Session preset key bindings: -# bind_save_preset = gsave _ -# bind_load_preset = gload _ -# bind_del_preset = gdel _ -# bind_list_presets = glist +# bind_save_preset = gsave _ +# bind_load_preset = gload _ +# bind_del_preset = gdel _ +# bind_list_presets = glist # # And uzbl_tabbed.py takes care of the actual binding of the commands via each # instances fifo socket. @@ -240,6 +241,7 @@ config = { 'bind_goto_first': 'g<', # Goto first tab. 'bind_goto_last': 'g>', # Goto last tab. 'bind_clean_slate': 'gQ', # Close all tabs and open new tab. + 'bind_exit': 'gZ', # Exit nicely. # Session preset key bindings 'bind_save_preset': 'gsave _', # Save session to file %s. @@ -324,8 +326,9 @@ def readconfig(uzbl_config, config): config[key] = value # Ensure that config keys that relate to paths are expanded. - expand = ['fifo_dir', 'socket_dir', 'session_file', 'icon_path'] - for key in expand: + pathkeys = ['fifo_dir', 'socket_dir', 'session_file', 'icon_path', + 'saved_sessions_dir'] + for key in pathkeys: config[key] = os.path.expandvars(config[key]) @@ -800,6 +803,9 @@ class UzblTabbed: # title {pid} {document-title} # updates tablist title. # uri {pid} {document-location} + # updates tablist uri + # exit + # exits uzbl_tabbed.py if cmd[0] == "new": if len(cmd) == 2: @@ -900,6 +906,9 @@ class UzblTabbed: elif cmd[0] == "clean": self.clean_slate() + elif cmd[0] == "exit": + self.quitrequest() + else: error("parse_command: unknown command %r" % ' '.join(cmd)) @@ -997,6 +1006,7 @@ class UzblTabbed: bind(config['bind_load_preset'], 'preset load %s') bind(config['bind_del_preset'], 'preset del %s') bind(config['bind_list_presets'], 'preset list %d' % uzbl.pid) + bind(config['bind_exit'], 'exit') # Set definitions here # set(key, command back to fifo) @@ -1108,9 +1118,8 @@ class UzblTabbed: if self.notebook.get_n_pages() == 0: if not self._killed and config['save_session']: - if len(self._closed): - d = {'curtab': 0, 'tabs': [self._closed[-1],]} - self.save_session(session=d) + if os.path.exists(config['session_file']): + os.remove(config['session_file']) self.quit() @@ -1191,7 +1200,7 @@ class UzblTabbed: return True - def save_session(self, session_file=None, session=None): + def save_session(self, session_file=None): '''Save the current session to file for restoration on next load.''' strip = str.strip @@ -1199,17 +1208,16 @@ class UzblTabbed: if session_file is None: session_file = config['session_file'] - if session is None: - tabs = self.tabs.keys() - state = [] - for tab in list(self.notebook): - if tab not in tabs: continue - uzbl = self.tabs[tab] - if not uzbl.uri: continue - state += [(uzbl.uri, uzbl.title),] + tabs = self.tabs.keys() + state = [] + for tab in list(self.notebook): + if tab not in tabs: continue + uzbl = self.tabs[tab] + if not uzbl.uri: continue + state += [(uzbl.uri, uzbl.title),] - session = {'curtab': self.notebook.get_current_page(), - 'tabs': state} + session = {'curtab': self.notebook.get_current_page(), + 'tabs': state} if config['json_session']: raw = json.dumps(session) @@ -1237,9 +1245,11 @@ class UzblTabbed: default_path = False strip = str.strip json_session = config['json_session'] + delete_loaded = False if session_file is None: default_path = True + delete_loaded = True session_file = config['session_file'] if not os.path.isfile(session_file): @@ -1294,6 +1304,10 @@ class UzblTabbed: for (index, (uri, title)) in enumerate(tabs): self.new_tab(uri=uri, title=title, switch=(curtab==index)) + # A saved session has been loaded now delete it. + if delete_loaded and os.path.exists(session_file): + os.remove(session_file) + # There may be other state information in the session dict of use to # other functions. Of course however the non-json session object is # just a dummy object of no use to no one. @@ -1301,16 +1315,16 @@ class UzblTabbed: def quitrequest(self, *args): - '''Called by delete-event signal to kill all uzbl instances.''' + '''Attempt to close all uzbl instances nicely and exit.''' self._killed = True if config['save_session']: - if len(list(self.notebook)): + if len(list(self.notebook)) > 1: self.save_session() else: - # Notebook has no pages so delete session file if it exists. + # Notebook has one page open so delete the session file. if os.path.isfile(config['session_file']): os.remove(config['session_file']) |