Revision d50ed8d4 snf-pithos-app/pithos/api/dispatch.py

b/snf-pithos-app/pithos/api/dispatch.py
1 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)
2
                                 BACKEND_BLOCK_MODULE, BACKEND_BLOCK_PATH,
3
                                 BACKEND_BLOCK_UMASK,
4
                                 BACKEND_QUEUE_MODULE, BACKEND_QUEUE_CONNECTION,
5
                                 BACKEND_QUOTA, BACKEND_VERSIONING)
6 6
from pithos.backends import connect_backend
7 7
from pithos.api.util import hashmap_md5
8 8

  
......
14 14
import socket
15 15
from smtplib import SMTPException
16 16

  
17

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

  
21 22
    backend = connect_backend(db_module=BACKEND_DB_MODULE,
22 23
                              db_connection=BACKEND_DB_CONNECTION,
23 24
                              block_module=BACKEND_BLOCK_MODULE,
......
27 28
                              queue_connection=BACKEND_QUEUE_CONNECTION)
28 29
    backend.default_policy['quota'] = BACKEND_QUOTA
29 30
    backend.default_policy['versioning'] = BACKEND_VERSIONING
30
    
31

  
31 32
    path = m['value']
32 33
    account, container, name = path.split('/', 2)
33 34
    version = m['details']['version']
34 35
    meta = None
35 36
    try:
36
        meta = backend.get_object_meta(account, account, container, name, 'pithos', version)
37
        meta = backend.get_object_meta(
38
            account, account, container, name, 'pithos', version)
37 39
        if meta['checksum'] == '':
38
            size, hashmap = backend.get_object_hashmap(account, account, container, name, version)
40
            size, hashmap = backend.get_object_hashmap(
41
                account, account, container, name, version)
39 42
            checksum = hashmap_md5(backend, hashmap, size)
40
            backend.update_object_checksum(account, account, container, name, version, checksum)
43
            backend.update_object_checksum(
44
                account, account, container, name, version, checksum)
41 45
            print 'INFO: Updated checksum for path "%s"' % (path,)
42 46
    except Exception, e:
43 47
        print 'WARNING: Can not update checksum for path "%s" (%s)' % (path, e)
44
    
48

  
45 49
    backend.close()
46 50

  
51

  
47 52
def send_sharing_notification(m):
48 53
    if m['resource'] != 'sharing':
49 54
        return
50
    
55

  
51 56
    members = m['details']['members']
52 57
    user = m['details']['user']
53 58
    path = m['value']
54 59
    account, container, name = path.split('/', 2)
55
    
60

  
56 61
    subject = 'Invitation to a Pithos+ shared object'
57 62
    from_email = DEFAULT_FROM_EMAIL
58 63
    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)
64
    message = 'User %s has invited you to a Pithos+ shared object. You can view it under "Shared to me" at "%s".' % (user, path)
60 65
    try:
61 66
        send_mail(subject, message, from_email, recipient_list)
62
        print 'INFO: Sharing notification sent for path "%s" to %s' % (path, ','.join(recipient_list))
67
        print 'INFO: Sharing notification sent for path "%s" to %s' % (
68
            path, ','.join(recipient_list))
63 69
    except (SMTPException, socket.error) as e:
64
        print 'WARNING: Can not update send email for sharing "%s" (%s)' % (path, e)
70
        print 'WARNING: Can not update send email for sharing "%s" (%s)' % (
71
            path, e)

Also available in: Unified diff