Commits

fredrik  committed 02ff9bb

A tiny bit more interesting example

  • Participants
  • Parent commits faa29b2

Comments (0)

Files changed (1)

File pyrest/examples/hg/changeset.py

 import hgapi.hgapi as hgapi
 from pyrest import pyrest
 
-def get(ref=None):
-    rev = hgapi.Repo('.')[ref]
+def get(ref=None, part=None):
+    repo = hgapi.Repo('.')
 
-    return pyrest.OkResponse({
-    'node': rev.node,
-    'desc': rev.desc
-    })
+    if ref is None:
+        return pyrest.OkResponse([{k: getattr(rev, k) for k in dir(rev) if not k.startswith('_')} 
+            for rev in repo[0:'tip']])
 
+    rev = repo[ref]
+    if not rev:
+        return pyrest.NotFoundResponse("Could not find changeset")
+
+    if part is None:
+        return pyrest.OkResponse({k: getattr(rev, k) for k in dir(rev) if not k.startswith('_')})
+    else:
+        try:
+            return pyrest.OkResponse(getattr(rev, part))
+        except:
+            return pyrest.NotFoundResponse("Could not find attribute %s of revision %s" % (part, ref))
+            
 def post(message=None, user=None):
     
     if message is None: