| 1 | #!/usr/bin/env python |
|---|
| 2 | # -*- coding: utf-8 -*- |
|---|
| 3 | """ |
|---|
| 4 | Bundle a Plugin |
|---|
| 5 | ~~~~~~~~~~~~~~~ |
|---|
| 6 | |
|---|
| 7 | This script creates a .plugin file from a plugin installed in |
|---|
| 8 | the given Zine instance (which usually is a development |
|---|
| 9 | instance of Zine). |
|---|
| 10 | |
|---|
| 11 | The file created can be used to distribute the plugin. |
|---|
| 12 | |
|---|
| 13 | :copyright: (c) 2010 by the Zine Team, see AUTHORS for more details. |
|---|
| 14 | :license: BSD, see LICENSE for more details. |
|---|
| 15 | """ |
|---|
| 16 | import sys |
|---|
| 17 | from os.path import isdir, join, dirname |
|---|
| 18 | from optparse import OptionParser |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | sys.path.append(dirname(__file__)) |
|---|
| 22 | from _init_zine import find_instance |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | def main(): |
|---|
| 26 | parser = OptionParser(usage='%prog [options] plugin [output-file]') |
|---|
| 27 | parser.add_option('--instance', '-I', dest='instance', |
|---|
| 28 | help='Use the path provided as Zine instance.') |
|---|
| 29 | parser.add_option('--dont-compile', '-N', default=False, |
|---|
| 30 | action='store_true', |
|---|
| 31 | help="don't compile available plugin translations") |
|---|
| 32 | options, args = parser.parse_args() |
|---|
| 33 | if len(args) not in (1, 2): |
|---|
| 34 | parser.error('incorrect number of arguments') |
|---|
| 35 | instance = options.instance or find_instance() |
|---|
| 36 | if instance is None: |
|---|
| 37 | parser.error('instance not found. Specify path to instance') |
|---|
| 38 | |
|---|
| 39 | import zine |
|---|
| 40 | try: |
|---|
| 41 | plugin = zine.setup(instance).plugins[args[0]] |
|---|
| 42 | except KeyError: |
|---|
| 43 | parser.error('Plugin not found') |
|---|
| 44 | |
|---|
| 45 | output_filename = None |
|---|
| 46 | if len(args) == 2: |
|---|
| 47 | output_filename = args[1] |
|---|
| 48 | |
|---|
| 49 | if output_filename is None or isdir(output_filename): |
|---|
| 50 | plugin_filename = '%s-%s.plugin' % ( |
|---|
| 51 | plugin.filesystem_name, |
|---|
| 52 | plugin.version |
|---|
| 53 | ) |
|---|
| 54 | if output_filename is not None: |
|---|
| 55 | output_filename = join(output_filename, plugin_filename) |
|---|
| 56 | else: |
|---|
| 57 | output_filename = plugin_filename |
|---|
| 58 | elif not output_filename.endswith('.plugin'): |
|---|
| 59 | output_filename += '.plugin' |
|---|
| 60 | |
|---|
| 61 | if not options.dont_compile: |
|---|
| 62 | from subprocess import call |
|---|
| 63 | compile_script = join(dirname(__file__), 'compile-translations') |
|---|
| 64 | call([sys.executable, compile_script, plugin.path, '-s']) |
|---|
| 65 | |
|---|
| 66 | plugin.dump(output_filename) |
|---|
| 67 | print 'Plugin written to %s' % output_filename |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | if __name__ == '__main__': |
|---|
| 71 | main() |
|---|