Commit cab39ed2 authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

pithos: Pep8 fixes

parent cbb94e69
...@@ -11,12 +11,10 @@ revision = '301fba21d9b8' ...@@ -11,12 +11,10 @@ revision = '301fba21d9b8'
down_revision = '54dbdde2d187' down_revision = '54dbdde2d187'
from alembic import op from alembic import op
import sqlalchemy as sa
def upgrade(): def upgrade():
op.create_index('idx_latest_version', 'nodes', op.create_index('idx_latest_version', 'nodes', ['latest_version'])
['latest_version'])
def downgrade(): def downgrade():
......
...@@ -39,6 +39,7 @@ from sqlalchemy import (Table, Integer, BigInteger, DECIMAL, Boolean, ...@@ -39,6 +39,7 @@ from sqlalchemy import (Table, Integer, BigInteger, DECIMAL, Boolean,
Column, String, MetaData, ForeignKey) Column, String, MetaData, ForeignKey)
from sqlalchemy.schema import Index from sqlalchemy.schema import Index
from sqlalchemy.sql import func, and_, or_, not_, select, bindparam, exists from sqlalchemy.sql import func, and_, or_, not_, select, bindparam, exists
from sqlalchemy.sql.expression import true
from sqlalchemy.exc import NoSuchTableError from sqlalchemy.exc import NoSuchTableError
from dbworker import DBWorker, ESCAPE_CHAR from dbworker import DBWorker, ESCAPE_CHAR
...@@ -675,26 +676,26 @@ class Node(DBWorker): ...@@ -675,26 +676,26 @@ class Node(DBWorker):
# This is why the full path is stored. # This is why the full path is stored.
if before != inf: if before != inf:
s = select([func.count(v.c.serial), s = select([func.count(v.c.serial),
func.sum(v.c.size), func.sum(v.c.size),
func.max(v.c.mtime)]) func.max(v.c.mtime)])
c1 = select([func.max(self.versions.c.serial)], c1 = select([func.max(self.versions.c.serial)],
and_(self.versions.c.mtime < before, and_(self.versions.c.mtime < before,
self.versions.c.node == v.c.node)) self.versions.c.node == v.c.node))
else: else:
inner_join = \ inner_join = self.versions.join(
self.versions.join(self.nodes, onclause=\ self.nodes,
self.versions.c.serial == self.nodes.c.latest_version) onclause=self.versions.c.serial == self.nodes.c.latest_version)
s = select([func.count(self.versions.c.serial), s = select([func.count(self.versions.c.serial),
func.sum(self.versions.c.size), func.sum(self.versions.c.size),
func.max(self.versions.c.mtime)], from_obj=[inner_join]) func.max(self.versions.c.mtime)], from_obj=[inner_join])
c2 = select([self.nodes.c.node], c2 = select([self.nodes.c.node],
self.nodes.c.path.like(self.escape_like(path) + '%', self.nodes.c.path.like(self.escape_like(path) + '%',
escape=ESCAPE_CHAR)) escape=ESCAPE_CHAR))
if before != inf: if before != inf:
s = s.where(and_(v.c.serial == c1, s = s.where(and_(v.c.serial == c1,
v.c.cluster != except_cluster, v.c.cluster != except_cluster,
v.c.node.in_(c2))) v.c.node.in_(c2)))
else: else:
s = s.where(and_(self.versions.c.cluster != except_cluster, s = s.where(and_(self.versions.c.cluster != except_cluster,
self.versions.c.node.in_(c2))) self.versions.c.node.in_(c2)))
...@@ -1000,12 +1001,13 @@ class Node(DBWorker): ...@@ -1000,12 +1001,13 @@ class Node(DBWorker):
v.c.node == self.versions.c.node)) v.c.node == self.versions.c.node))
else: else:
filtered = select([self.nodes.c.latest_version]) filtered = select([self.nodes.c.latest_version])
filtered = filtered.where(self.nodes.c.node == \ filtered = filtered.where(
self.versions.c.node).correlate(self.versions) self.nodes.c.node == self.versions.c.node).\
correlate(self.versions)
s = s.where(self.versions.c.serial == filtered) s = s.where(self.versions.c.serial == filtered)
s = s.where(self.versions.c.cluster != except_cluster) s = s.where(self.versions.c.cluster != except_cluster)
s = s.where(self.versions.c.node.in_(select([self.nodes.c.node], s = s.where(self.versions.c.node.in_(select([self.nodes.c.node],
self.nodes.c.parent == parent))) self.nodes.c.parent == parent)))
s = s.where(self.attributes.c.serial == self.versions.c.serial) s = s.where(self.attributes.c.serial == self.versions.c.serial)
s = s.where(self.attributes.c.domain == domain) s = s.where(self.attributes.c.domain == domain)
s = s.where(self.nodes.c.node == self.versions.c.node) s = s.where(self.nodes.c.node == self.versions.c.node)
...@@ -1014,12 +1016,12 @@ class Node(DBWorker): ...@@ -1014,12 +1016,12 @@ class Node(DBWorker):
conjb = [] conjb = []
for path, match in pathq: for path, match in pathq:
if match == MATCH_PREFIX: if match == MATCH_PREFIX:
conja.append(self.nodes.c.path.like(self.escape_like(path) + '%', conja.append(self.nodes.c.path.like(
escape=ESCAPE_CHAR)) self.escape_like(path) + '%', escape=ESCAPE_CHAR))
elif match == MATCH_EXACT: elif match == MATCH_EXACT:
conjb.append(path) conjb.append(path)
if conja or conjb: if conja or conjb:
s = s.where(or_(self.nodes.c.path.in_(conjb),*conja)) s = s.where(or_(self.nodes.c.path.in_(conjb), *conja))
rp = self.conn.execute(s) rp = self.conn.execute(s)
rows = rp.fetchall() rows = rp.fetchall()
rp.close() rp.close()
...@@ -1085,24 +1087,24 @@ class Node(DBWorker): ...@@ -1085,24 +1087,24 @@ class Node(DBWorker):
nextling = strnextling(prefix) nextling = strnextling(prefix)
v = self.versions.alias('v') v = self.versions.alias('v')
n = self.nodes.alias('n')
if before != inf: if before != inf:
filtered = select([func.max(v.c.serial)], filtered = select([func.max(v.c.serial)],
and_(v.c.mtime < before, and_(v.c.mtime < before,
v.c.node == self.versions.c.node)) v.c.node == self.versions.c.node))
inner_join = \ inner_join = self.nodes.join(
self.nodes.join(self.versions, self.versions,
onclause=self.versions.c.serial==filtered) onclause=self.versions.c.serial == filtered)
else: else:
filtered = select([self.nodes.c.latest_version]) filtered = select([self.nodes.c.latest_version])
filtered = filtered.where(self.nodes.c.node == self.versions.c.node).correlate(self.versions) filtered = filtered.where(
inner_join = \ self.nodes.c.node == self.versions.c.node).\
self.nodes.join(self.versions, correlate(self.versions)
onclause=\ inner_join = self.nodes.join(
self.versions.c.serial==filtered) self.versions,
onclause=self.versions.c.serial == filtered)
if not all_props: if not all_props:
s = select([self.nodes.c.path, s = select([self.nodes.c.path, self.versions.c.serial],
self.versions.c.serial],from_obj=[inner_join]).distinct() from_obj=[inner_join]).distinct()
else: else:
s = select([self.nodes.c.path, s = select([self.nodes.c.path,
self.versions.c.serial, self.versions.c.node, self.versions.c.serial, self.versions.c.node,
...@@ -1112,7 +1114,8 @@ class Node(DBWorker): ...@@ -1112,7 +1114,8 @@ class Node(DBWorker):
self.versions.c.mtime, self.versions.c.muser, self.versions.c.mtime, self.versions.c.muser,
self.versions.c.uuid, self.versions.c.uuid,
self.versions.c.checksum, self.versions.c.checksum,
self.versions.c.cluster],from_obj=[inner_join]).distinct() self.versions.c.cluster],
from_obj=[inner_join]).distinct()
s = s.where(self.versions.c.cluster != except_cluster) s = s.where(self.versions.c.cluster != except_cluster)
s = s.where(self.versions.c.node.in_(select([self.nodes.c.node], s = s.where(self.versions.c.node.in_(select([self.nodes.c.node],
...@@ -1120,17 +1123,18 @@ class Node(DBWorker): ...@@ -1120,17 +1123,18 @@ class Node(DBWorker):
s = s.where(self.versions.c.node == self.nodes.c.node) s = s.where(self.versions.c.node == self.nodes.c.node)
s = s.where(and_(self.nodes.c.path > bindparam('start'), s = s.where(and_(self.nodes.c.path > bindparam('start'),
self.nodes.c.path < nextling)) self.nodes.c.path < nextling))
conja = [] conja = []
conjb = [] conjb = []
for path, match in pathq: for path, match in pathq:
if match == MATCH_PREFIX: if match == MATCH_PREFIX:
conja.append(self.nodes.c.path.like(self.escape_like(path) + '%', conja.append(
escape=ESCAPE_CHAR)) self.nodes.c.path.like(self.escape_like(path) + '%',
escape=ESCAPE_CHAR))
elif match == MATCH_EXACT: elif match == MATCH_EXACT:
conjb.append(path) conjb.append(path)
if conja or conjb: if conja or conjb:
s = s.where(or_(self.nodes.c.path.in_(conjb),*conja)) s = s.where(or_(self.nodes.c.path.in_(conjb), *conja))
if sizeq and len(sizeq) == 2: if sizeq and len(sizeq) == 2:
if sizeq[0]: if sizeq[0]:
...@@ -1139,27 +1143,35 @@ class Node(DBWorker): ...@@ -1139,27 +1143,35 @@ class Node(DBWorker):
s = s.where(self.versions.c.size < sizeq[1]) s = s.where(self.versions.c.size < sizeq[1])
if domain and filterq: if domain and filterq:
a = self.attributes.alias('a')
included, excluded, opers = parse_filters(filterq) included, excluded, opers = parse_filters(filterq)
if included: if included:
subs = select([1]) subs = select([1])
subs = subs.where(self.attributes.c.serial == self.versions.c.serial).correlate(self.versions) subs = subs.where(
self.attributes.c.serial ==
self.versions.c.serial).correlate(self.versions)
subs = subs.where(self.attributes.c.domain == domain) subs = subs.where(self.attributes.c.domain == domain)
subs = subs.where(or_(*[self.attributes.c.key.op('=')(x) for x in included])) subs = subs.where(or_(*[self.attributes.c.key.op('=')(x) for
x in included]))
s = s.where(exists(subs)) s = s.where(exists(subs))
if excluded: if excluded:
subs = select([1]) subs = select([1])
subs = subs.where(self.attributes.c.serial == self.versions.c.serial).correlate(self.versions) subs = subs.where(
self.attributes.c.serial == self.versions.c.serial).\
correlate(self.versions)
subs = subs.where(self.attributes.c.domain == domain) subs = subs.where(self.attributes.c.domain == domain)
subs = subs.where(or_(*[self.attributes.c.key.op('=')(x) for x in excluded])) subs = subs.where(or_(*[self.attributes.c.key.op('=')(x) for
x in excluded]))
s = s.where(not_(exists(subs))) s = s.where(not_(exists(subs)))
if opers: if opers:
for k, o, val in opers: for k, o, val in opers:
subs = select([1]) subs = select([1])
subs = subs.where(self.attributes.c.serial == self.versions.c.serial).correlate(self.versions) subs = subs.where(
self.attributes.c.serial == self.versions.c.serial).\
correlate(self.versions)
subs = subs.where(self.attributes.c.domain == domain) subs = subs.where(self.attributes.c.domain == domain)
subs = subs.where( subs = subs.where(
and_(self.attributes.c.key.op('=')(k), self.attributes.c.value.op(o)(val))) and_(self.attributes.c.key.op('=')(k),
self.attributes.c.value.op(o)(val)))
s = s.where(exists(subs)) s = s.where(exists(subs))
s = s.order_by(self.nodes.c.path) s = s.order_by(self.nodes.c.path)
...@@ -1248,7 +1260,7 @@ class Node(DBWorker): ...@@ -1248,7 +1260,7 @@ class Node(DBWorker):
s = s.where(v.c.serial == a.c.serial) s = s.where(v.c.serial == a.c.serial)
s = s.where(a.c.domain == domain) s = s.where(a.c.domain == domain)
s = s.where(a.c.node == n.c.node) s = s.where(a.c.node == n.c.node)
s = s.where(a.c.is_latest == True) s = s.where(a.c.is_latest == true())
if paths: if paths:
s = s.where(n.c.path.in_(paths)) s = s.where(n.c.path.in_(paths))
...@@ -1264,11 +1276,12 @@ class Node(DBWorker): ...@@ -1264,11 +1276,12 @@ class Node(DBWorker):
def get_props(self, paths): def get_props(self, paths):
inner_join = \ inner_join = \
self.nodes.join(self.versions, self.nodes.join(
self.versions,
onclause=self.versions.c.serial == self.nodes.c.latest_version) onclause=self.versions.c.serial == self.nodes.c.latest_version)
cc = self.nodes.c.path.in_(paths) cc = self.nodes.c.path.in_(paths)
s = select([self.nodes.c.path, self.versions.c.type], s = select([self.nodes.c.path, self.versions.c.type],
from_obj=[inner_join]).where(cc).distinct() from_obj=[inner_join]).where(cc).distinct()
r = self.conn.execute(s) r = self.conn.execute(s)
rows = r.fetchall() rows = r.fetchall()
r.close() r.close()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment