Commit 15fbd540 authored by Daniel Stan's avatar Daniel Stan

impressions: storage_path modulaire

parent 949bbfe6
......@@ -13,18 +13,16 @@ import re
import os, os.path
import pwd
def get_storage_dir(login, filename):
def get_storage_path(login, filename):
"""Donne le chemin vers le fichier, pour enregistrement"""
if os.getenv('DBG_PRINTER', '0') == '0':
mkdir = ["sudo", "-n", "/usr/scripts/utils/chown_impressions.sh", login]
pattern = "/home/impressions/%s/%s"
cmd = ["sudo", "-n", "/usr/scripts/utils/chown_impressions.sh", login]
path = subprocess.check_output(cmd).strip()
return os.path.join(path, filename)
else:
curuser = pwd.getpwuid(os.getuid())[0]
mkdir = ["mkdir", "-p", "/tmp/intranet-%s/%s" % (curuser, login)]
pattern = "/tmp/intranet-%s/%%s/%%s" % curuser
subprocess.check_call(mkdir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
filepath = pattern % (login, filename)
return filepath
os.makedirs("/tmp/intranet-%s/%s" % (curuser, login))
return "/tmp/intranet-%s/%s/%s" % (curuser, login, filename)
def pdfinfo(filepath):
"""Renvoi le résultat d'un pdfinfo sur un fichier"""
......@@ -57,7 +55,7 @@ class UploadForm(forms.Form):
filename = out["fichier"].name
# On y enregistre ensuite le fichier
login_used = self.real_user
filepath = get_storage_dir(login_used, filename)
filepath = get_storage_path(login_used, filename)
with open(filepath, 'wb+') as destination:
for chunk in fichier.chunks():
destination.write(chunk)
......
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