Re: [pygtk] popt question
> This is OK -- I need to do it only once :-) This is fine then - unless getopt behaves differently to popt, or has less/more features that could cause problems. > > > IMHO, it boils down to: do you want/need the gnome/gtk standard > > command line options, or not? > > I do. As I understand it, I don't have to do anything about the standard > options -- they are taken care of by the gnome libs, right? As far as I can remember yes. You can blame me if this is not correct :) __ Do you Yahoo!? Yahoo! Mail is new and improved - Check it out! http://promotions.yahoo.com/new_mail ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] popt question
Rubens, On Wed, Jun 16, 2004 at 04:26:14PM -0700, Rubens Ramos wrote: > > > I guess so, but it's uglier. Not only that, the actual problem is that > > I want the program to guess formats if they are not explicitly supplied > > on the command line. So it should be possible to say > > > >./myprog -i file1 -i file2 -f format2 > > > > which means that the file1's format should be guessed. In your scenario, > >-i "file1,file2" -f "format2" > > becomes uncertain: is format2 applying to file1 or file2? > Hmm - I was afraid you were going to say this - unfortunately, > I dont know of a way to do it with the current implementation, > unless you do something like: > > -i "file1,file2" -f ",format2" > > which is even uglier. Right, so I guess I better stick with using getopt, which brings us right to the next point. > > Let me ask you this: I had no problem parsing the above type of > > arguments using getopt. However, I thought I'd want to use popt, > > if not for anything else then just to have the application options > > appear on ./myprog -- help and ./myprog --usage. [snip] > Now, thanks for asking this question ;-) > To do this, you would need to: > > * Have all options defined in a popt table, and pass it to gnome.init(). > This is so that popt will not scream about your application's > options. > * gnome.init() will call the popt parser anyway, but you wouldnt > use the results of that; > * After this is done, you then have to use getopt to check for your > own options. That's exactly what I had in mind. > Note, I am not in front of my Linux box now to try it, but I think > this was the main problem with this approach: > > The real issue with all this is that (I assume you are referring > to the standard Python getopt package), to use getopt, you need > to give it the full list of options - so this would have to include > all options (yes, the gnome/gtk ones as well), which is pretty > annoying (Otherwise you then get a getopt.GetoptError). > And this is because popt does not change the list of parameters > after it has finished parsing it. This is OK -- I need to do it only once :-) > IMHO, it boils down to: do you want/need the gnome/gtk standard > command line options, or not? I do. As I understand it, I don't have to do anything about the standard options -- they are taken care of by the gnome libs, right? Thanks again, Alex -- Alexander Roitman http://ebner.neuroscience.umn.edu/people/alex.html Dept. of Neuroscience, Lions Research Building 2001 6th Street SE, Minneapolis, MN 55455 Tel (612) 625-7566 FAX (612) 626-9201 signature.asc Description: Digital signature ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] popt question
> I guess so, but it's uglier. Not only that, the actual problem is that > I want the program to guess formats if they are not explicitly supplied > on the command line. So it should be possible to say > >./myprog -i file1 -i file2 -f format2 > > which means that the file1's format should be guessed. In your scenario, >-i "file1,file2" -f "format2" > becomes uncertain: is format2 applying to file1 or file2? Hmm - I was afraid you were going to say this - unfortunately, I dont know of a way to do it with the current implementation, unless you do something like: -i "file1,file2" -f ",format2" which is even uglier. > Let me ask you this: I had no problem parsing the above type of > arguments > using getopt. However, I thought I'd want to use popt, if not for > anything > else then just to have the application options appear on > ./myprog -- help and ./myprog --usage. > > What is the downside of this cheating: passing popt table to the > gnome.init() > (so that --help and --usage list my options) while actually using > getopt for parsing the command line? > > Unless I'm missing something, this is the best of both worlds, > at least for my situation, isn't it? Now, thanks for asking this question ;-) To do this, you would need to: * Have all options defined in a popt table, and pass it to gnome.init(). This is so that popt will not scream about your application's options. * gnome.init() will call the popt parser anyway, but you wouldnt use the results of that; * After this is done, you then have to use getopt to check for your own options. Note, I am not in front of my Linux box now to try it, but I think this was the main problem with this approach: The real issue with all this is that (I assume you are referring to the standard Python getopt package), to use getopt, you need to give it the full list of options - so this would have to include all options (yes, the gnome/gtk ones as well), which is pretty annoying (Otherwise you then get a getopt.GetoptError). And this is because popt does not change the list of parameters after it has finished parsing it. IMHO, it boils down to: do you want/need the gnome/gtk standard command line options, or not? Hope this helps Rubens __ Do you Yahoo!? New and Improved Yahoo! Mail - Send 10MB messages! http://promotions.yahoo.com/new_mail ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] popt question
Rubens, Thanks for your help! On Tue, Jun 15, 2004 at 08:27:52PM -0700, Rubens Ramos wrote: > > I guess the short answer to what you are trying to do is - it is > not possible, due to some constraints in how the popt wrappers were > written (please see the "technical yaddayadda" if you are interested). > > However, one workaround is to do it this way: > > ./myprog -i "file1,file2,file3" -f "format1,format2,format3" > > and then split the arguments after the parsing is done. Would that > work for you? I guess so, but it's uglier. Not only that, the actual problem is that I want the program to guess formats if they are not explicitly supplied on the command line. So it should be possible to say ./myprog -i file1 -i file2 -f format2 which means that the file1's format should be guessed. In your scenario, -i "file1,file2" -f "format2" becomes uncertain: is format2 applying to file1 or file2? > * Technical yaddayadda * > > Currently there is no way to use the pygtk popt bindings in a > loop like what you can do in C - the wrappers do that > for you, so the only option is to use get_popt_args() after > gnome.init() OR gnome.popt_parse(). > > There is no parallel between that (the C loop method) and the Python > interface. I see. > The misterious flags in the Python table are the POPT_ARGFLAG_* > constants defined in popt.h and explained in the man page. Oh, the man page is actually quite good, thanks! > And the callback functionality for the popt tables (as described > in the popt manpage) is not available in pygtk, as it is also > used internally by the wrappers - by the way, as I can see it, this > is also the only way you would be able to implement this: > > ./myprog -i file1 -f format1 -i file2 -f format2 -o file3 -f format3 > > in C. Pity. Let me ask you this: I had no problem parsing the above type of arguments using getopt. However, I thought I'd want to use popt, if not for anything else then just to have the application options appear on ./myprog -- help and ./myprog --usage. What is the downside of this cheating: passing popt table to the gnome.init() (so that --help and --usage list my options) while actually using getopt for parsing the command line? Unless I'm missing something, this is the best of both worlds, at least for my situation, isn't it? Thanks again, Alex -- Alexander Roitman http://ebner.neuroscience.umn.edu/people/alex.html Dept. of Neuroscience, Lions Research Building 2001 6th Street SE, Minneapolis, MN 55455 Tel (612) 625-7566 FAX (612) 626-9201 signature.asc Description: Digital signature ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
Re: [pygtk] popt question
Hi Alex, I guess the short answer to what you are trying to do is - it is not possible, due to some constraints in how the popt wrappers were written (please see the "technical yaddayadda" if you are interested). However, one workaround is to do it this way: ./myprog -i "file1,file2,file3" -f "format1,format2,format3" and then split the arguments after the parsing is done. Would that work for you? Hope this helps, Rubens * Technical yaddayadda * Currently there is no way to use the pygtk popt bindings in a loop like what you can do in C - the wrappers do that for you, so the only option is to use get_popt_args() after gnome.init() OR gnome.popt_parse(). There is no parallel between that (the C loop method) and the Python interface. The misterious flags in the Python table are the POPT_ARGFLAG_* constants defined in popt.h and explained in the man page. And the callback functionality for the popt tables (as described in the popt manpage) is not available in pygtk, as it is also used internally by the wrappers - by the way, as I can see it, this is also the only way you would be able to implement this: ./myprog -i file1 -f format1 -i file2 -f format2 -o file3 -f format3 in C. = Rubens Ramos Fernandes Junior [EMAIL PROTECTED] __ Do you Yahoo!? Yahoo! Mail is new and improved - Check it out! http://promotions.yahoo.com/new_mail ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
[pygtk] popt question
Hi, I'm trying to work out the example from popt.py and few things are not clear. Specifically, I can't seem to correctly parse something like this: ./myprog -i file1 -f format1 -i file2 -f format2 -o file3 -f format3 When the second "-i" (or -f, or -o) flags are supplied, they are being ignored. At the same time, there's this mysterious "flags" field in the table of arguments. I have a suspicion that this has to do with processing multiple options. The gnome popt reference mentions parsing options in a loop, but I can't seem to draw parallels between that API and the popt.py example. Could anybody please point me to the right direction? Thanks in advance for any help, Alex -- Alexander Roitman http://ebner.neuroscience.umn.edu/people/alex.html Dept. of Neuroscience, Lions Research Building 2001 6th Street SE, Minneapolis, MN 55455 Tel (612) 625-7566 FAX (612) 626-9201 signature.asc Description: Digital signature ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/