Robert Kern asked me to share my Atomisator configuration for the Unified Python Planet. So, here it is:
[atomisator]
# sources
sources =
rss http://www.planetpython.org/rss20.xml
rss http://planet.python.org/rss10.xml
# filters
# "doublons" is French for "duplicates" -- this is what de-dups the feed
filters =
doublons
# enhancers
# I'm not using any, just leave this blank (default)
enhancers =
# outputs
outputs =
rss /home2/mpirnat/webapps/pirnatwp/static/unified_python_planet.xml "http://feeds2.feedburner.com/UnifiedPythonPlanet" "Unified Python Planet" "A uniqued union of the Official and Unofficial Python planet feeds. Generated by Atomisator FTW!"
# database
database = sqlite:///atomisator/unified_python_planet.db
The example configuration files that come with Atomisator are really good at illustrating how you would use them; I’ve omitted the explanatory comments from my example, but they’re in the examples and will point you in the right direction. Thanks again to Tarek for this very handy tool!
geekery, python
atom, atomisator, config, geekery, python, rss
I mentioned the “Diaper Pattern” in a recent post and got some comments asking what the term meant. I had hoped to just link to an explanation, thinking it was a well-known antipattern, but several minutes of frustrated Googling have left me convinced that there’s actually a tiny knowledge gap to be filled here.
“Diaper Pattern” is a term that I picked up from working with Matt Wilson and David Stanek. It’s an anti-pattern about naively over-broad exception catching. A very basic example in Python might be:
try:
do_something_that_might_throw_various_exceptions()
except Exception:
pass
If anything at all goes wrong in do_something, the except will catch and silence it–but we know that errors should never pass silently (unless explicitly silenced). It’s called a Diaper because it catches all the shit.
In practice, unless you have a good reason to catch everything, it’s a lot better to only catch the specific exceptions that need special handling, so that you’ll know right away about any runtime surprises and where they came from:
try:
do_something_that_might_throw_various_exceptions()
except IOError, e:
# handle just IOErrors; let everything else make noise
Maybe it’s just a coincidence, but I’ve heard the term used more by developers who have young children than by those without kids.
geekery, naughty-words, python
antipattern, diaper, geekery, pattern, python
A coworker unearthed this little treasure today… I think it’s a vestigial structure to assist Diaper (anti)Pattern treatment during testing or debugging, but it’s still gross to see it in real, live production code. (Oddly enough, I couldn’t find a good “Diaper Pattern” link whilst Googling about–surely I’m not the only one who uses this term?) Anyway, without further ado:
try:
os.remove(filename)
except:
raise
pass
try:
os.remove(os.path.join(TMP,'out-%s' % base_filename))
except:
raise
pass
try:
os.remove(os.path.join(TMP,'properties_%s.lock' % brandid_human))
except:
raise
pass
If an exception is raised, raise an exception… It has a certain zenlike beauty to its awfulness. The use of the Diaper Pattern is bad enough, but this guarantees blowouts!
geekery, python, wtf
diaper pattern, geekery, horror, python, wtf
A coworker just showed me this little gem–a maintenance script that’s got no author attribution and isn’t in source control, so whoever has perpetrated this crime against all that’s good and holy remains anonymous and (for the moment) safe from our wrath. I’m so completely taken aback by this–I… I don’t know what to say. I just have to share.
#!/usr/bin/env python
import os,sys
C=os.chdir
S=os.system
M=os.mkdir
J=os.path.join
A=os.path.abspath
D=os.path.dirname
E=os.path.exists
W=sys.stdout.write
V=sys.argv
X=sys.exit
ERR=lambda m:W(m+"\n")
PRNT=lambda m:W(m+"\n")
assert len(V)==2,"you must provide a sandbox name"
SB=V[1]
H=A(D(__file__))
SBD=J(D(H),SB)
C(SBD)
PST=J(SBD,'bin/paster')
VAR=J(SBD,'var')
ETC=J(SBD,'etc')
S("mkdir -p "+VAR)
PRNT("restarting "+SB)
CMD=";".join(['source %s'%J(SBD,'bin/activate'),PST+" serve --daemon --pid-file=%s/sandbox.pid --log-file=%s/sandbox.log %s/sandbox.ini start"%(VAR,VAR,ETC)])
PRNT(CMD)
S(CMD)
PRNT("All done!")
X(0)
Weep for us.
geekery, python, wtf
geekery, horror, python, wtf