Frage

Ich bin an einem Punkt in meinem Pylons Projekt, bei denen ich Controller oft am Ende Erstellen und Löschen von (wahrscheinlich oft mehr als ich soll). Ich ermüden meine eigene Importe und kleine Änderungen an der Spitze jeder Controller hinzuzufügen. Es gab eine letzte Frage zu der neuen Controller-Vorlage zu modifizieren , die mir ein Stück weit bekamen das nicht zu tun haben - aber ich verstehe nicht, wie die controller.py_tmpl Datei von Paster verwendet wird, und wie ich Paster zu, für ein vorhandenes Projekt kann sagen: „hey, Verwendung diese template statt! "

Was Aufruf muss ich Paster sagen, meine Vorlage anstelle des Standard ein benutzen?

War es hilfreich?

Lösung

Pylons creates new controllers and projects by adding command to paste. The commands are defined in setup.py and you can add new commands.

For example (this is taken from the Paste docs) lets assume you have a project called Foo that is in a package also called foo.

In setup.py add 'foo' to the 'paster_plugins' list Then add a new command to entry_points.

ie entry_points=""" [paste.paster_command] mycommand = foo.commands.test_command:Test """

Create a directory called 'commands' under 'foo', add a __init.py__ file and create a file called test_command.py

In the file add

from paste.script import command

class TestCommand(command.Command):

    max_args = 1
    min_args = 1

    usage = "NAME"
    summary = "Say hello!"
    group_name = "My Package Name"

    parser = command.Command.standard_parser(verbose=True)
    parser.add_option('--goodbye',
                      action='store_true',
                      dest='goodbye',
                      help="Say 'Goodbye' instead")

    def command(self):
        name = self.args[0]
        if self.verbose:
            print "Got name: %r" % name
        if self.options.goodbye:
            print "Goodbye", name
        else:
            print "Hello", name

After you run 'python setup.py develop' you can now run 'paste mycommand bob' and you should get 'Hello bob' output.

To see how Pylons adds to this to create new files etc. look in pylons/commands.py they have commands for creating new Controllers and RestControllers that you can copy.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top