Python 脚本的 Bash 别名——可能吗?
我想要“分类”到 Python 脚本中的特定别名恰好是使用 cUrl -o(输出到文件)选项的别名。我想我可以很容易地将它变成 BASH 函数,但有人建议我,通过采用我的想法并将其制作为 Python 脚本,我可以避免 BASH 的不同版本和“风格”的怪癖和陷阱。
与这个想法相一致的是我必须制作旧版 Mac OS(正式称为“OS 9”或“Classic”)的一项与平台无关的下载功能:将 URL 写入文件中可见的文件的某些部分导航器 {Konqueror、Dolphin、Nautilus、Finder 或 Explorer}。我知道只有少数文件类型使用其他一些命令行工具(exiv2、wrjpgcom 等)支持这种事情。这对我来说完全没问题,因为我只使用这个别名来下载单页图像文件,例如 JPEG。
我想我也可以充分利用Python的强大功能,让脚本将下载的源URL字符串(由用户输入并首先由cUrl使用)传递给类似exiv2的东西,它可以将其写入注释块、EXIF 用户注释块以及(作为第一个也是最糟糕的示例)Windows XP 的文件描述字段。从小事做起有时是一个很好的开始方式。
希望有人给意见或者建议。
BZT
The particular alias I'm looking to "class up" into a Python script happens to be one that makes use of the cUrl -o (output to file) option. I suppose I could as easily turn it into a BASH function, but someone advised me that I could avoid the quirks and pitfalls of the different versions and "flavors" of BASH by taking my ideas and making them Python scripts.
Coincident with this idea is another notion I had to make a feature of legacy Mac OS (officially known as "OS 9" or "Classic") pertaining to downloads platform-independent: writing the URL to some part of the file visible from one's file navigator {Konqueror, Dolphin, Nautilus, Finder or Explorer}. I know that only a scant few file types support this kind of thing using some other command-line tools (exiv2, wrjpgcom, etc). Which is perfectly fine with me as I only use this alias to download single-page image files such as JPEGs anyways.
I reckon I might as well take full advantage of the power of Python by having the script pass the string which is the source URL of the download (entered by the user and used first by cUrl) to something like exiv2 which could write it to the Comment block, EXIF User Comment block, and (taking as a first and worst example) Windows XP's File Description field. Starting small is sometimes a good way to start.
Hope someone has advice or suggestions.
BZT
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Bash 手册中的相关部分指出:
因此,应该没有什么可以阻止您执行以下操作:
然后您可以像任何其他 shell 命令一样使用它:
这将简单地调用您的 Python 程序。
The relevant section from the Bash manual states:
So, there should be nothing preventing you from doing e.g.
Then you could use it like any other shell command:
And this would simply call your Python program.
我认为 Pycurl 可能就是答案。啊,丹尼尔·斯滕伯格和他天真的假设,即每个人都知道他在做什么。我在列表中询问 pycurl 是否有“curl -o”类似物,然后问“如果有:如何在 Python 脚本中对其进行编码?”他的回复如下:
“curl.setopt(pycurl.WRITEDATA,fp)
可能与:
curl.setopt(pycurl.WRITEFUNCITON,回调)”
...以及 Sourceforge 链接到retrieve.py 的两个修订版。我几乎不记得 easy_install 把我拥有的那个放在哪里了;我该如何比较它们?
很明显,这位先生从未在西半球从事过服务台或电话技术支持工作,你必须假设“客户”昨天刚刚学会了如何使用梳子,并准备好引导他们完成所有事情。单线(或带有深奥链接的三线作为追逐者)不适合我。
BZT
I thought Pycurl might be the answer. Ahh Daniel Sternberg and his innocent presumptions that everybody knows what he does. I asked on the list whether or not pycurl had a "curl -o" analogue, and then asked 'If so: How would one go about coding it/them in a Python script?' His reply was the following:
"curl.setopt(pycurl.WRITEDATA, fp)
possibly combined with:
curl.setopt(pycurl.WRITEFUNCITON, callback) "
...along with Sourceforge links to two revisions of retriever.py. I can barely recall where easy_install put the one I've got; how am I supposed to compare them?
It's pretty apparent this gentleman never had a helpdesk or phone tech support job in the Western Hemisphere, where you have to assume the 'customer' just learned how to use their comb yesterday and be prepared to walk them through everything and anything. One-liners (or three-liners with abstruse links as chasers) don't do it for me.
BZT