1. Sam Hart
  2. noink

Commits

Sam Hart  committed 32d6dac

rework init process for the main app and configuration parsing, more work on the manual test, stub the views directory, rework the testMain to use new conifguration parsing

  • Participants
  • Parent commits 63a4fae
  • Branches noink

Comments (0)

Files changed (5)

File src/noink/__init__.py

View file
 from flask import Flask
 from flask.ext.sqlalchemy import SQLAlchemy
 
-mainApp = Flask("noink")
-mainApp.config.from_object('noink.defaultConfig')
+import os
+
 try:
-    mainApp.config.from_envvar('NOINK_CONFIGURATION')
-    print "USING NOINK_CONFIGURATION"
+    __setup
 except:
-    pass
+    __setup = False
 
-mainApp.secret_key = mainApp.config['SECRET_KEY']
-mainDB = SQLAlchemy(mainApp)
+def _parseConfig():
+    '''
+    '''
+    try:
+        mainApp.config.from_envvar('NOINK_CONFIGURATION')
+    except:
+        mainApp.config.from_object('noink.defaultConfig')
 
+    mainApp.secret_key = mainApp.config['SECRET_KEY']
+
+    # Setup our template pathing
+    if mainApp.config['HTML_TEMPLATES']:
+        __newTemplatePath = []
+        from os.path import abspath
+        for element in mainApp.config['HTML_TEMPLATES']:
+            __newTemplatePath.append(abspath(element))
+        mainApp.jinja_loader.searchpath = __newTemplatePath
+
+def reInit():
+    '''
+    Call this method when you want to re-initialize as much as possible.
+    '''
+    _parseConfig()
+
+if not __setup:
+    mainApp = Flask("noink")
+    _parseConfig()
+    mainDB = SQLAlchemy(mainApp)
+    __setup = True
+

File src/noink/defaultConfig.py

View file
 # group in the database!
 ADMIN_GROUP = "admin"
 
-# The path to the HTML templates. Can be a relative path, or absolute.
-HTML_TEMPLATES = "../default_templates"
+# The path(s) to the HTML templates. Can be a relative path, or absolute.
+HTML_TEMPLATES = [
+    "../templates/default"
+]
 
 # The secret key is used by flask for session signing
 SECRET_KEY = 'Klaus Karl Kassbaum is Nick St. Nicholas'

File src/noink/views/__init__.py

Empty file added.

File src/tests/manual_tests/test_SimpleEntries.py

View file
         del(self.testMain)
 
     def run(self):
+        print "mainApp.jinja_env"
+        print "-----------------"
+        print dir(mainApp.jinja_env)
+        print "\nmainApp.jinja_loader"
+        print "___________________"
+        print dir(mainApp.jinja_loader)
+        print "\n%s" % mainApp.jinja_loader.searchpath
         mainApp.run()
 
 if __name__ == '__main__':

File src/tests/testMain.py

View file
 
 import tempfile
 import shutil
+import random
 
-#from noink import _setupDB
+from noink import mainApp
+from noink import reInit
+from noink import _setupDB
 
 class testMain(object):
     def __init__(self):
 
         # Need a temporary files and settings
         self.TEST_CONF_FILE = "%s/test.cfg" % self.TEST_ROOT
-        #os.environ['NOINK_CONFIGURATION'] = self.TEST_CONF_FILE
+        os.environ['NOINK_CONFIGURATION'] = self.TEST_CONF_FILE
 
         self.TEST_DB_FILE = "sqlite:///%s/noink.db" % self.TEST_ROOT
 
-        TEST_ADMINUSER = "admin"
-        TEST_ADMINFULL = "Administrator"
-        TEST_ADMINGROUP = "admin"
+        conf = [
+            'ADMIN_USER = "admin"\n',
+            'ADMIN_FULLNAME = "Administrator"\n',
+            'ADMIN_GROUP = "admin"\n',
+            'SQLALCHEMY_DATABASE_URI = "%s"\n' % self.TEST_DB_FILE,
+            'SECRET_KEY = "%032x"\n' % random.getrandbits(128),
+            'HTML_TEMPLATES = [ "../../templates/defaultPOO" ]\n'
+        ]
 
-        #confFile = open(self.TEST_CONF_FILE, 'w')
-        #confFile.writelines(['SQLALCHEMY_DATABASE_URI = "%s"' % self.TEST_DB_FILE])
-        #confFile.close()
+        with open(self.TEST_CONF_FILE, 'w') as f:
+            f.writelines(conf)
 
-        # Set ourselves up a test root for things
-        from noink import _setupDB
-        from noink import mainApp
-        mainApp.config['SQLALCHEMY_DATABASE_URI'] = self.TEST_DB_FILE
+        reInit()
+
         _setupDB.setupDB()
 
     def __del__(self):