The latest version is available from https://bitbucket.org/techtonik/trac-bootstrap-script
Created
October 17, 2011 15:56
-
-
Save techtonik/1292939 to your computer and use it in GitHub Desktop.
Trac - Bootstrap script to execute Trac with default environment from checkout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The code to bootstrap Trac with environment created in .trac | |
# subdir in current directory. | |
# | |
# Placed into public domain by anatoly techtonik | |
import os | |
import sys | |
import subprocess | |
DEVPATH = os.path.dirname(os.path.abspath(__file__)) | |
ENVPATH = os.path.join(DEVPATH, '.trac') | |
# path to download dependency modules | |
LIBPATH = os.path.join(DEVPATH, '.pylibs') | |
# module checkout URLs | |
GENSHI = 'http://svn.edgewall.org/repos/genshi/branches/stable/0.6.x/genshi' | |
print("Executing Trac from source checkout (using .trac/ environment)") | |
sys.path.insert(0, LIBPATH) | |
print("01. Patched sys.path with %s" % LIBPATH) | |
sys.path.insert(0, DEVPATH) | |
print("01. Patched sys.path with %s" % DEVPATH) | |
def get_module(url, path): | |
print("... checking out module from SVN") | |
if not os.path.exists(path): | |
print "... creating %s" % path | |
os.makedirs(path) | |
cmd = "svn co %s %s" % (url, path) | |
print("... executing: %s" % cmd) | |
retcode = subprocess.call(cmd, shell=True) | |
if retcode != 0: | |
sys.exit("Error while executing SVN. Aborting") | |
print("02. Check Genshi") | |
try: | |
import imp | |
imp.find_module('genshi') | |
except ImportError: | |
get_module(GENSHI, os.path.join(LIBPATH, 'genshi')) | |
import genshi | |
print("... imported Genshi %s" % genshi.__version__) | |
print("03. Importing Core Trac Modules") | |
# even core Trac modules are imported through setuptools, and | |
# here is a workaround to get rid of the dependency | |
imports = open(os.path.join(DEVPATH, 'setup.py')).readlines() | |
key = [x for x,y in enumerate(imports) if '[trac.plugins]' in y][0] | |
imports = imports[key+1:] | |
key = [x for x,y in enumerate(imports) if '"""' in y][0] | |
imports = imports[:key] | |
for line in imports: | |
# line format is "trac.db.sqlite = trac.db.sqlite_backend" | |
# or trac.mimeview.rst = trac.mimeview.rst[reST] | |
name = line.split('=',1)[1].strip() | |
if '[' in name: | |
name = name[:name.index('[')] | |
try: | |
__import__(name) | |
except ImportError, err: | |
print '... %s failed to load: %s' % (name, err) | |
if not os.path.exists(ENVPATH): | |
print("04. Creating .trac/ environment in %s" % ENVPATH) | |
import trac.admin.console | |
trac.admin.console.run(args=[ENVPATH, 'initenv', | |
'Default "Trac Environment" for Development', | |
'sqlite:db/trac.db']) | |
else: | |
print("04. .trac/ environment already exists - exiting") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: trac/web/__init__.py | |
=================================================================== | |
--- trac/web/__init__.py (revision 10832) | |
+++ trac/web/__init__.py (working copy) | |
@@ -3,21 +3,5 @@ | |
import mimetypes | |
mimetypes.init() | |
-# With mod_python we'll have to delay importing trac.web.api until | |
-# modpython_frontend.handler() has been called since the | |
-# PYTHON_EGG_CACHE variable is set from there | |
-# | |
-# TODO: Remove this once the Genshi zip_safe issue has been resolved. | |
-import os | |
-from pkg_resources import get_distribution | |
-if not os.path.isdir(get_distribution('genshi').location): | |
- try: | |
- import mod_python.apache | |
- import sys | |
- if 'trac.web.modpython_frontend' in sys.modules: | |
- from trac.web.api import * | |
- except ImportError: | |
- from trac.web.api import * | |
-else: | |
- from trac.web.api import * | |
+from trac.web.api import * | |
Index: trac/admin/console.py | |
=================================================================== | |
--- trac/admin/console.py (revision 10832) | |
+++ trac/admin/console.py (working copy) | |
@@ -35,7 +35,7 @@ | |
from trac.wiki.admin import WikiAdmin | |
from trac.wiki.macros import WikiMacroBase | |
-TRAC_VERSION = pkg_resources.get_distribution('Trac').version | |
+TRAC_VERSION = VERSION | |
rl_completion_suppress_append = None | |
LANG = os.environ.get('LANG') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pass actual initenv commands. Initialization still doesn't work in my environment. =/