Zdravim,<br><br>prime reseni tveho problemu jsem nenasel, kazdopadne prikladam kostru snad dostatecneho reseni - rozsiril jsem metodu add_options tridy OptionGroup, ktera zaregistruje (v tomto priklade jen vytiskne) prikaz a dal postoupi argumenty puvodni metode add_option(). Fantazii k dalsi implementaci ponechavam ciste na Vas. Argumenty si lze pamatovat v nejakem listu nebo jine strukture pro pozdejsi volani apod.<br>
<br>Stejnym zpusobem lze rozsirit i OptionParser, odkud (pretizeni konstruktoru) jde ziskavat treba informace o --version. Kazdopadne vhodnost takoveho rozsirovani je diskutabilni, asi zalezi na tom, co presne od toho ocekavate.<br>
<br>Marek<br><br><div class="gmail_quote">On Fri, Jun 20, 2008 at 5:55 PM, David Michal <<a href="mailto:dmichal@altien.com">dmichal@altien.com</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div link="blue" vlink="purple" lang="EN-US">
<div>
<p><span lang="EN-GB">Zdravim,</span></p>
<p><span lang="EN-GB">Pisu si scriptik, ktery muze byt spusten
jak s argumenty na prikazove radce tak v interaktivnim rezimu. S tim, ze v obou
rezimech bude pouzivat ten samy set prikazu.</span></p>
<p><span lang="EN-GB">Nevite nekdo jak z optparser dostat set
vsech moznych argumentu, jak tech co mu zadavam (viz nize), tak I napriklad
argumentu –version. Chci I v interaktivnim rezimu pouzit set prikazu
nadefnovany v optparseru.</span></p>
<p><span lang="EN-GB"> </span></p>
<p><span lang="EN-GB"> </span></p>
<p><span lang="EN-GB">Cele to definuju nejak takhle:</span></p>
<p><span lang="EN-GB"> </span></p>
<p><span lang="EN-GB">from optparse import OptionParser</span></p>
<p><span lang="EN-GB">from optparse import OptionGroup</span></p>
<p><span lang="EN-GB"> </span></p>
<p><span lang="EN-GB">class Options(object):</span></p>
<p><span lang="EN-GB"> usage = "usage:
%prog [options] [arg]"</span></p>
<p><span lang="EN-GB"> parser =
OptionParser(usage, version = programVersion)</span></p>
<p><span lang="EN-GB"> group =
OptionGroup(parser, 'To manage local database')</span></p>
<p><span lang="EN-GB">
group.add_option("--db", dest="DB_filename",</span></p>
<p><span lang="EN-GB">
help="path to DB filename")</span></p>
<p><span lang="EN-GB">
group.add_option("--db-refresh", dest="db_refresh",
action="store_true",</span></p>
<p><span lang="EN-GB">
help="gather
info from servers and refresh records in DB")</span></p>
<p><span lang="EN-GB">
group.add_option("--db-create", dest="DB_filename",</span></p>
<p><span lang="EN-GB">
help="create new DB")</span></p>
<p><span lang="EN-GB">
group.add_option("--db-commit", dest="db_commit",
action="store_true",</span></p>
<p><span lang="EN-GB">
help="commit info from DB to servers")</span></p>
<p><span lang="EN-GB">
parser.add_option_group(group)</span></p>
<p><span lang="EN-GB"> </span></p>
<p><span lang="EN-GB">….pak pridavam jeste nejake dalsi
groupy</span></p>
<p><span lang="EN-GB"> </span></p>
<p><span lang="EN-GB"> </span></p>
<p><span lang="EN-GB">A ted jak z OptionParser dostanu seznam
vsech options? </span></p>
<p><span lang="EN-GB">Kdyz zavolam (options, args) = parser.parse_args()
tak dostanu pouze seznam destinations.</span></p>
<p><span lang="EN-GB"> </span></p>
<p><span lang="EN-GB">Dik,</span></p>
<p><span lang="EN-GB">David</span></p>
</div>
</div>
<br>_______________________________________________<br>
Python mailing list<br>
<a href="mailto:Python@py.cz">Python@py.cz</a><br>
<a href="http://www.py.cz/mailman/listinfo/python" target="_blank">http://www.py.cz/mailman/listinfo/python</a><br></blockquote></div><br>