create blog

go home go home
  1. about
  2. code
  3. wiki
  4. blog

Archive for the ‘USPS’ Category

Python, Windows, and Network

Thursday, April 16th, 2009

We have several machines. All of them (except for mine, a MacBook Pro which I use for almost everything) run Windows.

I’ve been learning Python. It is a really useful language. It runs on the command line, and that is really important. If I could, I’d use JavaScript instead, but some things — such as connecting to MySQL servers — are a bit much for me to write JavaScript shells for at the moment (especially because it has been a year or three since I’ve dealt with the C++ MySQL APIs).

So, for a recent diversion which required MySQL database access, I decided to use Python. If I can remember, I’ll write about the project later. It was a simple script to keep track of sequence numbers for the new Intelligent Mail Barcode, so that we could ensure each piece had a unique number in any 45-day period.

Windows does not come with Python pre-installed. This is not usually a problem, as Python is not at all difficult to install. But in addition to having to install Python, I’d have to install the Python package for MySQL. This Python script could be used from several computers, so I’d have to do in on each computer. Even if I posted an article on our intra-office wiki (which it still seems like nobody reads), I would probably have to end up helping everyone install it.

And, what if I make a mistake? Having so many installations (at least 3 or 4, possibly more, and prone to change whenever we replace or add a computer) could make me very busy with things I don’t really want to be busy with.

What would be best is if I could install Python on a central server. Well, I couldn’t do that, but I could install Python on my Windows computer (which, alas, I still have to use sometimes), and figure out what I needed to copy to the server.

It is really quite simple in principle: just install Python on Windows. Copy C:\Python25 (or whatever your Python install directory is) to your central server.

Except… it still won’t run on the other computers.

It complains about missing a Python25.dll. It would seem that the Python installer was stupid enough to not install its DLLs in the install folder along with Python itself, but instead litter the already-overpopulated C:\Windows\System32 directory with them.

So, I found all of the DLLs that looked like they belonged to Python 2.5, and copied them into the Python25 directory on the central server:

  • python25.dll
  • pythoncom25.dll
  • pywintypes25.dll

Could I have missed some? Perhaps. But everything appeared to work.

I still had one complication: it would be nice if scripts could run without the command needing to say r:\path\to\Python25\python. For this, each computer would need to have Python’s path in their PATH system variable.

Instead of adding yet another item to PATH, however, I decided to make a simple command file that would “initialize” Python by adding it to the instance’s PATH. This would only last the duration of the Command window.

Here is the script, changed only slightly:

@echo off
 
IF "%INITIALIZED_PYTHON_25%"=="YES" GOTO END
 
SET PYTHONPATH=R:\path\to\python\python25\
SET PATH=R:\path\to\python\python25\;%PATH%
SET INITIALIZED_PYTHON_25=YES
 
:END

And that’s it. As the script I was working on (and likely any others in future) would be run from batch files anyway, they’d just need an extra line at the beginning to call this command. And that’s it.

Auto-Configuring, the Build, and the Barcode

Tuesday, March 17th, 2009

Last night, I wrote about how I could not easily add the barcode functionality to the build because it was not guaranteed that the library would be on every computer compiling it.

I did two main things:

  1. Added ENABLE() and HAVE() macros. Inspired by WebKit’s, here. This allows enabling and disabling the capabilities through a configuration header file (now located in config/config.h).
  2. Added a simple generate-config script. I know there are existing tools for this — I think GNU’s Autoconf does it — but I didn’t have time to learn something new, and I also didn’t want to invest in such complexity for a system which would not work in Windows. The Windows script is a command file; the Mac one is a shell script.

I like how the scripts have no prerequisites on Mac and Windows. Unfortunately, I will probably have to rewrite them later in a consolidated form, so that I only have on script; at this point, it will likely cease to have no prerequisites.

So, how do compile with support for the barcode? On Mac, you have to put the libUSPS4CB.dylib in /usr/local/lib/. On Windows, you have to put in in your WINDOWS folder. And that’s it.

Script & the USPS Intelligent Mail Barcode

Monday, March 16th, 2009

We need a way to integrate the new USPS Intelligent Mail Barcode nicely into our existing workflow. The software we use for most of our composition seems to have some… disagreements (or something)… with it at times, even though it officially supports it.

Other people using the same software recommend using the USPS’s library. That’s fine and all, but we don’t want to write a C program for each job — writing in C or C++ can be quite time consuming. And it requires compiling, creating projects, etc. In short, a lot of hassle.

While this may not be the course we end up following, I decided, tonight, that although I was half-asleep, I’d attempt to add scripting support for USPS’s library. At around 10:00, I downloaded the software from USPS. Now, roughly fifty minutes later, I have managed to write a script that uses the USPS barcode.

(more…)