2012-02-29

Using Boto and Python to connect to a specific region

Here is my slightly inelegant but working code to connect to specific region without setting up a configuration file or altering the default in the library (the access keys you can find under the tab security credentials on :

aaaa = your AWS Access key
sssss = your Secret Amazon key

from boto.ec2.connection import EC2Connection
default_conn = EC2Connection('aaaaa','sssss')

regions = default_conn.get_all_regions()

for r in regions:
    print r.name
    if r.name == 'eu-west-1':
       conn = EC2Connection('aaaaa',’sssss',region =r)

print regions

rs = conn.get_all_security_groups()
print rs

2012-02-15

Installing Python Pyjamas and Pyjamas desktop for Windows 7

I am testing out python pyjamas as a gui front end which I can scale from a desktop app to web app to cloud deployable scalable app with very little change.  I have tried a number of different GUI stacks, the last was pytgtk which only worked with 32 bit Python which I had to install on top of my 64 bit python.  To start I have gone back to 64 bit python.

Going to the pyjamas wiki getting started  I started using the windows help.  I noticed it was a little out of date so decided to write my experience here.  I have already got a working version of Python 2.72 64 bit on Windows.

Next I installed tortoiseGIT as I have used TortoiseSVN a lot.  I also needed to install the Windows GIT client which I should have done first.  Then I create a pyjamas directory in my download directory and use right click Git clone to create the directory.

gitClone

You need to change the URL to git://pyjs.org/git/pyjamas.git and press OK.

gitCloneDialogBox

The first time I did it it failed so I deleted everything and tried again and this time it worked.

I then installed comtypes which was version 0.6.2.  I had two versions of Python installed so I selected Python 2.7.  It then had an error at then end:

ComtypesError


Carrying on, assuming that GTK may not be needed as Pyjamas desktop is using MSHTML and for my desktop I am at the moment only worried about desktop Windows apps. (I really don’t want to go back to Python 32bit again) I copied the pyjamas directory to my C drive so that I had the following directory C:\pyjamas\pyjd

I updated the system path  ControlPanel->System->Advanced system settings->(Advanced Tab)Environment Variables->Edit path  I added C:\python27;C:\pyjamas\bin. Note the pyjamas bin directory is added in the next step:

Open up a command window and then run which will create the bin directory:

cd \pyjamas
python bootstrap.py

I then created a build.bat in the helloworld directory:

pyjsbuild.bat --print-statements Hello

and also a run file:

pyjd Hello.py

Pyjamas works by combining files from the public directory eg files and template html and your code.  In order to use either the output or the desktop you must run the build process first.  Then you can use the run file first the app just opened up  in a new windowSmile and worked:

helloworld

If I opened the browser with output\hello.html I just got the static text but need to change to the output directory and run the html file (so the default location of other files works) then I get the application in a browser window.  I was using by default IE and didn’t work on getting the others to work.  This from start to end took me about 3 hours including writing my notes as I went.

2012-02-06

SVN sync

SVN has a very nice sync feature.  I have used at the end of a project to hand over by coping the version control information to a client repository.

I normally use TortoiseSVN and AnkhSVN to access the SVN repository but for this you you need an SVN client.  I used the the SlikSVN client with the typical configuration since they are selling hosting they are likely to make sure it works well (I used CVSDude way back now its unclear if it is called Codesion or Collabnet).  This has the svnsync command in it.

I got started with a post by Paul Querna.  Since I was doing it on a Windows machine and had a couple of problems I have written about my experience here.

Instead of defining environment variables I just created a number of batch files.   The first to make sure my SVN environment is working:

"C:\Program Files\SLIKSVN\bin\svn" --version

This command should return the version and a whole lot more info.  Then I tested access to the destination and source repositories eg:

"C:\Program Files\SLIKSVN\bin\svn" list https://myAcct.svn.cvsdude.com/myProj –username secretUser --password

secretPW

or

"C:\Program Files\SLIKSVN\bin\svn" list svn://192.168.0.0.1/myProj –-username secretUser -–password secretPW

This will return nothing for the destination repository as nothing in it and the  list of directories in the source repository.  If the hook properties need to be changed then the following code should be executed in the root directory of the source repository:

$ echo "#!/bin/sh" > hooks/pre-revprop-change

$ chmod 755 hooks/pre-revprop-change

Now you are ready to initialise syncserve:

"C:\Program Files\SLIKSVN\bin\svnsync" init svn://192.168.0.1/myProj --sync-username desSecretUser --sync-password destSecretPassword https://myAcct.svn.cvsdude.com/myProj --source-username sourceSecretUser --source-password sourceSecretPassword --non-interactive

You may get a warning about no supporting atomic revision and upgrading to 1.7.  For 1.6 this was fine.

svnsync: warning: W200007: Target server does not support atomic revision property edits; consider upgrading it to 1.7 or using an external locking program
Copied properties for revision 0
.

And now you should be ready to start the sync (just change init to sync):

"C:\Program Files\SLIKSVN\bin\svnsync" sync svn://192.168.0.1/myProj --sync-username desSecretUser --sync-password destSecretPassword https://myAcct.svn.cvsdude.com/myProj --source-username sourceSecretUser --source-password sourceSecretPassword --non-interactive

You will then get a list of changes copied over (the . after Transmitted file data refer to the amount of data transferred):

Copied properties for revision 9.

Transmitting file data …..

Commited revision 9.