Fix a couple more errors, and move stuff into a function.
This commit is contained in:
parent
627a5008de
commit
fb7cfecb01
1 changed files with 93 additions and 93 deletions
|
@ -44,6 +44,7 @@ def check_form(form, var):
|
|||
send_error('Multiple values given for "%s". Aborting.' % var)
|
||||
return ret
|
||||
|
||||
def main():
|
||||
os.umask(002)
|
||||
|
||||
authenticated = False
|
||||
|
@ -78,7 +79,7 @@ filename = None
|
|||
# In a submission, we don;t get a filename, just the file.
|
||||
if form.has_key('filename'):
|
||||
action = 'check'
|
||||
filename = check_form('filename')
|
||||
filename = check_form(form, 'filename')
|
||||
filename = os.path.basename(filename)
|
||||
print >> sys.stderr, 'Checking file status: NAME=%s FILENAME=%s MD5SUM=%s' % (name, filename, md5sum)
|
||||
else:
|
||||
|
@ -87,10 +88,7 @@ else:
|
|||
upload_file = form['file']
|
||||
if not upload_file.file:
|
||||
send_error('No file given for upload. Aborting.')
|
||||
try:
|
||||
filename = os.path.basename(upload_file.filename)
|
||||
except:
|
||||
send_error('Could not extract the filename for upload. Aborting.')
|
||||
else:
|
||||
send_error('Required field "file" is not present.')
|
||||
print >> sys.stderr, 'Processing upload request: NAME=%s FILENAME=%s MD5SUM=%s' % (name, filename, md5sum)
|
||||
|
@ -126,7 +124,7 @@ if not os.path.isdir(module_dir):
|
|||
|
||||
# grab a temporary filename and dump our file in there
|
||||
tempfile.tempdir = module_dir
|
||||
tmpfile = tempfile.mktemp(md5sum)
|
||||
tmpfile = tempfile.mkstemp(md5sum)
|
||||
tmpfd = open(tmpfile, 'w')
|
||||
|
||||
# now read the whole file in
|
||||
|
@ -143,15 +141,17 @@ while True:
|
|||
# now we're done reading, check the MD5 sum of what we got
|
||||
tmpfd.close()
|
||||
check_md5sum = m.hexdigest()
|
||||
if md5sum != check_md5sum
|
||||
if md5sum != check_md5sum:
|
||||
send_error("MD5 check failed. Received %s instead of %s." % (check_md5sum, md5sum))
|
||||
|
||||
# wow, even the MD5SUM matches. make sure full path is valid now
|
||||
if not os.path.isdir(md5_dir):
|
||||
os.mkdirs(md5_dir, 02775)
|
||||
os.makedirs(md5_dir, 02775)
|
||||
print >> sys.stderr, 'mkdir %s' % md5_dir
|
||||
|
||||
os.rename(tmpfile, dest_file)
|
||||
print >> sys.stderr, 'Stored %s (%d bytes)' % (dest_file, filesize)
|
||||
print 'File %s size %d MD5 %s stored OK' % (filename, filesize, md5sum)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue