Tagged: python RSS

  • John 11:26 pm on April 26, 2010 Permalink | Reply
    Tags: bzr, , ontime, , python   

    Bazaar Plugin for OnTime Integration 

    I was playing around with bazaar, whilst reviewing distributed version control systems (DVCS), and created a simple plugin for use with axosoft’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 following:

    tar -vxzf bzr-ontime-0.0.1.tar.gz
    cd bzr-ontime-0.0.1
    sudo python setup.py install
    


    Configure

    Setup the database connection information.
    /etc/bzr-ontime.conf

    [ontime]
    server=your-mssql-server
    username=sa
    password=p4ssw0rd
    database=ontime
    


    Confirm Installation

    bzr hooks
    

    If the plugin is installed correct you should see the plugin listed under the post_commit section.

    Related Reading

     
  • John 11:59 pm on January 3, 2010 Permalink | Reply
    Tags: , nautilus, python   

    Upload Image to Imgur.com 

    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’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.

    upload to imgur screenshot

    The code is hosted at google.

    Update

    Thanks to the people over at reddit the script now supports automatically copies the url to the clipboard, and also correctly loads the glade file.

     
  • John 10:11 am on August 17, 2009 Permalink | Reply
    Tags: , , python   

    Hacking on Monodevelop for Django 

    MonoDevelop Django

    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 to add new django apps to the project, once I get familiar with the MonoDevelop code base.

     
  • John 8:56 pm on July 13, 2009 Permalink | Reply
    Tags: , , python   

    Python and CCTray Again 

    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.

    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.

    gtk.gdk.threads_init()
    

    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

    class ccnetworker(threading.Thread):
    
    	# init
    	def __init__(self,xmlPath,pycctray):
    		threading.Thread.__init__(self)
    		self.xmlPath = xmlPath
    		self.pycctray = pycctray
    

    Below is a screen shot of the system tray menu, listing the projects that are available to be force built.

    pycctray screenshot

    # example usage
    python pycctray.py http://localhost/ccnet/XmlServerReport.aspx
    

    You can get the latest source from the bazaar repository

    bzr branch http://bzr.yeticode.co.uk/pycctray
    

    Alternatively you can download the source files on their own: pycctray.tar.gz

     
  • John 9:25 am on July 10, 2009 Permalink | Reply
    Tags: , python, tux droid   

    Tux Droid with Cruise Control .NET 

    Tux Droid

    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, 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.

    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.

    You can get a copy of the source, which might be more up-to-date, frm the bzr repository.

    # bzr branch http://bzr.yeticode.co.uk/ccnet-tuxbot
    


    Usage:
    # python ccnet.py http://localhost/ccnet/XmlServerReport.aspx
    

    download ccnet.py
    Update 11-07-2009 12:00AM: update notifcations in ccnet.py script.

    #!/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. http://localhost/ccnet/XmlServerReport.aspx"
    
    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()
    

     
  • John 7:03 pm on June 20, 2009 Permalink | Reply
    Tags: , MSSQL, python,   

    Python and MSSQL 

    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 pymssql library.

    #!/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()
    

    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.

    #!/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()
    

    You can download mssql_client.py here

    So after only using for python for a couple of weeks It’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.

     
  • John 9:17 am on June 12, 2009 Permalink | Reply
    Tags: , python   

    Django and Python 

    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 about the project. There’s loads of the stuff, and its brilliant. Its readable. Its completely unlike reading other tech documents. If this isn’t a good selling point for checking it out then I don’t know what is because RTFMing has never been so easy.

     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
esc
cancel

Powered by Web Design Company Plugins