2010-10-24 35 views
2

我寫了一個bash腳本,它根據收到的數據重命名MythTV文件。我用bash編寫它,因爲bash具有文本數據操作和易用性的優點。
你可以在這裏看到腳本本身:http://code.google.com/p/mythicallibrarian/source/browse/trunk/mythicalLibrarianMythTV的Bash腳本,需要Python依賴關係

我有幾個用戶,這是第一次使用Linux的用戶。我在這裏創建了一個安裝腳本,它檢查依賴關係並以圖形方式設置。您可以在此處看到設置腳本:http://code.google.com/p/mythicallibrarian/source/browse/trunk/mythicalSetup.sh

最近,MythTV發生了一些變化,這要求我將mythicalLibrarian中的mysql數據庫訪問權移植到Python綁定腳本中。在這裏:http://code.google.com/p/mythicallibrarian/source/browse/trunk/pythonBindings/MythDataGrabber

使用的系統類似這樣的以前,我測試過的依賴關係:

test "`uname`" != "Darwin" && LinuxDep=1 || LinuxDep=0 

if which agrep >/dev/null; then 
     echo "Verified agrep exists" 
else 
     test "$LinuxDep" = "1" && echo "Please install 'agrep' on your system" || echo "Please obtain MacPorts and install package agrep" 
     d="agrep " 
fi 
......................... 
if which agrep>/dev/null && which curl>/dev/null && which dialog>/dev/null; then 
     echo "All checks complete!!!" 
else 
     echo "the proper dependencies must be installed..." 
     echo "The missing dependencies are $a$b$c$d$e" 
     test "$LinuxDep" = "1" && echo "Debian based users run: apt-get install $a$b$c$d$e" || echo "Please obtain MacPorts and run: port install $a$b$c" 
     if [ "$LinuxDep" = "0" ]; then 
       read -n1 -p " Would you like some help on installing MacPorts? Select: (y)/n" MacPortsHelp 

蟒蛇的依賴使其更有點困難。我不知道如何測試系統上是否有linux libacthge「libmyth-python」和「python-lxml」。

如何,從BASH,我可以測試我的Python腳本MythDataGrabber有

from MythTV import MythDB 

條件滿意嗎?

回答

5

您可以檢查的狀態代碼:

python -c "import MythDB.MythTV" 

如果返回非零值,有一個錯誤,可能一個ImportError。

0

寫Python腳本:

try: 
    from MythTV import MythDB 
    print "Yes" 
except ImportError: 
    print "No" 

然後運行從您的bash腳本的Python腳本,並檢查其輸出。