Skip to content
This repository has been archived by the owner on Aug 23, 2020. It is now read-only.

Commit

Permalink
修正linux下的utf8logger.py中的bug,增加virtualenv和test脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
pandolia committed Mar 3, 2017
1 parent dd48ea8 commit 91adc35
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 5 deletions.
14 changes: 14 additions & 0 deletions qqbot-venv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
sudo pip install virtualenv

mkdir ~/Py3Venv
cd ~/Py3Venv
virtualenv --python=python3 --no-site-packages qqbot-venv

cd qqbot-venv/bin/
source activate

pip install requests==2.7.0
pip install certifi==2015.4.28
pip install flask==0.12

pip install qqbot
1 change: 1 addition & 0 deletions qqbot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

from .qqbotcls import QQBot, Main
from .qterm import QTerm
from .common import CallInNewConsole, EchoRun
39 changes: 38 additions & 1 deletion qqbot/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

import json, subprocess, threading, sys
import json, subprocess, threading, sys, platform, os

PY3 = sys.version_info[0] == 3

Expand Down Expand Up @@ -58,3 +58,40 @@ def getVal(self):
with self.lock:
val = self.val
return val

# usage: CallInNewConsole(['python', 'qterm.py'])
def CallInNewConsole(args=None):
args = sys.argv[1:] if args is None else args

if not args:
return 1

osName = platform.system()

if osName == 'Windows':
return subprocess.call(['start'] + list(args), shell=True)

elif osName == 'Linux':
cmd = subprocess.list2cmdline(args)
if HasCommand('mate-terminal'):
args = ['mate-terminal', '-e', cmd]
elif HasCommand('gnome-terminal'):
args = ['gnome-terminal', '-e', cmd]
elif HasCommand('xterm'):
args = ['sh', '-c', 'xterm -e %s &' % cmd]
else:
return 1
# args = ['sh', '-c', 'nohup %s >/dev/null 2>&1 &' % cmd]
return subprocess.call(args, preexec_fn=os.setpgrp)

elif osName == 'Darwin':
return subprocess.call(['open','-W','-a','Terminal.app'] + list(args))

else:
return 1
# return subprocess.Popen(list(args) + ['&'])

def EchoRun():
sys.stdout.write('\n>> ' + subprocess.list2cmdline(sys.argv[1:]))
raw_input() if not PY3 else input()
sys.exit(subprocess.call(sys.argv[1:]))
2 changes: 1 addition & 1 deletion qqbot/qconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
if p not in sys.path:
sys.path.insert(0, p)

version = 'v2.0.11'
version = 'v2.0.12'

sampleConfStr = '''{
Expand Down
2 changes: 1 addition & 1 deletion qqbot/utf8logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def write(self, s):
if sys.stdout.encoding in ('gbk', 'cp936'):
utf8Stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='gb18030')
else:
uff8Stdout = sys.stdout
utf8Stdout = sys.stdout

def Utf8Logger(name):
logger = logging.getLogger(name)
Expand Down
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from setuptools import setup

version = '2.0.11'
version = '2.0.12'

setup(
name = 'qqbot',
Expand All @@ -11,7 +11,9 @@
entry_points = {
'console_scripts': [
'qqbot = qqbot:Main',
'qq = qqbot:QTerm'
'qq = qqbot:QTerm',
'popup = qqbot:CallInNewConsole',
'echorun = qqbot:EchoRun'
]
},
install_requires = ['requests', 'certifi', 'flask'],
Expand Down
24 changes: 24 additions & 0 deletions test-bot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
source ~/Py3Venv/qqbot-venv/bin/activate

echo 请等待 QQBot 启动成功...
read -n 1

echorun qq help
echorun qq list buddy
echorun qq list group
echorun qq list discuss

echorun qq send buddy hcj nihao 你好 wohao
echorun qq send group connie wohao 我好 wohao
echorun qq send discuss "Eva、hcj" tahao 他好 tahao

echorun qq get buddy hcj
echorun qq get group connie
echorun qq get discuss "Eva、hcj"

echorun qq member group connie
echorun qq member discuss "Eva、hcj"

echorun qq restart

echorun qq stop
7 changes: 7 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source ~/Py3Venv/qqbot-venv/bin/activate
pip uninstall qqbot
pip install .

popup bash test-bot.sh

qqbot -u eva

0 comments on commit 91adc35

Please sign in to comment.