Glad to help! You do excellent work. Thanks!

Den tisdagen den 11:e december 2012 kl. 15:25:21 UTC+1 skrev Massimo Di 
Pierro:
>
> How did that get in there? Fixed in trunk. Thanks Joel for reporting this.
>
> On Tuesday, 11 December 2012 02:51:15 UTC-6, Joel Samuelsson wrote:
>>
>> I'm not sure if we're using the same web2py version. I am using the 
>> current stable release (2.2.1). The call to listdir looks like this (just 
>> downloaded a fresh copy and double-checked):
>> models = listdir(path, '^\w+\.py$', 0, sort=False)
>> I.e. sort=False. Otherwise, what you describe is true. With sort=False 
>> though, sort order is not alphabetical and what you describe does not work 
>> since you can't know in what order models are run.
>>
>> /Joel
>>
>>
>> Den måndagen den 10:e december 2012 kl. 17:10:43 UTC+1 skrev Anthony:
>>>
>>> I've been testing the way you described above and it works, to a point. 
>>>> The models are not imported in alphabetical order. This seems to be 
>>>> controlled by this line (521):
>>>
>>> models = listdir(path, '^\w+\.py$', 0, sort=False) in compileapp.py
>>>> listdir is essentially os.walk with a regexp for filtering and os.walk 
>>>> doesn't give any guarantees for ordering at all from what I understand.
>>>>
>>>
>>> Note, it is not os.listdir -- it is the listdir function from 
>>> gluon/fileutils.py, which does sort the files alphabetically: 
>>> http://code.google.com/p/web2py/source/browse/gluon/fileutils.py#88.
>>>  
>>>
>>>> Later in compileapp, the models found with listdir are looped through, 
>>>> once (not dependant on the regexp) which gives changing the regexp between 
>>>> models limited use.
>>>>
>>>
>>> It loops through the files alphabetically -- within any given file, 
>>> response.models_to_run can be changed, which can affect whether models that 
>>> come *later* in alphabetical order get run (obviously it cannot cause 
>>> models that come earlier in alphabetical order to be run). Using 
>>> response.models_to_run does not change the order in which models are run, 
>>> nor the ability of later models to affect earlier ones. It merely controls 
>>> which models get run, with some ability for earlier models to make dynamic 
>>> changes that affect later ones.
>>>  
>>>
>>>> To explain my issue, I'll try to use an example. Please bear with me!
>>>> Let's say I have the following models:
>>>>
>>>> dbInterface/someDbFile.py
>>>>
>>>> anotherInterface/someAnotherInterface.py
>>>>
>>>> __init__.py
>>>> logic.py
>>>>
>>>>
>>>> Now let's assume that listdir lists the models root dir first, then 
>>>> anotherInterface dir and then dbInterface dir.
>>>>
>>>
>>> That should be exactly how listdir lists the models.
>>>  
>>>
>>>> I want the dbInterface to load before anotherInterface since 
>>>> anotherInterface is dependant on dbInterface.
>>>>
>>>
>>> Very simple -- just change the names so dbInterface comes before 
>>> anotherInterface.
>>>  
>>>
>>>> Is there any way I can control the order things are imported from 
>>>> subfolders without changing web2py? I am aware that just setting sort to 
>>>> true in the listdir-call will fix my issue but I would like to be able to 
>>>> update web2py without having to make that change each time, if possible.
>>>>
>>>
>>> As noted, sort is already True, so you should be OK. There is no way to 
>>> change the order in which web2py executes the models, though (other than to 
>>> generate your folder and file names to produce the order you desire).
>>>  
>>> Anthony
>>>
>>

-- 



Reply via email to