~jaap.karssenberg/zim/pyzim-0.43-backports

« back to all changes in this revision

Viewing changes to zim/stores/files.py

  • Committer: Jaap Karssenberg
  • Date: 2008-09-29 16:39:44 UTC
  • Revision ID: pardus@mirage-20080929163944-dqvdm6fciacc76wj
Added code for resolving page names

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 
5
5
'''Basic store module for storing pages as files.
6
6
 
 
7
See StoreClass in zim.stores for the API documentation.
 
8
 
7
9
Each page maps to a single text file in a normal directory structure.
8
10
Page names map almost one on one to the relative directory path.
9
11
Sub-namespaces are contained in directories of the same basename as
14
16
once we have it resolved.
15
17
'''
16
18
 
17
 
from base import *
18
19
from zim.fs import *
19
20
from zim import formats
20
21
from zim.notebook import Page, Namespace
 
22
from zim.stores import StoreClass
21
23
 
22
24
__store__ = 'files'
23
25
 
26
28
 
27
29
        def __init__(self, **args):
28
30
                '''Contruct a files store.
29
 
                Pass args needed for StoreClass init.
30
 
                Optionally pass a 'dir' attribute.
 
31
 
 
32
                Takes an optional 'dir' attribute.
31
33
                '''
32
34
                StoreClass.__init__(self, **args)
33
35
                if 'dir' in args:
71
73
        def list_pages(self, namespace):
72
74
                '''Generator function to iterate over pages in a namespace'''
73
75
                import os # using os directly here for efficiency
74
 
                # TODO need to add more logic to pair files and dirs
75
76
                dir = self._get_dir(namespace)
 
77
                pages = set() # collide files and dirs with same name
76
78
                for file in dir.list():
77
79
                        if file.startswith('.'):
78
80
                                continue # no hidden files in our page list
79
81
                        elif file.endswith('.txt'): # TODO: do not hard code extension
80
 
                                name = namespace + ':' + file[:-4]
81
 
                                file = File([dir, file])
82
 
                                yield self.get_page(name, _file=file)
 
82
                                pages.add(file[:-4])
83
83
                        elif os.path.isdir( os.path.join(dir.path, file) ):
84
 
                                #print "dir", file
85
 
                                name = namespace + ':' + file
86
 
                                yield self.get_page(name)
 
84
                                pages.add(file)
87
85
                        else:
88
86
                                pass # unknown file type
 
87
                for name in pages:
 
88
                        yield self.get_page(namespace+':'+name)
 
89
 
 
90
        #~ def move_page(self, name, newname):
 
91
                #~ '''FIXME'''
 
92
 
 
93
        #~ def copy_page(self, name, newname):
 
94
                #~ '''FIXME'''
 
95
 
 
96
        #~ def del_page(self, name):
 
97
                #~ '''FIXME'''
 
98
 
 
99
        #~ def search(self):
 
100
                #~ '''FIXME'''
 
101
                #~ pass # TODO search code