1
# -*- coding: utf-8 -*-
3
# Copyright 2011 Jaap Karssenberg <jaap.karssenberg@gmail.com>
5
'''Plugin to auto-mount notebooks when needed'''
7
from zim.plugins import PluginClass
10
from zim.config import config_file
11
from zim.applications import Application
14
class AutomountPlugin(PluginClass):
17
'name': _('Automount'), # T: plugin name
19
This plugin can automatically "mount" notebooks when needed. It can
20
e.g. be used to connect with remote drives or unlock an encrypted drive
21
when zim is trying to open a specific notebook.
23
This is a core plugin shipping with zim.
24
'''), # T: plugin description
25
'author': 'Jaap Karssenberg',
26
'help': 'Plugins:Automount',
29
# this plugin is profile independent
30
is_profile_independent = True
32
def get_config(self, uri):
33
'''Return the automount config for a specific notebook uri or C{None}
34
@param uri: a notebook uri
35
@returns: a config dict
37
config = config_file('automount.conf')
38
groups = [k for k in config.keys() if k.startswith('Path')]
40
path = group[4:].strip() # len('Path') = 4
41
myuri = Dir(path).uri # Allow "~/Folder" syntax
42
if uri.startswith(myuri):
47
def initialize_notebook(self, uri):
48
# check if the notebook exists
49
if not uri.startswith('file:') \
50
or Dir(uri).file('notebook.zim').exists():
53
# if it doesn't, see if we know how to mount it
54
config = self.get_config(uri)
55
if config and 'mount' in config:
56
if 'passwd' in config:
58
Application(config['mount']).run()