PEP8 fixes.

This commit is contained in:
yackob03 2013-10-08 11:29:42 -04:00
parent 427b745f2f
commit 6a038bb24e
7 changed files with 56 additions and 45 deletions

View file

@ -41,7 +41,7 @@ def create_confirm_email_code(user):
def confirm_user_email(code):
code = EmailConfirmation.get(EmailConfirmation.code == code,
EmailConfirmation.email_confirm == True)
EmailConfirmation.email_confirm is True)
user = code.user
user.verified = True
@ -96,14 +96,15 @@ def get_token(code):
return AccessToken.get(AccessToken.code == code)
def get_visible_repositories(username=None, include_public=True, limit=None, sort=False):
def get_visible_repositories(username=None, include_public=True, limit=None,
sort=False):
if not username and not include_public:
return []
query = Repository.select().distinct().join(Visibility)
or_clauses = []
if include_public:
or_clauses.append((Visibility.name == 'public'));
or_clauses.append((Visibility.name == 'public'))
if username:
with_perms = query.switch(Repository).join(RepositoryPermission,
@ -123,6 +124,7 @@ def get_visible_repositories(username=None, include_public=True, limit=None, sor
return query
def get_matching_repositories(repo_term, username=None):
namespace_term = repo_term
name_term = repo_term
@ -197,7 +199,7 @@ def set_repository_visibility(repo, visibility):
repo.visibility = visibility_obj
repo.save()
def create_repository(namespace, name, owner):
private = Visibility.get(name='private')

View file

@ -102,6 +102,7 @@ def create_repo_api():
@app.route('/api/find/repository', methods=['GET'])
def match_repos_api():
prefix = request.args.get('query', '')
def repo_view(repo):
return {
'namespace': repo.namespace,
@ -109,7 +110,10 @@ def match_repos_api():
'description': repo.description
}
username = current_user.db_user.username if current_user.is_authenticated() else None
username = None
if current_user.is_authenticated():
username = current_user.db_user.username
matching = model.get_matching_repositories(prefix, username)
response = {
'repositories': [repo_view(repo) for repo in matching]
@ -126,7 +130,7 @@ def list_repos_api():
'name': repo_obj.name,
'description': repo_obj.description,
}
limit = request.args.get('limit', None)
include_public = request.args.get('public', 'true')
include_private = request.args.get('private', 'true')
@ -141,10 +145,14 @@ def list_repos_api():
include_private = include_private == 'true'
sort = sort == 'true'
username = current_user.db_user.username if current_user.is_authenticated() and include_private else None
repos = [repo_view(repo)
for repo in model.get_visible_repositories(
username, limit = limit, include_public = include_public, sort = sort)]
username = None
if current_user.is_authenticated() and include_private:
username = current_user.db_user.username
repo_query = model.get_visible_repositories(username, limit=limit,
include_public=include_public,
sort=sort)
repos = [repo_view(repo) for repo in repo_query]
response = {
'repositories': repos
}
@ -170,7 +178,8 @@ def update_repo_api(namespace, repository):
abort(404)
@app.route('/api/repository/<path:repository>/changevisibility', methods=['POST'])
@app.route('/api/repository/<path:repository>/changevisibility',
methods=['POST'])
@api_login_required
@parse_repository_name
def change_repo_visibility_api(namespace, repository):
@ -348,7 +357,7 @@ def delete_permissions(namespace, repository, username):
abort(403) # Permission denied
def subscription_view(stripe_subscription, used_repos):
def subscription_view(stripe_subscription, used_repos):
return {
'currentPeriodStart': stripe_subscription.current_period_start,
'currentPeriodEnd': stripe_subscription.current_period_end,
@ -375,7 +384,7 @@ def subscribe():
cus = stripe.Customer.create(email=user.email, plan=plan, card=card)
user.stripe_id = cus.id
user.save()
resp = jsonify(subscription_view(cus.subscription, private_repos))
resp.status_code = 201
return resp
@ -422,4 +431,4 @@ def get_subscription():
return jsonify({
'plan': 'free',
'usedPrivateRepos': private_repos,
});
})

View file

@ -151,7 +151,7 @@ def update_images(namespace, repository):
for image in image_with_checksums:
logger.debug('Setting checksum for image id: %s to %s' %
(image['id'], image['checksum']))
(image['id'], image['checksum']))
model.set_image_checksum(image['id'], repository, image['checksum'])
return make_response('Updated', 204)

