Initial commit: файловое хранилище с веб-интерфейсом
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import os, shutil
|
||||
from flask import current_app
|
||||
|
||||
def get_disk_usage(path):
|
||||
try:
|
||||
usage = shutil.disk_usage(path)
|
||||
return {'total': usage.total, 'used': usage.used, 'free': usage.free, 'percent': round(usage.used/usage.total*100,2)}
|
||||
except:
|
||||
return {'total':0,'used':0,'free':0,'percent':0}
|
||||
|
||||
def allowed_file(filename):
|
||||
return '.' in filename and filename.rsplit('.',1)[1].lower() in current_app.config['ALLOWED_EXTENSIONS']
|
||||
|
||||
def format_size(bytes):
|
||||
if bytes == 0: return "0 Б"
|
||||
for unit in ['Б','КБ','МБ','ГБ','ТБ']:
|
||||
if bytes < 1024.0: return f"{bytes:.1f} {unit}"
|
||||
bytes /= 1024.0
|
||||
return f"{bytes:.1f} ПБ"
|
||||
Reference in New Issue
Block a user