<?xml version='1.0'?>
<rss version='0.92'>
<channel>
<title>JLandis - Life of Discovery</title>
<link>http://blog.jlandis.org/</link>
<description>A blog about learning and discovery</description>
<language>en-us</language>
<pubDate>Thu, 04 Mar 2010 10:13:32 EST</pubDate>
<lastBuildDate>Thu, 04 Mar 2010 10:13:32 EST</lastBuildDate>
<docs>http://backend.userland.com/rss092</docs>
<managingEditor>service@jlandis.org</managingEditor>
<webMaster>service@jlandis.org</webMaster>
<item>
<title>VNC Address Book Python</title>
<link>http://blog.jlandis.org/?pid=2</link>
<description><![CDATA[ This is just an RSS feed - for a direct link to this post on my blog visit the following link: <a href='http://blog.jlandis.org/?pid=2'>VNC Address Book Python</a><br><br>I work as an IT system administrator and use VNC daily to connect to internal machines. I find VNC to be the easiest way to manage all of the internal machines without having to physically sit in front of each machine when it needs to be serviced.<br /><br />I run Ubuntu as my desktop at work and home, and I have yet to find a VNC management system that I like. Terminal Server Client works just find, but their "Quick Connect" feature just doesn't cut it. Remote Desktop Viewer works fine with .vnc files, but the interface is awful. TightVnc is by far my favorite program, but there is no "address book" type feature, plus it has to be run from the command line. So to solve my problems I decided that I needed to write a GUI interface that would act like an address book to run my VNC connections through TightVnc.<br /><br />At the beginning of this project I knew nothing about Python, but from what I read I knew it would be powerful enough to handle what I needed it to do. Here is a screen shot to show you what the final product looks like (yes, all names have been changed to protect the innocent):<br /><br /><img src="http://blog.jlandis.org/images/20100304/screenshot.jpg"><br /><br />Let's take a look at the code.<br /><br />Here's the beginning of the code where we declare arrays and variables:<br /><code><br />#!/usr/bin/env python<br /><br />import pygtk # this is pythons GUI interface<br />pygtk.require('2.0')<br />import gtk # to use gtk functions<br />import fnmatch # needed for string functions<br />import os # needed to sort through os files<br />rootfolder=os.getenv("HOME") # find home directory<br />homefolder=rootfolder + "/VNC/" # where VNC files live<br />dirList=os.listdir(homefolder) # find all files in VNC folder<br />dirList.sort() # sort the files alphabetically <br />cntr=[0,1,2,3]<br />storeList=["10_*","20_*","30_*","40_*"]<br />storeName=["North","South","East","West",]<br /></code><br />This code was written 100% for me and my purposes. I'm sure it is portable, but understand that it was written to make my IT system administration life easier. I have a directory under my home folder called "VNC" - this folder contains standard .VNC files that I created for everyone in the company. In this example there are four different groupings (North South East West) that correspond to numbers (10, 20, 30, 40). So in my VNC folder you would see files called:<br />10_Doe_John.vnc, 20_Cartman_Eric.vnc and so forth.<br /><br />These standard VNC files have one key element that we need (the connection IP address):<br /><code><br />host=192.168.2.10<br /></code><br />In the next section of the code we get into the meat of the program:<br /><code><br />class AddressBook:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def close(self, widget, event, data=None):<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gtk.main_quit()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def okay_click(self, widget, data=None):<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data = open(data).readlines() # open the file<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sstring1="host=192.168" # basic host string<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for line in data:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if sstring1 in line:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;host = line[5:] # discard first host= characters<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;host = host.replace ( '\r\n', '' ) # remove line endings<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;os.system("xvncviewer " + host) #run xvncviewer with new string<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def __init__(self):<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.window.set_title("VNC Connections")<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.hbox = gtk.HBox(False, 0)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.window.connect("delete_event", self.close)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.window.add(self.hbox)<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for cnt in cntr:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.vbox = gtk.VBox(False, 0)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.hbox.add(self.vbox)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.label = gtk.Label(storeName[cnt])<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.vbox.pack_start(self.label, False, False, 2)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.label.show()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for fname in dirList:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if fnmatch.fnmatch(fname, storeList[cnt]):<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fstring=fname.replace ( '0_', '0-' )<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fstring=fstring.replace ( '_', ', ' )<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fstring=fstring.replace ( '.vnc', '' )<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.button = gtk.Button(label=fstring)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.button.connect("clicked", self.okay_click, homefolder + fname)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.vbox.pack_start(self.button, False, False, 2)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.button.show()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.vbox.show()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.hbox.show()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.window.show()<br /></code><br />Here's a basic overview of what the sections do:<br />The "def close" section is what the program does when you click on the close button.<br />The "def okay_click" section is what happen when you click on someone's name to connect to their computer. The program goes into the VNC file and extracts the host= portion of the file and formats a xvncviewer session to open a connection to that computer.<br />The "def __init__(self):" is the visual aspect of the program. Basically the program iterates through the /VNC/ folder and formats buttons for each person's name.<br /><br />The last bit of code completes the program;<br /><code><br />if __name__ == "__main__":<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AddressBook()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gtk.main()<br /></code> <br />I've found that the easiest way to get started with programs like this would be to look at examples of working programs and try to understand what each different section does. I still have a very basic understanding of Python programming, but this exercise helped me understand how powerful the program really is. In the future I can see many more applications where Python will come in handy.<br /> ]]></description>
</item>
<item>
<title>A Fresh Start and a New Format</title>
<link>http://blog.jlandis.org/?pid=1</link>
<description><![CDATA[ This is just an RSS feed - for a direct link to this post on my blog visit the following link: <a href='http://blog.jlandis.org/?pid=1'>A Fresh Start and a New Format</a><br><br>It has been quite some time since I last posted, but a recent email I received rejuvenated my interest in blogging. First - about this email. The letter was from Google notifying me of an important change to the Blogger platform. The basic message of the email can be foung here <a href="http://buzz.blogger.com/2010/01/important-note-to-ftp-users.html">Blogger Buzz</a>. My old method of publication via sftp to my own personal domain will no longer be supported. I have two options. 1 - convert myself over to a blogger.com domain or 2 - I could choose to redirect my current website's DNS records to a Google server. That means when someone would go to http://blog.jlandis.org it would automatically redirect itself to one of Google's servers which would contain my website.<br /><br />Now there is nothing terribly wrong with the second scenario, but I can be a bit possessive at times and I think that since I own jlandis.org I should have the right to keep my files stored on my domain and run them how I wanted them run. We could go into a brief discussion of conspiracy theories here about how Google is attempting to own all content on the web, but I'll spare that discussion. Blogger is Google's product and they can do with it what they want. They aren't charging me a fee, so I have no right to complain. This is what inspired me to create this new blog.<br /><br />Far too often we find ourselves latching on and becoming dependent on other people's technologies and discoveries.  We ourselves do not understand any of the underlying architecture, but we're more than happy to use the service. Personally I can't stand that. I want to be in a state of always learning and growing, so I decided to go and create my own blogging platform. I wrote 100% of the underlying code to this website. I crafted (albeit poorly) all of the graphics and design of this website. I wanted to understand how to do everything myself and in around 800 lines of code I discovered that I could do just that. Now the code might not be perfect and there may be a few bugs, but I would rather struggle and learn than just use someone else and their technology.<br /><br />That is what this blog will be about - learning new things that we all take for granted. Posting may not be all that frequent, but I thought it would be a good idea to share some of my discoveries. These will not be new concepts, but through the process of my learning maybe I can help someone else learn something new. And if nothing else at least I'll have a record of my own personal growth. ]]></description>
</item>
</channel></rss>