2007-08-18 02:12:56 +00:00
|
|
|
#!/usr/bin/python2.5
|
2007-07-16 20:22:38 +00:00
|
|
|
|
|
|
|
import os
|
|
|
|
import os.path
|
2007-08-02 04:01:11 +00:00
|
|
|
from config.Common import settings
|
2007-07-16 20:22:38 +00:00
|
|
|
from controller.Database import Database
|
|
|
|
from controller.Scheduler import Scheduler
|
2007-07-17 01:21:31 +00:00
|
|
|
from model.Note import Note
|
2007-09-26 23:49:27 +00:00
|
|
|
from model.User_list import User_list
|
2007-08-02 04:01:11 +00:00
|
|
|
from tools.initdb import fix_note_contents
|
2007-07-16 20:22:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Initializer( object ):
|
|
|
|
HTML_PATH = u"static/html"
|
2007-08-02 04:01:11 +00:00
|
|
|
NOTE_FILES = [ # the second element of the tuple is whether to show the note on startup
|
2007-07-16 20:22:38 +00:00
|
|
|
( u"about.html", True ),
|
|
|
|
( u"features.html", True ),
|
2007-09-28 23:54:19 +00:00
|
|
|
( u"sign up.html", False ),
|
2007-08-07 23:31:20 +00:00
|
|
|
( u"faq.html", False ),
|
2007-08-27 20:39:16 +00:00
|
|
|
( u"meet the team.html", False ),
|
|
|
|
( u"contact info.html", False ),
|
2007-07-16 20:22:38 +00:00
|
|
|
( u"login.html", False ),
|
|
|
|
( u"password reset.html", False ),
|
|
|
|
( u"supported browsers.html", False ),
|
|
|
|
( u"advanced browser features.html", False ),
|
|
|
|
]
|
|
|
|
|
2007-08-02 04:01:11 +00:00
|
|
|
def __init__( self, scheduler, database, navigation_note_id = None ):
|
2007-07-16 20:22:38 +00:00
|
|
|
self.scheduler = scheduler
|
|
|
|
self.database = database
|
2007-08-02 04:01:11 +00:00
|
|
|
self.navigation_note_id = navigation_note_id
|
2007-07-16 20:22:38 +00:00
|
|
|
|
|
|
|
threads = (
|
2007-09-26 23:49:27 +00:00
|
|
|
self.create_user_list(),
|
2007-07-16 20:22:38 +00:00
|
|
|
self.update_main_notebook(),
|
|
|
|
)
|
|
|
|
|
|
|
|
for thread in threads:
|
|
|
|
self.scheduler.add( thread )
|
|
|
|
self.scheduler.wait_for( thread )
|
|
|
|
|
2007-09-26 23:49:27 +00:00
|
|
|
def create_user_list( self ):
|
|
|
|
# if there's no user list, create one and populate it with all users in the database
|
|
|
|
self.database.load( u"User_list all", self.scheduler.thread )
|
|
|
|
user_list = ( yield Scheduler.SLEEP )
|
|
|
|
if user_list is not None:
|
|
|
|
return
|
|
|
|
|
|
|
|
self.database.next_id( self.scheduler.thread )
|
|
|
|
user_list_id = ( yield Scheduler.SLEEP )
|
|
|
|
user_list = User_list( user_list_id, u"all" )
|
|
|
|
|
|
|
|
for key in self.database._Database__db.keys():
|
|
|
|
if not key.startswith( "User " ): continue
|
|
|
|
|
|
|
|
self.database.load( key, self.scheduler.thread )
|
|
|
|
user = ( yield Scheduler.SLEEP )
|
|
|
|
if user:
|
|
|
|
user_list.add_user( user )
|
|
|
|
|
|
|
|
self.database.save( user_list )
|
|
|
|
|
2007-07-16 20:22:38 +00:00
|
|
|
def update_main_notebook( self ):
|
2007-07-31 22:53:57 +00:00
|
|
|
self.database.load( u"User anonymous", self.scheduler.thread )
|
2007-07-16 20:22:38 +00:00
|
|
|
anonymous = ( yield Scheduler.SLEEP )
|
2007-08-02 04:01:11 +00:00
|
|
|
read_only_main_notebook = anonymous.notebooks[ 0 ]
|
2007-07-16 20:22:38 +00:00
|
|
|
main_notebook = anonymous.notebooks[ 0 ]._Read_only_notebook__wrapped
|
2007-07-17 01:21:31 +00:00
|
|
|
startup_notes = []
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-08-02 04:01:11 +00:00
|
|
|
# get the id for each note
|
|
|
|
note_ids = {}
|
|
|
|
for ( filename, startup ) in self.NOTE_FILES:
|
2007-07-16 20:22:38 +00:00
|
|
|
title = filename.replace( u".html", u"" )
|
2007-07-17 01:21:31 +00:00
|
|
|
note = main_notebook.lookup_note_by_title( title )
|
2007-08-07 23:31:20 +00:00
|
|
|
|
|
|
|
if note is not None:
|
|
|
|
note_ids[ filename ] = note.object_id
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-08-02 04:01:11 +00:00
|
|
|
# update the navigation note if its id was given
|
|
|
|
if self.navigation_note_id:
|
|
|
|
self.database.next_id( self.scheduler.thread )
|
|
|
|
next_id = ( yield Scheduler.SLEEP )
|
|
|
|
note = main_notebook.lookup_note( self.navigation_note_id )
|
|
|
|
self.update_note( "navigation.html", True, main_notebook, read_only_main_notebook, startup_notes, next_id, note_ids, note )
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-08-02 04:01:11 +00:00
|
|
|
# update all of the notes in the main notebook
|
|
|
|
for ( filename, startup ) in self.NOTE_FILES:
|
|
|
|
self.database.next_id( self.scheduler.thread )
|
|
|
|
next_id = ( yield Scheduler.SLEEP )
|
|
|
|
title = filename.replace( u".html", u"" )
|
|
|
|
note = main_notebook.lookup_note_by_title( title )
|
|
|
|
self.update_note( filename, startup, main_notebook, read_only_main_notebook, startup_notes, next_id, note_ids, note )
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-17 01:21:31 +00:00
|
|
|
for note in startup_notes:
|
|
|
|
main_notebook.add_startup_note( note )
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-07-16 21:07:07 +00:00
|
|
|
main_notebook.name = u"Luminotes"
|
2007-07-16 20:22:38 +00:00
|
|
|
self.database.save( main_notebook )
|
|
|
|
|
2007-08-02 04:01:11 +00:00
|
|
|
def update_note( self, filename, startup, main_notebook, read_only_main_notebook, startup_notes, next_id, note_ids, note = None ):
|
|
|
|
full_filename = os.path.join( self.HTML_PATH, filename )
|
|
|
|
contents = fix_note_contents( file( full_filename ).read(), read_only_main_notebook.object_id, note_ids )
|
|
|
|
|
|
|
|
if note:
|
|
|
|
main_notebook.update_note( note, contents )
|
|
|
|
# if for some reason the note isn't present, create it
|
|
|
|
else:
|
|
|
|
note = Note( next_id, contents )
|
|
|
|
main_notebook.add_note( note )
|
|
|
|
|
|
|
|
main_notebook.remove_startup_note( note )
|
|
|
|
if startup:
|
|
|
|
startup_notes.append( note )
|
|
|
|
|
2007-07-16 20:22:38 +00:00
|
|
|
|
2007-08-02 04:01:11 +00:00
|
|
|
def main( args ):
|
2007-08-18 02:12:56 +00:00
|
|
|
print "IMPORTANT: Stop the Luminotes server before running this program."
|
|
|
|
|
2007-07-16 20:22:38 +00:00
|
|
|
scheduler = Scheduler()
|
|
|
|
database = Database( scheduler, "data.db" )
|
2007-08-02 04:01:11 +00:00
|
|
|
initializer = Initializer( scheduler, database, args and args[ 0 ] or None )
|
2007-07-16 20:22:38 +00:00
|
|
|
scheduler.wait_until_idle()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2007-08-02 04:01:11 +00:00
|
|
|
import sys
|
|
|
|
main( sys.argv[ 1: ] )
|