<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Development Blog &#187; python</title>
	<atom:link href="http://blog.yeticode.co.uk/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.yeticode.co.uk</link>
	<description>John Tindell's Blog For Development Related Things</description>
	<lastBuildDate>Wed, 23 Jun 2010 18:17:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Bazaar Plugin for OnTime Integration</title>
		<link>http://blog.yeticode.co.uk/2010/04/bazaar-plugin-for-ontime-integration/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=bazaar-plugin-for-ontime-integration</link>
		<comments>http://blog.yeticode.co.uk/2010/04/bazaar-plugin-for-ontime-integration/#comments</comments>
		<pubDate>Mon, 26 Apr 2010 22:26:01 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Development Log]]></category>
		<category><![CDATA[bzr]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[ontime]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://blog.yeticode.co.uk/?p=683</guid>
		<description><![CDATA[I was playing around with bazaar, whilst reviewing distributed version control systems (DVCS), and created a simple plugin for use with axosoft&#8217;s ontime. The plugin parses the commit message and links the files to the related task, defect or feature. Install Download the tar file from [download id="3"] Extract and run the installer using the [...]]]></description>
			<content:encoded><![CDATA[<p>I was playing around with <a href="http://bazaar.canonical.com/">bazaar</a>, whilst reviewing distributed version control systems (DVCS), and created a simple plugin for use with <a href="http://www.axosoft.com/ontime">axosoft&#8217;s ontime</a>. The plugin parses the commit message and links the files to the related task, defect or feature.<br />
<br/></p>
<h3>Install</h3>
<p>Download the tar file from [download id="3"]<br />
Extract and run the installer using the following:</p>
<pre>
tar -vxzf bzr-ontime-0.0.1.tar.gz
cd bzr-ontime-0.0.1
sudo python setup.py install
</pre>
<p><br/></p>
<h3>Configure</h3>
<p>Setup the database connection information.<br />
<strong>/etc/bzr-ontime.conf</strong></p>
<pre>[ontime]
server=your-mssql-server
username=sa
password=p4ssw0rd
database=ontime
</pre>
<p><br/></p>
<h3>Confirm Installation</h3>
<pre>bzr hooks
</pre>
<p>If the plugin is installed correct you should see the plugin listed under the post_commit section.</p>
<h3>Related Reading</h3>
<table>
<tr>
<td>
<a href="http://www.amazon.co.uk/gp/product/1590593561?ie=UTF8&#038;tag=worldoverride-21&#038;linkCode=as2&#038;camp=1634&#038;creative=19450&#038;creativeASIN=1590593561"><img border="0" src="http://static.yeticode.co.uk/blog/images/dive_into_python.jpg"></a><img src="http://www.assoc-amazon.co.uk/e/ir?t=worldoverride-21&#038;l=as2&#038;o=2&#038;a=1590593561" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />
</td>
</tr>
</table>]]></content:encoded>
			<wfw:commentRss>http://blog.yeticode.co.uk/2010/04/bazaar-plugin-for-ontime-integration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Upload Image to Imgur.com</title>
		<link>http://blog.yeticode.co.uk/2010/01/upload-image-to-imgur-com/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=upload-image-to-imgur-com</link>
		<comments>http://blog.yeticode.co.uk/2010/01/upload-image-to-imgur-com/#comments</comments>
		<pubDate>Sun, 03 Jan 2010 22:59:38 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Development Log]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[nautilus]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://blog.yeticode.co.uk/?p=626</guid>
		<description><![CDATA[I was looking for an easy way to upload images from my laptop to imgur.com without having to open my browser up. I found a post explaining how to upload an image from nautilus. The script worked well enough however I didn&#8217;t like the information it displayed to you at the end. So I rewrote [...]]]></description>
			<content:encoded><![CDATA[<p>I was looking for an easy way to upload images from my laptop to <a href="http://www.imgur.com">imgur.com</a> without having to open my browser up. I found a post explaining how to upload an <a href="http://www.webupd8.org/2009/12/upload-image-to-imgur-nautilus-actions.html">image from nautilus</a>. The script worked well enough however I didn&#8217;t like the information it displayed to you at the end. So I rewrote the script in python so that it displays a dialog with link buttons for the available options for the image.</p>
<p><img alt="upload to imgur screenshot" src="http://static.yeticode.co.uk/blog/images/posts/Screenshot-Imgur-Details.png" title="Post upload details"/></p>
<p>The code is <a href="https://code.google.com/p/imgur-upload/">hosted at google</a>.</p>
<p><b>Update</b></p>
<p>Thanks to the <a href="http://www.reddit.com/r/linux/comments/aldjc/upload_to_imgur_from_nautilus/">people over at reddit</a> the script now supports automatically copies the url to the clipboard, and also correctly loads the glade file.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.yeticode.co.uk/2010/01/upload-image-to-imgur-com/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hacking on Monodevelop for Django</title>
		<link>http://blog.yeticode.co.uk/2009/08/hacking-on-monodevelop-for-django/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=hacking-on-monodevelop-for-django</link>
		<comments>http://blog.yeticode.co.uk/2009/08/hacking-on-monodevelop-for-django/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 09:11:23 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Development Log]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[MonoDevelop]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://blog.yeticode.co.uk/?p=544</guid>
		<description><![CDATA[So I started to implement support for django with MonoDevelop. It currently has pretty good support for Python via PyBinding addon. At the moment I have only managed to add the ability to create a new django project, which acts in the same way as running django-admin.py startproject projectname But I aim to provide support [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://static.yeticode.co.uk/blog/images/posts/monodevelop-django-1.png" rel="lightbox"><img alt="MonoDevelop Django" src="http://static.yeticode.co.uk/blog/images/posts/monodevelop-django-1-thumb.png"/></a></p>
<p>So I started to implement support for django with MonoDevelop. It currently has pretty good support for Python via PyBinding addon. At the moment I have only managed to add the ability to create a new django project, which acts in the same way as running</p>
<pre>
django-admin.py startproject projectname
</pre>
<p>But I aim to provide support to add new django apps to the project, once I get familiar with the MonoDevelop code base.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.yeticode.co.uk/2009/08/hacking-on-monodevelop-for-django/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python and CCTray Again</title>
		<link>http://blog.yeticode.co.uk/2009/07/python-and-cctray-again/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=python-and-cctray-again</link>
		<comments>http://blog.yeticode.co.uk/2009/07/python-and-cctray-again/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 19:56:53 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Development Log]]></category>
		<category><![CDATA[cctray]]></category>
		<category><![CDATA[CruiseControl.NET]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://blog.yeticode.co.uk/?p=336</guid>
		<description><![CDATA[So after creating a python script that would use my tux droid to notify me when a build failed I decided to extend the script a little further. I decoupled it from the tux droid code and added in a status menu. It still requires that CruiseControl.NET has the webdashboard installed. This is my first [...]]]></description>
			<content:encoded><![CDATA[<p>So after creating a python script that would use my tux droid to notify me when a build failed I decided to extend the script a little further. I decoupled it from the tux droid code and added in a status menu. It still requires that CruiseControl.NET has the webdashboard installed. This is my first venture into using GTK with python, as well as threads.</p>
<p>One of the problems that I encountered when trying to use thread was that they were not behaving correctly. The Thread would appear to start however it would not run. This was easy to fix but adding the following line to initialize the threading.</p>
<pre name="code" class="python">
gtk.gdk.threads_init()
</pre>
<p> In addition to this the class that was running the thread not only had to inherit from the threading.Thread object but had to explicitly call the init on the threads base class</p>
<pre name="code" class="python">
class ccnetworker(threading.Thread):

	# init
	def __init__(self,xmlPath,pycctray):
		threading.Thread.__init__(self)
		self.xmlPath = xmlPath
		self.pycctray = pycctray
</pre>
<p>Below is a screen shot of the system tray menu, listing the projects that are available to be force built.</p>
<p><img src="http://static.yeticode.co.uk/blog/images/posts/pycctray_force_build_menu.png" alt="pycctray screenshot"/></p>
<pre>
# example usage
python pycctray.py <a href="http://localhost/ccnet/XmlServerReport.aspx" rel="nofollow">http://localhost/ccnet/XmlServerReport.aspx</a>
</pre>
<p>You can get the latest source from the bazaar repository</p>
<pre>
bzr branch <a href="http://bzr.yeticode.co.uk/pycctray" rel="nofollow">http://bzr.yeticode.co.uk/pycctray</a>
</pre>
<p>Alternatively you can download the source files on their own: <a href="http://static.yeticode.co.uk/blog/downloads/pycctray.tar.gz">pycctray.tar.gz</a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.yeticode.co.uk/2009/07/python-and-cctray-again/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tux Droid with Cruise Control .NET</title>
		<link>http://blog.yeticode.co.uk/2009/07/tux-droid-with-cruise-control-net/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=tux-droid-with-cruise-control-net</link>
		<comments>http://blog.yeticode.co.uk/2009/07/tux-droid-with-cruise-control-net/#comments</comments>
		<pubDate>Fri, 10 Jul 2009 08:25:34 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Development Log]]></category>
		<category><![CDATA[CruiseControl.NET]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tux droid]]></category>

		<guid isPermaLink="false">http://blog.yeticode.co.uk/?p=303</guid>
		<description><![CDATA[So after having my tux droid for a while I decided to put it to good use, opposed to making it swear at my housemates, which no matter how entertaining it was did not seem very productive. I decided to write a small script that would notify me when a build from Cruise Control.NET failed, [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://static.yeticode.co.uk/blog/images/posts/tux_droid.jpg" alt="Tux Droid" title="Tux Droid" style="float: left"/></p>
<p>So after having my <a href="http://www.tuxisalive.com/">tux droid</a> for a while I decided to put it to good use, opposed to making it swear at my housemates, which no matter how entertaining it was did not seem very productive.<br />
I decided to write a small script that would notify me when a build from <a href="http://ccnetlive.thoughtworks.com/">Cruise Control.NET</a> failed, or when a broken build has successfully been built. At the moment the tux droid speaks a simple message and flaps it wings a little.</p>
<p>The script uses the tux droid python API to make the noises and pulls down an Xml file, via CruiseControl.NET, using urllib and xml.dom, fairly simple stuff.</p>
<p>You can get a copy of the source, which might be more up-to-date, frm the bzr repository.</p>
<pre>
# bzr branch <a href="http://bzr.yeticode.co.uk/ccnet-tuxbot" rel="nofollow">http://bzr.yeticode.co.uk/ccnet-tuxbot</a>
</pre>
<p><br/></p>
<pre>
Usage:
# python ccnet.py <a href="http://localhost/ccnet/XmlServerReport.aspx" rel="nofollow">http://localhost/ccnet/XmlServerReport.aspx</a>
</pre>
<p><a href="http://static.yeticode.co.uk/blog/downloads/ccnet.py">download ccnet.py</a><br />
<b>Update 11-07-2009 12:00AM:</b> update notifcations in ccnet.py script.</p>
<pre name="code" class="python">
#!/usr/bin/python
import sys
import urllib
import time
from xml.dom import minidom
from tuxisalive.api import *

def main(xmlPath):
	# load the inital settings that we will use to compare against
	projects = []

	dom = minidom.parse(urllib.urlopen(xmlPath))
	for node in dom.getElementsByTagName('Project'):
		projects.append({
			'name': node.getAttribute('name'),
			'lastBuildStatus': node.getAttribute('lastBuildStatus'),
			'lastBuildTime': node.getAttribute('lastBuildTime')
		})

	# start a loop that will check for a build event every 10 seconds
	while True:
		try:
			dom = minidom.parse(urllib.urlopen(xmlPath))
			new_projects = []
			for node in dom.getElementsByTagName('Project'):
				new_projects.append({
					'name': node.getAttribute('name'),
					'lastBuildStatus': node.getAttribute('lastBuildStatus'),
					'lastBuildTime': node.getAttribute('lastBuildTime')
				})
				for project in new_projects:
					# check to see if the project is in the current list
					projectFound = False
					for p in projects:
						if p['name'] == project['name']:
							projectFound = True
							# check the status of the project against the old status
							# ignore if the old status is failed
							if (p['lastBuildStatus'] != 'Failure') and (project['lastBuildStatus'] == 'Failure'):
								display_message_fail(project)
							if (p['lastBuildStatus'] == 'Failure') and (project['lastBuildStatus'] == 'Success'):
								display_message_success(project)
							if (project['lastBuildStatus'] == 'Success') and (project['lastBuildTime']  != p['lastBuildTime'] ):
								display_message_success_build_again(project)

							# reset the project status
							p['lastBuildStatus'] = project['lastBuildStatus']
							p['lastBuildTime'] = project['lastBuildTime']
					if not projectFound:
						projects.append(project)
						display_message_newproject(project)
			time.sleep(10)
		except KeyboardInterrupt:
			# exit time
			break

def display_message_fail(project):
	msg = 'Someone has broken the %s build' % (project['name'])
	speakPhrase(msg)

def display_message_success(project):
	msg = '%s is now fixed' % (project['name'])
	speakPhrase(msg)

def display_message_new(project):
	msg = '%s has been added to cruise control' % (project['name'])
	speakPhrase(msg)

def display_message_success_build_again(project):
	msg = '%s has successfuly been built' % (project['name'])
	speakPhrase(msg)

def speakPhrase(msg):
	tux.mouth.open()

	tux.tts.setLocutor("Lucy")
	tux.tts.speak(msg.encode('utf-8'));
	print msg
	tux.flippers.on(4)

	tux.mouth.close()

def tuxConnect():
    """ Wait connected """
    tux.server.autoConnect(CLIENT_LEVEL_RESTRICTED, 'TuxPidgin', 'NONE')
    if tux.server.waitConnected(10.0):
        if tux.dongle.waitConnected(10.0):
            if tux.radio.waitConnected(10.0):
                return True
            else:
                print "radio not connected"
                return False
        else:
            print "radio not connected"
            return False
    else:
        print "server not connected"
        return False

def printUsage():
	print "ccnet.py [url]"
	print "\turl - Url of CruiseControl.NET"
	print "\t\t eg. <a href="http://localhost/ccnet/XmlServerReport.aspx" rel="nofollow">http://localhost/ccnet/XmlServerReport.aspx</a>"

if __name__ == "__main__":
	if len(sys.argv) == 2:

		tgp_ip = "127.0.0.1"
		tgp_port = 270
		tux = TuxAPI(tgp_ip, tgp_port)
		if not tuxConnect():
		    sys.exit(1)
		tux.tts.setEncoding("utf-8")

		speakPhrase("Starting Build Bot")
		main(sys.argv[1])
		speakPhrase("Stopping Build Bot")
		tux.server.disconnect()
		tux.destroy()
		sys.exit(0)
	else:
		printUsage()
</pre>
<p><iframe src="http://rcm-uk.amazon.co.uk/e/cm?lt1=_blank&#038;bc1=000000&#038;IS2=1&#038;bg1=FFFFFF&#038;fc1=000000&#038;lc1=0000FF&#038;t=yetiblog-21&#038;o=2&#038;p=8&#038;l=as1&#038;m=amazon&#038;f=ifr&#038;md=0M5A6TN3AXP2JHJBWT02&#038;asins=B001Q7YIPE" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe></p>]]></content:encoded>
			<wfw:commentRss>http://blog.yeticode.co.uk/2009/07/tux-droid-with-cruise-control-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python and MSSQL</title>
		<link>http://blog.yeticode.co.uk/2009/06/python-and-mssql/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=python-and-mssql</link>
		<comments>http://blog.yeticode.co.uk/2009/06/python-and-mssql/#comments</comments>
		<pubDate>Sat, 20 Jun 2009 18:03:53 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Development Log]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[MSSQL]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://blog.yeticode.co.uk/?p=246</guid>
		<description><![CDATA[I have been playing about with django a fair bit over the last week. After written a small app with django I wanted to import some data from an existing MSSQL database. To get the data into the django model I created a seperate python script to perform the import. Below is a script to [...]]]></description>
			<content:encoded><![CDATA[<p>I have been playing about with django a fair bit over the last week. After written a small app with django I wanted to import some data from an existing MSSQL database. To get the data into the django model I created a seperate python script to perform the import. Below is a script to import data from a table compaines in a mssql data to a django model called Company. To connect to the mssql server I used the <a href="http://pymssql.sourceforge.net">pymssql</a> library.</p>
<pre name="code" class="python">
#!/usr/bin/env python
import sys,os
os.environ['DJANGO_SETTINGS_MODULE'] ='settings'
# import the modules needed to start the import
import pymssql
from datetime import *
import unicodedata
from django.core.management import setup_environ
import settings

setup_environ(settings)

#import the django models
from apps.clients.models import *

def importCompanies(conn):
	cur = conn.cursor()
	cur.execute("""SELECT
			liCompanyPk,
			szCompanyName
		FROM companies""")
	row = cur.fetchone()
	while row:
		company = Company()
		company.pk = row[0]
		company.Name = row[1]
		company.save()
		row = cur.fetchone()

if len(sys.argv) != 5:
	print 'data_import.py [server] [username] [password] [database]'
else:
	print 'host=%s, user=%s, password=%s, database=%s' % (sys.argv[1],sys.argv[2],sys.argv[3],sys.argv[4])
	conn = pymssql.connect(host=sys.argv[1], user=sys.argv[2], password=sys.argv[3], database=sys.argv[4])
	importCompanies(conn)
	conn.close()
</pre>
<p>After this I started to play around with pymssql I wanted a quick way to execute simple sql queries, not knowing of an linux alternative to the mysql console client I write another simple script to provide this basic functionality.</p>
<pre name="code" class="python">
#!/usr/bin/env python
import sys,os
import _mssql

if len(sys.argv) != 5:
	print 'data_import.py [server] [username] [password] [database]'
else:
	print 'host=%s, user=%s, password=%s, database=%s' % (sys.argv[1],sys.argv[2],sys.argv[3],sys.argv[4])
	conn = _mssql.connect(server=sys.argv[1], user=sys.argv[2], password=sys.argv[3], database=sys.argv[4])
	print '>',
	cmd = raw_input()
	while cmd != 'exit':
		if cmd != '':
			print cmd
			try:
				conn.execute_query(cmd)
				for row in conn:
					for i in range(0,( len(row) / 2 )):
						print row[i],'|',
					print ''
			except _mssql.MssqlDatabaseException,e:
				print e
		print '>',
		cmd = raw_input();

	conn.close()
</pre>
<p><a href="http://dev.yeticode.co.uk/python/mssql_client.py">You can download mssql_client.py here</a></p>
<p>So after only using for python for a couple of weeks It&#8217;s definitely powerful and fun to code with. Now to try out for all of the libraries that provide bindings such as pysvn or pyldap.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.yeticode.co.uk/2009/06/python-and-mssql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Django and Python</title>
		<link>http://blog.yeticode.co.uk/2009/06/django-and-python/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=django-and-python</link>
		<comments>http://blog.yeticode.co.uk/2009/06/django-and-python/#comments</comments>
		<pubDate>Fri, 12 Jun 2009 08:17:28 +0000</pubDate>
		<dc:creator>John</dc:creator>
				<category><![CDATA[Development Log]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://blog.yeticode.co.uk/?p=228</guid>
		<description><![CDATA[I have recently started having a play about with django. After reading loads of about it and have a little play about with snowy (a django based note sync for tomboy). After getting used to coding in python I found django really quick to develop in. But the documentation is by far the best thing [...]]]></description>
			<content:encoded><![CDATA[<p>I have recently started having a play about with <a href="http://djangoproject.com/">django</a>. After reading loads of about it and have a little play about with <a href="http://git.gnome.org/cgit/snowy">snowy</a> (a django based note sync for <a href="http://projects.gnome.org/tomboy/">tomboy</a>). After getting used to coding in python I found django really quick to develop in. But the documentation is by far the best thing about the project. There&#8217;s loads of the stuff, and its brilliant. Its readable. Its completely unlike reading other tech documents. If this isn&#8217;t a good selling point for checking it out then I don&#8217;t know what is because RTFMing has never been so easy.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.yeticode.co.uk/2009/06/django-and-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
