def get_slide_urls(task, slide_files): subdir_path = helpers.get_id_subdir_path(task.id) return [ "http://" + localsettings.POWERPOINT_SERVER + "/" + subdir_path + "/" + task.id + "/" + os.path.basename(file) for file in slide_files ]
def backup_filename(bucket_name, key_name, filename): if localsettings.S3_BACKUP_DIR == "": return path = localsettings.S3_BACKUP_DIR + "/" + bucket_name + "/" if len(key_name) > 4: path += helpers.get_id_subdir_path(key_name) + "/" path += key_name dir = os.path.dirname(path) helpers._mkdir(dir) shutil.copyfile(filename, path)
def backup_string(bucket_name, key_name, contents): if localsettings.S3_BACKUP_DIR == "": return path = localsettings.S3_BACKUP_DIR + "/" + bucket_name + "/" if len(key_name) > 4: path += helpers.get_id_subdir_path(key_name) + "/" path += key_name dir = os.path.dirname(path) helpers._mkdir(dir) f = open(path, "wb") f.write(contents) f.close()
def backup_file(bucket_name, key_name, file): if localsettings.S3_BACKUP_DIR == "": return path = localsettings.S3_BACKUP_DIR + "/" + bucket_name + "/" if len(key_name) > 4: path += helpers.get_id_subdir_path(key_name) + "/" path += key_name dir = os.path.dirname(path) helpers._mkdir(dir) destfile = open(path, "wb") file.seek(0) shutil.copyfileobj(file, destfile) file.seek(0) destfile.close()
def process(self, task): print ("processing %s" % task.id) task.attempts += 1 task.started_at = datetime.datetime.now() task.save() success = False try: # 2. Extract the ppt file temp_dir = tempfile.mkdtemp() temp_path = temp_dir + "\\" + task.id + "." + task.filetype print ("temp_dir = %s" % temp_dir) print ("temp_path = %s" % temp_path) download_file(task.get_s3_url(), temp_path) output_dir = localsettings.POWERPOINT_DIR + "/" + helpers.get_id_subdir_path(task.id) + "/" + task.id helpers._mkdir(output_dir + "/") # 3. Send the ppt file to the C# program slide_files = process_ppt_file(temp_path, output_dir) # s3_slide_urls = save_slides_to_s3(task, slide_files) slide_urls = get_slide_urls(task, slide_files) for url in slide_urls: extension = url[-3:] if extension.lower() == "swf": html = ( "<html>" "<head>" "<title>Slide</title>" '<script src="%s"></script>' "</head>" "<body>" '<div id="swfwrapper">' '<div id="swfholder">' "You either have JavaScript turned off or an old version of Adobe's Flash Player." '<a href="http://www.macromedia.com/go/getflashplayer/">Click here to get the latest Flash player</a>.' "</div>" "</div>" "<script>" 'swfobject.embedSWF("%s",' '"swfholder",' '"100%%",' '"100%%",' '"9.0.60",' '"/media/swf/expressInstall.swf",' "{}," "{" "wmode: 'opaque'," "bgcolor: '#FFFFFF'," "allowScriptAccess: 'always'" "}," "{" "id: 'FlexClient2'" "});" "</script>" "</body>" "</html>" % (SWFOBJECT_URL, url) ) else: html = ( "<html>" "<head>" "<title>Slide</title>" '<style>@import url("/media/css/photo_importers.css");</style>' "</head>" "<body>" "<center>" '<img src="%s" />' "</center>" "</body>" "</html>" % (url) ) data = { "flowgram_id": task.flowgram.id, "ppt_req_id": task.id, "title": "Slide", "url": url, "html": html, } u = urllib2.urlopen(ADD_PPT_SLIDE_URL, urllib.urlencode(data)) u.close() task.status_code = StatusCode.DONE task.save() print ("task saved and status_code set to DONE") success = True except DownloadException: pass except Exception, e: print e print ("Failed attempt to process %s" % task.id)