Andrew Bogott has uploaded a new change for review.
https://gerrit.wikimedia.org/r/67903
Change subject: Pep8 cleanup for swiftcleaner and fwconfigtool.
......................................................................
Pep8 cleanup for swiftcleaner and fwconfigtool.
Change-Id: Ibd3f921a33ff61aa4512d561d0a45d0d24292978
---
M .pep8
M fwconfigtool/fwconfigtool.py
M swiftcleaner/swiftcleaner
M swiftcleaner/swiftcleaner_helper.py
M swiftcleaner/swiftcleanermanager
5 files changed, 25 insertions(+), 20 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/operations/software
refs/changes/03/67903/1
diff --git a/.pep8 b/.pep8
index 8517a51..b9cd335 100644
--- a/.pep8
+++ b/.pep8
@@ -11,3 +11,4 @@
; E302 expected 2 blank lines, found 1
ignore = W191,E225,E231,E501,E301,E302
+exclude=swiftcleaner.conf
diff --git a/fwconfigtool/fwconfigtool.py b/fwconfigtool/fwconfigtool.py
index f9dfc82..8ec710a 100755
--- a/fwconfigtool/fwconfigtool.py
+++ b/fwconfigtool/fwconfigtool.py
@@ -40,7 +40,7 @@
# The standard opening directives for the SLAX firewall configuraation:
SLAX_DIRECTIVES = ('match configuration',
- '<change>')
+ '<change>')
def slax_header():
# Assumptions:
@@ -75,8 +75,8 @@
source dir: str, directory to read inputs from.
output file: str, filename to write the rules into.
"""
- parser = argparse.ArgumentParser(
- description='Converts puppet resources to junos SLAX')
+ parser = argparse.ArgumentParser(description=
+ 'Converts puppet resources to junos SLAX')
parser.add_argument('sourcedir', help='Source directory with files')
parser.add_argument('outputfile', help='Output SLAX file')
diff --git a/swiftcleaner/swiftcleaner b/swiftcleaner/swiftcleaner
index 794b36b..5908960 100755
--- a/swiftcleaner/swiftcleaner
+++ b/swiftcleaner/swiftcleaner
@@ -29,9 +29,16 @@
#### re-read live.
####
-import re, urllib2, urllib, threading, time, sys, subprocess
from optparse import OptionParser
+import re
+import subprocess
+import sys
+import threading
+import time
+import urllib
+import urllib2
import random
+
from swiftcleaner_helper import Token, read_config
class Stats():
@@ -61,8 +68,8 @@
threading.Thread.__init__(self)
self.objlist = objlist
self.delay = delay
- self.swift_obj_details = {} # hash for memorizing details
- self.ms5_obj_details = {} # hash for memorizing details
+ self.swift_obj_details = {} # hash for memorizing details
+ self.ms5_obj_details = {} # hash for memorizing details
#self.token = 'AUTH_abcd1234' #testing bad token exception catching
self.token = None
self.conf = conf
@@ -77,12 +84,12 @@
for obj in self.objlist:
res = self.check_object(obj)
print "checked out %s for object %s" % (res, obj[1])
- if(res == False):
+ if (res is False):
# we've found ourselves a bad object!
# go clean it up but don't slow us down.
threading.Thread(target=bad_object,
args=(obj,self.conf)).start()
# sleep for the delay time between checks
- if(self.delay != 0):
+ if (self.delay != 0):
time.sleep(self.delay)
return
@@ -138,7 +145,7 @@
we shouldn't do any more checks but we also shouldn't try and delete
it."""
res = self.get_object_details_swift(obj)
- if res == None:
+ if res is None:
# no dice.
return False
return True
@@ -260,7 +267,7 @@
print "deleting from swift failed for obj %s with error %s" % (obj,e)
purge_from_squid(obj)
time.sleep(0.5)
- purge_from_squid(obj) #purge a second time just for good measure
+ purge_from_squid(obj) # purge a second time just for good measure
def download_from_swift_and_ms5(obj, conf):
print "downloading %s from both swift and ms5" % obj_to_url(obj)
diff --git a/swiftcleaner/swiftcleaner_helper.py
b/swiftcleaner/swiftcleaner_helper.py
index eb0ee05..0e6992e 100644
--- a/swiftcleaner/swiftcleaner_helper.py
+++ b/swiftcleaner/swiftcleaner_helper.py
@@ -23,7 +23,7 @@
@classmethod
def get_token(cls):
# if we already have the token, return it.
- if(cls._token != None):
+ if(cls._token is not None):
#print " old token; returning token %s" % cls._token
return cls._token
# otherwise get a new token from Swift
@@ -74,7 +74,7 @@
val = float(val)
if opt in boolconfs:
# if it's set to anything but 'False', go ahead and enter
testing mode. safer that way.
- val = (False if val == False or val == 'False' else True)
+ val = (False if val is False or val == 'False' else True)
conf[opt] = val
configfh.close()
except (IOError, TypeError), e:
diff --git a/swiftcleaner/swiftcleanermanager b/swiftcleaner/swiftcleanermanager
index 6104014..4789478 100755
--- a/swiftcleaner/swiftcleanermanager
+++ b/swiftcleaner/swiftcleanermanager
@@ -20,9 +20,9 @@
## get a listing from swift (list of all containers or list of specific
container)
def get_swift_listing(conf, container=None):
swiftlist = []
- expectedswiftlistlen = 1 #this will get reset by the response header
+ expectedswiftlistlen = 1 # this will get reset by the response header
prevswiftlen = len(swiftlist)
- trycounter = 0 #if we try to get more 3 times without getting any, bail
even if we don't have all of them.
+ trycounter = 0 # if we try to get more 3 times without getting any, bail
even if we don't have all of them.
trycountermax = 3
headers = {}
headers['X-Auth-Token'] = Token.get_token()
@@ -76,7 +76,7 @@
# in case there are more still to come, prep the URL with the last
seen item
#
http://docs.openstack.org/api/openstack-object-storage/1.0/content/list-large-number-of-objects.html
- url = url.rsplit("?marker=", 1)[0] #strip off the ?marker=.* if it
exists
+ url = url.rsplit("?marker=", 1)[0] # strip off the ?marker=.* if it
exists
try:
url = "%s?marker=%s" % (url, urllib.pathname2url(swiftlist[-1]))
except IndexError:
@@ -100,7 +100,7 @@
contlist.append(cont)
continue
# we should keep containers that end with -thumb.[0-9a-f]{2}
- if(cont[-9:-3].endswith('-thumb')): #aka cut off the .a2 and then
compare
+ if(cont[-9:-3].endswith('-thumb')): # aka cut off the .a2 and then
compare
contlist.append(cont)
continue
# we didn't explicitly skip it, but we didn't include it either.
@@ -213,7 +213,7 @@
# But wait! there's a race condition!
# so let's pause for 0-0.1 sec and then
# let's check again and make sure that we actually put our own pid in that
file and someone else didn't jump in the middle.
- time.sleep(random()/10)
+ time.sleep(random() / 10)
otherpid = int(open(pidfile).readline().strip())
if(otherpid == pid):
# hooray! we're really the only one running.
@@ -223,8 +223,6 @@
time.sleep(random())
# recurse as many times as necessary to stop fighting. probably only once.
return am_i_alone(conf)
-
-
def main():
@@ -298,4 +296,3 @@
main()
# vim: set nu list expandtab tabstop=4 shiftwidth=4 autoindent:
-
--
To view, visit https://gerrit.wikimedia.org/r/67903
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibd3f921a33ff61aa4512d561d0a45d0d24292978
Gerrit-PatchSet: 1
Gerrit-Project: operations/software
Gerrit-Branch: master
Gerrit-Owner: Andrew Bogott <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits