2015-06-16 26 views
1

我想通過子過程調用鵜鶘進行自動化博客發佈,但是當我在shell中嘗試which pelican並將其打開時。我發現這個是用戶從shell執行的pelican可執行腳本?

#!/usr/bin/python 
# EASY-INSTALL-ENTRY-SCRIPT: 'pelican==3.5.0','console_scripts','pelican' 
__requires__ = 'pelican==3.5.0' 
import sys 
from pkg_resources import load_entry_point 

sys.exit(
    load_entry_point('pelican==3.5.0', 'console_scripts', 'pelican')() 
) 

,而我期待看到主函數的調用被調用時,有人通過從外殼到鵜鶘的說法。(我不是在談論pelican-quickstart

我試圖尋找到鵜鶘項目我認爲它的主要功能__init__.py,但通常我會有一個可執行的包裝,調用這個主要功能,所以任何人都可以重定向到哪個函數上面的代碼傳遞參數傳遞給用戶?

+0

這些包裝是由產生的easy_install如你所期望的。然而,這是一個實現細節 - 爲什麼你需要知道這個通過'subprocess'模塊調用它?如果你想直接調用'main()'函數*,不需要通過包裝器,這是更相關的信息。 –

回答

1

pelican's setup.py

entry_points = { 
    'console_scripts': [ 
     'pelican = pelican:main', 
     'pelican-import = pelican.tools.pelican_import:main', 
     'pelican-quickstart = pelican.tools.pelican_quickstart:main', 
     'pelican-themes = pelican.tools.pelican_themes:main' 
    ] 
} 

因此,入口點pelican命令是pelican模塊中的main()功能;你也可以通過import pelican; pelican.main()來達到目的。 (同樣,對於pelican-quickstartimport pelican.tools.pelican_quickstart; pelican.tools.pelican_quickstart.main())。

要查找的文件:

import pelican 
print pelican.__file__ 

...或者,以獲得直接的main功能的手柄:

>>> from pkg_resources import load_entry_point 
>>> mainfunc = load_entry_point('pelican', 'console_scripts', 'pelican') 
>>> print mainfunc.__module__ 
'pelican' 
>>> mainfunc() 
WARNING: Feeds generated without SITEURL set properly may not be valid