Sunday, December 7, 2008
Mobicules
Both of them worked for Mentor (EDA) for about 5 years.
The company website is http://www.mobicules.com/.
Wednesday, November 5, 2008
Zope 3 Views as multi-adapters
The diagram is not accurate reflection of design of browser views in Zope. It is just for demonstration of the idea of multi-adapters.
Sunday, September 28, 2008
Cron in Python
At times, different software solutions may need to incorporate cron like functionality. I ended up doing the same recently. As usual, I first tried to find out if there are any existing implementations of cron available so that I do not have to re-invent the wheel again. I was looking for a Python based implementation and found the following: http://sourceforge.net/projects/pycron/ (Python Cron, Great Cron for Windows).
Although the title mentions Windows but the implementation can work on any Python based environment. The software is GPL licensed. Its a small and simple implementation of Cron in Python. The solution is easy to read and understand. It helped me understand some of the intricacies of cron implementation (like matching the cron table information with current time, taking care of system clock issues, etc.).
The algorithm is based on the initial simple implementation of cron by Brian Kernighan.
- Read the cron file
- Determine if any commands are to be run at the current date and time and if so, run them.
- Sleep for one minute
- Repeat from step 1.
Friday, August 15, 2008
Unicode Email in Python
Read http://mg.pov.lt/blog/unicode-emails-in-python to know about it more.
Friday, August 8, 2008
SVN configuration file
The file resides at: %APPDATA%\Subversion\config on Windows systems.
Some of the uses of this file are:
- Identifying different file extensions which should be ignored by default
- Identifying different file extensions for which svn:eol-style=native can be set by default.
Working with the SubVersion Config file
In the following I will show you some examples of how you can use this config file to make your life easier.
Global Ignores
Typically when I work on my python projects, a number of *.pyc files are generated when Python compiles my source files. It is annoying to see them listed whenever I run svn update or svn status commands. Fortunately one can specify a set of file name patterns (typically wild-card based) which will be ignored by default.
In your configuration file:
- Search for a line with keyword global-ignores
- If the line is commented, un-comment it
- add a list of file patterns which you wish to ignore
On my side it looks like:
global-ignores = *.o *.lo *.la *.pyc *.obj .DS_Store
VC++ programmers may like to add *.obj, *.exe, *.lib, *.dll etc.
Auto Props
SVN allows you to set some properties on the files. Some of the commonly used ones are svn:externals, svn:eol-style, svn:keywords etc.
I work on multiple platforms (Windows/Mac/Linux). Hence I usually need to check-in my source code with svn:eol-style=native so that when it is checked out on different platforms, the end of line characters are adjusted accordingly. (Read more about it in SubVersion manual).
My problem was that I had to do this manually for each file. Later on I found that its possible to specify in the configuration file a few automatic properties which get attached to a new file the moment its added to SVN repository.
- Find out a line which has enable-auto-props
- Make sure its un-commented
- Make sure that it looks like: enable-auto-props=yes
- Find out a section [auto-props]
- For each file pattern of your interest (*.c, *.cpp, *.py), define the automatic properties which you would like to be setup. e.g.: *.py = svn:eol-style=native;svn:keywords=Id
- You are done!!!
SubClipse and SVN
SubClipse supports two different SVN interfaces. JavaHL and SVNKit. JavaHL uses the same configuration files as the command-line client viz. %APPDATA%\Subversion\. SVNKit caches information in Eclipse keyring. I don't know much about it and won't talk about it. I am happy with JavaHL SVN interface for SubClipse.
I hope this post is useful to SubVersion users around the world.
Tuesday, July 29, 2008
AJAX and Browser Caching Problem
The caching problem is observed for HTTP GET requests only. There is no caching issue for HTTP POST requests. It turns out that this is actually very easy to achieve.
A URL is different if it has any of the GET request keys are different. Hence to bypass caching, all one needs to do is add a parameter to the URL which has a new value everytime the URL is accessed, and is not really used by the client/server programs.
For more information see:
http://www.spacebug.com/solving_browser_caching_problem_of_ajax.html
http://www.howtoadvice.com/StopCaching
Friday, July 18, 2008
Running Python Scripts with Administrator Privileges on MAC OS X
do shell script ¬
"echo 'abc' > /Applications/MyTestFile" with administrator privileges
You can open Script Editor from /Applications/AppleScript/Script Editor.app and write the above example.
- I am trying to do something which will not succeed with administrator privileges
- The "with administrator privileges" clause ensures that AppleScript will ask you to grant administrator privileges to the shell script before execution
- If you don't grant administrator privileges (may be you don't know or you forgot the password, or may be you don't want the shell script to run), the script will not be run.
- If you grant the privileges, it will do as programmed above; i.e. write 'abc' to a file in /Applications.
do shell script ¬
"/usr/bin/python myPythonProgram.py" with administrator privileges
- The solution requires you to request for privileges even before the python program started running. Thus if you wanted something where you could request the privileges only on need basis, this solution won't work. But at least something is better than nothing.
Thursday, July 17, 2008
SVK for SVN users
Objectives
At the end of reading this article you should:
- Understand how to mirror an SVN repository
- Understand how to Synchronize development between your local SVK repository and your central SVN repository
- Understand how to create local development branches
- Know typical day to day tricks for SVK usage
- Mirror an SVN repository in your local file system
- Do your day to day development using the local SVK repository (online/offline)
- Publish your changes back to the central SVN repository when deemed suitable (and when you are online)
svn://192.199.4.232/reposNow you want to mirror the whole of trunk of your mycalc project.
- third-party
- mycalc
- trunk
- gui
- arithmetic
- tags
- branches
- crm
- trunk
- tags
- branches
- The default depot has no name. Hence // above
- I chose to use mycalc/trunk as the local mirror path. This way I would essentially replicate the same directory structure as is there in the central repository, avoiding other parts of the structure which I don't wish to replicate (like branches and tags)
- Entire revision history for this repository is downloaded from central SVN server
- This operation would consume quite a lot of time depending upon how large the repository is
- To checkout : svk co //mycalc/trunk
- To update : svk update
- To commit : svk commit
- To see the status: svk status
- Listing the contents of a folder on repository: svk ls //mycalc/trunk/gui
Tuesday, July 15, 2008
Python Socket Library Hostname quirks
Objective
I wanted to setup a portable way to detect whether I am connected to network or not.
When a computer is connected to some TCP/IP network (using either static or dynamic IP), it gets an IP address. Otherwise by default it has got a loopback IP address which is 127.0.0.1.
So I thought that I could use this idea for detection of presence of network.
Problem
>>> import socket # imports the socket library
>>> print socket.gethostname()
shailesh-macbook-pro.local
The above is on the my macbook-pro laptop.
If I do the same on my windows laptop I get:
>>> import socket # imports the socket library
>>> print socket.gethostname()
shailesh_lap
So far so good.
Things get weird with the following:
On Windows
>>> print socket.gethostbyname(socket.gethostname())
192.9.199.152
And on MAC Book Pro
>>> print socket.gethostbyname(socket.gethostname())
...
socket.gaierror: (8, 'nodename nor servname provided, or not known')
Now I don't really know what went wrong here. I had just sometime back restarted the system.
After some time, I found that this started working fine again
On MAC Book Pro Again after some time
>>> print socket.gethostbyname(socket.gethostname())
192.9.199.159
It is my guess that either Python on MAC, or MAC OS itself takes some time in setting up some of these IP address hostname mappings for the local host.
Work Around
But I needed to get the IP address of the host computer. My objective was to identify whether my computer is connected to some network or not. So I eventually sat down and wrote the following:
def gethostaddress():
hostname = socket.gethostname()
hostaddr = u''
try:
hostaddr = socket.gethostbyaddr(hostname)
except socket.gaierror, e:
try:
hostaddr = socket.gethostbyaddr(u'localhost')
except: pass
except: pass
return hostaddr
def networkIsPresent():
return u'127.0.0.1' == gethostaddress()
Although this may not be perfect, but I guess I will work with this for now, till I have a better solution.
Monday, July 14, 2008
Background of this blog
I have done a lot of Python based development over the last two years and learnt quite a few tricks.
Have always thought of writing a book on Python, but that seems to be too grand a project, and I probably don't yet know enough to be able to do justice to such an attempt.
Nevertheless I can at least start blogging on Python.
Hence this blog.
UPDATE
During development, I usually use a lot of other tools too. I wanted to write about them also. Initially I thought to create a separate blog for general software related activities. But later I decided, it won't be possible for me to maintain multiple blogs. Hence I am renaming this blog to Shailesh on Software Development and will collect all my discussions related to software under this blog only.