Commits

illume  committed f5c3ec4

adding py_dirs config item which can be used to set modules for app to look in.

  • Participants
  • Parent commits ff2b41c

Comments (0)

Files changed (2)

File newsletter/newsletterapp/newsletterapp.ini

 db_dir = "db"
 #db_dir = "/home/site/newsletter/db/"
 
+# py_dirs are directories to add to sys.path.
+#    this is useful for loading in validation modules
+py_dirs = []
+#py_dir = [".", "/home/me/myawesomepythonmodules/]
+
 
 #Where the emails will be sent from.
 #from_addr = "yourname@example.com"
 # if this is None then we try and get this from the toaddr input.
 toaddr = "sendingto@example.com"
 
+
 # validate_input is a function which can be used to validate the input.
 #    set to None to do no validation
 validate_input = None
-#validate_input = lambda kwargs: kwargs.get('input', '') == 'ok input'
+# It my be useful to use py_dirs config item, 
+#   or an environment variable to put a module into your path.
 #validate_input = mypackage.myvalidator
 
 

File newsletter/newsletterapp/newsletterapp.py

         # see if a validation function has been used defined in the config file.
         validate_input = self.send_message_config.get('validate_input', None)
         if validate_input is not None:
+            #validate_input = eval(validate_input)
             return validate_input(kwargs)
         
         return True
 
         self.static_dir = self.config.get("static_dir")
         self.db_dir = self.config.get("db_dir")
+        self.py_dirs = self.config.get("py_dirs", None)
+
+        if self.py_dirs is not None:
+            for py_dir in self.py_dirs:
+                if py_dir not in sys.path:
+                    sys.path.append(py_dir)
+
         self.fromaddr = self.config.get("from_addr")
 
         self._default_vars = {"base_url" : self.config.get('base_url'),
         mount_point = options.mount_point
         cfg = options.config
 
+        # inject some paths into here so we can load modules from somewhere else.
+        py_dirs_line = [l for l in open(cfg, "r") if l.startswith("py_dirs")]
+        if py_dirs_line:
+            py_dirs = eval(py_dirs_line[0].split("=")[-1].strip())
+
+            for py_dir in py_dirs:
+                if py_dir not in sys.path:
+                    sys.path.append(py_dir)
+
+
         # Site-wide (global) config
         log_dir = os.path.join("log")
         #if not os.path.exists(log_dir):