Revision 72e191e5 snf-pithos-backend/pithos/backends/lib/sqlalchemy/alembic/versions/165ba3fbfe53_update_path_account.py
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) |
Also available in: Unified diff