Mercurial > p > roundup > code
comparison roundup/init.py @ 190:996eaf90c01e
Instance import now imports the instance using imp.load_module...
...so that we can have instance homes of "roundup" or other existing
python package names.
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Fri, 03 Aug 2001 00:59:34 +0000 |
| parents | 0791d13baea7 |
| children | 241a0323aacb |
comparison
equal
deleted
inserted
replaced
| 189:636ceccc7ed7 | 190:996eaf90c01e |
|---|---|
| 1 # $Id: init.py,v 1.8 2001-07-29 07:01:39 richard Exp $ | 1 # $Id: init.py,v 1.9 2001-08-03 00:59:34 richard Exp $ |
| 2 | 2 |
| 3 import os, shutil, sys, errno | 3 import os, shutil, sys, errno, imp |
| 4 | 4 |
| 5 def copytree(src, dst, symlinks=0): | 5 def copytree(src, dst, symlinks=0): |
| 6 """Recursively copy a directory tree using copy2(). | 6 """Recursively copy a directory tree using copy2(). |
| 7 | 7 |
| 8 The destination directory os allowed to exist. | 8 The destination directory os allowed to exist. |
| 29 elif os.path.isdir(srcname): | 29 elif os.path.isdir(srcname): |
| 30 copytree(srcname, dstname, symlinks) | 30 copytree(srcname, dstname, symlinks) |
| 31 else: | 31 else: |
| 32 shutil.copy2(srcname, dstname) | 32 shutil.copy2(srcname, dstname) |
| 33 | 33 |
| 34 def init(instance, template, backend, adminpw): | 34 def init(instance_home, template, backend, adminpw): |
| 35 ''' initialise an instance using the named template | 35 ''' initialise an instance using the named template |
| 36 ''' | 36 ''' |
| 37 # first, copy the template dir over | 37 # first, copy the template dir over |
| 38 import roundup.templatebuilder | 38 import roundup.templatebuilder |
| 39 | 39 |
| 40 template_dir = os.path.split(__file__)[0] | 40 template_dir = os.path.split(__file__)[0] |
| 41 template_name = template | 41 template_name = template |
| 42 template = os.path.join(template_dir, 'templates', template) | 42 template = os.path.join(template_dir, 'templates', template) |
| 43 copytree(template, instance) | 43 copytree(template, instance_home) |
| 44 | 44 |
| 45 roundup.templatebuilder.installHtmlBase(template_name, instance) | 45 roundup.templatebuilder.installHtmlBase(template_name, instance_home) |
| 46 | 46 |
| 47 # now select database | 47 # now select database |
| 48 db = '''# WARNING: DO NOT EDIT THIS FILE!!! | 48 db = '''# WARNING: DO NOT EDIT THIS FILE!!! |
| 49 from roundup.backends.back_%s import Database'''%backend | 49 from roundup.backends.back_%s import Database'''%backend |
| 50 open(os.path.join(instance, 'select_db.py'), 'w').write(db) | 50 open(os.path.join(instance_home, 'select_db.py'), 'w').write(db) |
| 51 | 51 |
| 52 # now import the instance and call its init | 52 # now import the instance and call its init |
| 53 path, instance = os.path.split(instance) | 53 instance = imp.load_module('instance', None, instance_home, ('', '', 5)) |
| 54 sys.path.insert(0, path) | |
| 55 instance = __import__(instance) | |
| 56 instance.init(adminpw) | 54 instance.init(adminpw) |
| 57 | 55 |
| 58 # | 56 # |
| 59 # $Log: not supported by cvs2svn $ | 57 # $Log: not supported by cvs2svn $ |
| 58 # Revision 1.8 2001/07/29 07:01:39 richard | |
| 59 # Added vim command to all source so that we don't get no steenkin' tabs :) | |
| 60 # | |
| 60 # Revision 1.7 2001/07/28 07:59:53 richard | 61 # Revision 1.7 2001/07/28 07:59:53 richard |
| 61 # Replaced errno integers with their module values. | 62 # Replaced errno integers with their module values. |
| 62 # De-tabbed templatebuilder.py | 63 # De-tabbed templatebuilder.py |
| 63 # | 64 # |
| 64 # Revision 1.6 2001/07/24 11:18:25 anthonybaxter | 65 # Revision 1.6 2001/07/24 11:18:25 anthonybaxter |
