Plone site broken? Fix ir through the zodb

Today someone changed the ip on a dev box running an instance that had the ip as part of the url in CacheFu. So of course it won't load a page anymore. What to do? reinstall? nah. Let 's think for a second. Plone is a nice interface to Zope/CMF. Zope/CMF is a lovely interface to ZODB. ZODB is a persistence engine for Python objects. CacheFu's settings are persisted as atributes of a cache object in the ZODB. Let's just fix it directly....

/usr/local/{instance}/bin/zopectl debug
Starting debugger (the name "app" is bound to the top-level Zope object)
...{ 8< snip } ...
>>> import readline, rlcompleter, transaction
>>> readline.parse_and_bind("tab: complete")
# now we have tab completion
# bind the plone root to s
>>> s = app.itcd
# bind our (s)ites cache settings to cc
>>> cc = s.portal_cache_settings
>>> cc.getDomains()
('',) ## <<== look there is our old value!!
# yup it needs to be this new value
>>> cc.setDomains("")
# and persisted. Otherwise it will be aborted at exit
>>> transaction.commit()

That was easy, no?


Quick and dirty regexen search for spamd & postfix logs

#!/usr/bin/env python
# Name: finder.py
# Purpose: This is a script to search through Posfix
# and spamd logs for the last x days and return
# hits. Mostly it is a quick and dirty way to
# find entris regarding emails blocked by
# spamd/postfix
# Author: Reed L. O'Brien reed at reedobrien com
# Created: 2007-01-05
# Modified: 2007-01-05
# Copyright: (c) Reed L. O'Brien 2007
# License: DWYWWI (improvements welcome)

#Do the imports
import os, re, bz2, sys, time

# make sure there is a regex
# compile the regex
regx = re.compile(sys.argv[1], re.IGNORECASE)
except IndexError:
print """
finder [days back to search]

ex: finder foobar 2
will find all occurences of 'foobar' in the last 2
days of spamd and maillog files.\n\tThe number of days
is optional and defaults to 1 if not given."""

# empty list to store hits in
found = []

# move to the log directory
# Start a counter for the number counted
s = 0

#get and set days
days = int(sys.argv[2])
days = 1
# Get a list of qualifying files NOTE: you may need stat(x).[st_ctime|st_mtime] depending on your OS
L = [f for f in os.listdir('.')
if os.stat(f).st_birthtime > time.time() - (days * 86400)
and (f.startswith('spamd') or f.startswith('maillog'))]
# get a count of how many files to search
n = len(L)

# start a loop on the list
for f in L:
# If it is a bz2 open it as a bz2 object
if (f.startswith('spamd') or f.startswith('maillog')) and f.endswith('2'):
# tell em what is happening
sys.stdout.write("\rsearching: %2s remain %s " % (f,n))
# set a line count
c = 1
# get a handle on the file
handle = bz2.BZ2File(f)
# iterate through the lines
for line in handle:
# if the regex is found
if regx.search(line):
# append the filename, line count and line content to the found list

found.append("%-10s : %s\n%s" % (c, f, line))
# increment the line count
c += 1
# or just increment the count if no regex match
c += 1
# decrement the number of files remaining
n -= 1
# increment the number of files searched
s += 1

## DO the same as above as a regular file object if not a bz2 file SEE NOTES FOR last loop
if (f.startswith('spamd') or f.startswith('maillog')) and not f.endswith('2'):
sys.stdout.write("\rsearching: %2s remain %s " % (f,n))
c = 1
handle = open(f)
for line in handle:
if regx.search(line):
found.append("%-10s : %s\n%s" % (c, f, line))
c += 1
c += 1
n -= 1
s += 1
##make some space to overwrite the sys.stdout text
print '\n\n\n\n\n'
print 'Searched:', s # Print how many files were searched

#print the results from the found list.
for x in found:
print x