Revision 2715ade4 other/migrate.py
b/other/migrate.py | ||
---|---|---|
1 | 1 |
#!/usr/bin/env python |
2 | 2 |
|
3 | 3 |
# Copyright 2011-2012 GRNET S.A. All rights reserved. |
4 |
#
|
|
4 |
# |
|
5 | 5 |
# Redistribution and use in source and binary forms, with or |
6 | 6 |
# without modification, are permitted provided that the following |
7 | 7 |
# conditions are met: |
8 |
#
|
|
8 |
# |
|
9 | 9 |
# 1. Redistributions of source code must retain the above |
10 | 10 |
# copyright notice, this list of conditions and the following |
11 | 11 |
# disclaimer. |
12 |
#
|
|
12 |
# |
|
13 | 13 |
# 2. Redistributions in binary form must reproduce the above |
14 | 14 |
# copyright notice, this list of conditions and the following |
15 | 15 |
# disclaimer in the documentation and/or other materials |
16 | 16 |
# provided with the distribution. |
17 |
#
|
|
17 |
# |
|
18 | 18 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
19 | 19 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
20 | 20 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
... | ... | |
27 | 27 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
28 | 28 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | 29 |
# POSSIBILITY OF SUCH DAMAGE. |
30 |
#
|
|
30 |
# |
|
31 | 31 |
# The views and conclusions contained in the software and |
32 | 32 |
# documentation are those of the authors and should not be |
33 | 33 |
# interpreted as representing official policies, either expressed |
... | ... | |
41 | 41 |
|
42 | 42 |
from pithos.backends.modular import ModularBackend |
43 | 43 |
|
44 |
|
|
44 | 45 |
class Migration(object): |
45 | 46 |
def __init__(self, db): |
46 | 47 |
self.engine = create_engine(db) |
47 | 48 |
self.metadata = MetaData(self.engine) |
48 | 49 |
#self.engine.echo = True |
49 | 50 |
self.conn = self.engine.connect() |
50 |
|
|
51 |
|
|
51 | 52 |
options = getattr(settings, 'BACKEND', None)[1] |
52 | 53 |
self.backend = ModularBackend(*options) |
53 |
|
|
54 |
|
|
54 | 55 |
def execute(self): |
55 | 56 |
pass |
56 | 57 |
|
58 |
|
|
57 | 59 |
class Cache(): |
58 | 60 |
def __init__(self, db): |
59 | 61 |
self.engine = create_engine(db) |
60 | 62 |
metadata = MetaData(self.engine) |
61 |
|
|
62 |
columns=[]
|
|
63 |
|
|
64 |
columns = []
|
|
63 | 65 |
columns.append(Column('path', String(2048), primary_key=True)) |
64 | 66 |
columns.append(Column('hash', String(255))) |
65 | 67 |
self.files = Table('files', metadata, *columns) |
66 | 68 |
self.conn = self.engine.connect() |
67 | 69 |
self.engine.echo = True |
68 | 70 |
metadata.create_all(self.engine) |
69 |
|
|
71 |
|
|
70 | 72 |
def put(self, path, hash): |
71 | 73 |
# Insert or replace. |
72 |
s = self.files.delete().where(self.files.c.path==path)
|
|
74 |
s = self.files.delete().where(self.files.c.path == path)
|
|
73 | 75 |
r = self.conn.execute(s) |
74 | 76 |
r.close() |
75 | 77 |
s = self.files.insert() |
76 | 78 |
r = self.conn.execute(s, {'path': path, 'hash': hash}) |
77 | 79 |
r.close() |
78 |
|
|
80 |
|
|
79 | 81 |
def get(self, path): |
80 | 82 |
s = select([self.files.c.hash], self.files.c.path == path) |
81 | 83 |
r = self.conn.execute(s) |
Also available in: Unified diff