Skip to main content

Posts

Showing posts from 2008

PdfPoster - a simple fix for Windows

I have tried a couple of times over the last 3 months to use PdfPoster on some Erwin documents. Unfortunately, I am using Windows XP on my work PC. It was clearly documented that I needed to install PyPdf 1.11 or higher, so I did easy_setup to install 1.12. Recently, I tried "C:\test>pdfposter -vvv -s 2.0 SCHEDULING.pdf scheduling_2x.pdf" ... and received a nice traceback (see below). This led me on a wild goose chase, under the assumption that my PyPDF library was not installed correctly. After a while, I decided to start python in immediate mode and just exercise PyPdf. It worked fine, but I noticed that the example opened a file using "rb" mode (read only, binary). So, I opened pdfposter/__init__.py under my site library directory, scrolled down to the bottom and changed the 3rd line of "def main" from "inpdf = PdfFileReader(open(infilename))" to "inpdf = PdfFileReader(open(infilename, "rb" ))". Problem solved!...

Google Chrome and Iron

I'm sure most of you have heard of Google's new WebKit based browser "Chrome" . Well, a German company has released a more privacy friendly version called "Iron" , with the browser usage tracking removed. Their site is written in German, but here is a translation thanks to Google's Language Translation tools. I haven't had a chance to try it out yet, but I'm glad someone is taking advantage of the open source nature of Google's offering.

Python Turtle and Links

I just discovered the Turtle graphics module for Python 2.5 using the Tk graphics library. It is very "kid friendly", and it sets up a screen when you make your first function call. This was very fun, just like when I first played with LOGO on my Commodore 64! >>> from turtle import * >>> clear() >>> down() >>> goto(66,66) >>> for step in range(24): ... right(105) ... forward(100) ... >>> up() >>> goto(0,0) >>> color("red") >>> write("Done!") >>> exit() Seen on the Web in August 2008 Iron Python on ASP.Net http://ironpythonresource.com/post/2008/08/03/Beginning-IronPython-Creating-a-basic-ASPNET-Form-(Part-1).aspx Connecting to a database http://ironpythonresource.com/post/2008/08/09/Connecting-to-a-database-and-using-the-gridview.aspx Creating a class http://ironpythonresource.com/post/2008/08/10/Beginning-IronPython-Creating-a-class.aspx Creating an updat...

The pains of browser page refresh

I like to play Chess sometimes, and I like the MKGI Chess Club . It is great for guys like me who do not have time to play a complete game in one sitting. The site uses a "postal chess" model, where I can play a move in several games, then wait for my opponent to move, or go on with my day, and check later or the next day. The site has an unfortunate quirk. It allows you to write notes about the game, but if it is the opponent's turn, the game page has a 30 second refresh. It is <meta http-equiv="refresh" content="30" >. I tried deleting this from the page using Grease Monkey (an HTML rewriting tool for FireFox), but even after I remove the element, the refresh occurs. So finally, I go into FireFox's about:config and type refresh in the finder. There is "accessibility.blockautorefresh"! So now, I get a notice that the page wants to refresh, instead of losing my notes!

Python 2.6 beta 1 and 3.0 beta 1

Python is sticking pretty close to their release schedule for Python 2.6 and 3.0 as documented in PEP 361 . They released Python 2.6 beta 1 and 3.0 beta 1 today. If you&apos're curious about their progress, check the 2.6 release notes . By the way, I noticed that they fixed a problem with one of the rotating log handlers - it was using a simple filename instead of the full file path when deleting old log files. I have been wanting to check my code in both 2.6 and 3.0 latest releases. Now that it is in beta, I should be able to get a pretty good idea of what has changed. All I want is for it to "feel" like python.

Monitoring SQL Server on the cheap

Use WMI with Python . Thanks to Tim Golden , Python on Win32 (I use ActiveState Python ) can use COM to talk to WMI. WMI allows you to run SQL-like queries to determine available memory, free disk space, database size, transaction log size, transaction log space available, when a database was last backed up, ... all of the good stuff. Any DBA knows that databases need free disk space and frequent backups. I don't want to imply that this is the only work a DBA would perform, but I have worked at shops where there really wasn't a DBA in our department. My programs occasionally failed because there was no disk space, and the transaction logs had not been backed up for a few weeks (sure, the database was backed up, but not the logs). If you don't want to use WMI, SqlServerCentral has some great articles for SQL 2000 and 2005. Give them time and they will have 2008 as well. If you want to to check a backup, try this .

Custom Python Logging Handler

Python has some nice basic logging facilities, but I really wanted a rotating logger that would rotate on each execution. I tried the obvious - just specifying class=MyModule.MyClassName, but I received a NameError exception for my trouble. After some hacking on /python25/lib/logging (a big no-no!), I did another google search and discovered that I could just import the class in my application, and set a reference to my custom class. Hard-coding a logging handler doesn't feel very dynamic, but at least I did't have to hack any more. from MyCustomHandlers import SessionRotatingFileHandler logging.SessionRotatingFileHandler = SessionRotatingFileHandler logfile_name = "test.l4p" logging.config.fileConfig(logfile_name) This allows me to place my custom log handler in my application directory. I still need to figure out how to add things to site-packages.