开发者

conditional command-line arguments [ possibly using getopt()?? ]

This is related to my previous post here. Running the actual script, I outpu开发者_运维问答t the result like this:

[root@test_vm /]# torque_history.py -m 4
Job Id       User      Real User       Start Date      S  End Date        Exec Host    Queue  
-----------  --------  --------------  --------------  -  --------------  -----------  -------
0.vmtest2    dteam001  Kashif M. Raza  18/04 16:53:03  C  18/04 16:53:05  vmtest1.abc  express
2.vmtest2    dteam007  Arnau Hahkala   19/04 13:21:19  C  19/04 13:23:26  vmtest3.abc  medium
....
....
160.vmtest2  sgmatlas  Andrew Lloyd    30/04 15:44:36  C  30/04 15:54:04  node029.abc  short  
162.vmtest2  sgmops    Maarten Lapka   30/04 16:44:36  C  30/04 16:45:48  vmtest1.abc  express
---------------------------------
107 records in history (0.04 sec)

-m 4 prints the records only for April, if no option is given prints entire records and so on. I want my user to be able to construct the conditional query string, like: m == "4" && RealUser == "Maarten Lapka" and also output the result with the only fields they want, in their desired format, like: JobId && StartDate && User, which means the user is looking for the job records those are submitted by Maarten Lapka in April and want to print only the job-id, job start-date and the user-name in the order he mentioned. So, a possible command could be:

torque_history.py -c 'm == "4" && RealUser == "Maarten Lapka"' -f 'JobId && ExecHost && StartDate'

where -c is the short for --constraint and -f for --format or whatever. Can anyone suggest me some way of doing this? Is it possible using getopt()?

The part of my problem is we use variant of RHEL5 (i.e. SL5, SLC5, CentOS), they all come with python v2.4 as standard and I can't make sure that every site run v2.6 in parallel. So, I want to stay close as much as possible to v2.4 and using getopt() if possible. My plan is to compile the python code using shedskin and distribute the c++ file to minimize the compatibility issue. In that case I can use v2.6 but I've to use the modules that shedskin support and getopt() is one of them.

I'm sorry if I'm making it's hard for you guys but I'm really looking forward to some help and suggestions. Thanks for your time. Cheers!!!


optparse is pure Python, so I'd forget about getopt() and pull it into your app if need be.

try:
  import optparse
except ImportError:
  import external.optparse as optparse

Don't forget to create external/__init__.py.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