Cleanup some indentation and imports

This commit is contained in:
Jake Moshenko 2016-01-05 12:12:57 -05:00
parent fff016d0f5
commit 8d5f4466d6
3 changed files with 34 additions and 33 deletions

View file

@ -9,10 +9,10 @@ def prefix_search(field, prefix_query):
""" Returns the wildcard match for searching for the given prefix query. """ """ Returns the wildcard match for searching for the given prefix query. """
# Escape the known wildcard characters. # Escape the known wildcard characters.
prefix_query = (prefix_query prefix_query = (prefix_query
.replace('!', '!!') .replace('!', '!!')
.replace('%', '!%') .replace('%', '!%')
.replace('_', '!_') .replace('_', '!_')
.replace('[', '![')) .replace('[', '!['))
return field ** Clause(prefix_query + '%', SQL("ESCAPE '!'")) return field ** Clause(prefix_query + '%', SQL("ESCAPE '!'"))
@ -46,8 +46,9 @@ def filter_to_repos_for_user(query, username=None, namespace=None, include_publi
where_clause = (Namespace.username == namespace) where_clause = (Namespace.username == namespace)
if include_public: if include_public:
queries.append(query.clone() queries.append(query
.where(Repository.visibility == get_public_repo_visibility(), where_clause)) .clone()
.where(Repository.visibility == get_public_repo_visibility(), where_clause))
if username: if username:
UserThroughTeam = User.alias() UserThroughTeam = User.alias()
@ -57,29 +58,32 @@ def filter_to_repos_for_user(query, username=None, namespace=None, include_publi
AdminUser = User.alias() AdminUser = User.alias()
# Add repositories in which the user has permission. # Add repositories in which the user has permission.
queries.append(query.clone() queries.append(query
.switch(RepositoryPermission) .clone()
.join(User) .switch(RepositoryPermission)
.where(User.username == username, where_clause)) .join(User)
.where(User.username == username, where_clause))
# Add repositories in which the user is a member of a team that has permission. # Add repositories in which the user is a member of a team that has permission.
queries.append(query.clone() queries.append(query
.switch(RepositoryPermission) .clone()
.join(Team) .switch(RepositoryPermission)
.join(TeamMember) .join(Team)
.join(UserThroughTeam, on=(UserThroughTeam.id == TeamMember.user)) .join(TeamMember)
.where(UserThroughTeam.username == username, where_clause)) .join(UserThroughTeam, on=(UserThroughTeam.id == TeamMember.user))
.where(UserThroughTeam.username == username, where_clause))
# Add repositories under namespaces in which the user is the org admin. # Add repositories under namespaces in which the user is the org admin.
queries.append(query.clone() queries.append(query
.switch(Repository) .clone()
.join(Org, on=(Repository.namespace_user == Org.id)) .switch(Repository)
.join(AdminTeam, on=(Org.id == AdminTeam.organization)) .join(Org, on=(Repository.namespace_user == Org.id))
.join(TeamRole, on=(AdminTeam.role == TeamRole.id)) .join(AdminTeam, on=(Org.id == AdminTeam.organization))
.switch(AdminTeam) .join(TeamRole, on=(AdminTeam.role == TeamRole.id))
.join(AdminTeamMember, on=(AdminTeam.id == AdminTeamMember.team)) .switch(AdminTeam)
.join(AdminUser, on=(AdminTeamMember.user == AdminUser.id)) .join(AdminTeamMember, on=(AdminTeam.id == AdminTeamMember.team))
.where(AdminUser.username == username, where_clause)) .join(AdminUser, on=(AdminTeamMember.user == AdminUser.id))
.where(AdminUser.username == username, where_clause))
return reduce(lambda l, r: l | r, queries) return reduce(lambda l, r: l | r, queries)

View file

@ -21,11 +21,11 @@ def get_repository_image_and_deriving(docker_image_id, storage_uuid):
""" """
try: try:
image_found = (Image image_found = (Image
.select() .select()
.join(ImageStorage) .join(ImageStorage)
.where(Image.docker_image_id == docker_image_id, .where(Image.docker_image_id == docker_image_id,
ImageStorage.uuid == storage_uuid) ImageStorage.uuid == storage_uuid)
.get()) .get())
except Image.DoesNotExist: except Image.DoesNotExist:
return Image.select().where(Image.id < 0) # Empty query return Image.select().where(Image.id < 0) # Empty query

View file

@ -1,6 +1,3 @@
from multiprocessing import Queue
import os
class QueueFile(object): class QueueFile(object):
""" Class which implements a file-like interface and reads from a blocking """ Class which implements a file-like interface and reads from a blocking
multiprocessing queue. multiprocessing queue.