> > On Sunday, 19 June 2016 14:35:37 UTC-4, Anthony wrote: >> >> I suppose you could put web2py in one directory, and then symlink to an >> application folder in some other directory. But it seems odd that you >> somehow don't have control over how the application code gets updated. >> There are lots of mechanisms by which you could update application code. >> For example, if you need to ensure that after the files in an application >> folder are updated some additional special file gets injected into the >> folder, you could presumably use a script or an automation tool such as >> Ansible to manage the whole process. >> >> > It is not odd. You force me to be on the defensive. Please follow me with > an analogy. In this analogy, the execution of an application is like going > to a restaurant. A person entering the restaurant is like a request. The > code is the menu. The bathroom is the configuration file where you need to > go before you eat. The issue, in this analogy, is that the person needs to > know where is the bathroom. Your solution is simply put the location of > the bathroom in the menu. It's not stupid. It's true that, if we have a > chain of restaurants, we could have a script that make sure that each menu > has the correct location. My solution is simply to have the person ask > when it enters the restaurant. >
I'm not sure I follow. You say you want your application to be able to "ask" where the configuration file is. But you have simply pushed the problem into the next layer -- now you have to determine how to ask, and your application must know the protocol for asking. Why is it any easier to know the protocol for asking than to simply know what is being asked to begin with? Either way, you have to embed some data in the application that enables it to know where/how to retrieve the relevant information. For example, we could set things up so your application could retrieve the location of a given configuration file by looking in request.global_settings.config_filepath. But now we must encode the identifier "request.global_settings.config_filepath" into the application code. Why bother when it would be just as easy to include the file path directly? Now I take it you might not want to include the file path directly because perhaps the same application will be deployed on different systems, which may keep the configuration file in different locations. But that's the problem with your original request -- you did not make this clear. So, I offered you quite a number of different options, at least two of which are quite simple and should satisfy your concerns: 1. Put the configuration data in a Python module, and have the application import it. As long as the module is anywhere in the Python path on the system (e.g., in site-packages), it will be available. 2. Use request.global_settings, which can be set in routes.py. The bottom line is that you ultimately need some identifier or set of identifiers encoded in the application itself in order to access the configuration data. > It's not odd at all. I actually think that it is better, more natural, > than your solution, which, I agree, is the common approach. > Just to be clear, I wasn't saying your requirement was odd. I was saying you made it sound as if you have no control over the environment in which this application is being installed. Assuming you do have control, there are lots of ways to tackle this problem, and the proper approach will depend on the details of what needs to be static, what needs to be modifiable, the nature of the environment(s), and the nature of the deploy/update process. Actually, if all you need is to set some configuration options, you could > do that by putting them in (a) a Python module that gets imported by the > app, (b) a configuration file that gets loaded via AppConfig, (c) OS > environment variables, etc. > > In my research, I already considered all these aspects. I am learning > web2py and even python, but I am not new at these things. I will use (b), > but this does not say where is the location of the config file. Yes (c) > could be used to set the location of the configuration file or directly > store the configuration, but it has its drawbacks. The location of the > env. var. can depend on the systems. > In Python, you would use os.getenv to retrieve an environment variable. Why would the location depend on the system? Just use the same environment variable name on each system. > Also, some installer might not have access to these env. var. > Not sure how that is relevant to a web2py application. Just include code directly in the application to read the environment variable. There is no installer involved. Anyway, if you have a particular setup and workflow in mind, perhaps you >> can explain how it would be achieved when using an alternative web >> framework (either another Python framework, such as Django or Flask) or a >> PHP framework. Then maybe we can see if there is an analog for web2py. >> >> > It is not because what I propose for myself is not implemented in a > framework that it is odd. > To be honest, it still isn't quite clear what "it" is. Whatever "it" is, I'm not suggesting "it" is or isn't implemented in any given framework. However, you mentioned that "it" is "very easy to do in PHP," so it might help if you explained in more detail how you would achieve what you want in a PHP-based web application. > > >> Anyway, for simply setting some configuration options, this approach is >> overkill. >> > > It maybe a complicated way to implement what, in my opinion, should be > very easy to implement. To return the same to you, I would say that "it's > odd that it needs to be so complicated", just joking. > Again, if you just need to make some configuration data available within a web2py application, I think that is fairly easy to implement, and there is no need for WSGI middleware. WSGI middleware itself need not be particularly complicated either -- it's just more complex than other alternatives that would get the job done just as well. Anthony -- 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. For more options, visit https://groups.google.com/d/optout.