Skip to content

Commit

Permalink
Making new hacking happy
Browse files Browse the repository at this point in the history
Docker-DCO-1.1-Signed-off-by: Olivier Gambier <[email protected]> (github: dmp42)
  • Loading branch information
Olivier Gambier committed Aug 16, 2014
1 parent cc65b23 commit 4ff08ca
Show file tree
Hide file tree
Showing 30 changed files with 70 additions and 54 deletions.
6 changes: 3 additions & 3 deletions docker_registry/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
except ImportError as e:
_bugsnag_import_error = e
bugsnag = None
import flask

from . import toolkit
from .lib import config
from .server import __version__
import flask

# configure logging prior to subsequent imports which assume
# logging has been configured
Expand All @@ -22,8 +23,7 @@
level=getattr(logging, cfg.loglevel.upper()),
datefmt="%d/%b/%Y:%H:%M:%S %z")

from .lib import mirroring
from .server import __version__
from .lib import mirroring # noqa

app = flask.Flask('docker-registry')

Expand Down
2 changes: 1 addition & 1 deletion docker_registry/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .lib import mirroring
from .lib import signals

from .app import app
from .app import app # noqa


store = storage.load()
Expand Down
1 change: 0 additions & 1 deletion docker_registry/lib/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# -*- coding: utf-8 -*-
1 change: 1 addition & 0 deletions docker_registry/lib/cache.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

import logging

import redis

from docker_registry.core import lru
Expand Down
2 changes: 1 addition & 1 deletion docker_registry/lib/checksums.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ def compute_simple(fp, json_data):
json_data = file(sys.argv[1]).read()
fp = open(sys.argv[2])
print(compute_simple(fp, json_data))
#print compute_tarsum(fp, json_data)
# print compute_tarsum(fp, json_data)
4 changes: 3 additions & 1 deletion docker_registry/lib/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

import os

import rsa
import yaml

Expand All @@ -9,7 +10,8 @@


class Config(object):
"""A simple config class that:
"""A simple config class
* gives properties access through either items or attributes
* enforce types (thanks to yaml)
* interpolate from ENV
Expand Down
7 changes: 3 additions & 4 deletions docker_registry/lib/index/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
"""An SQLAlchemy backend for the search endpoint
"""

from ... import storage
from .. import config
from . import Index
import sqlalchemy
import sqlalchemy.exc
import sqlalchemy.ext.declarative
import sqlalchemy.orm
import sqlalchemy.sql.functions

from ... import storage
from .. import config
from . import Index


Base = sqlalchemy.ext.declarative.declarative_base()

Expand Down
6 changes: 6 additions & 0 deletions docker_registry/lib/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import tempfile

import backports.lzma as lzma

from docker_registry.core import compat
json = compat.json

Expand Down Expand Up @@ -60,6 +61,7 @@ def generate_ancestry(image_id, parent_id=None):

