Merge lp:~mbp/python-oops-datedir-repo/bsondump into lp:python-oops-datedir-repo

Proposed by Martin Pool
Status: Merged
Merged at revision: 32
Proposed branch: lp:~mbp/python-oops-datedir-repo/bsondump
Merge into: lp:python-oops-datedir-repo
Diff against target: 58 lines (+34/-0)
3 files modified
.bzrignore (+1/-0)
scripts/bsondump (+30/-0)
setup.py (+3/-0)
To merge this branch: bzr merge lp:~mbp/python-oops-datedir-repo/bsondump
Reviewer Review Type Date Requested Status
Robert Collins (community) Approve
Gavin Panella (community) Needs Fixing
Review via email: mp+86338@code.launchpad.net

Description of the change

This copies in the little bsondump script to make oops files readable.

It's a bit unclear which of the many oops components this really belongs in - it's not specific to storing it in per-date directories - but wgrant wanted it here, so here it is.

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) wrote :

Typically a script like this would go in utilities/ and the first thing it would do is import _pythonpath. Alternatively you could put it in and use buildout's templating to get the path setup. In either case you could then rely on having access to the same bson library that Launchpad depends on (bson 0.3.2 right now), and the code could cry a little less :)

You could consider using fileinput to deal with stdin and/or named files, though I'm not sure how well bson would cope with a stream containing multiple documents (for want of a better term).

Something like this might be a worthy addition to https://github.com/mongodb/mongo-python-driver (upstream for the python-bson package), so that we could use, say, `python -m bson/dump` anywhere python-bson is installed.

review: Needs Fixing
Revision history for this message
Gavin Panella (allenap) wrote :

> Alternatively you could put it in and use buildout's

s/it in and/it in buildout-templates and/

Revision history for this message
Robert Collins (lifeless) wrote :

Actually, we currently use the pypi bson package, not the mongo one, which is a wart itself. I don't want this stalled though, so I'm going to JFDI it as a regular buildout entry point.

Revision history for this message
Robert Collins (lifeless) wrote :

Other issues (fixing, but noting for easier ride next time:)

the new script was missing (C) header stuff (nab from any other file in the project).

No tests (I'm ignoring this for now given it's triviality... I bet this will bite later tho!)

bson doesn't handle multiple documents well, so using named files only is fine IMO.

review: Approve
Revision history for this message
Martin Pool (mbp) wrote :

thanks!

Revision history for this message
Martin Pool (mbp) wrote :

... as a follow on, we could delete it from lp:launchpad scripts/

Revision history for this message
Robert Collins (lifeless) wrote :

On Wed, Feb 1, 2012 at 7:38 PM, Martin Pool <email address hidden> wrote:
> ... as a follow on, we could delete it from lp:launchpad scripts/

please do!

Revision history for this message
Martin Pool (mbp) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2011-11-11 04:48:53 +0000
3+++ .bzrignore 2011-12-20 05:30:30 +0000
4@@ -9,3 +9,4 @@
5 ./dist
6 ./MANIFEST
7 .testrepository
8+./build
9
10=== added directory 'scripts'
11=== added file 'scripts/bsondump'
12--- scripts/bsondump 1970-01-01 00:00:00 +0000
13+++ scripts/bsondump 2011-12-20 05:30:30 +0000
14@@ -0,0 +1,30 @@
15+#! /usr/bin/python
16+
17+"""Print a BSON document for easier human inspection.
18+
19+This can be used for oopses, which are commonly (though not necessarily)
20+stored as BSON.
21+
22+usage: bsondump FILE
23+"""
24+
25+import bson
26+from pprint import pprint
27+import sys
28+
29+if len(sys.argv) != 2:
30+ print __doc__
31+ sys.exit(1)
32+
33+
34+def decode_somehow(filename):
35+ """There are several bson apis: try to decode it while crying."""
36+ fn = getattr(bson, 'loads', None) or getattr(bson, 'decode_all')
37+ return fn(file(filename, 'rb').read())
38+
39+
40+# I'd like to use json here, but not everything serializable in bson is
41+# easily representable in json - even before getting in to the weird parts,
42+# oopses commonly have datetime objects. -- mbp 2011-12-20
43+
44+pprint(decode_somehow(sys.argv[1]))
45
46=== modified file 'setup.py'
47--- setup.py 2011-12-08 03:05:06 +0000
48+++ setup.py 2011-12-20 05:30:30 +0000
49@@ -30,6 +30,9 @@
50 url="https://launchpad.net/python-oops-datedir-repo",
51 packages=['oops_datedir_repo'],
52 package_dir = {'':'.'},
53+ scripts = [
54+ 'scripts/bsondump',
55+ ],
56 classifiers = [
57 'Development Status :: 2 - Pre-Alpha',
58 'Intended Audience :: Developers',

Subscribers

People subscribed via source and target branches

to all changes: