123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # 用于批量处理转换 运行多个转换容器
- import time
- import subprocess
- import os
- import pprint
- timeSleep = 15
- def redis():
- import redis
- host = '0.0.0.0'
- port = 6379
- pool = redis.ConnectionPool(host=host, port=int(port))
- return redis.Redis(connection_pool=pool)
- def command(file):
- #return 'dm call office-convert_call id=' + file
- return 'docker run -d -it --entrypoint python --rm -v /data/dm/container/share:/share -v /etc/hosts:/etc/hosts.main --env HOSTIP="172.30.0.6" --net=dm -v /data/dm/container/web:/www -v /data/dm/container/web/convert/static:/usr/local/convert/front/static -v /data/dm/container/web/convert/files:/usr/local/convert/runtime/files docker.dever.cc/office/convert /usr/local/convert/convert.py -f ' + file
- def popen(command, bg=False):
- string = command
- if bg == True:
- command = command + ' &'
- print command
- process = os.popen(command)
- output = process.read()
- process.close()
- print output
- return output
- # 文档转换
- def convert():
- r = redis()
- c = 'office_file'
- i = 0
- while 1:
- file = r.lpop(c)
- if file:
- g = command(file)
- popen(g, False)
- i = i+1
- if i >= 10:
- time.sleep(timeSleep)
- i = 0
- def handle():
- convert()
- handle()
|