Code

more verbose description of password hashing, thanks to Eli Collins
[roundup.git] / roundup / init.py
index b334c087faf3d7e1a80e2ca713cc62019a14f799..d4afecc9e8a50da5e33c7fc7d0dee6a3ff4e6918 100644 (file)
 # FOR A PARTICULAR PURPOSE.  THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
-# 
-# $Id: init.py,v 1.29 2004-02-11 23:55:08 richard Exp $
+#
+# $Id: init.py,v 1.36 2005-12-03 11:22:50 a1s Exp $
 
 """Init (create) a roundup instance.
 """
 __docformat__ = 'restructuredtext'
 
-import os, sys, errno, rfc822
+import os, errno, rfc822
 
-import roundup.instance, password
-from roundup import install_util
+from roundup import install_util, password
+from roundup.configuration import CoreConfig
+from roundup.i18n import _
 
 def copytree(src, dst, symlinks=0):
     """Recursively copy a directory tree using copyDigestedFile().
 
-    The destination directory os allowed to exist.
+    The destination directory is allowed to exist.
 
     If the optional symlinks flag is true, symbolic links in the
     source tree result in symbolic links in the destination tree; if
@@ -38,7 +39,9 @@ def copytree(src, dst, symlinks=0):
 
     This was copied from shutil.py in std lib.
     """
-    names = os.listdir(src)
+
+    # Prevent 'hidden' files (those starting with '.') from being considered.
+    names = [f for f in os.listdir(src) if not f.startswith('.')]
     try:
         os.mkdir(dst)
     except OSError, error:
@@ -54,35 +57,39 @@ def copytree(src, dst, symlinks=0):
         else:
             install_util.copyDigestedFile(srcname, dstname)
 
-def install(instance_home, template):
+def install(instance_home, template, settings={}):
     '''Install an instance using the named template and backend.
 
     'instance_home'
        the directory to place the instance data in
     'template'
        the directory holding the template to use in creating the instance data
+    'settings'
+       config.ini setting overrides (dictionary)
 
     The instance_home directory will be created using the files found in
-    the named template (roundup.templates.<name>). A standard instance_home
+    the named template (roundup.templates.<name>). A usual instance_home
     contains:
 
-    config.py
-      simple configuration of things like the email address for the
-      mail gateway, the mail domain, the mail host, ...
-    dbinit.py and select_db.py
-      defines the schema for the hyperdatabase and indicates which
-      backend to use.
+    config.ini
+      tracker configuration file
+    schema.py
+      database schema definition
+    initial_data.py
+      database initialization script, used to populate the database
+      with 'roundup-admin init' command
     interfaces.py
-      defines the CGI Client and mail gateway MailGW classes that are
+      (optional, not installed from standard templates) defines
+      the CGI Client and mail gateway MailGW classes that are
       used by roundup.cgi, roundup-server and roundup-mailgw.
-    __init__.py
-      ties together all the instance information into one interface
     db/
       the actual database that stores the instance's data
     html/
       the html templates that are used by the CGI Client
     detectors/
       the auditor and reactor modules for this instance
+    extensions/
+      code extensions to Roundup
     '''
     # At the moment, it's just a copy
     copytree(template, instance_home)
@@ -92,6 +99,13 @@ def install(instance_home, template):
     ti['name'] = ti['name'] + '-' + os.path.split(instance_home)[1]
     saveTemplateInfo(instance_home, ti)
 
+    # if there is no config.ini or old-style config.py
+    # installed from the template, write default config text
+    config_ini_file = os.path.join(instance_home, CoreConfig.INI_FILE)
+    if not os.path.isfile(config_ini_file):
+        config = CoreConfig(settings=settings)
+        config.save(config_ini_file)
+
 
 def listTemplates(dir):
     ''' List all the Roundup template directories in a given directory.
@@ -118,6 +132,12 @@ def loadTemplateInfo(dir):
     if not os.path.exists(ti):
         return None
 
+    if os.path.exists(os.path.join(dir, 'config.py')):
+        print _("WARNING: directory '%s'\n"
+            "\tcontains old-style template - ignored"
+            ) % os.path.abspath(dir)
+        return None
+
     # load up the template's information
     f = open(ti)
     try:
@@ -156,23 +176,18 @@ def saveTemplateInfo(dir, info):
     finally:
         f.close()
 
-def write_select_db(instance_home, backend):
+def write_select_db(instance_home, backend, dbdir = 'db'):
     ''' Write the file that selects the backend for the tracker
     '''
-    # now select database
-    db = '''# WARNING: DO NOT EDIT THIS FILE!!!
-from roundup.backends.back_%s import Database, Class, FileClass, IssueClass
-'''%backend
-    open(os.path.join(instance_home, 'select_db.py'), 'w').write(db)
-
+    # dbdir may be a relative pathname, os.path.join does the right
+    # thing when the second component of a join is an absolute path
+    dbdir = os.path.join (instance_home, dbdir)
+    if not os.path.exists(dbdir):
+        os.makedirs(dbdir)
+    f = open(os.path.join(dbdir, 'backend_name'), 'w')
+    f.write(backend+'\n')
+    f.close()
 
-def initialise(instance_home, adminpw):
-    '''Initialise an instance's database
 
-    adminpw    - the password for the "admin" user
-    '''
-    # now import the instance and call its init
-    instance = roundup.instance.open(instance_home)
-    instance.init(password.Password(adminpw))
 
-# vim: set filetype=python ts=4 sw=4 et si
+# vim: set filetype=python sts=4 sw=4 et si :