Statistics
| Branch: | Tag: | Revision:

root / snf-pithos-app / pithos / api / dispatch.py @ 18cd931f

History | View | Annotate | Download (1.9 kB)

1
#from pithos.backends import connect_backend
2
from pithos.api.util import hashmap_md5, get_backend
3

    
4
from django.core.mail import send_mail
5

    
6
from django.conf import settings
7

    
8
import socket
9
from smtplib import SMTPException
10

    
11

    
12
def update_md5(m):
13
    if m['resource'] != 'object' or m['details']['action'] != 'object update':
14
        return
15

    
16
    backend = get_backend()
17

    
18
    path = m['value']
19
    account, container, name = path.split('/', 2)
20
    version = m['details']['version']
21
    meta = None
22
    try:
23
        meta = backend.get_object_meta(
24
            account, account, container, name, 'pithos', version)
25
        if meta['checksum'] == '':
26
            size, hashmap = backend.get_object_hashmap(
27
                account, account, container, name, version)
28
            checksum = hashmap_md5(backend, hashmap, size)
29
            backend.update_object_checksum(
30
                account, account, container, name, version, checksum)
31
            print 'INFO: Updated checksum for path "%s"' % (path,)
32
    except Exception, e:
33
        print 'WARNING: Can not update checksum for path "%s" (%s)' % (path, e)
34

    
35
    backend.close()
36

    
37

    
38
def send_sharing_notification(m):
39
    if m['resource'] != 'sharing':
40
        return
41

    
42
    members = m['details']['members']
43
    user = m['details']['user']
44
    path = m['value']
45
    account, container, name = path.split('/', 2)
46

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