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