[Yt-svn] commit/yt: 2 new changesets
Bitbucket
commits-noreply at bitbucket.org
Tue Mar 15 20:08:34 PDT 2011
2 new changesets in yt:
http://bitbucket.org/yt_analysis/yt/changeset/aa050afd50b8/
changeset: r3846:aa050afd50b8
branch: yt
user: MatthewTurk
date: 2011-03-16 02:17:56
summary: Adding an indent to the JSON serializer
affected #: 1 file (12 bytes)
--- a/yt/utilities/pasteboard.py Tue Mar 15 18:16:22 2011 -0700
+++ b/yt/utilities/pasteboard.py Tue Mar 15 18:17:56 2011 -0700
@@ -125,6 +125,6 @@
fn = os.path.join(self.repo_fn, "inventory.json")
f = open(fn, "w")
f.write("var inventory_data = ")
- json.dump(vals, f)
+ json.dump(vals, f, indent = 1)
f.write(";")
return fn
http://bitbucket.org/yt_analysis/yt/changeset/9bc94ca8b886/
changeset: r3847:9bc94ca8b886
branch: yt
user: MatthewTurk
date: 2011-03-16 04:08:05
summary: Adding a "pastegrab" command to pull from a given username's pastebin, based on
the time modifier or the UUID.
affected #: 2 files (1.4 KB)
--- a/yt/utilities/command_line.py Tue Mar 15 18:17:56 2011 -0700
+++ b/yt/utilities/command_line.py Tue Mar 15 20:08:05 2011 -0700
@@ -603,6 +603,13 @@
from yt.utilities.pasteboard import PostInventory
pp = PostInventory()
pp.add_post(arg, desc=opts.desc)
+
+ @cmdln.option("-o", "--output", action="store",
+ default = None, dest="output_fn",
+ help="File to output to; else, print.")
+ def do_pastegrab(self, subcmd, opts, username, paste_id):
+ from yt.utilities.pasteboard import retrieve_pastefile
+ retrieve_pastefile(username, paste_id, opts.output_fn)
def run_main():
for co in ["--parallel", "--paste"]:
--- a/yt/utilities/pasteboard.py Tue Mar 15 18:17:56 2011 -0700
+++ b/yt/utilities/pasteboard.py Tue Mar 15 20:08:05 2011 -0700
@@ -26,6 +26,7 @@
import os
import time
import uuid
+import urllib
from yt.config import ytcfg
@@ -128,3 +129,32 @@
json.dump(vals, f, indent = 1)
f.write(";")
return fn
+
+def retrieve_pastefile(username, paste_id, output_fn = None):
+ # First we get the username's inventory.json
+ s = urllib.urlopen("http://%s.bitbucket.org/inventory.json" % (username))
+ data = s.read()
+ # This is an ugly, ugly hack for my lack of understanding of how best to
+ # handle this JSON stuff.
+ data = data[data.find("=")+1:data.rfind(";")]
+ #import pdb;pdb.set_trace()
+ inv = json.loads(data)
+ k = None
+ if len(paste_id) == 36:
+ # Then this is a UUID
+ for k in inv:
+ if k['fullname'][6:42] == paste_id: break
+ elif len(paste_id) == 10:
+ pp = int(paste_id)
+ for k in inv:
+ if k['modtime'] == pp: break
+ if k is None: raise KeyError(k)
+ # k is our key
+ url = "http://%s.bitbucket.org/%s" % (username, k['fullname'])
+ s = urllib.urlopen(url)
+ data = s.read()
+ if output_fn is not None:
+ if os.path.exists(output_fn): raise IOError(output_fn)
+ open(output_fn, "w").write(data)
+ else:
+ print data
Repository URL: https://bitbucket.org/yt_analysis/yt/
--
This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
More information about the yt-svn
mailing list