条件命令行参数[可能使用getopt()?? ]
这与我之前的帖子此处相关。运行实际的脚本,我输出如下结果:
[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
仅打印四月份的记录,如果没有给出选项则打印整个记录等。我希望我的用户能够构造条件查询字符串,例如: m == "4" && RealUser == "Maarten Lapka"
并以他们想要的格式输出他们想要的唯一字段的结果,例如:JobId &&开始日期 && User,这意味着用户正在查找 Maarten Lapka 在 4 月份提交的作业记录,并且只想按照他提到的顺序打印作业 ID、作业开始日期和用户名。因此,可能的命令是:
torque_history.py -c 'm == "4" && RealUser == "Maarten Lapka"' -f 'JobId && ExecHost && StartDate'
,其中 -c
是 --constraint
的缩写,-f
是 --format
的缩写> 或其他什么。谁能建议我一些方法来做到这一点?是否可以使用getopt()
?
我的问题是我们使用 RHEL5 的变体(即 SL5、SLC5、CentOS),它们都以 python v2.4 作为标准,我无法确保每个站点都并行运行 v2.6。因此,我希望尽可能接近 v2.4,并尽可能使用 getopt()
。我的计划是使用 shedskin 编译 python 代码并分发 c++ 文件以最小化兼容性问题。在这种情况下,我可以使用 v2.6,但我必须使用 shedskin 支持的模块, getopt() 就是其中之一。
如果我让你们感到困难,我很抱歉,但我真的很期待一些帮助和建议。感谢您抽出时间。干杯!!!
This is related to my previous post here. Running the actual script, I output 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!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
optparse
是纯 Python,所以我会忘记getopt()
并在需要时将其拉入您的应用程序。不要忘记创建
external/__init__.py
。optparse
is pure Python, so I'd forget aboutgetopt()
and pull it into your app if need be.Don't forget to create
external/__init__.py
.