pyflakes cleanups, unused modules, and variables

This commit is contained in:
kapil.foss@gmail.com 2010-07-30 08:20:07 -04:00
parent 138cf266e7
commit 65358e873f
19 changed files with 28 additions and 60 deletions

View File

@ -17,7 +17,6 @@ import os
import socket import socket
import time import time
from random import choice, random from random import choice, random
from urllib import quote
from eventlet import Timeout from eventlet import Timeout
@ -72,7 +71,6 @@ class AccountAuditor(object):
time.sleep(random() * self.interval) time.sleep(random() * self.interval)
while True: while True:
begin = time.time() begin = time.time()
pids = []
for device in os.listdir(self.devices): for device in os.listdir(self.devices):
if self.mount_check and not \ if self.mount_check and not \
os.path.ismount(os.path.join(self.devices, device)): os.path.ismount(os.path.join(self.devices, device)):

View File

@ -14,24 +14,22 @@
# limitations under the License. # limitations under the License.
from __future__ import with_statement from __future__ import with_statement
import errno
import os import os
import time import time
import traceback import traceback
from datetime import datetime
from urllib import unquote from urllib import unquote
from swift.common.utils import get_logger from swift.common.utils import get_logger
import sqlite3
from webob import Request, Response from webob import Request, Response
from webob.exc import HTTPAccepted, HTTPBadRequest, HTTPConflict, \ from webob.exc import HTTPAccepted, HTTPBadRequest, \
HTTPCreated, HTTPForbidden, HTTPInternalServerError, \ HTTPCreated, HTTPForbidden, HTTPInternalServerError, \
HTTPMethodNotAllowed, HTTPNoContent, HTTPNotFound, HTTPPreconditionFailed HTTPMethodNotAllowed, HTTPNoContent, HTTPNotFound, HTTPPreconditionFailed
import simplejson import simplejson
from xml.sax import saxutils from xml.sax import saxutils
from swift.common.db import AccountBroker from swift.common.db import AccountBroker
from swift.common.exceptions import MessageTimeout
from swift.common.utils import get_param, split_path, storage_directory, \ from swift.common.utils import get_param, split_path, storage_directory, \
hash_path hash_path
from swift.common.constraints import ACCOUNT_LISTING_LIMIT, \ from swift.common.constraints import ACCOUNT_LISTING_LIMIT, \

View File

@ -27,7 +27,7 @@ from webob.exc import HTTPBadRequest, HTTPNoContent, HTTPUnauthorized, \
HTTPServiceUnavailable, HTTPNotFound HTTPServiceUnavailable, HTTPNotFound
from swift.common.bufferedhttp import http_connect 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.ring import Ring
from swift.common.utils import get_logger, normalize_timestamp, split_path from swift.common.utils import get_logger, normalize_timestamp, split_path

View File

@ -13,8 +13,6 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from ConfigParser import ConfigParser, NoOptionError
import os
import time import time
from webob.request import Request from webob.request import Request

View File

@ -38,8 +38,6 @@ CONTAINER_LISTING_LIMIT = 10000
ACCOUNT_LISTING_LIMIT = 10000 ACCOUNT_LISTING_LIMIT = 10000
def check_metadata(req): def check_metadata(req):
""" """
Check metadata sent for objects in the request headers. Check metadata sent for objects in the request headers.

View File

