def videomaker_test(self): # Make sure tmp directory is clean to start with delete_files("tmp/*.mp4") key = "nosetest:video" path = [{'lineColor': 'black', 'y': 397, 'oldx': 813, 'oldy': 397, 'lineWidth': '3px', 'type': 'touchmove', 'x': 811}, {'lineColor': 'black', 'y': 398, 'oldx': 811, 'oldy': 397, 'lineWidth': '3px', 'type': 'touchmove', 'x': 809}, {'lineColor': 'black', 'y': 398, 'oldx': 809, 'oldy': 398, 'lineWidth': '3px', 'type': 'touchend', 'x': 809}, {'lineColor': 'black', 'y': 399, 'oldx': 809, 'oldy': 398, 'lineWidth': '3px', 'type': 'touchend', 'x': 900}, {'lineColor': 'black', 'y': 400, 'oldx': 900, 'oldy': 399, 'lineWidth': '3px', 'type': 'touchend', 'x': 910}, {'lineColor': 'black', 'y': 401, 'oldx': 910, 'oldy': 400, 'lineWidth': '3px', 'type': 'touchend', 'x': 920}, {'lineColor': 'black', 'y': 402, 'oldx': 920, 'oldy': 401, 'lineWidth': '3px', 'type': 'touchend', 'x': 930}, {'lineColor': 'black', 'y': 403, 'oldx': 930, 'oldy': 402, 'lineWidth': '3px', 'type': 'touchend', 'x': 940}, {'lineColor': 'black', 'y': 404, 'oldx': 940, 'oldy': 403, 'lineWidth': '3px', 'type': 'touchend', 'x': 950}, {'lineColor': 'black', 'y': 500, 'oldx': 950, 'oldy': 404, 'lineWidth': '3px', 'type': 'touchend', 'x': 960}, {'lineColor': 'black', 'y': 508, 'oldx': 960, 'oldy': 500, 'lineWidth': '3px', 'type': 'touchend', 'x': 1000}, {'lineColor': 'black', 'y': 511, 'oldx': 1000, 'oldy': 508, 'lineWidth': '3px', 'type': 'touchend', 'x': 900}, ] db_client = DbClientFactory.getDbClient(config.DB_CLIENT_TYPE) db_client.set(key, path) make_video(key) # Validation files = glob.glob("tmp/*") self.assertEquals(len(files), 1, "Expecting exactly one file in tmp directory") self.assertIn("mp4", files[0], "Expecting an video file") # Cleanup db_client.delete(key) delete_files("tmp/*.mp4") os.rmdir("tmp")
def process_uploaded_file_pdf(dir_path ,fname, room_topic, body): no=RealtimeHandler.gen_page_id() tmp_name=no # save target file os.makedirs(dir_path, exist_ok=True) file_path = os.path.join(dir_path, "%d.pdf"%tmp_name) # get file extension fext = os.path.splitext(fname)[1] # Convert the ppt files to pdf if fext.lower() != '.pdf': src_file = os.path.join(dir_path, "%d%s"%(tmp_name,fext.lower())) fh = open(src_file, 'wb') fh.write(body) fh.close() subprocess.call(['soffice', '--headless', '--invisible', '--convert-to', 'pdf', src_file, '--outdir', dir_path]) else: fh = open(file_path, 'wb') fh.write(body) fh.close() # Split the pdf files by pages subprocess.call(['pdfseparate', file_path, "%s/%d_%%d.pdf"%(dir_path,tmp_name)]) pages=len(glob.glob("%s/%d_*.pdf"%(dir_path,tmp_name))) page_list=[i+no for i in range(pages)] # Convert the pdf files to jpg subprocess.call(['mogrify', '-format', 'jpg', '--', "%s/%d_*.pdf"%(dir_path,tmp_name)]) ret=collections.OrderedDict() prefix=unsigned_hash("%s:%s:%s"%(dir_path,config.APP_IP_ADDRESS,config.APP_PORT)) q = queue.Queue() res='succ' with ThreadPoolExecutor(max_workers=100) as executor: for i in page_list: filename="%x%x.jpg"%(prefix, i) ret[i]=filename localfile = "%s/%d_%d.jpg"%(dir_path,tmp_name,i-tmp_name+1) with open(localfile, 'rb') as f: executor.submit(uploadfile, filename, f.read(), q) while not q.empty(): if q.get() != 'succ' : res='fail' break logger.info("upload all %s"%res) # Delete all the files delete_files('%s/%d_*.pdf'%(dir_path , tmp_name)) delete_files('%s/%d_*.jpg'%(dir_path , tmp_name)) if res=='succ': tornado.ioloop.IOLoop.instance().add_callback(callback=lambda: RealtimeHandler.on_uploadfile(room_topic,ret)) return res
def process_uploaded_file(dir_path, fname, key): logger = logging.getLogger("websocket") db_client = DbClientFactory.getDbClient(config.DB_CLIENT_TYPE) file_path = os.path.join(dir_path, fname) logger.info("Processing file %s" % file_path) # Split the pdf files by pages subprocess.call(["pdfseparate", file_path, dir_path + "/%d_image.pdf"]) # Convert the pdf files to png subprocess.call(["mogrify", "-format", "png", "--", dir_path + "/*image.pdf"]) # Delete all the files delete_files(dir_path + "/*image.pdf") logger.info("Finished processing file") # Insert the number of pages processed for that room db_key = "info:%s:npages" % key db_client.set(db_key, len(glob.glob(dir_path + "/*.png")))
def process_uploaded_file(dir_path, fname, key): logger = logging.getLogger('websocket') db_client = DbClientFactory.getDbClient(config.DB_CLIENT_TYPE) file_path = os.path.join(dir_path, fname) logger.info("Processing file %s" % file_path) # Split the pdf files by pages subprocess.call(['pdfseparate', file_path, dir_path + '/%d_image.pdf']) # Convert the pdf files to png subprocess.call( ['mogrify', '-format', 'png', '--', dir_path + '/*image.pdf']) # Delete all the files delete_files(dir_path + '/*image.pdf') logger.info("Finished processing file") # Insert the number of pages processed for that room db_key = "info:%s:npages" % key db_client.set(db_key, len(glob.glob(dir_path + '/*.png')))
def uploadprocessor_test(self): dir_path = os.path.abspath("./files") key = "nosetest:upload" process_uploaded_file(dir_path, "sample.pdf", key) output_files = os.listdir(dir_path) self.assertEquals(len(output_files), 11) self.assertIn("sample.pdf", output_files) for i in range(0, 10): self.assertIn(str(i + 1) + "_image.png", output_files) key = "info:%s:npages" % key db_client = DbClientFactory.getDbClient(config.DB_CLIENT_TYPE) self.assertEquals(int(db_client.get(key)), 10) # Cleanup db_client.delete(key) delete_files(dir_path + "/*.png")
def videomaker_test(self): # Make sure tmp directory is clean to start with delete_files("tmp/*.mp4") key = "nosetest:video" path = [ { 'lineColor': 'black', 'y': 397, 'oldx': 813, 'oldy': 397, 'lineWidth': '3px', 'type': 'touchmove', 'x': 811 }, { 'lineColor': 'black', 'y': 398, 'oldx': 811, 'oldy': 397, 'lineWidth': '3px', 'type': 'touchmove', 'x': 809 }, { 'lineColor': 'black', 'y': 398, 'oldx': 809, 'oldy': 398, 'lineWidth': '3px', 'type': 'touchend', 'x': 809 }, { 'lineColor': 'black', 'y': 399, 'oldx': 809, 'oldy': 398, 'lineWidth': '3px', 'type': 'touchend', 'x': 900 }, { 'lineColor': 'black', 'y': 400, 'oldx': 900, 'oldy': 399, 'lineWidth': '3px', 'type': 'touchend', 'x': 910 }, { 'lineColor': 'black', 'y': 401, 'oldx': 910, 'oldy': 400, 'lineWidth': '3px', 'type': 'touchend', 'x': 920 }, { 'lineColor': 'black', 'y': 402, 'oldx': 920, 'oldy': 401, 'lineWidth': '3px', 'type': 'touchend', 'x': 930 }, { 'lineColor': 'black', 'y': 403, 'oldx': 930, 'oldy': 402, 'lineWidth': '3px', 'type': 'touchend', 'x': 940 }, { 'lineColor': 'black', 'y': 404, 'oldx': 940, 'oldy': 403, 'lineWidth': '3px', 'type': 'touchend', 'x': 950 }, { 'lineColor': 'black', 'y': 500, 'oldx': 950, 'oldy': 404, 'lineWidth': '3px', 'type': 'touchend', 'x': 960 }, { 'lineColor': 'black', 'y': 508, 'oldx': 960, 'oldy': 500, 'lineWidth': '3px', 'type': 'touchend', 'x': 1000 }, { 'lineColor': 'black', 'y': 511, 'oldx': 1000, 'oldy': 508, 'lineWidth': '3px', 'type': 'touchend', 'x': 900 }, ] db_client = DbClientFactory.getDbClient(config.DB_CLIENT_TYPE) db_client.set(key, path) make_video(key) # Validation files = glob.glob("tmp/*") self.assertEquals(len(files), 1, "Expecting exactly one file in tmp directory") self.assertIn("mp4", files[0], "Expecting an video file") # Cleanup db_client.delete(key) delete_files("tmp/*.mp4") os.rmdir("tmp")