Statistics
| Branch: | Tag: | Revision:

root / snf-pithos-app / pithos / api / dispatch.py @ f5b1b80e

History | View | Annotate | Download (2.1 kB)

1
from pithos.api.settings import (BACKEND_QUOTA, BACKEND_VERSIONING)
2

    
3
#from pithos.backends import connect_backend
4
from pithos.api.util import hashmap_md5, get_backend
5

    
6
from django.core.mail import send_mail
7
from django.utils.translation import ugettext as _
8

    
9
from astakos.im.settings import DEFAULT_FROM_EMAIL
10

    
11
import socket
12
from smtplib import SMTPException
13

    
14

    
15
def update_md5(m):
16
    if m['resource'] != 'object' or m['details']['action'] != 'object update':
17
        return
18

    
19
    backend = get_backend()
20
    backend.default_policy['quota'] = BACKEND_QUOTA
21
    backend.default_policy['versioning'] = BACKEND_VERSIONING
22

    
23
    path = m['value']
24
    account, container, name = path.split('/', 2)
25
    version = m['details']['version']
26
    meta = None
27
    try:
28
        meta = backend.get_object_meta(
29
            account, account, container, name, 'pithos', version)
30
        if meta['checksum'] == '':
31
            size, hashmap = backend.get_object_hashmap(
32
                account, account, container, name, version)
33
            checksum = hashmap_md5(backend, hashmap, size)
34
            backend.update_object_checksum(
35
                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

    
43
def send_sharing_notification(m):
44
    if m['resource'] != 'sharing':
45
        return
46

    
47
    members = m['details']['members']
48
    user = m['details']['user']
49
    path = m['value']
50
    account, container, name = path.split('/', 2)
51

    
52
    subject = 'Invitation to a Pithos+ shared object'
53
    from_email = DEFAULT_FROM_EMAIL
54
    recipient_list = members
55
    message = 'User %s has invited you to a Pithos+ shared object. You can view it under "Shared to me" at "%s".' % (user, path)
56
    try:
57
        send_mail(subject, message, from_email, recipient_list)
58
        print 'INFO: Sharing notification sent for path "%s" to %s' % (
59
            path, ','.join(recipient_list))
60
    except (SMTPException, socket.error) as e:
61
        print 'WARNING: Can not update send email for sharing "%s" (%s)' % (
62
            path, e)