Github project list
September 29, 2010 at 10:24 PM | categories: Website, Version Control | View Comments
Adding in more stuff
It's mostly what I am working on atm for the blog. After using blogofile for a few days now I've really gotten accustomed to writing up new things for it. It is only python after all. So that helps. My newest idea was to have a listing of my github projects in the sidebar.
Seems simple enough
Found a good api in python for this. There was one that used javascript that would have also done the job, but I decided this could be slow and updated when the site was built, instead of needing to be updated real time.
After installing the github2 module, I got right to it and started making a controller for the widget. And I ended up with something like this:
github.py
import logging
from blogofile.cache import bf
github = bf.config.controllers.github
from github2.client import Github
github_api = Github()
config = {
"name": "Github",
"description": "Makes a nice github project listing for the sidebar",
"priority": 90.0,
}
def get_list(user):
"""
Each item in the list has:
name, url, description, forks, watchers, homepage, open_issues
"""
return [g for g in github_api.repos.list(user) if not g.fork]
def run():
github.logger = logging.getLogger(config['name'])
github.repo_list = get_list(github.user)
With a configuration in _config.py like this:
#### github projects ####
controllers.github.enabled = True
github = controllers.github
github.user = "goosemo"
And a simple github.mako file that I used mako's include function for:
<div class="sidebar_item">
<h3>Github Projects</h3>
<ul>
% for project in bf.config.controllers.github.repo_list:
<li><a href="${project.url}" title="${project.name}">
${project.name}</a> ${project.description}</li>
<br/>
% endfor
</ul>
</div>
<br />
I did run into an issue
After getting this all down the site was acting strange. The frontage had the listing of my git repos just as it was supposed to be. But I found that on every other page the github section was blank.
After tweaking and getting a bit frustrated, I read the blogofile code a bit more for the controller sections, and got the idea to up the priority from 70 to 90.
This did the trick, and I figure it was because the permalinks and other page creation work was being done before the github.repo_list could be populated.
Thoughts so far
Overall the process from idea to working in blogofile is straightforward, since it's nothing new in form of coding. Mako and python go well together.
Now I just need to get down a coherent way to publish these little bits I keep adding, and to also make them completely configurable via the _config.py and isolated into their own units so that installation/use is a simple procedure.
Github and Bitbucket hooks
September 29, 2010 at 05:40 PM | categories: Version Control | View Comments
I use hg but like github
I also dislike unevenness. Having recently read about the hg-git plugin and read about a setup that uses the paths definitions for hg to make simple names to push to, and decided to combine them all together. I ended up with a ~/.hgrc that I had this:
[extensions]
hgext.bookmarks =
hggit =
And then in the repo's .hg/hgrc I'd add something like this:
[paths]
github = git+ssh://git@github.com:goosemo/hooks.git
bitbucket = ssh://hg@bitbucket.org/morgan_goose/hooks
That worked well
But I had to remember to push to both, and that was annoying. Then I dug into hooks and found that I could easily make a shell script to push to both for me. What I ended up with was a bash script that would determine which path I had pushes to, and then push to the other:
#!/bin/bash
# This script takes in the args that a hg push is given and checks for the paths
# that I've defined in my hg repos for either a push to bitbucket or github,
# and then does the other, so that regardless of which of these sites I push to
# the other also get pushed to.
#post-push to bitbucket
if [[ $HG_ARGS =~ "push bitbucket" ]]
then
hg push github --quiet
fi
#post-push to github
if [[ $HG_ARGS =~ "push github" ]]
then
hg push bitbucket --quiet
fi
Note that the quiet flags or similar must be employed, otherwise you'll get caught in an infinite loop. After that I added this line into my ~/.hgrc
[hooks]
post-push = $HOME/workspace/hooks/github.sh
Success
Now regardless of where I push the other will get the update:
~/workspace/hooks$ hg push bitbucket
pushing to ssh://hg@bitbucket.org/morgan_goose/hooks
searching for changes
no changes found
~/workspace/hooks$ hg push github
pushing to git+ssh://git@github.com:goosemo/hooks.git
importing Hg objects into Git
creating and sending data
github::refs/heads/master => GIT:b4fb4c58
Next Page ยป