Skip to content

Commit

Permalink
支持模块自定义配置安装
Browse files Browse the repository at this point in the history
  • Loading branch information
lovesoo committed Oct 30, 2017
1 parent 1cadb3c commit 4559e71
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 9 deletions.
27 changes: 20 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ QQ交流群:[25452556](https://jq.qq.com/?_wv=1027&k=5pqB0UV)

## 0. 更新记录

20171030 v1.6 支持模块自定义配置安装,详见[**setup.py**](https://github.com/lovesoo/Taffy/blob/master/setup.py)

20171015 v1.5 新增《[**Taffy入门教学视频**](http://v.youku.com/v_show/id_XMzA4NTk2MDI5Mg==.html)

20171010 v1.4 支持分布式模式运行locust

20171009 v1.3 统一配置文件格式为YAML

20170928 v1.2 集成locust,同一脚本可同时进行功能自动化及性能测试,详见[附录7-1](https://github.com/lovesoo/Taffy#71-locust框架集成使用说明)
20170928 v1.2 集成locust,同一脚本可同时进行功能自动化及性能测试,详见[**附录7-1**](https://github.com/lovesoo/Taffy#71-locust框架集成使用说明)

20170922 v1.1 集成selenium,新增相关测试demo

Expand Down Expand Up @@ -95,17 +97,28 @@ QQ交流群:[25452556](https://jq.qq.com/?_wv=1027&k=5pqB0UV)
3) 第三方lib
[Taffy/requirements.txt文件 ](https://github.com/lovesoo/Taffy/blob/master/requirements.txt)中存放了Taffy用到的第三方lib,可以使用pip直接安装
[requirements.txt ](https://github.com/lovesoo/Taffy/blob/master/requirements.txt)中存放了Taffy用到的第三方lib库,可以通过[setup.py](https://github.com/lovesoo/Taffy/blob/master/setup.py)进行最大化、最小化及自定义模块安装配置
```
#批量安装
pip install -r requirements.txt
# 默认最大化安装全部模块
$ python setup.py
# -m或--min,最小化安装
$ python setup.py -m
# -w或--without A B,不安装模块A,B
$ python setup.py --without db redis locust
# --with A B,在最小化安装基础上,只安装模块A,B
$ python setup.py --with db redis locust
# --with及--without 支持配置的模块列表为:[redis,security,db,webservice,selenium,locust,hessian]
#可以单独安装xxxlib
pip install xxxlib
# -h或--help,查看帮助
$ python setup.py -h
```
Windows下,一些棘手的lib安装方法:
当默认最大化安装全部模块时,Windows系统下一些棘手的lib安装方法:
1) mysql-python
Expand Down
2 changes: 2 additions & 0 deletions Tests/test_Selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,5 @@ def test_Err_User(self):
def test_Err_Passwd(self):
# 测试用例:密码错误,登陆失败
test_login.login(self, self.user, '123456', self.tips)


2 changes: 0 additions & 2 deletions Util/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#coding=utf-8

from checkTool import *
from commonTool import *
from DBTool import *
Expand Down
85 changes: 85 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# coding:utf-8
import sys
import os

# Taffy运行lib库自定义配置安装
# 默认全部安装,可选最小配置 -m,或选择只需 --with /不需安装 --without的模块
# 可自选只需/不需安装的模块列表[redis,security,db,webservice,selenium,locust,hessian]
# 更多帮助请查看:python setup.py --help


def markfile(modules=[], mark=True):
try:
# 注释/解除注释模块
if not modules:
for tfile in [init_file, requirements_file]:
lines = open(tfile, 'r').readlines()
flen = len(lines)
for i in range(flen):
if '#' not in lines[i] and mark:
lines[i] = lines[i].replace(lines[i], '#' + lines[i])
elif '#' in lines[i] and not mark:
lines[i] = lines[i].replace(lines[i], lines[i].strip('#'))
open(tfile, 'w').writelines(lines)
else:
if 'security' in modules:
modules.append('pycrypto')
if 'db' in modules:
modules.append('sql')
if 'webservice' in modules:
modules.append('suds')

for tfile in [init_file, requirements_file]:
for module in modules:
lines = open(tfile, 'r').readlines()
flen = len(lines)
for i in range(flen):
if '#' not in lines[i] and mark and module.lower() in lines[i].lower():
lines[i] = lines[i].replace(lines[i], '#' + lines[i])
elif '#' in lines[i] and not mark and module.lower() in lines[i].lower():
lines[i] = lines[i].replace(lines[i], lines[i].strip('#'))
open(tfile, 'w').writelines(lines)
except Exception as e:
print e


if __name__ == '__main__':
requirements_file = 'requirements.txt'
init_file = 'Util/__init__.py'
ROOT = os.path.abspath(os.path.dirname(__file__))
requirements_file = os.path.join(ROOT, requirements_file)
init_file = os.path.join(ROOT, init_file)
all_modules = ['redis', 'security', 'db', 'webservice', 'selenium', 'locust', 'hessian']

# 默认安装所有模块
markfile(mark=False)
if len(sys.argv) < 2:
print 'Taffy setup with all modules.'
elif '-m' == sys.argv[1] or 'min'in sys.argv[1]:
print 'Taffy setup with the minimum modules.'
markfile(all_modules)
elif '-w' == sys.argv[1] or 'without' in sys.argv[1]:
if all([m in all_modules for m in sys.argv[2:]]):
print 'Taffy setup without the modules:', sys.argv[2:]
markfile(sys.argv[2:])
else:
print '{0} not all in the supported modules list {1}'.format(sys.argv[2:], all_modules)
elif '-with' == sys.argv[1] or '--with' == sys.argv[1]:
if all([m in all_modules for m in sys.argv[2:]]):
print 'Taffy setup with the modules:', sys.argv[2:]
markfile([m for m in all_modules if m not in sys.argv[2:]])
else:
print '{0} not all in the supported modules list {1}'.format(sys.argv[2:], all_modules)
elif '-h' == sys.argv[1] or 'help' in sys.argv[1]:
print 'Taffy setup.py help document.'
print 'Usage: python setup.py [options]'
print 'Options:'
print '\t-h, --help\tshow this help message and exit'
print '\t-m, --min\tsetup with the minimum modules'
print '\t-w module A [module B...], --without module A [module B...]\tsetup without the modules, eg "--without redis security db".'
print '\t--with module A [module B...]\tsetup only with the modules, eg "--with redis security db".'
print '\t\tSupported setup with/without modules are [redis,security,db,webservice,selenium,locust,hessian]'
else:
assert False, 'Not supported option and see --help for available options.'

os.system('pip install -r {0}'.format(requirements_file))

0 comments on commit 4559e71

Please sign in to comment.