~bkidwell/zim/pyzim-win-installer

« back to all changes in this revision

Viewing changes to zim/notebook.py

  • Committer: Jaap Karssenberg
  • Date: 2011-08-28 13:48:27 UTC
  • Revision ID: jaap.karssenberg@gmail.com-20110828134827-13aj5dsipuuh74ny
* Improve Add Notebook dialog, name and folder fields update each other
* Fixed bug in custom tools when tool name is not a valid file name

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
'\', '/', ':', '*', '?', '"', '<', '>', '|'
60
60
(checked both win32 & posix)
61
61
 
62
 
Do not allow '\n' for obvious reasons
 
62
Do not allow '\n' and '\t' for obvious reasons
63
63
 
64
64
Allowing '%' will cause problems with sql wildcards sooner
65
65
or later - also for url decoding ambiguity it is better to
456
456
        return notebook, path
457
457
 
458
458
 
459
 
def get_notebook(path):
460
 
        '''Convenience method that constructs a notebook from either a
461
 
        uri, or a File or a Dir object.
462
 
        '''
463
 
        # TODO this is where the hook goes to automount etc.
 
459
def _get_path_object(path):
464
460
        if isinstance(path, basestring):
465
461
                file = File(path)
466
462
                if file.exists(): # exists and is a file
469
465
                        path = Dir(path)
470
466
        else:
471
467
                assert isinstance(path, (File, Dir))
 
468
        return path
 
469
 
 
470
def get_notebook_info(path):
 
471
        '''Look up the notebook info for either a uri,
 
472
        or a File or a Dir object.
 
473
        @param path: path as string, L{File} or L{Dir} object
 
474
        @returns: L{NotebookInfo} object, or C{None} if no notebook config
 
475
        was found
 
476
        '''
 
477
        path = _get_path_object(path)
 
478
        info = NotebookInfo(path.uri)
 
479
        if info.update():
 
480
                return info
 
481
        else:
 
482
                return None
 
483
 
 
484
def get_notebook(path):
 
485
        '''Convenience method that constructs a notebook from either a
 
486
        uri, or a File or a Dir object.
 
487
        @param path: path as string, L{File} or L{Dir} object
 
488
        @returns: a L{Notebook} object, or C{None} if the path does not
 
489
        exist
 
490
        '''
 
491
        path = _get_path_object(path)
472
492
 
473
493
        if path.exists():
474
494
                if isinstance(path, File):
1074
1094
                        # Note that leading "_" is stripped, due to strip() below
1075
1095
 
1076
1096
                if purge:
1077
 
                        for char in ("?", "#", "/", "\\", "*", '"', "<", ">", "|", "%", "\n"):
 
1097
                        for char in ("?", "#", "/", "\\", "*", '"', "<", ">", "|", "%", "\t", "\n"):
1078
1098
                                name = name.replace(char, '')
1079
1099
                else:
1080
 
                        for char in ("?", "#", "/", "\\", "*", '"', "<", ">", "|", "%", "\n"):
 
1100
                        for char in ("?", "#", "/", "\\", "*", '"', "<", ">", "|", "%", "\t", "\n"):
1081
1101
                                if char in name:
1082
1102
                                        raise PageNameError, orig
1083
1103