Change to the application directory you provided as target for the generated output. You will see one sub-directory for each generation you run with this specification. The name of the sub-directory is the timestamp of when the generation did happen.
Inside this generated sub-directory you will find several files and directories, see Section 3.3, “ Content of the generated output ” for a full description.
petstore/ is the top-level package of your recently created pyswarm application. Browse through the tree. As sub-directories you will find the nodes. Change to the internet directory which has the sub-directories contacts, core, shop and logistics (which are sub-packages). Change to contacts. In contacts you see two directories, one for the logic-component adm and one for its corresponding database-component admDB.
Change to adm - uh, this directory is rather populated. Your entity and zone classes resides here in their appropriate modules and have a big party together. You easily recognize them at their names. There are also some modules named like some of your association-roles, but usually you will never work with them. And last, but not least, you see a module with the same name as your logic-component, adm.py. This is the module you will later need to import when writing a client to access the component and all its entity objects. An example client is described later.
In order to install your pyswarm application and initialize all its databases the pyswarm SDK has generated two scripts which you may consider as very useful, especially if you deploy a new generation on the local host.
In the output directory you will find the initdb.py which we will use to initialize the databases of our PetStore project. The same directory also contains setup.py, which we will use to install the Python packages on the local host.
The very first time you will need initdb to create the login-roles that are used by the logic-component to access them, but these logins also are used to drop and/or create the database and create its tables, insert the primary object and so on. I assume you have a locally installed PostgreSQL server and still know the user and password of the postgres role that is created during PostgreSQL installation - or at least you have any other login-role in the database server that has the privilege to create new login-roles, I refer to it as a super-user, although it is not really necessary to have a full super-user account to create roles at this server.
In the shell change to the output directory, where initdb.py resides.
Execute the script:
~/projects/apps/PetStore/2007-04-21-15-39-55/$ python initdb.py --database=admDB
Now you will be prompted by the command to enter super-user and password for the localhost:5432 database server which is specified in the UML model. Enter the user and password.
Now the command will login as this super-user to the host and will create the login-role for admDB. After that it will reconnect and login with this new role. Then it will create the database and reconnect again, but this time to the new database. Now it will create all tables and fill the database with some initial data. The SQL for doing these detail tasks are from the admDB/setup.sql file. That's it. After the command has finished successfully you have the database initialized as we need it.
Procedure 2.34. Initialize the databases
|
Tip |
|---|---|
|
See Section 3.9, “ Initialize Databases: initdb ” to learn other options of this command. |
|
In the shell change to the output directory, where setup.py resides.
Execute the script as super-user:
~/projects/apps/PetStore/2007-04-21-15-39-55/# python setup.py install
Now this distutils-based setup will install petstore on your PC using the local Python default configuration. The script petstore-populate.py from the scripts/ will be copied as executable file into the default directory for such scripts, e.g. /usr/bin/.
Procedure 2.35. Install the Python packages
|
Tip |
|---|---|
|
See Chapter 3, Installing pyswarm Applications to learn how to use this command. |
|
Execute the script:
$ petstore-populate.py
The first time you call this script it will tell you that it found the primary object of the adm component, but no other objects. It will create some example recipients and addresses for them.
Execute the script again:
$ petstore-populate.py
Now the script tells you that it also found recipients and addresses created right before. It will modify these objects and prints some information to the screen. You can repeat this and examine how there subjects and last-changed timestamps are modified from execution to execution.
Procedure 2.36. Populate with addresses and recipients
|
Tip |
|---|---|
|
The next chapter Section 2.5, “ Running Your Application ” will show you how you can implement yourself a script like petstore-populate.py. |
|