Revision af75e8a5
b/pithos/backends/lib/sqlalchemy/public.py | ||
---|---|---|
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 | 34 |
from dbworker import DBWorker |
35 |
from sqlalchemy import Table, Column, String, Integer, MetaData |
|
36 |
from sqlalchemy.sql import select |
|
35 |
from sqlalchemy import Table, Column, String, Integer, Boolean, MetaData
|
|
36 |
from sqlalchemy.sql import and_, select
|
|
37 | 37 |
from sqlalchemy.schema import Index |
38 | 38 |
|
39 | 39 |
|
... | ... | |
45 | 45 |
metadata = MetaData() |
46 | 46 |
columns=[] |
47 | 47 |
columns.append(Column('public_id', Integer, primary_key=True)) |
48 |
columns.append(Column('path', String(2048))) |
|
48 |
columns.append(Column('path', String(2048), nullable=False)) |
|
49 |
columns.append(Column('active', Boolean, nullable=False, default=True)) |
|
49 | 50 |
self.public = Table('public', metadata, *columns, mysql_engine='InnoDB', sqlite_autoincrement=True) |
50 | 51 |
# place an index on path |
51 | 52 |
Index('idx_public_path', self.public.c.path, unique=True) |
52 | 53 |
metadata.create_all(self.engine) |
53 | 54 |
|
54 | 55 |
def public_set(self, path): |
55 |
s = self.public.select()
|
|
56 |
s = select([self.public.c.public_id])
|
|
56 | 57 |
s = s.where(self.public.c.path == path) |
57 | 58 |
r = self.conn.execute(s) |
58 |
public = r.fetchall()
|
|
59 |
row = r.fetchone()
|
|
59 | 60 |
r.close() |
60 |
if len(public) == 0: |
|
61 |
if row: |
|
62 |
s = self.public.update().where(self.public.c.public_id == row[0]) |
|
63 |
s = s.values(active=True) |
|
64 |
else: |
|
61 | 65 |
s = self.public.insert() |
62 |
r = self.conn.execute(s, path = path) |
|
63 |
r.close() |
|
66 |
s = s.values(path=path, active=True) |
|
67 |
r = self.conn.execute(s) |
|
68 |
r.close() |
|
64 | 69 |
|
65 | 70 |
def public_unset(self, path): |
66 |
s = self.public.delete().where(self.public.c.path == path) |
|
71 |
s = self.public.update() |
|
72 |
s = s.where(self.public.c.path == path) |
|
73 |
s = s.values(active=False) |
|
67 | 74 |
r = self.conn.execute(s) |
68 | 75 |
r.close() |
69 | 76 |
|
70 | 77 |
def public_get(self, path): |
71 |
s = select([self.public.c.public_id], self.public.c.path == path) |
|
78 |
s = select([self.public.c.public_id]) |
|
79 |
s = s.where(and_(self.public.c.path == path, |
|
80 |
self.public.c.active == True)) |
|
72 | 81 |
r = self.conn.execute(s) |
73 | 82 |
row = r.fetchone() |
74 | 83 |
r.close() |
... | ... | |
77 | 86 |
return None |
78 | 87 |
|
79 | 88 |
def public_path(self, public): |
80 |
s = select([self.public.c.path], self.public.c.public_id == public) |
|
89 |
s = select([self.public.c.path]) |
|
90 |
s = s.where(and_(self.public.c.public_id == public, |
|
91 |
self.public.c.active == True)) |
|
81 | 92 |
r = self.conn.execute(s) |
82 | 93 |
row = r.fetchone() |
83 | 94 |
r.close() |
b/pithos/backends/lib/sqlite/public.py | ||
---|---|---|
43 | 43 |
|
44 | 44 |
execute(""" create table if not exists public |
45 | 45 |
( public_id integer primary key autoincrement, |
46 |
path text ) """) |
|
46 |
path text not null, |
|
47 |
active boolean not null default 1 ) """) |
|
47 | 48 |
execute(""" create unique index if not exists idx_public_path |
48 | 49 |
on public(path) """) |
49 | 50 |
|
50 | 51 |
def public_set(self, path): |
51 | 52 |
q = "insert or ignore into public (path) values (?)" |
52 | 53 |
self.execute(q, (path,)) |
54 |
q = "update public set active = 1 where path = ?" |
|
55 |
self.execute(q, (path,)) |
|
53 | 56 |
|
54 | 57 |
def public_unset(self, path): |
55 |
q = "delete from public where path = ?"
|
|
58 |
q = "update public set active = 0 where path = ?"
|
|
56 | 59 |
self.execute(q, (path,)) |
57 | 60 |
|
58 | 61 |
def public_get(self, path): |
59 |
q = "select public_id from public where path = ?" |
|
62 |
q = "select public_id from public where path = ? and active = 1"
|
|
60 | 63 |
self.execute(q, (path,)) |
61 | 64 |
row = self.fetchone() |
62 | 65 |
if row: |
... | ... | |
64 | 67 |
return None |
65 | 68 |
|
66 | 69 |
def public_path(self, public): |
67 |
q = "select path from public where public_id = ?" |
|
70 |
q = "select path from public where public_id = ? and active = 1"
|
|
68 | 71 |
self.execute(q, (public,)) |
69 | 72 |
row = self.fetchone() |
70 | 73 |
if row: |
b/pithos/backends/modular.py | ||
---|---|---|
645 | 645 |
@backend_method |
646 | 646 |
def get_uuid(self, user, uuid): |
647 | 647 |
"""Return the (account, container, name) for the UUID given.""" |
648 |
|
|
648 | 649 |
logger.debug("get_uuid: %s", uuid) |
649 | 650 |
info = self.node.latest_uuid(uuid) |
650 | 651 |
if info is None: |
... | ... | |
657 | 658 |
@backend_method |
658 | 659 |
def get_public(self, user, public): |
659 | 660 |
"""Return the (account, container, name) for the public id given.""" |
661 |
|
|
660 | 662 |
logger.debug("get_public: %s", public) |
661 | 663 |
if public is None or public < ULTIMATE_ANSWER: |
662 | 664 |
raise NameError |
Also available in: Unified diff