Kommandozeilen-Interface ähnlich distutils?
Hallo, das Kommandozeilen-Interface von distutils ist ziemlich Klasse. Ich suche eine *einfache* Möglichkeit ein solches Interface zu bauen. Es muss nicht erweiterbar sein, alle Kommandos und Optionen sind bekannt. Irgendwelche Tipps? python setup.py --help python setup.py --help-commands python setup.py bdist --help python setup.py bdist --eine-bdists-option -- Schönen Gruß - Regards Hartmut Goebel Dipl.-Informatiker (univ.), CISSP, CSSLP Goebel Consult Spezialist für IT-Sicherheit in komplexen Umgebungen http://www.goebel-consult.de Monatliche Kolumne: http://www.cissp-gefluester.de/ Goebel Consult mit Mitglied bei http://www.7-it.de
Hallo Hartmut, da gibt es optparse (in der standard library) und argparse http://code.google.com/p/argparse/ das Kommandozeilen-Interface von distutils ist ziemlich Klasse. Ich
suche eine *einfache* Möglichkeit ein solches Interface zu bauen. Es muss nicht erweiterbar sein, alle Kommandos und Optionen sind bekannt.
Gruß Harald -- GHUM Harald Massa persuadere et programmare Harald Armin Massa Spielberger Straße 49 70435 Stuttgart 0173/9409607 no fx, no carrier pigeon - %s is too gigantic of an industry to bend to the whims of reality
Hallo Harald,
da gibt es optparse (in der standard library)
Das kann aber keien Subcommands, oder ist mir was entgangen?
und argparse http://code.google.com/p/argparse/
Danke, das ist das, was ich braucht. Wobei das von Peter genannt 'script' evtl. noch einfach für meine Zwecke ist. Mal ansehen. -- Schönen Gruß - Regards Hartmut Goebel Dipl.-Informatiker (univ.), CISSP, CSSLP Goebel Consult Spezialist für IT-Sicherheit in komplexen Umgebungen http://www.goebel-consult.de Monatliche Kolumne: http://www.cissp-gefluester.de/ Goebel Consult mit Mitglied bei http://www.7-it.de
Hallo Hartmut, On 2010-03-24 17:18, Hartmut Goebel wrote:
da gibt es optparse (in der standard library)
Das kann aber keien Subcommands, oder ist mir was entgangen?
eventuell könntest du sys.argv[1] auswerten und dann die Optionen anhand des gefundenen Wertes definieren und sys.argv[2:] (statt üblicherweise sys.argv[1:]) auswerten. Viele Grüße Stefan
Am 26.03.2010 18:26, schrieb Stefan Schwarzer:
Hallo Hartmut,
On 2010-03-24 17:18, Hartmut Goebel wrote:
da gibt es optparse (in der standard library)
Das kann aber keien Subcommands, oder ist mir was entgangen?
eventuell könntest du sys.argv[1] auswerten und dann die Optionen anhand des gefundenen Wertes definieren und sys.argv[2:] (statt üblicherweise sys.argv[1:]) auswerten.
Nachdem ich heute (zufällig) festgestellt habe, das argparse in Python 2.7 sein wird, werde ich wohl das nehmen. Danke für den Tipp. -- Schönen Gruß - Regards Hartmut Goebel Dipl.-Informatiker (univ.), CISSP, CSSLP Goebel Consult Spezialist für IT-Sicherheit in komplexen Umgebungen http://www.goebel-consult.de Monatliche Kolumne: http://www.cissp-gefluester.de/ Goebel Consult mit Mitglied bei http://www.7-it.de
Wenn es schnell gehen soll nehme ich dafür immer http://werkzeug.pocoo.org/documentation/script z.B: test.py from werkzeug import script # actions go here def action_foo(name=""): """action foo does foo""" pass def action_bar(id=0, title="default title"): """action bar does bar""" pass if __name__ == '__main__': script.run() Jede Funktion die mit action_* anfängt wird als action angesehen. python test.py --help ergibt dann: usage: test.py <action> [<options>] test.py --help actions: bar: action bar does bar --id integer 0 --title string default title foo: action foo does foo --name string Gruss Peter 2010/3/24 Hartmut Goebel <h.goebel@goebel-consult.de>:
Hallo,
das Kommandozeilen-Interface von distutils ist ziemlich Klasse. Ich suche eine *einfache* Möglichkeit ein solches Interface zu bauen. Es muss nicht erweiterbar sein, alle Kommandos und Optionen sind bekannt.
Irgendwelche Tipps?
python setup.py --help python setup.py --help-commands python setup.py bdist --help python setup.py bdist --eine-bdists-option
Am 24.03.2010 15:33, schrieb Peter Hoffmann:
Wenn es schnell gehen soll nehme ich dafür immer http://werkzeug.pocoo.org/documentation/script
Das schaut gut aus. Danke. -- Schönen Gruß - Regards Hartmut Goebel Dipl.-Informatiker (univ.), CISSP, CSSLP Goebel Consult Spezialist für IT-Sicherheit in komplexen Umgebungen http://www.goebel-consult.de Monatliche Kolumne: http://www.cissp-gefluester.de/ Goebel Consult mit Mitglied bei http://www.7-it.de
participants (4)
-
Hartmut Goebel
-
Massa, Harald Armin
-
Peter Hoffmann
-
Stefan Schwarzer