Пример #1
0
def resolve_notebook(string, pwd=None):
	'''Takes either a notebook name or a file or dir path. For a name
	it resolves the path by looking for a notebook of that name in the
	notebook list.
	Note that the L{NotebookInfo} for an file path is not using any
	actual info from the notebook, it just passes on the uri. Use
	L{build_notebook()} to split the URI in a notebook location and
	an optional page path.
	@returns: a L{NotebookInfo} or C{None}
	'''
	assert isinstance(string, str)
	from zim.fs import isabs

	if '/' in string or os.path.sep in string:
		# FIXME do we need a isfilepath() function in fs.py ?
		if is_url_re.match(string):
			uri = string
		elif pwd and not isabs(string):
			uri = pwd + os.sep + string
		else:
			uri = string
		return NotebookInfo(uri)
	else:
		nblist = get_notebook_list()
		return nblist.get_by_name(string)
Пример #2
0
    def parse_options(self, *args):
        self.opts['option'] = []  # allow list

        if all(not a.startswith('-') for a in args):
            # Backward compartibility for options not prefixed by "--"
            # used "=" as separator for values
            # template options came as "option:KEY=VALUE"
            for arg in args:
                if arg.startswith('option:'):
                    self.opts['option'].append(arg[7:])
                elif arg == 'help':
                    self.opts['help'] = True
                else:
                    key, value = arg.split('=', 1)
                    self.opts[key] = value
        else:
            GtkCommand.parse_options(self, *args)

        self.template_options = {}
        for arg in self.opts['option']:
            key, value = arg.split('=', 1)
            self.template_options[key] = value

        if 'append' in self.opts:
            self.opts['append'] = \
             self.opts['append'].lower() == 'true'

        if self.opts.get('attachments', None):
            if isabs(self.opts['attachments']):
                self.opts['attachments'] = Dir(self.opts['attachments'])
            else:
                self.opts['attachments'] = Dir(
                    (self.pwd, self.opts['attachments']))