Commits

Steve Losh committed bd8895e

Lots more.

  • Participants
  • Parent commits 825cee4

Comments (0)

Files changed (14)

+import os
+from fabric.api import *
+
+
+SITE_NAME = 'noodlebucket'
+
+def refresh_fixtures():
+    os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
+    from django.conf import settings
+    apps = [
+        a.split('.')[-1] for a in settings.INSTALLED_APPS
+        if a.startswith('%s.' % SITE_NAME)
+    ]
+    for app in apps:
+        target_dir = os.path.join(app, 'fixtures')
+        if not os.path.exists(target_dir):
+            os.mkdir(target_dir)
+        target = os.path.join(target_dir, 'initial_data.json')
+        local('python manage.py dumpdata --indent=2 %s > %s' % (app, target))

File feedback/fixtures/initial_data.json

+[]

File feedback/models.py

     def __unicode__(self):
         return u"Request: %s" % self.repo_name
     
+

File media/css/base.css

     width: 50em;
     margin: 1em auto 6em;
 }
+div#content {
+    margin-bottom: 6em;
+}
+div#footer {
+    font-family: Palatino, "Palatino Linotype";
+    font-style: italic;
+    color: #666;
+    text-align: right;
+}
 
 a, a:active, a:visited {
     color: #0B80AD;
 span#fancy-by {
     font-family: Palatino, "Palatino Linotype";
     font-style: italic;
+    font-weight: normal;
     color: #666;
+    margin-left: 0.25em;
+    margin-right: 0.25em;
 }
 
 form div.field textarea {
     list-style-type: none;
     display: inline;
     font-family: Palatino, "Palatino Linotype";
+    font-style: italic;
     line-height: 0em;
 }
 form div.field ul.errorlist li {
     display: inline;
     margin-left: 1em;
     color: #E2003B;
-    font-style: italic;
 }
 
 ul#repo-list {
     margin-left: 0;
     font-size: 1.25em;
     line-height: 1.2em;
-}
+}

File mercurial_data/admin.py

 from django.contrib import admin
-from noodlebucket.mercurial_data.models import Repository
+from noodlebucket.mercurial_data.models import Changeset, Repository
 
 class RepositoryAdmin(admin.ModelAdmin):
     search_fields = ('user_name', 'repo_name')
     list_filter = ('refreshed', 'created', 'updated')
 
 admin.site.register(Repository, RepositoryAdmin)
+
+class ChangesetAdmin(admin.ModelAdmin):
+    list_display = ('cset_hash', 'cset_parent', 'cset_author')
+    list_filter = ('created', 'updated')
+
+admin.site.register(Changeset, ChangesetAdmin)

File mercurial_data/bitbucket/scrape.py

+#!/usr/bin/env python
+from django.core.management import setup_environ
+import settings
+setup_environ(settings)
+
+import sys, urllib2
+try:
+    import simplejson as json
+except ImportError:
+    import json
+from noodlebucket.mercurial_data.models import Changeset, Repository
+
+
+# We'll refresh 5 repos at a time
+repos = Repository.objects.order_by('-refreshed')[:5]
+
+for repo in repos:
+    repo_url = 'http://api.bitbucket.org/1.0/repositories/%s/%s/' % (repo.user_name, repo.repo_name)
+    repo_data = json.loads(urllib2.urlopen(repo_url).read())
+    repo.description = repo_data['description']
+    repo.save()
+    
+    cset_url = 'http://api.bitbucket.org/1.0/repositories/%s/%s/changesets/' % (repo.user_name, repo.repo_name)
+    cset_data = json.loads(urllib2.urlopen(cset_url).read())
+    for cset in cset_data['changesets']:
+        if Changeset.objects.filter(repo=repo, cset_hash=cset['node']).count() == 0:
+            c = Changeset(repo=repo, cset_hash=cset['node'], cset_parent=None,
+                cset_author=None, cset_date=None, cset_message=cset['message'])
+            print cset['author']
+
+

File mercurial_data/fixtures/initial_data.json

