Updates for PEP8.

This commit is contained in:
Scott Wallace 2013-07-13 08:44:35 +01:00
parent dfc8e231af
commit 396501a0f4
2 changed files with 38 additions and 29 deletions

View file

@ -1,4 +1,5 @@
#!/usr/bin/python
"""Script to create a simple mod_access style list for inclusion within Apache."""
import blocklist
import sys
@ -12,13 +13,16 @@ class ApacheBlockList(blocklist.BlockList):
print "\tDeny from %s/32" % address
print "\tAllow from all"
if __name__ == "__main__":
blocklist = ApacheBlockList()
def main():
"""Main program loop."""
block_list = ApacheBlockList()
blocklist.read("http://server1.example.com/default/blocks.txt")
blocklist.read("http://server2.example.com/default/blocks.txt")
block_list.read("http://server1.example.com/default/blocks.txt")
block_list.read("http://server2.example.com/default/blocks.txt")
blocklist.export()
block_list.export()
sys.exit(0)
if __name__ == "__main__":
main()

View file

@ -1,4 +1,5 @@
#!/usr/bin/python
"""Script to create a SQLite DB from the blocklist data."""
import blocklist
import sys
@ -15,27 +16,31 @@ class SQLiteBlockList(blocklist.BlockList):
"""Exports blocklist criteria to a SQLite file."""
try:
db = sqlite3.connect(self.config.get("sqlite", "database"))
cur = db.cursor()
database = sqlite3.connect(self.config.get("sqlite", "database"))
cur = database.cursor()
cur.execute("CREATE TABLE IF NOT EXISTS blocklist(remote_ip VARCHAR(15), forwarded_ip VARCHAR(15), useragent VARCHAR(256), cookie VARCHAR(1024), PRIMARY KEY(remote_ip))")
cur.execute("DELETE FROM blocklist")
for key,item in self.data.iteritems():
for item in self.data.values():
if item["useragent"] == 'NULL':
item["useragent"] = '(null)'
cur.execute("INSERT INTO blocklist VALUES ('%s', '%s', '%s', '%s')" % (item["remote_ip"], item["forwarded_ip"], item["useragent"], item["cookie"]))
db.commit()
database.commit()
cur.close()
except Exception, e:
logging.error("There was a problem exporting the data to SQLite. %s" % e)
except sqlite3.Error, error:
logging.error("There was a problem exporting the data to SQLite. %s", error)
if __name__ == "__main__":
blocklist = SQLiteBlockList()
def main():
"""Main program loop."""
block_list = SQLiteBlockList()
blocklist.read("http://example.com/default/blocks.txt")
block_list.read("http://example.com/default/blocks.txt")
blocklist.export()
block_list.export()
sys.exit(0)
if __name__ == "__main__":
main()