Tag Archives: Programming

Python, PHP and a Pet Project

php-code-1242330Over the past month or so I’ve been working on a personal pet project (on my own time) to parse Cisco IOS configurations. My project goal is to provide output based on a Cisco IOS configuration to help increase my own efficiency for some troubleshooting and configuration tasks at work and also possibly help others with less experience more easily sift through some of the complexities of the configuration and understand the relationships between the various elements.

In addition to the project goal stated above, I Initially was also using this project to learn Python. Once I got the basics of Python down (I really like the language) I made some solid progress, largely thanks to the outstanding ciscoconfparse Python package. However, I eventually wanted to make this project available online via this site so others could possibly benefit from the work but I couldn’t get the ciscoconfparse package to integrate with my hosting provider system even after wasting more time than I’m willing to admit or should have trying (it works fine in my development environment, the problem has something to do with Python, security and permissions on a shared host). So I’m keeping Python and the ciscoconfparse package in my technical tool belt, but I decided to switch to PHP for this project.

Switching to PHP for this project means I don’t have a nice pre-built package to provide the base framework to parse Cisco configurations and so I’ll have to build that myself. Frankly I feel my PHP skills have become stale and so this presents a good “write erase” opportunity to refresh those and learn about and use object oriented programming.

To get up-to-speed I’ve been reading through “PHP in a Nutshell” along with some other books via my Safari Books Online account (a highly recommended resource), experimenting along the way. As far as environment goes I’m using a CentOS 6.6 virtual machine with a standard LAMP base installation as my development server and a laptop running Windows 8.1 for writing code. NuSphere PhpED had everything I was looking for and more in a PHP IDE (Integrated Development Environment) and has proven to be very helpful in my development efforts.

I’ve made some headway and at a point where I want to be able to maintain revision control. Until today I had been manually taking periodic snapshots of the project files so I could recover if I broke something that had previously been working. This was quite cumbersome so I did a little research on revision control systems and settled on Mercurial since it seemed simple and appropriate for my intents and purposes. The installation was ridiculously easy on my CentOS server.

# yum install mercurial

Once Mercurial was installed I created a basic .hgrc file in my home directory on my development VM.

[ui]
username = Walter Streeter <MY@EMAIL.ADDRESS>

After that the “Lone developer with nonlinear history” section of the Mercurial guide provided instruction for usage. The basic process I used is listed below including comments.

$ cd /path/to/projects/ # cd to where I keep my project hierarchy
$ hg init projectname # in my case projectname already existed with files
$ cd projectname
$ (add files) # in my case projectname already existed with files
$ hg add # told Mercurial to track all files
$ hg commit -m "Initial code base" # committed existing files
$ (made some changes) # made changes in a code file in PhpED and uploaded
$ hg diff # noted changes
$ hg commit -m "" # saved changes
$ hg log # noted history of changes
$ hg update 0 # reverted back to original code base
$ cat changedfile # confirmed file reverted
$ hg cp # note that hg should be used to copy files or folders
$ hg mv # note that hg should be used to move files or folders

That’s it for this post. I thought some others might benefit from what I’ve found and experienced so thought I’d share it. Now back to my personal pet programming project for some weekend fun doing “nerd stuff” as my wife would say.