From 53164b56a8de0a95940e057e8d79b06378ecdb8b Mon Sep 17 00:00:00 2001 From: pandolia Date: Fri, 17 Feb 2017 22:15:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0raspbian=E7=9A=84=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ qqbot/common.py | 13 +++++-------- qqbot/qrcodemanager.py | 9 +++++++-- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 19b51d9..59c4640 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,8 @@ QQBot 是一个用 python 实现的、基于腾讯 SmartQQ 协议的简单 QQ 在命令行输入: **qqbot** 。启动过程中会自动弹出二维码图片,需要用手机 QQ 客户端扫码并授权登录。启动成功后,会将本次登录信息保存到本地文件中,下次启动时,可以输入: **qqbot -q qq号码** ,先尝试从本地文件中恢复登录信息(不需要手动扫码),只有恢复不成功或登录信息已过期时才会需要手动扫码登录。一般来说,保存的登录信息将在 2 ~ 3 天之后过期。 +注意: Linux 下,需要系统中有 gvfs-open 或者 shotwell 命令才能自动弹出二维码图片(一般系统中安装有 GNOME 虚拟文件系统 gvfs 的系统中都会含这两个命令之一)。若系统无法自动弹出二维码图片,可以手动打开图片文件进行扫码,也可以将二维码显示模式设置为邮箱模式或服务器模式进行远程扫码,详见本文档的第六节。 + ##### 2. 操作 QQBot QQBot 启动后,会自动弹出一个控制台窗口( qterm 客户端)用来输入操作 QQBot 的命令,目前提供以下命令: diff --git a/qqbot/common.py b/qqbot/common.py index e673f7f..764617e 100644 --- a/qqbot/common.py +++ b/qqbot/common.py @@ -45,11 +45,11 @@ def CallInNewConsole(args): elif osName == 'Linux': cmd = subprocess.list2cmdline(args) - if hasCommand('mate-terminal'): + if HasCommand('mate-terminal'): args = ['mate-terminal', '-e', cmd] - elif hasCommand('gnome-terminal'): + elif HasCommand('gnome-terminal'): args = ['gnome-terminal', '-x', cmd] - elif hasCommand('xterm'): + elif HasCommand('xterm'): args = ['sh', '-c', 'xterm -e %s &' % cmd] else: return 1 @@ -63,11 +63,8 @@ def CallInNewConsole(args): return 1 # return subprocess.Popen(list(args) + ['&']) -def hasCommand(procName): - try: - return procName in subprocess.check_output(['which', procName]) - except subprocess.CalledProcessError: - return False +def HasCommand(procName): + return subprocess.call(['which', procName], stdout=subprocess.PIPE) == 0 def StartThread(target, *args, **kwargs): daemon = kwargs.pop('daemon', False) diff --git a/qqbot/qrcodemanager.py b/qqbot/qrcodemanager.py index 3a2eb7e..d10d757 100644 --- a/qqbot/qrcodemanager.py +++ b/qqbot/qrcodemanager.py @@ -3,7 +3,7 @@ import os, platform, uuid, subprocess, time from utf8logger import WARN, INFO, DEBUG -from common import StartThread, LockedValue +from common import StartThread, LockedValue, HasCommand from qrcodeserver import QrcodeServer from mailagent import MailAgent @@ -118,7 +118,12 @@ def showImage(filename): filename = filename.decode('utf8').encode('cp936') retcode = subprocess.call([filename], shell=True) elif osName == 'Linux': - retcode = subprocess.call(['gvfs-open', filename]) + if HasCommand('gvfs-open'): + retcode = subprocess.call(['gvfs-open', filename]) + elif HasCommand('shotwell'): + retcode = subprocess.call(['shotwell', filename]) + else: + retcode = 1 elif osName == 'Darwin': # by @Naville retcode = subprocess.call(['open', filename]) else: