AJI schrieb: > All: > Let me ask a more pertinent question: what *should* I do to create the > initial blank database for a new (production) environment? > > I could include either a blank sqlite3 database or a script to create > one in the egg, and instruct the user to run that script. > > Is manually including a script a best practice? Or is the error I > wrote about just a bug waiting for me to file?
I was pondering over that problem for a while now too, and I was about to write a section about this on the DeployWithAnEgg page on the doc wiki. I haven't finished the text, so I haven't uploaded it yet, but as it answers some of your questions, I'll post it here in advance. HTH, Chris Deploying as an EGG =================== Deployment configuration and database ------------------------------------- When you distribute your application as a Python egg, users will also need to install a deployment configuration file and, in most cases, a database to be able to actually start your application. How can you provide a configuration file and an initial database (let's call these *runtime files* from now on) or a database initialization script for your users without requiring them to download separate files? Generally speaking, you have the following two options: # Include the configuration file in your egg and use it directly. You will need to adapt your start script so that it can find the configuration file. See section "Packaging data files in the egg" on how to do this. This technique doesn't work for a database file (e.g an SQLite database) though, since the user may install your egg file in a non-writeable location. # Provide an "init" command from your start script that generates the configuration and maybe also sets up the database. This command can use the first technique for including and finding configuration templates and an initial database or database initialization scripts. Creating runtime files from your start script ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Ideally, the creation of the runtime files is fully automatic, with no user intervention required, but this may be impossible if your application wants to connect to a database server and needs to know the database connection info. To make it easy for the user to supply the necessary information, your "init" command can use some interactive prompts, similar to the way ``tg-admin quickstart`` does. Typically, it would ask for the following information: * The IP address the CherryPy server should bind to * The port the CherryPy server should should bind to * The database type (postgres, mysql, sqlite, etc.) * The database name (or file name for an SQLite database) * The database server and port * The database user and password * The database name The following script asks for the information listed above and writes it to the configuration file specified on the command-line. To use this script, the user needs to be able to run shell commands on the server. How to handle users that have only FTP access to their server, is outside the scope of this tutorial, but you might want to have a look at TurboSetup_. :: [script still in development, see http://paste.turbogears.org/paste/1341] .. _TurboSetup: http://python.org/pypi/TurboSetup Packaging data files in the egg ------------------------------- The distutils normally install general "data files" to a platform-specific location (e.g. /usr/share). This feature is intended to be used for things like documentation, example configuration files, and the like. setuptools does not install these data files in a separate location, however. They are bundled inside the egg file or directory, alongside the Python modules and packages. The data files can also be accessed using the Resource Management API, by specifying a Requirement instead of a package name:: from pkg_resources import Requirement, resource_filename filename = resource_filename(Requirement.parse("MyProject"),"sample.conf") The above code will obtain the filename of the "sample.conf" file in the data root of the "MyProject" distribution. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/turbogears?hl=en -~----------~----~----~----~------~----~------~--~---

