|
@@ -0,0 +1,53 @@
|
|
|
|
+#!/usr/bin/env python
|
|
|
|
+# -*- coding: utf-8 -*-
|
|
|
|
+# 用于批量处理转换 运行多个转换容器
|
|
|
|
+import time
|
|
|
|
+import subprocess
|
|
|
|
+import os
|
|
|
|
+import pprint
|
|
|
|
+timeSleep = 15
|
|
|
|
+
|
|
|
|
+def redis(self):
|
|
|
|
+ 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
|
|
|
|
+
|
|
|
|
+def popen(command, bg=False):
|
|
|
|
+ string = command
|
|
|
|
+ if bg == True:
|
|
|
|
+ command = command + ' 1>/dev/null 2>&1 &'
|
|
|
|
+
|
|
|
|
+ popen = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
|
|
|
|
+ output = ''
|
|
|
|
+ Demeter.echo(string)
|
|
|
|
+ while True:
|
|
|
|
+ output = popen.stdout.readline()
|
|
|
|
+ pprint.pprint(output)
|
|
|
|
+ if popen.poll() is not None:
|
|
|
|
+ break
|
|
|
|
+ return output
|
|
|
|
+
|
|
|
|
+# 文档转换
|
|
|
|
+def convert():
|
|
|
|
+ r = redis()
|
|
|
|
+ c = 'office_file'
|
|
|
|
+ i = 0
|
|
|
|
+ while 1:
|
|
|
|
+ file = r.lpop(c)
|
|
|
|
+ if file:
|
|
|
|
+ g = command(file)
|
|
|
|
+ Shell.popen(g, True)
|
|
|
|
+ i = i+1
|
|
|
|
+ if i >= 10:
|
|
|
|
+ time.sleep(timeSleep)
|
|
|
|
+ i = 0
|
|
|
|
+
|
|
|
|
+def handle():
|
|
|
|
+ convert()
|
|
|
|
+
|
|
|
|
+handle()
|