Personal wiki notebook (not under development)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

updatedb.py 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/usr/bin/python2.4
  2. import os
  3. import os.path
  4. from config.Common import settings
  5. from controller.Database import Database
  6. from model.Notebook import Notebook
  7. from model.Note import Note
  8. from model.User import User
  9. from tools.initdb import fix_note_contents
  10. class Updater( object ):
  11. HTML_PATH = u"static/html"
  12. NOTE_FILES = [ # the second element of the tuple is whether to show the note on startup
  13. ( u"sign up.html", False ),
  14. ( u"faq.html", False ),
  15. ( u"meet the team.html", False ),
  16. ( u"contact info.html", False ),
  17. ( u"login.html", False ),
  18. ( u"source code.html", False ),
  19. ( u"password reset.html", False ),
  20. ( u"advanced browser features.html", False ),
  21. ( u"supported browsers.html", False ),
  22. ( u"community.html", False ),
  23. ( u"enable JavaScript.html", False ),
  24. ]
  25. def __init__( self, database, settings ):
  26. self.database = database
  27. self.settings = settings
  28. self.update_main_notebook()
  29. self.database.commit()
  30. def update_main_notebook( self ):
  31. anonymous = self.database.select_one( User, User.sql_load_by_username( u"anonymous" ) )
  32. main_notebook = self.database.select_one( Notebook, anonymous.sql_load_notebooks() )
  33. # get the id for each note
  34. note_ids = {}
  35. for ( filename, startup ) in self.NOTE_FILES:
  36. title = filename.replace( u".html", u"" )
  37. note = self.database.select_one( Note, main_notebook.sql_load_note_by_title( title ) )
  38. if note is not None:
  39. note_ids[ filename ] = note.object_id
  40. # update all of the notes in the main notebook
  41. for ( filename, startup ) in self.NOTE_FILES:
  42. title = filename.replace( u".html", u"" )
  43. note = self.database.select_one( Note, main_notebook.sql_load_note_by_title( title ) )
  44. self.update_note( filename, startup, main_notebook, note_ids, note )
  45. if main_notebook.name != u"Luminotes":
  46. main_notebook.name = u"Luminotes"
  47. self.database.save( main_notebook, commit = False )
  48. def update_note( self, filename, startup, main_notebook, note_ids, note = None ):
  49. full_filename = os.path.join( self.HTML_PATH, filename )
  50. contents = fix_note_contents( file( full_filename ).read(), main_notebook.object_id, note_ids, self.settings )
  51. if note:
  52. if note.contents == contents:
  53. return
  54. note.contents = contents
  55. # if for some reason the note isn't present, create it
  56. else:
  57. next_id = self.database.next_id( Note )
  58. note = Note.create( next_id, contents, notebook_id = main_notebook.object_id, startup = startup )
  59. self.database.save( note, commit = False )
  60. def main( args ):
  61. import cherrypy
  62. from config import Common
  63. cherrypy.config.update( Common.settings )
  64. if args and "-d" in args:
  65. from config import Development
  66. settings = Development.settings
  67. elif args and "-l" in args:
  68. from config import Desktop
  69. settings = Desktop.settings
  70. else:
  71. from config import Production
  72. settings = Production.settings
  73. cherrypy.config.update( settings )
  74. database = Database(
  75. host = cherrypy.config.configMap[ u"global" ].get( u"luminotes.db_host" ),
  76. ssl_mode = cherrypy.config.configMap[ u"global" ].get( u"luminotes.db_ssl_mode" ),
  77. data_dir = ".",
  78. )
  79. initializer = Updater( database, cherrypy.config.configMap )
  80. if __name__ == "__main__":
  81. import sys
  82. main( sys.argv[ 1: ] )