In my production environment, new web2py apps are installed every day. 
In fact, it is the same app that it is installed several times with a 
different name. 
Each installed application corresponds to a website that has its own domain.

In the root folder of web2py, I have a file called "domains_apps" where I 
store which domain corresponds to which application. 
The file looks like this:

domain1.com!app1
domain2.com!app2
domain3.com!app3


Then, in my routes.py file I read the domains_apps file to construct the 
"domains" dictionary that is provided for the routers.
My routes.py file looks like this:

# -*- coding: utf-8 -*-

domains = {}
archivo = open('domains_apps', 'r')
lines = archivo.readlines()
archivo.close()
for line in lines:
    if line:
        domain, app = line.split('!')
        if domain and app:
            domains[domain] = app

routers = dict(
  BASE=dict(
    default_controller='default',
    default_function='index',
    domains=domains,
    root_static=['robots.txt', 'ads.txt'],
    map_static=True,
    exclusive_domain=True,
  )
)


This works smoothly. 
Now I'm trying to add a checkpoint: before adding an domain/app, I would 
like to check that the application is indeed installed in web2py. *How do I 
do that?*

I've tried checking if the folder exists inside applications folder, but it 
doesn't work (I created an empty dir and it does pass the validation, but 
then web2py throws an error saying application doesn't exist).
I've also tried checking if the folder exists and it has an __init__.py 
file inside it, but it doesn't work (again, I tried creating a folder with 
an __init__.py file inside, it passes validation but web2py throws error 
saying application doesn't exist).

You may wonder why do I need to check that in routes.py? 
Well, as applications are installed/removed by an external process, 
something could break during this process. And if for some reason my 
domains_apps file ends up including an application that was removed, my 
uWSGI instance will fail loading the application, and all my requests will 
fail. 

So, considering the routes.py I previously showed, how can I check if an 
application exists? 
Does this approach make any sense?



-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/ddb1a05a-b5ea-4ab4-ba73-9c95243d052b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to