class Archive(lzma.LZMAFile):
"""file-object wrapper for decompressing xz compressed tar archives
This class wraps a file-object that contains tar archive data. The data
will be optionally decompressed with lzma/xz if found to be a compressed
archive.
Expand Down Expand Up @@ -120,6 +122,7 @@ def json(self):

def serialize_tar_info(tar_info):
'''serialize a tarfile.TarInfo instance
Take a single tarfile.TarInfo instance and serialize it to a
tuple. Consider union whiteouts by filename and mark them as
deleted in the third element. Don't include union metadata
Expand Down Expand Up @@ -190,6 +193,7 @@ def get_image_files_from_fobj(layer_file):

def get_image_files_json(image_id):
'''return json file listing for given image id
Download the specified layer and determine the file contents.
Alternatively, process a passed in file-object containing the
layer data.
Expand All @@ -212,6 +216,7 @@ def get_image_files_json(image_id):

def get_file_info_map(file_infos):
'''convert a list of file info tuples to dictionaries
Convert a list of layer file info tuples to a dictionary using the
first element (filename) as the key.
'''
Expand All @@ -231,6 +236,7 @@ def set_image_diff_cache(image_id, diff_json):

def get_image_diff_json(image_id):
'''get json describing file differences in layer
Calculate the diff information for the files contained within
the layer. Return a dictionary of lists grouped by whether they
were deleted, changed or created in this layer.
Expand Down
4 changes: 2 additions & 2 deletions docker_registry/lib/mirroring.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# -*- coding: utf-8 -*-

import flask
import functools
import logging
import requests

from .. import storage
from .. import toolkit
from . import cache
from . import config
import flask
import requests

logger = logging.getLogger(__name__)
cfg = config.load()
Expand Down
3 changes: 2 additions & 1 deletion docker_registry/lib/rlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

# https://gist.github.com/adewes/6103220

import redis
import time

import redis


class LockTimeout(BaseException):
pass
Expand Down
1 change: 1 addition & 0 deletions docker_registry/lib/rqueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def clear(self):

class CappedCollection(BaseQueue):
"""a bounded queue
Implements a capped collection (the collection never
gets larger than the specified size).
"""
Expand Down
4 changes: 1 addition & 3 deletions docker_registry/lib/xtarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@


def _proc_pax(self, filetar):
"""Process an extended or global header as described in
POSIX.1-2001.
"""
"""Process an extended or global header as described in POSIX.1-2001."""
# Read the header information.
buf = filetar.fileobj.read(self._block(self.size))

Expand Down
10 changes: 4 additions & 6 deletions docker_registry/search.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# -*- coding: utf-8 -*-

import flask
import flask_cors

from .lib import config
from .lib import index

from . import toolkit
from .app import app
from .lib import config
from .lib import index
import flask
import flask_cors


cfg = config.load()
Expand Down
1 change: 1 addition & 0 deletions docker_registry/server/env.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

import os

import yaml

__all__ = ['source']
Expand Down
7 changes: 4 additions & 3 deletions docker_registry/toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,9 @@ def get_remote_ip():

def is_ssl():
for header in ('X-Forwarded-Proto', 'X-Forwarded-Protocol'):
if header in flask.request.headers and \
flask.request.headers[header].lower() in ('https', 'ssl'):
if header in flask.request.headers and (
flask.request.headers[header].lower() in ('https', 'ssl')
):
return True
return False

Expand Down Expand Up @@ -294,6 +295,6 @@ def get_repository():
def get_endpoints(overcfg=None):
registry_endpoints = (overcfg or cfg).registry_endpoints
if not registry_endpoints:
#registry_endpoints = socket.gethostname()
# registry_endpoints = socket.gethostname()
registry_endpoints = flask.request.environ['HTTP_HOST']
return registry_endpoints
3 changes: 2 additions & 1 deletion docker_registry/wsgi.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from .server import env
import logging

from .server import env

_new_relic_ini = env.source('NEW_RELIC_INI')
if _new_relic_ini:
try:
Expand Down
1 change: 1 addition & 0 deletions requirements/test.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
coverage>=3.7,<4.0
mock>=1.0,<2.0
nose>=1.3,<2.0
six>=1.6,<2.0
18 changes: 10 additions & 8 deletions scripts/bandwidth_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import json
import logging
import re
import redis
import sys

import redis

logging.basicConfig(format='%(asctime)s %(levelname)s: %(message)s',
level=logging.INFO)
logger = logging.getLogger('metrics')
Expand Down Expand Up @@ -213,20 +214,21 @@ def generate_bandwidth_data(start_time, min_time, time_interval):
num_items)
if not most_recent_parsing:
most_recent_parsing = str_end_time
time_interval, items = \
time_interval, items = (
update_current_interval(items,
logging_interval,
start_time)
)
else:
time_interval, items = \
time_interval, items = (
adjust_current_interval(time_interval,
end_time,
items)
bandwidth_items[time_interval] = \
bandwidth_items.get(time_interval, 0.0) \
+ bandwidth
num_items[time_interval] = \
num_items.get(time_interval, 0.0) + 1
)
bandwidth_items[time_interval] = (
bandwidth_items.get(time_interval, 0.0) + bandwidth
)
num_items[time_interval] = num_items.get(time_interval, 0.0) + 1
end_times.pop(key, None)
if most_recent_parsing:
save_last_line_parsed(most_recent_parsing)
Expand Down
1 change: 1 addition & 0 deletions scripts/diff-worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def get_redis_connection(options):

def handle_request(layer_id, redis_conn):
'''handler for any item pulled from worker job queue
This handler is called every time the worker is able to pop a message
from the job queue filled by the registry. The worker blocks until a
message is available. This handler will then attempt to aquire a lock
Expand Down
3 changes: 2 additions & 1 deletion tests/lib/index/test__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import mock
import unittest

import mock

from docker_registry.lib import index


Expand Down
3 changes: 2 additions & 1 deletion tests/lib/index/test_db.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import mock
import unittest

import mock

from docker_registry.lib.index import db


Expand Down
4 changes: 3 additions & 1 deletion tests/mock_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
'''Monkeypatch s3 Storage preventing parallel key stream read in unittesting.
It is called from lib/storage/s3'''

import six

from docker_registry.core import exceptions
import docker_registry.drivers.s3 as s3
from docker_registry.testing import utils


@six.add_metaclass(utils.monkeypatch_class)
class Storage(s3.Storage):
__metaclass__ = utils.monkeypatch_class

# def stream_read(self, path, bytes_range=None):
# path = self._init_path(path)
Expand Down
1 change: 0 additions & 1 deletion tests/test_all_installed_drivers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-

from docker_registry.core import driver as driveengine

from docker_registry import testing
# Mock any boto
from docker_registry.testing import mock_boto # noqa
Expand Down
3 changes: 2 additions & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
# from docker_registry.core import exceptions
# import docker_registry.testing as testing

import mock
import os
import unittest

import mock

from docker_registry.lib import config


Expand Down
7 changes: 3 additions & 4 deletions tests/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import base

from docker_registry.core import compat
import docker_registry.images as images

json = compat.json


Expand All @@ -22,17 +24,14 @@ def test_nginx_accel_redirect_layer(self):
layer_data = self.gen_random_string(1024)
self.upload_image(image_id, parent_id=None, layer=layer_data)

import docker_registry.images as images

# ensure the storage mechanism is LocalStorage or this test is bad
self.assertTrue(images.store.scheme == 'file',
'Store must be LocalStorage')

# set the nginx accel config
accel_header = 'X-Accel-Redirect'
accel_prefix = '/registry'
images.cfg._config['nginx_x_accel_redirect'] \
= accel_prefix
images.cfg._config['nginx_x_accel_redirect'] = accel_prefix

layer_path = 'images/{0}/layer'.format(image_id)

Expand Down
5 changes: 3 additions & 2 deletions tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

class TestIndex(base.TestCase):

"""The Index module is fake at the moment, hence the unit tests only
test the return codes
"""The Index module is fake at the moment
hence the unit tests only test the return codes
"""

def test_users(self):
Expand Down
Loading

0 comments on commit 4ff08ca

Please sign in to comment.