root / snf-pithos-app / pithos / api / dispatch.py @ 1427ce62
History | View | Annotate | Download (2.8 kB)
1 |
from pithos.api.settings import (BACKEND_DB_MODULE, BACKEND_DB_CONNECTION, |
---|---|
2 |
BACKEND_BLOCK_MODULE, BACKEND_BLOCK_PATH, |
3 |
BACKEND_BLOCK_UMASK, |
4 |
BACKEND_QUEUE_MODULE, BACKEND_QUEUE_CONNECTION, |
5 |
BACKEND_QUOTA, BACKEND_VERSIONING) |
6 |
from pithos.backends import connect_backend |
7 |
from pithos.api.util import hashmap_md5 |
8 |
|
9 |
from django.core.mail import send_mail |
10 |
from django.utils.translation import ugettext as _ |
11 |
|
12 |
from astakos.im.settings import DEFAULT_FROM_EMAIL |
13 |
|
14 |
import socket |
15 |
from smtplib import SMTPException |
16 |
|
17 |
def update_md5(m): |
18 |
if m['resource'] != 'object' or m['details']['action'] != 'object update': |
19 |
return
|
20 |
|
21 |
backend = connect_backend(db_module=BACKEND_DB_MODULE, |
22 |
db_connection=BACKEND_DB_CONNECTION, |
23 |
block_module=BACKEND_BLOCK_MODULE, |
24 |
block_path=BACKEND_BLOCK_PATH, |
25 |
block_umask=BACKEND_BLOCK_UMASK, |
26 |
queue_module=BACKEND_QUEUE_MODULE, |
27 |
queue_connection=BACKEND_QUEUE_CONNECTION) |
28 |
backend.default_policy['quota'] = BACKEND_QUOTA
|
29 |
backend.default_policy['versioning'] = BACKEND_VERSIONING
|
30 |
|
31 |
path = m['value']
|
32 |
account, container, name = path.split('/', 2) |
33 |
version = m['details']['version'] |
34 |
meta = None
|
35 |
try:
|
36 |
meta = backend.get_object_meta(account, account, container, name, 'pithos', version)
|
37 |
if meta['checksum'] == '': |
38 |
size, hashmap = backend.get_object_hashmap(account, account, container, name, version) |
39 |
checksum = hashmap_md5(backend, hashmap, size) |
40 |
backend.update_object_checksum(account, account, container, name, version, checksum) |
41 |
print 'INFO: Updated checksum for path "%s"' % (path,) |
42 |
except Exception, e: |
43 |
print 'WARNING: Can not update checksum for path "%s" (%s)' % (path, e) |
44 |
|
45 |
backend.close() |
46 |
|
47 |
def send_sharing_notification(m): |
48 |
if m['resource'] != 'sharing': |
49 |
return
|
50 |
|
51 |
members = m['details']['members'] |
52 |
user = m['details']['user'] |
53 |
path = m['value']
|
54 |
account, container, name = path.split('/', 2) |
55 |
|
56 |
subject = 'Invitation to a Pithos+ shared object'
|
57 |
from_email = DEFAULT_FROM_EMAIL |
58 |
recipient_list = members |
59 |
message = 'User %s has invited you to a Pithos+ shared object. You can view it under "Shared to me" at "%s".' %(user, path)
|
60 |
try:
|
61 |
send_mail(subject, message, from_email, recipient_list) |
62 |
print 'INFO: Sharing notification sent for path "%s" to %s' % (path, ','.join(recipient_list)) |
63 |
except (SMTPException, socket.error) as e: |
64 |
print 'WARNING: Can not update send email for sharing "%s" (%s)' % (path, e) |