source: TracAccountManager/0.10/contrib/sessionstore_convert.py @ 6

Last change on this file since 6 was 2, checked in by guillaume, 17 years ago

Ajout TracAccountManager en français

File size: 1.3 KB
RevLine 
[2]1import os
2import sys
3
4from trac.env import Environment
5from acct_mgr.api import AccountManager
6from acct_mgr.htfile import HtPasswdStore, HtDigestStore
7from acct_mgr.pwhash import HtPasswdHashMethod, HtDigestHashMethod
8
9env = Environment(sys.argv[1])
10
11store = AccountManager(env).password_store
12if isinstance(store, HtPasswdStore):
13    env.config.set('account-manager', 'hash_method', 'HtPasswdHashMethod')
14    prefix = ''
15elif isinstance(store, HtDigestStore):
16    env.config.set('account-manager', 'hash_method', 'HtDigestHashMethod')
17    prefix = store.realm + ':'
18else:
19    print >>sys.stderr, 'Unsupported password store:', store.__class__.__name__
20    sys.exit(1)
21
22password_file = os.path.join(env.path, env.config.get('account-manager',
23                                                      'password_file'))
24hashes = [line.strip().split(':', 1) for line in open(password_file)]
25hashes = [(u,p) for u,p in hashes if p.startswith(prefix)]
26if hashes:
27    db = env.get_db_cnx()
28    cursor = db.cursor()
29    cursor.executemany("INSERT INTO session_attribute "
30                       "(sid,authenticated,name,value) "
31                       "VALUES (%s,1,'password',%s)",
32                       hashes)
33    db.commit()
34
35env.config.set('account-manager', 'password_store', 'SessionStore')
36env.config.save()
Note: See TracBrowser for help on using the repository browser.