Revision 72e191e5

b/snf-pithos-backend/pithos/backends/lib/sqlalchemy/alembic/versions/165ba3fbfe53_update_path_account.py
13 13
from alembic import op
14 14
from sqlalchemy.sql import table, column, and_
15 15

  
16
from pithos.api.settings import (SERVICE_TOKEN, ASTAKOS_BASE_URL)
17

  
18 16
from astakosclient import AstakosClient
19 17
from astakosclient.errors import NoUserName, NoUUID
20
astakos_client = AstakosClient(ASTAKOS_BASE_URL, retry=3, use_pool=True)
18

  
19
import functools
21 20

  
22 21
try:
23 22
    from progress.bar import IncrementalBar
......
37 36
catalog = {}
38 37

  
39 38

  
40
def get_uuid(account):
39
def _get_uuid(account, service_token, astakos_client):
41 40
    global catalog
42 41
    if account in catalog:
43 42
        return catalog[account]
44 43
    try:
45
        catalog[account] = astakos_client.service_get_uuid(
46
            SERVICE_TOKEN, account
47
        )
44
        catalog[account] = astakos_client.service_get_uuid(service_token,
45
                                                           account)
48 46
        print '\n', account, '-->', catalog[account]
49 47
    except NoUUID:
50 48
        return None
......
56 54
inverse_catalog = {}
57 55

  
58 56

  
59
def get_displayname(account):
57
def _get_displayname(account, service_token, astakos_client):
60 58
    global inverse_catalog
61 59
    if account in inverse_catalog:
62 60
        return inverse_catalog[account]
63 61
    try:
64 62
        inverse_catalog[account] = astakos_client.service_get_username(
65
            SERVICE_TOKEN, account
66
        )
63
            service_token, account)
67 64
        print '\n', account, '-->', inverse_catalog[account]
68 65
    except NoUserName:
69 66
        return None
......
219 216

  
220 217

  
221 218
def upgrade():
222
    migrate(get_uuid)
219
    try:
220
        from pithos.api import settings
221
    except ImportError:
222
        return
223
    else:
224
        astakos_client = AstakosClient(settings.ASTAKOS_BASE_URL,
225
                                       retry=3,
226
                                       use_pool=True)
227
        get_uuid = functools.partial(_get_uuid,
228
                                     service_token=settings.SERVICE_TOKEN,
229
                                     astakos_client=astakos_client)
230
        migrate(get_uuid)
223 231

  
224 232

  
225 233
def downgrade():
226
    migrate(get_displayname)
234
    try:
235
        from pithos.api import settings
236
    except ImportError:
237
        return
238
    else:
239
        astakos_client = AstakosClient(settings.ASTAKOS_BASE_URL,
240
                                       retry=3,
241
                                       use_pool=True)
242
        get_displayname = functools.partial(
243
            _get_displayname,
244
            service_token=settings.SERVICE_TOKEN,
245
            astakos_client=astakos_client)
246
        migrate(get_displayname)
b/snf-pithos-backend/pithos/backends/lib/sqlalchemy/alembic/versions/27381099d477_alter_public_add_col.py
14 14
import sqlalchemy as sa
15 15

  
16 16
from pithos.backends.modular import ULTIMATE_ANSWER
17
from pithos.api.short_url import encode_url
18 17

  
19 18

  
20 19
def upgrade():
......
27 26
        sa.sql.column('public_id', sa.Integer),
28 27
        sa.sql.column('url', sa.String),
29 28
    )
30
    get_url = lambda x: encode_url(x + ULTIMATE_ANSWER)
31
    conn = op.get_bind()
32
    s = sa.select([p.c.public_id])
33
    rows = conn.execute(s).fetchall()
34
    for r in rows:
35
        s = p.update().values(url=get_url(r[0])).where(p.c.public_id == r[0])
36
        op.execute(s)
29

  
30
    try:
31
        from pithos.api.short_url import encode_url
32
    except ImportError:
33
        return
34
    else:
35
        get_url = lambda x: encode_url(x + ULTIMATE_ANSWER)
36
        conn = op.get_bind()
37
        s = sa.select([p.c.public_id])
38
        rows = conn.execute(s).fetchall()
39
        for r in rows:
40
            s = p.update().values(url=get_url(r[0])).where(
41
                p.c.public_id == r[0])
42
            op.execute(s)
37 43

  
38 44

  
39 45
def downgrade():

Also available in: Unified diff