@ -27,7 +27,6 @@ import cPickle as pickle
import errno import errno
from random import randint from random import randint
from tempfile import mkstemp from tempfile import mkstemp
import math
from eventlet import sleep from eventlet import sleep
import sqlite3 import sqlite3
@ -332,7 +331,7 @@ class DatabaseBroker(object):
:param delete_timestamp: delete timestamp :param delete_timestamp: delete timestamp
""" """
with self.get() as conn: with self.get() as conn:
row = conn.execute(''' conn.execute('''
UPDATE %s_stat SET created_at=MIN(?, created_at), UPDATE %s_stat SET created_at=MIN(?, created_at),
put_timestamp=MAX(?, put_timestamp), put_timestamp=MAX(?, put_timestamp),
delete_timestamp=MAX(?, delete_timestamp) delete_timestamp=MAX(?, delete_timestamp)
@ -919,7 +918,7 @@ class ContainerBroker(DatabaseBroker):
with self.get() as conn: with self.get() as conn:
max_rowid = -1 max_rowid = -1
for rec in item_list: for rec in item_list:
curs = conn.execute(''' conn.execute('''
DELETE FROM object WHERE name = ? AND DELETE FROM object WHERE name = ? AND
(created_at < ?) (created_at < ?)
''', (rec['name'], rec['created_at'])) ''', (rec['name'], rec['created_at']))

View File

@ -14,7 +14,6 @@
# limitations under the License. # limitations under the License.
from array import array from array import array
from bisect import bisect
from random import randint from random import randint
from time import time from time import time

View File

@ -15,7 +15,6 @@
import cPickle as pickle import cPickle as pickle
from gzip import GzipFile from gzip import GzipFile
from hashlib import md5
from os.path import getmtime from os.path import getmtime
from struct import unpack_from from struct import unpack_from
from time import time from time import time

View File

@ -67,6 +67,7 @@ def load_libc_function(func_name):
except AttributeError: except AttributeError:
logging.warn("Unable to locate %s in libc. Leaving as a no-op." logging.warn("Unable to locate %s in libc. Leaving as a no-op."
% func_name) % func_name)
def noop_libc_function(*args): def noop_libc_function(*args):
return 0 return 0
return noop_libc_function return noop_libc_function

View File

@ -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 # We might be able to pull pieces of this out to test, but right now it seems
# like more work than it's worth. # like more work than it's worth.
def run_wsgi(app, conf, *args, **kwargs): # pragma: no cover def run_wsgi(app, conf, *args, **kwargs): # pragma: no cover
""" """
Loads common settings from conf, then instantiates app and runs Loads common settings from conf, then instantiates app and runs

View File

@ -87,7 +87,6 @@ class ContainerAuditor(object):
time.sleep(random() * self.interval) time.sleep(random() * self.interval)
while True: while True:
begin = time.time() begin = time.time()
pids = []
for device in os.listdir(self.devices): for device in os.listdir(self.devices):
if self.mount_check and not\ if self.mount_check and not\
os.path.ismount(os.path.join(self.devices, device)): os.path.ismount(os.path.join(self.devices, device)):
@ -184,7 +183,6 @@ class ContainerAuditor(object):
resp = conn.getresponse() resp = conn.getresponse()
body = resp.read() body = resp.read()
if 200 <= resp.status <= 299: if 200 <= resp.status <= 299:
good_reponse = True
for cname in body.split('\n'): for cname in body.split('\n'):
if cname == info['container']: if cname == info['container']:
found = True found = True

View File

@ -14,9 +14,8 @@
# limitations under the License. # limitations under the License.
from __future__ import with_statement from __future__ import with_statement
import errno
import os import os
import socket
import time import time
import traceback import traceback
from urllib import unquote from urllib import unquote
@ -25,20 +24,19 @@ from datetime import datetime
import simplejson import simplejson
from eventlet.timeout import Timeout from eventlet.timeout import Timeout
from eventlet import TimeoutError
from webob import Request, Response from webob import Request, Response
from webob.exc import HTTPAccepted, HTTPBadRequest, HTTPConflict, \ from webob.exc import HTTPAccepted, HTTPBadRequest, HTTPConflict, \
HTTPCreated, HTTPException, HTTPInternalServerError, HTTPNoContent, \ HTTPCreated, HTTPInternalServerError, HTTPNoContent, \
HTTPNotFound, HTTPPreconditionFailed, HTTPMethodNotAllowed HTTPNotFound, HTTPPreconditionFailed, HTTPMethodNotAllowed
from swift.common.db import ContainerBroker from swift.common.db import ContainerBroker
from swift.common.utils import get_logger, get_param, hash_path, \ 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, \ from swift.common.constraints import CONTAINER_LISTING_LIMIT, \
check_mount, check_float, check_xml_encodable check_mount, check_float, check_xml_encodable
from swift.common.bufferedhttp import http_connect from swift.common.bufferedhttp import http_connect
from swift.common.healthcheck import healthcheck 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 from swift.common.db_replicator import ReplicatorRpc
DATADIR = 'containers' DATADIR = 'containers'

View File

@ -13,11 +13,9 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import errno
import logging import logging
import os import os
import signal import signal
import socket
import sys import sys
import time import time
from random import random, shuffle from random import random, shuffle
@ -67,7 +65,6 @@ class ContainerUpdater(object):
:returns: a list of paths :returns: a list of paths
""" """
paths = [] paths = []
ips = whataremyips()
for device in os.listdir(self.devices): for device in os.listdir(self.devices):
dev_path = os.path.join(self.devices, device) dev_path = os.path.join(self.devices, device)
if self.mount_check and not os.path.ismount(dev_path): if self.mount_check and not os.path.ismount(dev_path):

View File

@ -13,10 +13,8 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import cPickle as pickle
import os import os
import socket import socket
import sys
import time import time
from hashlib import md5 from hashlib import md5
from random import choice, random from random import choice, random
@ -71,7 +69,6 @@ class ObjectAuditor(object):
time.sleep(random() * self.interval) time.sleep(random() * self.interval)
while True: while True:
begin = time.time() begin = time.time()
pids = []
# read from container ring to ensure it's fresh # read from container ring to ensure it's fresh
self.get_container_ring().get_nodes('') self.get_container_ring().get_nodes('')
for device in os.listdir(self.devices): for device in os.listdir(self.devices):
@ -192,7 +189,6 @@ class ObjectAuditor(object):
resp = conn.getresponse() resp = conn.getresponse()
body = resp.read() body = resp.read()
if 200 <= resp.status <= 299: if 200 <= resp.status <= 299:
good_reponse = True
for oname in body.split('\n'): for oname in body.split('\n'):
if oname == obj: if oname == obj:
found = True found = True

View File

@ -14,9 +14,7 @@
# limitations under the License. # limitations under the License.
import os import os
import sys
from os.path import isdir, join from os.path import isdir, join
from ConfigParser import ConfigParser
import random import random
import shutil import shutil
import time import time
@ -385,7 +383,7 @@ class ObjectReplicator(object):
remote_hash.get(suffix, -1)] remote_hash.get(suffix, -1)]
if not suffixes: if not suffixes:
continue continue
success = self.rsync(node, job, suffixes) self.rsync(node, job, suffixes)
recalculate_hashes(job['path'], suffixes, recalculate_hashes(job['path'], suffixes,
reclaim_age=self.reclaim_age) reclaim_age=self.reclaim_age)
with Timeout(60): with Timeout(60):
@ -409,7 +407,6 @@ class ObjectReplicator(object):
""" """
if self.replication_count: if self.replication_count:
rate = self.replication_count / (time.time() - self.start) 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 " self.logger.info("%d/%d (%.2f%%) partitions replicated in %.2f "
"seconds (%.2f/sec, %s remaining)" "seconds (%.2f/sec, %s remaining)"
% (self.replication_count, self.job_count, % (self.replication_count, self.job_count,

View File

@ -19,7 +19,6 @@ from __future__ import with_statement
import cPickle as pickle import cPickle as pickle
import errno import errno
import os import os
import socket
import time import time
import traceback import traceback
from datetime import datetime from datetime import datetime
@ -30,13 +29,12 @@ from contextlib import contextmanager
from webob import Request, Response, UTC from webob import Request, Response, UTC
from webob.exc import HTTPAccepted, HTTPBadRequest, HTTPCreated, \ from webob.exc import HTTPAccepted, HTTPBadRequest, HTTPCreated, \
HTTPInternalServerError, HTTPLengthRequired, HTTPNoContent, HTTPNotFound, \ HTTPInternalServerError, HTTPNoContent, HTTPNotFound, \
HTTPNotImplemented, HTTPNotModified, HTTPPreconditionFailed, \ HTTPNotModified, HTTPPreconditionFailed, \
HTTPRequestTimeout, HTTPUnprocessableEntity, HTTPMethodNotAllowed HTTPRequestTimeout, HTTPUnprocessableEntity, HTTPMethodNotAllowed
from xattr import getxattr, setxattr from xattr import getxattr, setxattr
from eventlet import sleep, Timeout from eventlet import sleep, Timeout
from swift.common.exceptions import MessageTimeout
from swift.common.utils import mkdirs, normalize_timestamp, \ from swift.common.utils import mkdirs, normalize_timestamp, \
storage_directory, hash_path, get_logger, renamer, fallocate, \ storage_directory, hash_path, get_logger, renamer, fallocate, \
split_path, drop_buffer_cache split_path, drop_buffer_cache
@ -331,12 +329,12 @@ class ObjectController(object):
return Response(status='507 %s is not mounted' % device) return Response(status='507 %s is not mounted' % device)
file = DiskFile(self.devices, device, partition, account, container, file = DiskFile(self.devices, device, partition, account, container,
obj, disk_chunk_size=self.disk_chunk_size) obj, disk_chunk_size=self.disk_chunk_size)
deleted = file.is_deleted()
if file.is_deleted(): if file.is_deleted():
response_class = HTTPNotFound response_class = HTTPNotFound
else: else:
response_class = HTTPAccepted response_class = HTTPAccepted
old_metadata = file.metadata
metadata = {'X-Timestamp': request.headers['x-timestamp']} metadata = {'X-Timestamp': request.headers['x-timestamp']}
metadata.update(val for val in request.headers.iteritems() metadata.update(val for val in request.headers.iteritems()
if val[0].lower().startswith('x-object-meta-')) if val[0].lower().startswith('x-object-meta-'))

View File

@ -14,8 +14,6 @@
# limitations under the License. # limitations under the License.
import cPickle as pickle import cPickle as pickle
import errno
import logging
import os import os
import signal import signal
import sys import sys
@ -28,7 +26,6 @@ from swift.common.bufferedhttp import http_connect
from swift.common.exceptions import ConnectionTimeout from swift.common.exceptions import ConnectionTimeout
from swift.common.ring import Ring from swift.common.ring import Ring
from swift.common.utils import get_logger, renamer from swift.common.utils import get_logger, renamer
from swift.common.db_replicator import ReplConnection
from swift.obj.server import ASYNCDIR from swift.obj.server import ASYNCDIR
@ -149,7 +146,7 @@ class ObjectUpdater(object):
""" """
try: try:
update = pickle.load(open(update_path, 'rb')) update = pickle.load(open(update_path, 'rb'))
except Exception, err: except Exception:
self.logger.exception( self.logger.exception(
'ERROR Pickle problem, quarantining %s' % update_path) 'ERROR Pickle problem, quarantining %s' % update_path)
renamer(update_path, os.path.join(device, renamer(update_path, os.path.join(device,

View File

@ -14,22 +14,18 @@
# limitations under the License. # limitations under the License.
from __future__ import with_statement from __future__ import with_statement
import errno
import mimetypes import mimetypes
import os import os
import socket
import time import time
from ConfigParser import ConfigParser, NoOptionError from ConfigParser import ConfigParser
from urllib import unquote, quote from urllib import unquote, quote
import uuid import uuid
import sys
import functools import functools
from eventlet.timeout import Timeout from eventlet.timeout import Timeout
from webob.exc import HTTPAccepted, HTTPBadRequest, HTTPConflict, \ from webob.exc import HTTPBadRequest, HTTPMethodNotAllowed, \
HTTPCreated, HTTPLengthRequired, HTTPMethodNotAllowed, HTTPNoContent, \ HTTPNotFound, HTTPPreconditionFailed, \
HTTPNotFound, HTTPNotModified, HTTPPreconditionFailed, \ HTTPRequestTimeout, HTTPServiceUnavailable, \
HTTPRequestTimeout, HTTPServiceUnavailable, HTTPUnauthorized, \
HTTPUnprocessableEntity, HTTPRequestEntityTooLarge, HTTPServerError, \ HTTPUnprocessableEntity, HTTPRequestEntityTooLarge, HTTPServerError, \
status_map status_map
from webob import Request, Response from webob import Request, Response

View File

@ -40,11 +40,12 @@ class TestObjectHandoff(unittest.TestCase):
container = 'container-%s' % uuid4() container = 'container-%s' % uuid4()
client.put_container(self.url, self.token, container) client.put_container(self.url, self.token, container)
apart, anodes = self.account_ring.get_nodes(self.account) apart, anodes = self.account_ring.get_nodes(self.account)
anode = anodes[0]
cpart, cnodes = self.container_ring.get_nodes(self.account, container) cpart, cnodes = self.container_ring.get_nodes(self.account, container)
cnode = cnodes[0] cnode = cnodes[0]
obj = 'object-%s' % uuid4() 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] onode = onodes[0]
kill(self.pids[self.port2server[onode['port']]], SIGTERM) kill(self.pids[self.port2server[onode['port']]], SIGTERM)
client.put_object(self.url, self.token, container, obj, 'VERIFY') 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) kill(self.pids[self.port2server[onode['port']]], SIGTERM)
client.post_object(self.url, self.token, container, obj, client.post_object(self.url, self.token, container, obj,
{'probe': 'value'}) {'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': if ometadata.get('probe') != 'value':
raise Exception('Metadata incorrect, was %s' % repr(ometadata)) raise Exception('Metadata incorrect, was %s' % repr(ometadata))
exc = False exc = False
@ -180,8 +182,8 @@ class TestObjectHandoff(unittest.TestCase):
raise Exception('Container listing still knew about object') raise Exception('Container listing still knew about object')
for cnode in cnodes: for cnode in cnodes:
objs = [o['name'] for o in objs = [o['name'] for o in
direct_client.direct_get_container(cnode, cpart, direct_client.direct_get_container(
self.account, container)] cnode, cpart, self.account, container)]
if obj in objs: if obj in objs:
raise Exception( raise Exception(
'Container server %s:%s still knew about object' % 'Container server %s:%s still knew about object' %