| 1 | #!/usr/bin/env python |
|---|
| 2 | # -*- coding: utf-8 -*- |
|---|
| 3 | """ |
|---|
| 4 | Create an Apache Config |
|---|
| 5 | ~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 6 | |
|---|
| 7 | This creates an apache config for static exports. |
|---|
| 8 | |
|---|
| 9 | :copyright: (c) 2010 by the Zine Team, see AUTHORS for more details. |
|---|
| 10 | :license: BSD, see LICENSE for more details. |
|---|
| 11 | """ |
|---|
| 12 | import sys |
|---|
| 13 | from os.path import abspath, dirname |
|---|
| 14 | from optparse import OptionParser |
|---|
| 15 | from urlparse import urlparse |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | HELP_TEXT = '''\ |
|---|
| 19 | This script generates an Apache config for the static data Zine or |
|---|
| 20 | Zine plugins export. It's recommended to generate this configuration |
|---|
| 21 | every time a plugin is enabled/disabled and included in the vhost |
|---|
| 22 | of your regular Zine Apache configuration. |
|---|
| 23 | |
|---|
| 24 | This will greatly improve the performance of your Zine installation.\ |
|---|
| 25 | ''' |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | sys.path.append(dirname(__file__)) |
|---|
| 29 | from _init_zine import find_instance |
|---|
| 30 | from zine import setup |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | def main(): |
|---|
| 34 | parser = OptionParser(usage='%prog [options]\n\n' + HELP_TEXT) |
|---|
| 35 | parser.add_option('--instance', '-I', dest='instance', |
|---|
| 36 | help='Use the path provided as Zine instance.') |
|---|
| 37 | options, args = parser.parse_args() |
|---|
| 38 | if args: |
|---|
| 39 | parser.error('incorrect number of arguments') |
|---|
| 40 | instance = options.instance or find_instance() |
|---|
| 41 | if instance is None: |
|---|
| 42 | parser.error('instance not found. Specify path to instance') |
|---|
| 43 | |
|---|
| 44 | app = setup(instance) |
|---|
| 45 | |
|---|
| 46 | prefix = urlparse(app.cfg['blog_url'])[2].rstrip('/') |
|---|
| 47 | |
|---|
| 48 | for alias, dst in app._shared_exports.iteritems(): |
|---|
| 49 | dst = abspath(dst) |
|---|
| 50 | if len(dst.split()) != 1: |
|---|
| 51 | dst = '"%s"' % dst |
|---|
| 52 | print 'Alias %s%s %s' % (prefix, alias, dst) |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | if __name__ == '__main__': |
|---|
| 56 | main() |
|---|