From 65358e873fde11cf31bffa8a1eddce27d4f25516 Mon Sep 17 00:00:00 2001 From: "kapil.foss@gmail.com" <> Date: Fri, 30 Jul 2010 08:20:07 -0400 Subject: [PATCH] pyflakes cleanups, unused modules, and variables --- swift/account/auditor.py | 2 -- swift/account/server.py | 8 +++----- swift/auth/server.py | 2 +- swift/common/auth.py | 2 -- swift/common/constraints.py | 2 -- swift/common/db.py | 5 ++--- swift/common/ring/builder.py | 1 - swift/common/ring/ring.py | 1 - swift/common/utils.py | 1 + swift/common/wsgi.py | 1 - swift/container/auditor.py | 2 -- swift/container/server.py | 10 ++++------ swift/container/updater.py | 3 --- swift/obj/auditor.py | 4 ---- swift/obj/replicator.py | 5 +---- swift/obj/server.py | 10 ++++------ swift/obj/updater.py | 5 +---- swift/proxy/server.py | 12 ++++-------- test/probe/test_object_handoff.py | 12 +++++++----- 19 files changed, 28 insertions(+), 60 deletions(-) diff --git a/swift/account/auditor.py b/swift/account/auditor.py index 94eb5523bf..a21ed0849b 100644 --- a/swift/account/auditor.py +++ b/swift/account/auditor.py @@ -17,7 +17,6 @@ import os import socket import time from random import choice, random -from urllib import quote from eventlet import Timeout @@ -72,7 +71,6 @@ class AccountAuditor(object): time.sleep(random() * self.interval) while True: begin = time.time() - pids = [] for device in os.listdir(self.devices): if self.mount_check and not \ os.path.ismount(os.path.join(self.devices, device)): diff --git a/swift/account/server.py b/swift/account/server.py index dc741daa2a..6e5dd7472e 100644 --- a/swift/account/server.py +++ b/swift/account/server.py @@ -14,24 +14,22 @@ # limitations under the License. from __future__ import with_statement -import errno + import os import time import traceback -from datetime import datetime + from urllib import unquote from swift.common.utils import get_logger -import sqlite3 from webob import Request, Response -from webob.exc import HTTPAccepted, HTTPBadRequest, HTTPConflict, \ +from webob.exc import HTTPAccepted, HTTPBadRequest, \ HTTPCreated, HTTPForbidden, HTTPInternalServerError, \ HTTPMethodNotAllowed, HTTPNoContent, HTTPNotFound, HTTPPreconditionFailed import simplejson from xml.sax import saxutils from swift.common.db import AccountBroker -from swift.common.exceptions import MessageTimeout from swift.common.utils import get_param, split_path, storage_directory, \ hash_path from swift.common.constraints import ACCOUNT_LISTING_LIMIT, \ diff --git a/swift/auth/server.py b/swift/auth/server.py index a06c867302..676b6fc6d9 100644 --- a/swift/auth/server.py +++ b/swift/auth/server.py @@ -27,7 +27,7 @@ from webob.exc import HTTPBadRequest, HTTPNoContent, HTTPUnauthorized, \ HTTPServiceUnavailable, HTTPNotFound from swift.common.bufferedhttp import http_connect -from swift.common.db import DatabaseConnectionError, get_db_connection +from swift.common.db import get_db_connection from swift.common.ring import Ring from swift.common.utils import get_logger, normalize_timestamp, split_path diff --git a/swift/common/auth.py b/swift/common/auth.py index c2da4e1e70..6830b60ba7 100644 --- a/swift/common/auth.py +++ b/swift/common/auth.py @@ -13,8 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from ConfigParser import ConfigParser, NoOptionError -import os import time from webob.request import Request diff --git a/swift/common/constraints.py b/swift/common/constraints.py index eda4d80dff..c43bec89e6 100644 --- a/swift/common/constraints.py +++ b/swift/common/constraints.py @@ -38,8 +38,6 @@ CONTAINER_LISTING_LIMIT = 10000 ACCOUNT_LISTING_LIMIT = 10000 - - def check_metadata(req): """ Check metadata sent for objects in the request headers. diff --git a/swift/common/db.py b/swift/common/db.py index 1df8b13a69..e2eb2a2901 100644 --- a/swift/common/db.py +++ b/swift/common/db.py @@ -27,7 +27,6 @@ import cPickle as pickle import errno from random import randint from tempfile import mkstemp -import math from eventlet import sleep import sqlite3 @@ -332,7 +331,7 @@ class DatabaseBroker(object): :param delete_timestamp: delete timestamp """ with self.get() as conn: - row = conn.execute(''' + conn.execute(''' UPDATE %s_stat SET created_at=MIN(?, created_at), put_timestamp=MAX(?, put_timestamp), delete_timestamp=MAX(?, delete_timestamp) @@ -919,7 +918,7 @@ class ContainerBroker(DatabaseBroker): with self.get() as conn: max_rowid = -1 for rec in item_list: - curs = conn.execute(''' + conn.execute(''' DELETE FROM object WHERE name = ? AND (created_at < ?) ''', (rec['name'], rec['created_at'])) diff --git a/swift/common/ring/builder.py b/swift/common/ring/builder.py index 5826c112df..7c0b08adea 100644 --- a/swift/common/ring/builder.py +++ b/swift/common/ring/builder.py @@ -14,7 +14,6 @@ # limitations under the License. from array import array -from bisect import bisect from random import randint from time import time diff --git a/swift/common/ring/ring.py b/swift/common/ring/ring.py index 4cc47680b5..fea22e8ffa 100644 --- a/swift/common/ring/ring.py +++ b/swift/common/ring/ring.py @@ -15,7 +15,6 @@ import cPickle as pickle from gzip import GzipFile -from hashlib import md5 from os.path import getmtime from struct import unpack_from from time import time diff --git a/swift/common/utils.py b/swift/common/utils.py index e51b15fd25..dab0b9d255 100644 --- a/swift/common/utils.py +++ b/swift/common/utils.py @@ -67,6 +67,7 @@ def load_libc_function(func_name): except AttributeError: logging.warn("Unable to locate %s in libc. Leaving as a no-op." % func_name) + def noop_libc_function(*args): return 0 return noop_libc_function diff --git a/swift/common/wsgi.py b/swift/common/wsgi.py index 06b2e8f157..f0045e0393 100644 --- a/swift/common/wsgi.py +++ b/swift/common/wsgi.py @@ -58,7 +58,6 @@ def monkey_patch_mimetools(): # We might be able to pull pieces of this out to test, but right now it seems # like more work than it's worth. - def run_wsgi(app, conf, *args, **kwargs): # pragma: no cover """ Loads common settings from conf, then instantiates app and runs diff --git a/swift/container/auditor.py b/swift/container/auditor.py index 6947db7e5c..b507b0c57d 100644 --- a/swift/container/auditor.py +++ b/swift/container/auditor.py @@ -87,7 +87,6 @@ class ContainerAuditor(object): time.sleep(random() * self.interval) while True: begin = time.time() - pids = [] for device in os.listdir(self.devices): if self.mount_check and not\ os.path.ismount(os.path.join(self.devices, device)): @@ -184,7 +183,6 @@ class ContainerAuditor(object): resp = conn.getresponse() body = resp.read() if 200 <= resp.status <= 299: - good_reponse = True for cname in body.split('\n'): if cname == info['container']: found = True diff --git a/swift/container/server.py b/swift/container/server.py index 44fedf913a..57775ee661 100644 --- a/swift/container/server.py +++ b/swift/container/server.py @@ -14,9 +14,8 @@ # limitations under the License. from __future__ import with_statement -import errno + import os -import socket import time import traceback from urllib import unquote @@ -25,20 +24,19 @@ from datetime import datetime import simplejson from eventlet.timeout import Timeout -from eventlet import TimeoutError from webob import Request, Response from webob.exc import HTTPAccepted, HTTPBadRequest, HTTPConflict, \ - HTTPCreated, HTTPException, HTTPInternalServerError, HTTPNoContent, \ + HTTPCreated, HTTPInternalServerError, HTTPNoContent, \ HTTPNotFound, HTTPPreconditionFailed, HTTPMethodNotAllowed from swift.common.db import ContainerBroker from swift.common.utils import get_logger, get_param, hash_path, \ - storage_directory, split_path, mkdirs + storage_directory, split_path from swift.common.constraints import CONTAINER_LISTING_LIMIT, \ check_mount, check_float, check_xml_encodable from swift.common.bufferedhttp import http_connect from swift.common.healthcheck import healthcheck -from swift.common.exceptions import ConnectionTimeout, MessageTimeout +from swift.common.exceptions import ConnectionTimeout from swift.common.db_replicator import ReplicatorRpc DATADIR = 'containers' diff --git a/swift/container/updater.py b/swift/container/updater.py index 486cb45959..a0db68cfa6 100644 --- a/swift/container/updater.py +++ b/swift/container/updater.py @@ -13,11 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -import errno import logging import os import signal -import socket import sys import time from random import random, shuffle @@ -67,7 +65,6 @@ class ContainerUpdater(object): :returns: a list of paths """ paths = [] - ips = whataremyips() for device in os.listdir(self.devices): dev_path = os.path.join(self.devices, device) if self.mount_check and not os.path.ismount(dev_path): diff --git a/swift/obj/auditor.py b/swift/obj/auditor.py index 91079ebade..62484ffb0b 100644 --- a/swift/obj/auditor.py +++ b/swift/obj/auditor.py @@ -13,10 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -import cPickle as pickle import os import socket -import sys import time from hashlib import md5 from random import choice, random @@ -71,7 +69,6 @@ class ObjectAuditor(object): time.sleep(random() * self.interval) while True: begin = time.time() - pids = [] # read from container ring to ensure it's fresh self.get_container_ring().get_nodes('') for device in os.listdir(self.devices): @@ -192,7 +189,6 @@ class ObjectAuditor(object): resp = conn.getresponse() body = resp.read() if 200 <= resp.status <= 299: - good_reponse = True for oname in body.split('\n'): if oname == obj: found = True diff --git a/swift/obj/replicator.py b/swift/obj/replicator.py index 33b6dcb94f..5dd06056b3 100644 --- a/swift/obj/replicator.py +++ b/swift/obj/replicator.py @@ -14,9 +14,7 @@ # limitations under the License. import os -import sys from os.path import isdir, join -from ConfigParser import ConfigParser import random import shutil import time @@ -385,7 +383,7 @@ class ObjectReplicator(object): remote_hash.get(suffix, -1)] if not suffixes: continue - success = self.rsync(node, job, suffixes) + self.rsync(node, job, suffixes) recalculate_hashes(job['path'], suffixes, reclaim_age=self.reclaim_age) with Timeout(60): @@ -409,7 +407,6 @@ class ObjectReplicator(object): """ if self.replication_count: rate = self.replication_count / (time.time() - self.start) - left = int((self.job_count - self.replication_count) / rate) self.logger.info("%d/%d (%.2f%%) partitions replicated in %.2f " "seconds (%.2f/sec, %s remaining)" % (self.replication_count, self.job_count, diff --git a/swift/obj/server.py b/swift/obj/server.py index 6139b402e3..39c2ca2276 100644 --- a/swift/obj/server.py +++ b/swift/obj/server.py @@ -19,7 +19,6 @@ from __future__ import with_statement import cPickle as pickle import errno import os -import socket import time import traceback from datetime import datetime @@ -30,13 +29,12 @@ from contextlib import contextmanager from webob import Request, Response, UTC from webob.exc import HTTPAccepted, HTTPBadRequest, HTTPCreated, \ - HTTPInternalServerError, HTTPLengthRequired, HTTPNoContent, HTTPNotFound, \ - HTTPNotImplemented, HTTPNotModified, HTTPPreconditionFailed, \ + HTTPInternalServerError, HTTPNoContent, HTTPNotFound, \ + HTTPNotModified, HTTPPreconditionFailed, \ HTTPRequestTimeout, HTTPUnprocessableEntity, HTTPMethodNotAllowed from xattr import getxattr, setxattr from eventlet import sleep, Timeout -from swift.common.exceptions import MessageTimeout from swift.common.utils import mkdirs, normalize_timestamp, \ storage_directory, hash_path, get_logger, renamer, fallocate, \ split_path, drop_buffer_cache @@ -331,12 +329,12 @@ class ObjectController(object): return Response(status='507 %s is not mounted' % device) file = DiskFile(self.devices, device, partition, account, container, obj, disk_chunk_size=self.disk_chunk_size) - deleted = file.is_deleted() + if file.is_deleted(): response_class = HTTPNotFound else: response_class = HTTPAccepted - old_metadata = file.metadata + metadata = {'X-Timestamp': request.headers['x-timestamp']} metadata.update(val for val in request.headers.iteritems() if val[0].lower().startswith('x-object-meta-')) diff --git a/swift/obj/updater.py b/swift/obj/updater.py index 3609c1ca95..e974364090 100644 --- a/swift/obj/updater.py +++ b/swift/obj/updater.py @@ -14,8 +14,6 @@ # limitations under the License. import cPickle as pickle -import errno -import logging import os import signal import sys @@ -28,7 +26,6 @@ from swift.common.bufferedhttp import http_connect from swift.common.exceptions import ConnectionTimeout from swift.common.ring import Ring from swift.common.utils import get_logger, renamer -from swift.common.db_replicator import ReplConnection from swift.obj.server import ASYNCDIR @@ -149,7 +146,7 @@ class ObjectUpdater(object): """ try: update = pickle.load(open(update_path, 'rb')) - except Exception, err: + except Exception: self.logger.exception( 'ERROR Pickle problem, quarantining %s' % update_path) renamer(update_path, os.path.join(device, diff --git a/swift/proxy/server.py b/swift/proxy/server.py index c900108601..804bf65bcc 100644 --- a/swift/proxy/server.py +++ b/swift/proxy/server.py @@ -14,22 +14,18 @@ # limitations under the License. from __future__ import with_statement -import errno import mimetypes import os -import socket import time -from ConfigParser import ConfigParser, NoOptionError +from ConfigParser import ConfigParser from urllib import unquote, quote import uuid -import sys import functools from eventlet.timeout import Timeout -from webob.exc import HTTPAccepted, HTTPBadRequest, HTTPConflict, \ - HTTPCreated, HTTPLengthRequired, HTTPMethodNotAllowed, HTTPNoContent, \ - HTTPNotFound, HTTPNotModified, HTTPPreconditionFailed, \ - HTTPRequestTimeout, HTTPServiceUnavailable, HTTPUnauthorized, \ +from webob.exc import HTTPBadRequest, HTTPMethodNotAllowed, \ + HTTPNotFound, HTTPPreconditionFailed, \ + HTTPRequestTimeout, HTTPServiceUnavailable, \ HTTPUnprocessableEntity, HTTPRequestEntityTooLarge, HTTPServerError, \ status_map from webob import Request, Response diff --git a/test/probe/test_object_handoff.py b/test/probe/test_object_handoff.py index 6afec71450..20a29772c4 100755 --- a/test/probe/test_object_handoff.py +++ b/test/probe/test_object_handoff.py @@ -40,11 +40,12 @@ class TestObjectHandoff(unittest.TestCase): container = 'container-%s' % uuid4() client.put_container(self.url, self.token, container) apart, anodes = self.account_ring.get_nodes(self.account) - anode = anodes[0] + cpart, cnodes = self.container_ring.get_nodes(self.account, container) cnode = cnodes[0] obj = 'object-%s' % uuid4() - opart, onodes = self.object_ring.get_nodes(self.account, container, obj) + opart, onodes = self.object_ring.get_nodes( + self.account, container, obj) onode = onodes[0] kill(self.pids[self.port2server[onode['port']]], SIGTERM) client.put_object(self.url, self.token, container, obj, 'VERIFY') @@ -126,7 +127,8 @@ class TestObjectHandoff(unittest.TestCase): kill(self.pids[self.port2server[onode['port']]], SIGTERM) client.post_object(self.url, self.token, container, obj, {'probe': 'value'}) - ometadata = client.head_object(self.url, self.token, container, obj)[-1] + ometadata = client.head_object( + self.url, self.token, container, obj)[-1] if ometadata.get('probe') != 'value': raise Exception('Metadata incorrect, was %s' % repr(ometadata)) exc = False @@ -180,8 +182,8 @@ class TestObjectHandoff(unittest.TestCase): raise Exception('Container listing still knew about object') for cnode in cnodes: objs = [o['name'] for o in - direct_client.direct_get_container(cnode, cpart, - self.account, container)] + direct_client.direct_get_container( + cnode, cpart, self.account, container)] if obj in objs: raise Exception( 'Container server %s:%s still knew about object' %