4

I have a app divided in 5 modules (see my beautiful ascii art) Each have their own directory, just like this structure

      AppEngine App     <--Here's the dispatch.yaml
 ---------------------
 |    |    |    |    |
 |    |    |    |    |
Mod1 Mod2 Mod3 Mod4 Mod5
 ^                     ^
 \__Here's the models  |__ Here i wanna read the models
    .py file 
    with the __init__.py

The NDB models are defined in one module (mod1 by example) and i wanna read some data in the Mod5, the official documentation says that's posible, but i can't do it. I'm importing the model in this ways

#this is in mod5 py file
import Mod1.models # No module named Mod1.models
from Path.Mod1 import models  #No module named Path.Mod1 
from Mod1 import models  #No module named Mod1 
from Mod1.models import specific_model  #No module named Mod1.models 
from Path.models import specific_model  #No module named Path.models 

I change the --storage_path setting to each module to be able tu run all modules at the same time in the launcher, i think that could be the problem. But if i leave the same directory how can run at the same time all the modules (i got "OperationalError: database is locked" error) Any clue here?

Dan McGrath
  • 37,828
  • 10
  • 90
  • 123
Kristian Damian
  • 1,337
  • 3
  • 21
  • 40

3 Answers3

2

According to this answer from google cloud support there are 3 ways.

  1. Symbolic link to a single file with definitions... this can get sticky when using different OSs. According to this SO answer linked in Dan's comment, GAE copies the contents of a directory to the target directory.
  2. Write a build script to copy model definitions to each service.
  3. Manually copy model definitions to each service.
Community
  • 1
  • 1
Alex
  • 15,252
  • 6
  • 48
  • 75
1

Based on the given information, I am wondering if you are missing the __init__.py file in each of the subdirectories. This will allow the Python modules to be usable in those directorie. See https://docs.python.org/2/tutorial/modules.html#packages

Can you share the file structure in the directories?

Lipis
  • 19,958
  • 18
  • 88
  • 117
ChrisC73
  • 1,577
  • 11
  • 14
  • i already have the __init__.py file in each sub-directory but had not realized it that doesn't have the corresponding .pyc, so i think that app engine is ignoring it – Kristian Damian Oct 17 '14 at 14:00
1

I found a answer, not ideal, but works.

If i clone (A.K.A copy-paste) the models.py file in the Mod5 folder and remove the --storage_path setting (the db is shared in the same temp folder in the develop server) i can read the data stored.

Obviously the models needs to be sync in EVERY change, but at least i can move forward in my code

The directory structure stay as follows:

-- Main (with the dispatch.yaml)
 |__ Mod1
 |      |__ model.py
 |      |__ app.yaml
 |      |__ specificMod1Code.py
 |      |______ Templates
 |      |______ js
 |      |______ css
 |      |______ img
 :
 :
 :
 |__ Mod5
        |__ model.py #equal that mod1
        |__ app.yaml #with the mod5 instace and stuff
        |__ specificMod5Code.py
        |______ Templates
        |______ js
        |______ css
        |______ img

To run all the modules at the same time it's necesary run the dev_appserver command in the root directory of the app (source)

python dev_appserver.py mod1\app.yaml mod2\app.yaml mod3\app.yaml mod4\app.yaml mod5\app.yaml

Runnind in this URL's

Mod1=> localhost:8080

Mod2=> localhost:8081

Mod3=> localhost:8082

Mod4=> localhost:8083

Mod5=> localhost:8084

Kristian Damian
  • 1,337
  • 3
  • 21
  • 40