dever 6 年 前
コミット
ffded38873
5 ファイル変更71 行追加39 行削除
  1. 2 2
      admin/page/site.py
  2. 9 1
      front/static/document.js
  3. 1 0
      front/static/layer.js
  4. 30 32
      master_cron.py
  5. 29 4
      service/convert.py

+ 2 - 2
admin/page/site.py

@@ -85,7 +85,7 @@ class convert_path(Load):
 			,width = '600'
 			,height = '600'
 			,edit = False
-			,search = (('label-1','cdate-time-start','cdate-time-end','site_id-select-','status-select-','name-input-mlike'), (u'日期范围',u'开始时间',u'截止时间',u'选择站点',u'选择状态',u'文件名'))
+			,search = (('label-1','cdate-time-start','cdate-time-end','site_id-select-','status-select-','name-input-mlike','url-input-mlike','file_id-input-'), (u'日期范围',u'开始时间',u'截止时间',u'选择站点',u'选择状态',u'文件名',u'新文件名',u'文件ID'))
 			,thead = (u'文件id',u'所属站点', u'源文件', u'文件名', u'访问路径', u'状态', u'更新时间')
 			,tbody = ('id','site', 'file','name', 'url', 'status', 'cdate')
 			,state = True
@@ -104,7 +104,7 @@ class convert_path(Load):
 				site = self.service('common').one('site', id=value['site_id'])
 				self.data['list'][key]['site'] = site['name']
 				if value['status'] == 3:
-					self.data['list'][key]['url'] = '<a href="'+str(value['url'])+'" target="_blank">[点此访问]</a>'
+					self.data['list'][key]['url'] = '<a href="'+str(value['url']).replace('.html', '.pdf')+'" target="_blank">[点此访问]</a>'
 				else:
 					self.data['list'][key]['url'] = '无法访问'
 				self.data['list'][key]['status'] = status[value['status']]

+ 9 - 1
front/static/document.js

@@ -29,9 +29,11 @@ var Document =
     left : 0,
     zoom : 18,
     path : '',
+    loadNum : 0,
     Init : function(option)
     {
         var self = this;
+        this.loadNum = 0;
 
         $(window).load(function()
         {
@@ -164,7 +166,13 @@ var Document =
         if (doc.find('.pc').length) {
             this.SetOffset(i,index,doc);
         } else {
-            this.LoadDoc(i,index,doc);
+            if (this.loadNum > 5) {
+                this.loadNum = 1;
+                layer.close(index);
+            } else {
+                this.loadNum = this.loadNum + 1;
+                this.LoadDoc(i,index,doc); 
+            }
         }
     }
 

ファイルの差分が大きいため隠しています
+ 1 - 0
front/static/layer.js


+ 30 - 32
master_cron.py

@@ -7,47 +7,45 @@ 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 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 '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 + ' 1>/dev/null 2>&1 &'
+        string = command
+        if bg == True:
+                command = command + ' &'
 
-	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
+        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)
-			Shell.popen(g, True)
-		i = i+1
-		if i >= 10:
-			time.sleep(timeSleep)
-			i = 0
+        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()
+        convert()
 
 handle()

+ 29 - 4
service/convert.py

@@ -1,4 +1,5 @@
 # -*- coding: utf-8 -*-
+from __future__ import division
 from .__load__ import *
 
 class Convert(object):
@@ -300,10 +301,24 @@ class Convert(object):
 
 			Demeter.curl(api, param, 'post')
 
-
 	def cut(self, info):
+		from pdf2jpg import pdf2jpg
+		from wand.image import Image
+		dest = info['html'] + '.photo'
+		result = pdf2jpg.convert_pdf2jpg(info['pdf'], dest, pages="0")
+		source = result[0]['output_jpgfiles'][0]
+		dest = info['html'] + '.jpg'
+		command = 'mv '+source+' ' + dest
+		Shell.popen(command)
+		target_width = 300
+		with Image(filename=dest) as img:
+			target_width, target_height = self.getSize(target_width, img.width, img.height)
+			img.sample(target_width, target_height)
+			img.save(filename=dest)
+
+		'''
 		from wand.image import Image
-		pdf = Image(filename=info['pdf'], resolution=50)
+		pdf = Image(filename=source, resolution=50)
 		jpg = pdf.convert('jpg')
 		req_image = []
 		i = 0
@@ -313,11 +328,21 @@ class Convert(object):
 				req_image.append(img_page.make_blob('jpg'))
 			i = i+1
 
-		dest = info['html']
 		for img in req_image:
-			ff = open(dest + '.jpg','wb')
+			ff = open(dest, 'wb')
 			ff.write(img)
 			ff.close()
+		'''
+
+
+	def getSize(self, target_width, img_width, img_height):
+		if img_width > target_width:
+			ratio = target_width / img_width
+			target_height = int(ratio * img_height)
+		else:
+			target_width = img_width
+			target_height = img_height
+		return target_width, target_height
 
 	def string_switch(self, x,y,z,s=1):
 		with open(x, "r", encoding="utf-8") as f:

この差分においてかなりの量のファイルが変更されているため、一部のファイルを表示していません