def __init__(self, config='~/.worknoteBook/server.cfg'):
        print_enter('worknoteBookServer.__init__')
        from whoosh.index import create_in
        from whoosh.fields import *
        from os.path import exists, join, split
        from os import makedirs
        import worknoteBookHelpers
        if type(config) == str:
            from os.path import expanduser
            from worknoteBookHelpers import Configuration
            cfg_file = config
            if not exists(split(expanduser(cfg_file))[0]):
                makedirs(split(expanduser(cfg_file))[0])
            default_cfg = {'server': {'storagedir': '~/.worknoteBook/storage',
                                      'user_db': '~/.worknoteBook/users.dat',
                                      'url': '0.0.0.0',
                                      'port': 8080}}
            config = Configuration(expanduser(cfg_file), default_cfg)
            if not exists(expanduser(cfg_file)):
                config.update_cfg_file()
        self.config = config
        self.storagedir = self.__getabsdir(self.config[['server', 'storagedir']])
        print 'Storagedir is "{:s}"'.format(self.storagedir)
        if not exists(self.storagedir):
            makedirs(self.storagedir)
        self.staticdir = join(split(worknoteBookHelpers.__file__)[0], 'static')
        self.worknote_list = []
        self.worknotes = {}
        print 'HTML static dir is "{:s}"'.format(self.staticdir)
        self.head = '''<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <link rel="stylesheet" type="text/css" href="static/index.css">
        {metadata:s}
    </head>
    <body>'''
        self.foot = '''    </body>
</html>'''
        print 'Defining search index...'
        schema = Schema(index=ID(stored=True),
                        title=TEXT(stored=True),
                        date=TEXT(stored=True),
                        link=STORED,
                        content=TEXT)
        if not exists(join(self.storagedir, '.search_index')):
            makedirs(join(self.storagedir, '.search_index'))
        self.search_index = create_in(join(self.storagedir, '.search_index'), schema)
        print 'Loading chapters...'
        self.__load_chapters()
        print 'Reloading worknotes...'
        self.__reload_worknotes()
        print 'Updating CherryPy config...'
        self.__update_config()
        self.auth = AuthController(self.__getabsdir(self.config[['server', 'user_db']]),
                                   self.head,
                                   self.foot,
                                   self.staticdir)
 def __init__(self, config='~/.worknoteBook/client.cfg'):
     if type(config) == str:
         from os.path import exists, expanduser, split
         from os import makedirs
         from worknoteBookHelpers import Configuration
         cfg_file = config
         if not exists(split(expanduser(cfg_file))[0]):
             makedirs(split(expanduser(cfg_file))[0])
         default_cfg = {'client_defaults': {'server': 'localhost'},
                        'localhost': {'url': '127.0.0.1',
                                      'port': 8080}}
         config = Configuration(expanduser(cfg_file), default_cfg)
         if not exists(expanduser(cfg_file)):
             config.update_cfg_file()            
     self.config = config
     self.config.update_cfg_file()