View file

@ -44,7 +44,7 @@ def require_completion(f):
def wrapper(namespace, repository, *args, **kwargs):
if store.exists(store.image_mark_path(namespace, repository,
kwargs['image_id'])):
abort(400) #'Image is being uploaded, retry later')
abort(400) # 'Image is being uploaded, retry later')
return f(namespace, repository, *args, **kwargs)
return wrapper
@ -85,7 +85,7 @@ def get_image_layer(namespace, repository, image_id, headers):
return Response(store.stream_read(store.image_layer_path(
namespace, repository, image_id)), headers=headers)
except IOError:
abort(404) #'Image not found', 404)
abort(404) # 'Image not found', 404)
abort(403)
@ -102,11 +102,11 @@ def put_image_layer(namespace, repository, image_id):
json_data = store.get_content(store.image_json_path(namespace, repository,
image_id))
except IOError:
abort(404) #'Image not found', 404)
abort(404) # 'Image not found', 404)
layer_path = store.image_layer_path(namespace, repository, image_id)
mark_path = store.image_mark_path(namespace, repository, image_id)
if store.exists(layer_path) and not store.exists(mark_path):
abort(409) #'Image already exists', 409)
abort(409) # 'Image already exists', 409)
input_stream = request.stream
if request.headers.get('transfer-encoding') == 'chunked':
# Careful, might work only with WSGI servers supporting chunked
@ -127,7 +127,7 @@ def put_image_layer(namespace, repository, image_id):
tmp.close()
except (IOError, checksums.TarError) as e:
logger.debug('put_image_layer: Error when computing tarsum '
'{0}'.format(e))
'{0}'.format(e))
try:
checksum = store.get_content(store.image_checksum_path(namespace,
repository,
@ -140,7 +140,7 @@ def put_image_layer(namespace, repository, image_id):
# We check if the checksums provided matches one the one we computed
if checksum not in csums:
logger.debug('put_image_layer: Wrong checksum')
abort(400) #'Checksum mismatch, ignoring the layer')
abort(400) # 'Checksum mismatch, ignoring the layer')
# Checksum is ok, we remove the marker
store.remove(mark_path)
return make_response('true', 200)
@ -156,14 +156,14 @@ def put_image_checksum(namespace, repository, image_id):
checksum = request.headers.get('X-Docker-Checksum')
if not checksum:
abort(400) #'Missing Image\'s checksum')
abort(400) # 'Missing Image\'s checksum')
if not session.get('checksum'):
abort(400) #'Checksum not found in Cookie')
abort(400) # 'Checksum not found in Cookie')
if not store.exists(store.image_json_path(namespace, repository, image_id)):
abort(404) #'Image not found', 404)
abort(404) # 'Image not found', 404)
mark_path = store.image_mark_path(namespace, repository, image_id)
if not store.exists(mark_path):
abort(409) #'Cannot set this image checksum', 409)
abort(409) # 'Cannot set this image checksum', 409)
err = store_checksum(namespace, repository, image_id, checksum)
if err:
abort(err)
@ -171,7 +171,7 @@ def put_image_checksum(namespace, repository, image_id):
logger.debug('session checksums: %s' % session.get('checksum', []))
logger.debug('client supplied checksum: %s' % checksum)
logger.debug('put_image_layer: Wrong checksum')
abort(400) #'Checksum mismatch')
abort(400) # 'Checksum mismatch')
# Checksum is ok, we remove the marker
store.remove(mark_path)
return make_response('true', 200)
@ -184,15 +184,15 @@ def put_image_checksum(namespace, repository, image_id):
@set_cache_headers
def get_image_json(namespace, repository, image_id, headers):
permission = ReadRepositoryPermission(namespace, repository)
if (not permission.can() and not
model.repository_is_public(namespace, repository)):
if not permission.can() and not model.repository_is_public(namespace,
repository):
abort(403)
try:
data = store.get_content(store.image_json_path(namespace, repository,
image_id))
except IOError:
abort(404) #'Image not found', 404)
abort(404) # 'Image not found', 404)
try:
size = store.get_size(store.image_layer_path(namespace, repository,
image_id))
@ -214,15 +214,15 @@ def get_image_json(namespace, repository, image_id, headers):
@set_cache_headers
def get_image_ancestry(namespace, repository, image_id, headers):
permission = ReadRepositoryPermission(namespace, repository)
if (not permission.can() and not
model.repository_is_public(namespace, repository)):
if not permission.can() and not model.repository_is_public(namespace,
repository):
abort(403)
try:
data = store.get_content(store.image_ancestry_path(namespace, repository,
image_id))
except IOError:
abort(404) #'Image not found', 404)
abort(404) # 'Image not found', 404)
response = make_response(json.dumps(json.loads(data)), 200)
response.headers.extend(headers)
return response
@ -265,9 +265,9 @@ def put_image_json(namespace, repository, image_id):
except json.JSONDecodeError:
pass
if not data or not isinstance(data, dict):
abort(400) #'Invalid JSON')
abort(400) # 'Invalid JSON')
if 'id' not in data:
abort(400) #'Missing key `id\' in JSON')
abort(400) # 'Missing key `id\' in JSON')
# Read the checksum
checksum = request.headers.get('X-Docker-Checksum')
if checksum:
@ -279,16 +279,16 @@ def put_image_json(namespace, repository, image_id):
# We cleanup any old checksum in case it's a retry after a fail
store.remove(store.image_checksum_path(namespace, repository, image_id))
if image_id != data['id']:
abort(400) #'JSON data contains invalid id')
abort(400) # 'JSON data contains invalid id')
parent_id = data.get('parent')
if parent_id and not store.exists(store.image_json_path(namespace,
repository,
data['parent'])):
abort(400) #'Image depends on a non existing parent')
abort(400) # 'Image depends on a non existing parent')
json_path = store.image_json_path(namespace, repository, image_id)
mark_path = store.image_mark_path(namespace, repository, image_id)
if store.exists(json_path) and not store.exists(mark_path):
abort(409) #'Image already exists', 409)
abort(409) # 'Image already exists', 409)
# If we reach that point, it means that this is a new image or a retry
# on a failed push
# save the metadata
@ -311,4 +311,4 @@ def delete_repository_storage(namespace, repository):
repository_path = store.repository_namespace_path(namespace, repository)
logger.debug('Recursively deleting path: %s' % repository_path)
store.remove(repository_path)
store.remove(repository_path)

View file

@ -19,7 +19,7 @@ logger = logging.getLogger(__name__)
@app.route('/v1/repositories/<path:repository>/tags',
methods=['GET'])
methods=['GET'])
@process_auth
@parse_repository_name
def get_tags(namespace, repository):
@ -34,7 +34,7 @@ def get_tags(namespace, repository):
@app.route('/v1/repositories/<path:repository>/tags/<tag>',
methods=['GET'])
methods=['GET'])
@process_auth
@parse_repository_name
def get_tag(namespace, repository, tag):
@ -48,7 +48,7 @@ def get_tag(namespace, repository, tag):
@app.route('/v1/repositories/<path:repository>/tags/<tag>',
methods=['PUT'])
methods=['PUT'])
@process_auth
@parse_repository_name
def put_tag(namespace, repository, tag):
@ -64,7 +64,7 @@ def put_tag(namespace, repository, tag):
@app.route('/v1/repositories/<path:repository>/tags/<tag>',
methods=['DELETE'])
methods=['DELETE'])
@process_auth
@parse_repository_name
def delete_tag(namespace, repository, tag):
@ -79,7 +79,7 @@ def delete_tag(namespace, repository, tag):
@app.route('/v1/repositories/<path:repository>/tags',
methods=['DELETE'])
methods=['DELETE'])
@process_auth
@parse_repository_name
def delete_repository_tags(namespace, repository):

View file

@ -60,7 +60,7 @@ def common_login(db_user):
identity=Identity(db_user.username, 'username'))
return True
else:
logger.debug('User could not be logged in, inactive?.');
logger.debug('User could not be logged in, inactive?.')
return False

View file

@ -1,4 +1,4 @@
from data.database import initialize_db
if __name__ == '__main__':
initialize_db()
initialize_db()