+[
+  {
+    "pk": 2, 
+    "model": "mercurial_data.repository", 
+    "fields": {
+      "updated": "2010-02-18 20:20:03", 
+      "description": "", 
+      "parent": null, 
+      "created": "2010-02-18 20:20:03", 
+      "refreshed": null, 
+      "user_name": "jespern", 
+      "repo_name": "django-piston"
+    }
+  }, 
+  {
+    "pk": 1, 
+    "model": "mercurial_data.repository", 
+    "fields": {
+      "updated": "2010-02-18 20:19:55", 
+      "description": "", 
+      "parent": null, 
+      "created": "2010-02-18 20:19:55", 
+      "refreshed": null, 
+      "user_name": "sjl", 
+      "repo_name": "hg-prompt"
+    }
+  }
+]

File mercurial_data/models.py

 from django.db import models
 
+
 class Repository(models.Model):
     """A Mercurial repository on BitBucket."""
     
     refreshed = models.DateTimeField(
         null=True, blank=True
     )
+    description = models.TextField(
+        blank=True, null=True
+    )
     
     created = models.DateTimeField(editable=False, auto_now_add=True)
     updated = models.DateTimeField(editable=False, auto_now=True)
         return u"%s/%s" % (self.user_name, self.repo_name)
     
 
+
+class Changeset(models.Model):
+    """A single changeset in a repository."""
+    
+    repo = models.ForeignKey(Repository)
+    cset_hash = models.CharField(
+        max_length=40,
+        verbose_name="hash"
+    )
+    cset_parent = models.CharField(
+        max_length=40,
+        verbose_name="parent"
+    )
+    cset_author = models.CharField(
+        max_length=150,
+        verbose_name="author"
+    )
+    cset_date = models.DateTimeField(
+        verbose_name="date"
+    )
+    cset_message = models.TextField(
+        blank=True, null=True,
+        verbose_name="message"
+    )
+    
+    created = models.DateTimeField(editable=False, auto_now_add=True)
+    updated = models.DateTimeField(editable=False, auto_now=True)
+    
+    class Meta:
+        pass
+    
+    def __unicode__(self):
+        return u"%s@%s" % (self.repo, self.cset_hash)
+    
+

File mercurial_data/views.py

 from django.core.urlresolvers import reverse
-from django.shortcuts import render_to_response
+from django.shortcuts import get_object_or_404, render_to_response
 from django.template import RequestContext
 
 from noodlebucket.mercurial_data.models import Repository
 
 def repo_list(request):
     """List all the repos that Noodle Bucket tracks."""
+    
     repos = sorted(
         Repository.objects.all(),
         key=lambda r: (r.user_name, r.repo_name),
 
 
 def repo(request, user_name=None, repo_name=None):
-    pass
+    """Display a particular repo."""
+    
+    repo = get_object_or_404(Repository, user_name=user_name, repo_name=repo_name)
+    
+    return render_to_response(
+        'repos/repo.html',
+        { 'repo': repo },
+        context_instance=RequestContext(request)
+    )
 

File templates/base.html

             <div id="content">
                 {% block content %}{% endblock %}
             </div>
+            
+            <div id="footer">
+                Noodle Bucket was made by
+                <a href="http://stevelosh.com/">Steve Losh</a>
+                with some help from a
+                <a href="http://djangoproject.com/">pony</a>
+                and a very friendly
+                <a href="http://fecklessmind.com/2009/01/20/aardvark-css-framework/">aardvark</a>.
+            </div>
         </div>
     </body>
 </html>

File templates/repos/repo.html

+{% extends "base.html" %}
+
+{% block title %}{{ repo.user_name }}/{{ repo.repo_name }} – {% endblock %}
+
+{% block content %}
+    <h2>{{ repo.user_name }}/{{ repo.repo_name }}</h2>
+    
+{% endblock %}

File templates/repos/repo_list.html

 
 {% block content %}
     <p>
-        Noodle bucket is a proof-of-concept site to provide a network graph
+        Noodle Bucket is a proof-of-concept site to provide a network graph
         for BitBucket repositories.
     </p>
     

File util/fixtures/initial_data.json

+[]

File util/models.py

Empty file added.