Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rip out configure-aspen.py #381

Merged
merged 9 commits into from
Jun 29, 2015
5 changes: 2 additions & 3 deletions aspen/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
from __future__ import print_function
from __future__ import unicode_literals

from aspen import serve, Website
from aspen import serve, website

if __name__ == '__main__':
website = Website()
serve(website)
serve(website.Website())
2 changes: 1 addition & 1 deletion aspen/auth/cookie.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

# Public config knobs
# ===================
# Feel free to set these in, e.g., configure-aspen.py
# Feel free to modify for your application.

NAME = "auth"
DOMAIN = None
Expand Down
2 changes: 1 addition & 1 deletion aspen/auth/httpdigest.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def send_403(self, html, extraheaders):
## make a generator of containers that aspen will like

def inbound_responder(*args, **kw):
""" This should be used in your configure-aspen.py like so:
""" This should be used in your startup script like so:

import aspen.auth.httpdigest as digestauth

Expand Down
66 changes: 1 addition & 65 deletions aspen/configuration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
# name is supposed to match the options in our optparser. I like it wet.

KNOBS = \
{ 'configuration_scripts': (lambda: [], parse.list_)
, 'project_root': (None, parse.identity)
{ 'project_root': (None, parse.identity)
, 'logging_threshold': (0, int)
, 'www_root': (None, parse.identity)

Expand All @@ -56,7 +55,6 @@
, 'show_tracebacks': (False, parse.yes_no)
}

DEFAULT_CONFIG_FILE = 'configure-aspen.py'

# Configurable
# ============
Expand Down Expand Up @@ -235,12 +233,6 @@ def safe_getcwd(errorstr):
users_mimetypes = os.path.join(self.project_root, 'mime.types')
mimetypes.knownfiles += [users_mimetypes]

# configure-aspen.py
configure_aspen_py = os.path.join( self.project_root
, DEFAULT_CONFIG_FILE
)
self.configuration_scripts.append(configure_aspen_py) # last word

# PYTHONPATH
sys.path.insert(0, self.project_root)

Expand Down Expand Up @@ -292,7 +284,6 @@ def safe_getcwd(errorstr):
if not mimetypes.inited:
mimetypes.init()

self.run_config_scripts()
self.show_renderers()

def show_renderers(self):
Expand All @@ -316,58 +307,3 @@ def show_renderers(self):
aspen.log_dammit(msg % self.renderer_default)
sys.excepthook(*default_renderer.info)
raise default_renderer


def run_config_scripts(self):
# Finally, exec any configuration scripts.
# ========================================
# The user gets self as 'website' inside their configuration scripts.
default_cfg_filename = None
if self.project_root is not None:
default_cfg_filename = os.path.join(self.project_root, DEFAULT_CONFIG_FILE)

for filepath in self.configuration_scripts:
if not filepath.startswith(os.sep):
if self.project_root is None:
raise ConfigurationError("You must set project_root in "
"order to specify a configuratio"
"n_script relatively.")
filepath = os.path.join(self.project_root, filepath)
filepath = os.path.realpath(filepath)
try:
execfile(filepath, {'website': self})
except IOError, err:
# Re-raise the error if it happened inside the script.
if err.filename != filepath:
raise

# I was checking os.path.isfile for these, but then we have a
# race condition that smells to me like a potential security
# vulnerability.

## determine if it's a default configscript or a specified one
cfgtype = "configuration"
if filepath == default_cfg_filename:
cfgtype = "default " + cfgtype
## pick the right error mesage
if err.errno == errno.ENOENT:
msg = ("The %s script %s doesn't seem to exist.")
elif err.errno == errno.EACCES:
msg = ("It appears that you don't have permission to read "
"the %s script %s.")
else:
msg = ("There was a problem reading the %s script %s:")
msg += os.sep + traceback.format_exc()
## do message-string substitutions
msg = msg % (cfgtype, filepath)
## output the message
if not "default" in cfgtype:
# if you specify a config file, it's an error if there's a problem
raise ConfigurationError(msg)
else:
# problems with default config files are okay, but get logged
aspen.log(msg)




6 changes: 0 additions & 6 deletions aspen/configuration/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ def OptionParser():

basic = optparse.OptionGroup(optparser, "Basic Options")

basic.add_option( "-f", "--configuration_scripts"
, help=("comma-separated list of paths to configuration "
"files in Python syntax to exec in addition to "
"$ASPEN_PROJECT_ROOT/configure-aspen.py")
, default=DEFAULT
)
basic.add_option( "-l", "--logging_threshold"
, help=("a small integer; 1 will suppress most of aspen's "
"internal logging, 2 will suppress all it [0]")
Expand Down
4 changes: 2 additions & 2 deletions aspen/renderers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class CheeseFactory(Factory):
website.renderer_factories['excited-about-cheese'] = CheeseFactory(website)


You could put that in configure-aspen.py in your --project_root, for example.
Now you can use it in a negotiated or rendered resource:
Put that in your startup script. Now you can use it in a negotiated or rendered
resource:

^L #!excited-about-cheese
I like cheese!
Expand Down
72 changes: 72 additions & 0 deletions aspen_io.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"""Configuration script for the http://aspen.io/ website.
"""
import os
import os.path
from aspen.configuration import parse
from aspen.website import Website

distribution_root = os.path.dirname(__file__)
www_root = os.path.join(distribution_root, 'doc')
project_root = os.path.join(www_root, '.aspen')
website = Website(['--www_root', www_root, '--project_root', project_root])
opts = {}

def add_stuff_to_request_context(website, dispatch_result):

# Define some closures for generating image markup.
# =================================================

def translate(src):
if src[0] != '/':
rel = os.path.dirname(dispatch_result.match)[len(website.www_root):]
src = '/'.join([rel, src])
src = opts['base'] + src
return src

def img(src):
src = translate(src)
html = '<img src="%s" />' % src
return html

def screenshot(short, imgtype='png', href=''):
"""Given foo, go with foo.small.png and foo.png.
"""
small = img(short + '.small.' + imgtype)
if not href:
href = translate(short + '.' + imgtype)
html = ('<a title="Click for full size" href="%s"'
'class="screencap">%s</a>')
return html % (href, small)


# Make these available within simplates.
# ======================================

return {
'img': img,
'screenshot': screenshot,
'translate': translate,
'version': opts['version'],
'homepage': False,
'show_ga': opts['show_ga'],
}


opts['show_ga'] = parse.yes_no(os.environ.get( 'ASPEN_IO_SHOW_GA'
, 'no'
).decode('US-ASCII'))
opts['base'] = ''

# this is a dirty nasty hack. We should store the version in the aspen module somewhere
opts['version'] = open(os.path.join(website.www_root,'..','version.txt')).read()[:-len('-dev')]

# no idea why this doesn't work
website.renderer_default = 'tornado'
open('/tmp/debugout','a').write('doccnf:' + website.renderer_default + '\n')

website.algorithm.insert_after('dispatch_request_to_filesystem', add_stuff_to_request_context)


if __name__ == '__main__':
from aspen import serve
serve(website)
2 changes: 1 addition & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def docserve():
deps()
run(_virt('pip'), 'install', 'aspen-tornado')
run(_virt('pip'), 'install', 'pygments')
shell(_virt('python'), '-m', 'aspen', '-wdoc', '-pdoc/.aspen', silent=False)
shell(_virt('python'), '-m', 'aspen_io', silent=False)


def smoke():
Expand Down
47 changes: 0 additions & 47 deletions doc/.aspen/aspen_io.py

This file was deleted.

18 changes: 0 additions & 18 deletions doc/.aspen/configure-aspen.py

This file was deleted.

19 changes: 7 additions & 12 deletions doc/api/website/index.html.spt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ doc_next = ""

<p>Aspen creates an instance of <code>aspen.website.Website</code> when it
starts up. It holds all of the global configuration for your application. It is
placed in the namespace of your <a
href="/configure-aspen.py/">configuration scripts</a> and <a
href="/simplates/">simplates</a>, where it is available from the first page
onwards.</p>
placed in the namespace of your <a href="/simplates/">simplates</a>, where it
is available from the first page onwards.</p>

<p>The following attributes are defined when aspen starts up based on
configuration in the environment (<code>ASPEN_NAME</code>) and on the command
Expand All @@ -20,7 +18,6 @@ line (<code>--name</code>):</p>
<tr><td>changes_reload</td><td>False</td> </tr>
<tr><td>charset_dynamic</td><td>UTF-8</td> </tr>
<tr><td>charset_static</td><td>None</td> </tr>
<tr><td>configuration_scripts&nbsp;</td><td>[]</td> </tr>
<tr><td>indices</td><td>['index', 'index.html', 'index.json',
'index.html.spt', 'index.json.spt']</td> </tr>
<tr><td>list_directories</td><td>False</td> </tr>
Expand All @@ -38,9 +35,7 @@ line (<code>--name</code>):</p>
<h3>Computations</h3>

<p>The following computations are performed after environment and command line
configuration is processed, and before your <a
href="/configure-aspen.py/">configuration
scripts</a> run.</p>
configuration is processed.</p>

<ul>

Expand All @@ -51,10 +46,10 @@ configuration is processed, and before your <a

<li>If <b>project_root</b> is set, then the directory it points to is used
to resolve <code>{&#37; extends %}</code> and {&#37; include %} <a
href="/simplates/template/">templates</a> tags; any <a
href="/mime.types/">mime.types</a> file in there will be loaded; any
configure-aspen.py script in there will be executed; and it will be placed
at the front of sys.path, so you can import Python modules from there</li>
href="/simplates/template/">templates</a> tags; any <a
href="/mime.types/">mime.types</a> file in there will be loaded; and it will be
placed at the front of sys.path, so you can import Python modules from
there</li>

<li>Two dictionaries associated with resolving renderers are instantiated
and populated: <b>renderer_factories</b> and
Expand Down
12 changes: 2 additions & 10 deletions doc/configuration/index.html.spt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ line. For each of the following there is an environment variable like
<tr><td>changes_reload</td> <td>yes</td> </tr>
<tr><td>charset_dynamic</td> <td>ISO-8859-1</td> </tr>
<tr><td>charset_static</td> <td>windows-1252</td> </tr>
<tr><td>configuration_scripts&nbsp;</td><td>script-one.py,another.py</td> </tr>
<tr><td>indices</td> <td>index.html, README</td> </tr>
<tr><td>list_directories</td> <td>False</td> </tr>
<tr><td>logging_threshold</td> <td>1</td> </tr>
Expand All @@ -26,11 +25,8 @@ line. For each of the following there is an environment variable like
<tr><td>unavailable</td> <td>0</td> </tr>
</table>

<p>Once aspen is initially configured, the <a
href="/configure-aspen.py/">scripts named by
<code>configuration_scripts</code></a> are executed with <a
href="/api/website/">the website object</a> in their namespace. Please
refer to <a href="/api/website/">the website page</a> for defaults.</p>
<p>Please refer to <a href="/api/website/">the website page</a> for
defaults.</p>

<h4 id="command-line-options">Command Line Options</h4>

Expand All @@ -52,10 +48,6 @@ Options:
-h, --help show this help message and exit

Basic Options:
-f CONFIGURATION_SCRIPTS, --configuration_scripts=CONFIGURATION_SCRIPTS
comma-separated list of paths to configuration files
in Python syntax to exec in addition to
$ASPEN_PROJECT_ROOT/configure-aspen.py
-l LOGGING_THRESHOLD, --logging_threshold=LOGGING_THRESHOLD
a small integer; 1 will suppress most of aspen's
internal logging, 2 will suppress all it [0]
Expand Down
Loading