Commit 2fe62fcb authored by Mikaël Salson's avatar Mikaël Salson Committed by Vidjil Team
Browse files

Server: Move useful function in another module

The reason is not clear. But it avoids web2py complaining about not knowing format_size
parent 1910a774
# coding: utf8 # coding: utf8
import gluon.contrib.simplejson import gluon.contrib.simplejson
import defs import defs
import vidjil_utils
import os import os
if request.env.http_origin: if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
...@@ -129,7 +130,7 @@ def upload(): ...@@ -129,7 +130,7 @@ def upload():
mes = f.filename + ": upload finished" mes = f.filename + ": upload finished"
seq_file = defs.DIR_SEQUENCES+db.sequence_file[request.vars["id"]].data_file seq_file = defs.DIR_SEQUENCES+db.sequence_file[request.vars["id"]].data_file
size = defs.format_size(os.path.getsize(seq_file)) size = vidjil_utils.format_size(os.path.getsize(seq_file))
db.sequence_file[request.vars["id"]] = dict(size_file = size) db.sequence_file[request.vars["id"]] = dict(size_file = size)
res = {"message": mes} res = {"message": mes}
......
import math
### Upload directory for .fasta/.fastq. ### Upload directory for .fasta/.fastq.
### Old sequences files could be thrown away. ### Old sequences files could be thrown away.
### No regular backup. ### No regular backup.
...@@ -16,20 +14,3 @@ DIR_RESULTS = '/mnt/result/results/' ...@@ -16,20 +14,3 @@ DIR_RESULTS = '/mnt/result/results/'
DIR_OUT_VIDJIL_ID = '/mnt/result/tmp/out-%06d/' DIR_OUT_VIDJIL_ID = '/mnt/result/tmp/out-%06d/'
def format_size(n):
'''
Takes an integer n, representing a filesize and returns a string
where the size is formatted in M, G, ...
Example:
>>> format_size(1000000)
1.0 MB
>>> format_size(1024*1014*1024)
1.073 GB
'''
size = math.floor((n/1000)/1000)
if size > 1000 :
size = str( round( (size/1000), 3 ) ) + " GB"
else :
size = str( math.floor(size) ) + " MB"
return size
import math
def format_size(n):
'''
Takes an integer n, representing a filesize and returns a string
where the size is formatted in M, G, ...
Example:
>>> format_size(1000000)
1.0 MB
>>> format_size(1024*1014*1024)
1.073 GB
'''
size = math.floor((n/1000)/1000)
if size > 1000 :
size = str( round( (size/1000), 3 ) ) + " GB"
else :
size = str( math.floor(size) ) + " MB"
return size
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment