Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# cur.execute("SELECT filename FROM uploads where indexno=%s and key=%s", [file_number, session['uid']])
# for d in cur:
# result['path'] = get_path_from_file_number(file_number)
# result['filename'] = d[0]
# result['extension'], result['mimetype'] = get_ext_and_mimetype(result['filename'])
# result['fullpath'] = result['path'] + '.' + result['extension']
# break
# conn.commit()
if 'path' not in result:
logmessage("path is not in result for " + str(file_number))
return result
filename = result['path'] + '.' + result['extension']
if os.path.isfile(filename):
add_info_about_file(filename, result)
else:
logmessage("Filename DID NOT EXIST.")
return(result)
audio_file = SavedFile(new_file_number, extension='mp3', fix=True)
audio_file.fetch_url(url)
if audio_file.size_in_bytes() > 100:
call_array = [daconfig['pacpl'], '-t', 'ogg', audio_file.path + '.mp3']
result = call(call_array)
if result != 0:
logmessage("Failed to convert downloaded mp3 (" + path + ") to ogg")
abort(404)
entry.upload = new_file_number
audio_file.finalize()
db.session.commit()
else:
logmessage("Download from voicerss (" + path + ") failed")
abort(404)
if not entry.upload:
logmessage("Upload file number was not set")
abort(404)
if not audio_file:
audio_file = SavedFile(entry.upload, extension='mp3', fix=True)
the_path = audio_file.path + '.' + file_format
if not os.path.isfile(the_path):
logmessage("Could not serve speak file because file (" + the_path + ") not found")
abort(404)
return(send_file(the_path, mimetype=audio_mimetype_table[file_format]))
result['filename'] = upload.filename
result['extension'], result['mimetype'] = get_ext_and_mimetype(result['filename'])
result['savedfile'] = SavedFile(file_number, extension=result['extension'], fix=True)
result['path'] = result['savedfile'].path
result['fullpath'] = result['path'] + '.' + result['extension']
# cur = conn.cursor()
# cur.execute("SELECT filename FROM uploads where indexno=%s and key=%s", [file_number, session['uid']])
# for d in cur:
# result['path'] = get_path_from_file_number(file_number)
# result['filename'] = d[0]
# result['extension'], result['mimetype'] = get_ext_and_mimetype(result['filename'])
# result['fullpath'] = result['path'] + '.' + result['extension']
# break
# conn.commit()
if 'path' not in result:
logmessage("path is not in result for " + str(file_number))
return result
filename = result['path'] + '.' + result['extension']
if os.path.isfile(filename):
add_info_about_file(filename, result)
else:
logmessage("Filename DID NOT EXIST.")
return(result)
def update_references(filename):
initialize_libreoffice()
subprocess_arguments = [LIBREOFFICE_PATH, '--headless', '--invisible', 'macro:///Standard.Module1.PysIndexer(' + filename + ')']
tries = 0
while tries < 5:
docassemble.base.functions.server.applock('obtain', 'libreoffice')
p = subprocess.Popen(subprocess_arguments, cwd=tempfile.gettempdir())
result = p.wait()
docassemble.base.functions.server.applock('release', 'libreoffice')
if result == 0:
break
logmessage("update_references: call to LibreOffice returned non-zero response")
tries += 1
time.sleep(0.5 + tries*random.random())
if result != 0:
return False
return True
if use_libreoffice:
initialize_libreoffice()
#logmessage("Trying libreoffice with " + repr(subprocess_arguments))
docassemble.base.functions.server.applock('obtain', 'libreoffice')
p = subprocess.Popen(subprocess_arguments, cwd=tempdir)
result = p.wait()
docassemble.base.functions.server.applock('release', 'libreoffice')
if os.path.isfile(to_file):
break
result = 1
tries += 1
time.sleep(0.5 + tries*random.random())
if use_libreoffice:
logmessage("Retrying libreoffice with " + repr(subprocess_arguments))
else:
logmessage("Retrying convertapi")
continue
if result == 0:
if password:
pdf_encrypt(to_file, password)
shutil.copyfile(to_file, out_file)
if tempdir is not None:
shutil.rmtree(tempdir)
if result != 0:
return False
return True
logmessage("Failed to convert downloaded mp3 (" + path + ") to ogg")
abort(404)
entry.upload = new_file_number
audio_file.finalize()
db.session.commit()
else:
logmessage("Download from voicerss (" + path + ") failed")
abort(404)
if not entry.upload:
logmessage("Upload file number was not set")
abort(404)
if not audio_file:
audio_file = SavedFile(entry.upload, extension='mp3', fix=True)
the_path = audio_file.path + '.' + file_format
if not os.path.isfile(the_path):
logmessage("Could not serve speak file because file (" + the_path + ") not found")
abort(404)
return(send_file(the_path, mimetype=audio_mimetype_table[file_format]))
def pixels_in(length):
m = re.search(r"([0-9.]+) *([a-z]+)", text_type(length).lower())
if m:
value = float(m.group(1))
unit = m.group(2)
#logmessage("value is " + text_type(value) + " and unit is " + unit + "\n")
if unit in unit_multipliers:
size = float(unit_multipliers[unit]) * value
#logmessage("size is " + text_type(size) + "\n")
return(int(size))
logmessage("Could not read " + text_type(length) + "\n")
return(300)
def page_path(self, page, prefix, wait=True):
"""Returns a path and filename at which a PDF page image can be accessed."""
if not hasattr(self, 'number'):
raise Exception("Cannot get path of file without a file number.")
if not hasattr(self, 'file_info'):
self.retrieve()
if 'fullpath' not in self.file_info:
raise Exception("fullpath not found.")
if 'pages' not in self.file_info:
raise Exception("number of pages not found.")
test_path = self.file_info['path'] + prefix + '-in-progress'
#logmessage("Test path is " + test_path)
if wait and os.path.isfile(test_path):
#logmessage("Test path exists")
while (os.path.isfile(test_path) and time.time() - os.stat(test_path)[stat.ST_MTIME]) < 30:
logmessage("Waiting for test path to go away")
if not os.path.isfile(test_path):
break
time.sleep(1)
if os.path.isfile(test_path) and hasattr(self, '_task' + prefix):
if wait:
server.wait_for_task(getattr(self, '_task' + prefix))
else:
return None
max_pages = 1 + int(self.file_info['pages'])
formatter = '%0' + str(len(str(max_pages))) + 'd'
the_path = self.file_info['path'] + prefix + '-' + (formatter % int(page)) + '.png'
if os.path.isfile(the_path):
return the_path
if hasattr(self, '_task' + prefix):
if server.wait_for_task(getattr(self, '_task' + prefix)):
self.retrieve()
elif isinstance(attachment, string_types) and re.search(r'^https?://', attachment):
attachment_list.append(attachment)
else:
logmessage("send_sms: attachment " + repr(attachment) + " is not valid.")
success = False
if success:
for the_attachment in attachment_list:
if type(the_attachment) is DAFile and the_attachment.ok:
#url = url_start + server.url_for('serve_stored_file', uid=this_thread.current_info['session'], number=the_attachment.number, filename=the_attachment.filename, extension=the_attachment.extension)
media.append(the_attachment.url_for(_external=True))
if type(the_attachment) is DAStaticFile:
media.append(the_attachment.url_for(_external=True))
elif isinstance(the_attachment, string_types):
media.append(the_attachment)
if len(media) > 10:
logmessage("send_sms: more than 10 attachments were provided; not sending message")
success = False
if success:
twilio_client = TwilioRestClient(tconfig['account sid'], tconfig['auth token'])
for recipient in to:
phone_number = phone_string(recipient)
if phone_number is not None:
if phone_number.startswith('whatsapp:'):
from_number = 'whatsapp:' + tconfig.get('whatsapp number', tconfig['number'])
else:
from_number = tconfig['number']
try:
if len(media):
message = twilio_client.messages.create(to=phone_number, from_=from_number, body=body, media_url=media)
else:
message = twilio_client.messages.create(to=phone_number, from_=from_number, body=body)
except Exception as errstr:
attached_file_count = 0
attachment_info = list()
for the_attachment in interview_status.attachments:
file_formats = list()
if 'pdf' in the_attachment['valid_formats'] or '*' in the_attachment['valid_formats']:
file_formats.append('pdf')
if include_rtfs and ('rtf' in the_attachment['valid_formats'] or '*' in the_attachment['valid_formats']):
file_formats.append('rtf')
for the_format in file_formats:
the_filename = the_attachment['file'][the_format]
if the_format == "pdf":
mime_type = 'application/pdf'
elif the_format == "rtf":
mime_type = 'application/rtf'
attachment_info.append({'filename': str(the_attachment['filename']) + '.' + str(the_format), 'path': str(the_filename), 'mimetype': str(mime_type), 'attachment': the_attachment})
logmessage("Need to attach to the e-mail a file called " + str(the_attachment['filename']) + '.' + str(the_format) + ", which is located on the server at " + str(the_filename) + ", with mime type " + str(mime_type))
attached_file_count += 1
if attached_file_count > 0:
doc_names = list()
for attach_info in attachment_info:
if attach_info['attachment']['name'] not in doc_names:
doc_names.append(attach_info['attachment']['name'])
subject = comma_and_list(doc_names)
if len(doc_names) > 1:
body = "Your " + subject + " are attached."
else:
body = "Your " + subject + " is attached."
html = "<p>" + body + "</p>"
logmessage("Need to send an e-mail with subject " + subject + " to " + str(attachment_email_address) + " with " + str(attached_file_count) + " attachment(s)")
msg = Message(subject, recipients=[attachment_email_address], body=body, html=html)
for attach_info in attachment_info:
with open(attach_info['path'], 'r') as fp: