uploader with progress bar. reown log file
This commit is contained in:
11
code/app.py
11
code/app.py
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os,sys,time,stat
|
||||
import os, sys, time
|
||||
import json
|
||||
from datetime import datetime
|
||||
from flask import Flask, render_template, jsonify, current_app, Response, \
|
||||
@@ -883,15 +883,6 @@ def secure_filename_hidden(filename):
|
||||
return secure
|
||||
|
||||
|
||||
def set_rights(path):
|
||||
os.chown(path, app.config['UID'], app.config['GID'])
|
||||
st = os.stat(path)
|
||||
if app.config['UID'] > 0:
|
||||
os.chmod(path, st.st_mode | stat.S_IRUSR | stat.S_IWUSR)
|
||||
if app.config['GID'] > 0:
|
||||
os.chmod(path, st.st_mode | stat.S_IRGRP | stat.S_IWGRP)
|
||||
|
||||
|
||||
def zip_share(share):
|
||||
if not os.path.exists(app.config['ZIP_FOLDER']):
|
||||
os.makedirs(app.config['ZIP_FOLDER'])
|
||||
|
||||
@@ -3,18 +3,15 @@ test -n "$1" || {
|
||||
echo "Add files to upload as argument"
|
||||
exit 1
|
||||
}
|
||||
CAT=$( which cat )
|
||||
which pv &> /dev/null && CAT=$( which pv )
|
||||
ROOTURL="{{ rooturl }}"
|
||||
SHARE="{{ name }}"
|
||||
TOKEN="{{ token }}"
|
||||
|
||||
send_file() {
|
||||
$CAT "$file_name" | curl -F "file=@-;filename=${base_name}" "${ROOTURL}upload/${SHARE}/${TOKEN}"
|
||||
cat "$file_name" | curl --progress-bar -F "file=@-;filename=${base_name}" "${ROOTURL}upload/${SHARE}/${TOKEN}" | cat -
|
||||
}
|
||||
send_folder() {
|
||||
which pv &> /dev/null && printf -v dusize -- "--size %dk" $( du -s -k "$file_name" | cut -f1 )
|
||||
tar cz "$file_name" | $CAT $dusize - | curl -F "file=@-;filename=${base_name}.tgz" ${ROOTURL}upload/${SHARE}/${TOKEN}
|
||||
tar cz "$file_name" | curl --progress-bar -F "file=@-;filename=${base_name}.tgz" "${ROOTURL}upload/${SHARE}/${TOKEN}" | cat -
|
||||
}
|
||||
|
||||
for file_name in "$@"; do
|
||||
|
||||
@@ -4,6 +4,7 @@ from flask import current_app as app
|
||||
import requests
|
||||
import re
|
||||
import json
|
||||
import stat
|
||||
try:
|
||||
import magic
|
||||
except ImportError:
|
||||
@@ -21,8 +22,10 @@ except ImportError:
|
||||
from urlparse import urlparse
|
||||
|
||||
class Logger:
|
||||
def __init__(self, filename):
|
||||
def __init__(self, filename, uid = 0, gid = 0):
|
||||
self.filename = filename
|
||||
self.uid = uid
|
||||
self.gid = gid
|
||||
self.init()
|
||||
|
||||
|
||||
@@ -32,6 +35,26 @@ class Logger:
|
||||
|
||||
def init(self):
|
||||
self.info("Service started")
|
||||
self.set_rights()
|
||||
|
||||
|
||||
def set_rights(self):
|
||||
os.chown(
|
||||
self.filename,
|
||||
self.uid,
|
||||
self.gid
|
||||
)
|
||||
st = os.stat(self.filename)
|
||||
if self.uid > 0:
|
||||
os.chmod(
|
||||
self.filename,
|
||||
st.st_mode | stat.S_IRUSR | stat.S_IWUSR
|
||||
)
|
||||
if self.gid > 0:
|
||||
os.chmod(
|
||||
self.filename,
|
||||
st.st_mode | stat.S_IRGRP | stat.S_IWGRP
|
||||
)
|
||||
|
||||
|
||||
def warning(self, message):
|
||||
@@ -230,7 +253,6 @@ def read_config(app):
|
||||
app.config['LOG_FILE'] = config_values['log_file']
|
||||
else:
|
||||
app.config['LOG_FILE'] = os.path.join(app.config['UPLOAD_FOLDER'], 'flees.log')
|
||||
app.config['LOGGER'] = Logger(app.config['LOG_FILE'])
|
||||
app.config['ZIP_FOLDER'] = config_values['zip_folder']
|
||||
app.config['MAX_ZIP_SIZE'] = config_values['max_zip_size'] # megabytes
|
||||
app.config['DATE_FORMAT'] = config_values['date_format']
|
||||
@@ -239,6 +261,11 @@ def read_config(app):
|
||||
app.config['DEBUG'] = config_values['debug']
|
||||
app.config['VERSION_FOLDER'] = config_values['version_folder']
|
||||
app.config['SESSION_COOKIE_NAME'] = secure_filename(config_values['site_name'])
|
||||
app.config['LOGGER'] = Logger(
|
||||
app.config['LOG_FILE'],
|
||||
app.config['UID'],
|
||||
app.config['GID']
|
||||
)
|
||||
return config_values
|
||||
|
||||
def safe_name(s):
|
||||
@@ -255,3 +282,12 @@ def safe_string(s, valid, no_repeat = False):
|
||||
if no_repeat:
|
||||
safe = re.sub(r'_+', '_', safe)
|
||||
return safe
|
||||
|
||||
|
||||
def set_rights(path):
|
||||
os.chown(path, app.config['UID'], app.config['GID'])
|
||||
st = os.stat(path)
|
||||
if app.config['UID'] > 0:
|
||||
os.chmod(path, st.st_mode | stat.S_IRUSR | stat.S_IWUSR)
|
||||
if app.config['GID'] > 0:
|
||||
os.chmod(path, st.st_mode | stat.S_IRGRP | stat.S_IWGRP)
|
||||
|
||||
Reference in New Issue
Block a user