2010-10-24 36 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脚本,并检查其输出。