Archive for June, 2007

More xargs hackery

Monday, June 25th, 2007

Oftentimes, one will create a number of files in a source-controlled working copy when implementing a feature. When you go to commit, you realize you have to run svn add on each file. You might try to re-add the working copy, but SVN will balk and return this error:

svn: warning: 'nameofworkingcopy' is already under version control

But this is Linux, right? Surely you don’t have to manually add each file!

Sure enough, xargs can save us some time. The following command will run svn add on each file in the working copy that is not under version control and whose filename does not contain ‘.pyc‘ (in this instance, compiled Python bytecode.)

svn status | grep '?' | grep -v '.pyc' | sed -Ee 's/?      //' | xargs svn add

The breakdown:

  • svn status will list any files that have changed in the working copy, along with files that are not under version control, appended by a question mark
  • grep '?' and grep -v '.pyc' match (and in the case of the inverted -v, does not match) lines signifying an unknown file or filenames to a compiled Python bytecode file
  • sed performs text manipulation specified by -e, which is interpreted as a -E extended regular expression, replacing all question marks followed by space with nothing
  • Finally, xargs passes each line from the previous chain as an argument to svn add, putting these files under version control.

If you have a few files you don’t want to add, add the -P -l1 option to xargs for a confirmation on each execution.

Cleaning up patch backups

Tuesday, June 19th, 2007

Something like this should work well to get rid of those pesky .orig and .rej files that patch creates:

find . -name *.orig -or -name *.rej | xargs rm

OS X and Linux network printing

Sunday, June 17th, 2007

Linux CUPS printing is a funny thing.

Every time we reinstall Linux (I think, though, we’re going to stay with Ubuntu for the foreseeable future) I have to reconfigure printing.

When our Lexmark Z51 finally died, everybody stood around and swore they’d never buy another product from Lexmark, So we went out and bought an HP Deskjet 5740, because I’d heard that HP printers had great Linux support.

This is completely true.

But keep in mind we’re talking about Linux support. Very rarely are things point-and-click.

After installing the proper packages and the PPD file, setting up the printer wasn’t too hard. I had to change the CUPS configuration file to make it allow access from the local network, and I also made printing work from the Ubuntu machine in my room—a relatively straightforward undertaking—and so, things were happy on the LAN.

Now that I’m using OS X, though, I’m having to relearn some tricks, and today I learned how to get OS X to print to a CUPS printer.

First, make sure you can access the other machine’s CUPS server. Type something like this into Firefox:

http://192.168.1.xx:631/

You should get the CUPS information page. If you don’t, you probably need to change the configuration to allow access from the local network.

The next step depends on how your printer is set up. In my case, each client must have the PPD file for the printer, as CUPS does no translation, so I open a terminal and type:

lpadmin -p Deskjet -v ipp://192.168.1.100:631/printers/DeskJet-5740 -P ~/Desktop/HP-DeskJet_5740-hpijs.ppd -E -u allow:phil

192.168.1.100 is the IP (or hostname) of the CUPS server, DeskJet-5740 is the name of the printer queue, ~/Desktop/HP-DeskJet_5740-hpijs.ppd is the name of the PPD file for my printer (which can be had from linuxprinting.org), and -E is the magical make-it-work option. -E enables the printer. I have no idea why it is necessary to do so or why it cannot be done from the OS X print administration dialog. I assume -u allow:your_username is not required, but I don’t want to break it to find out.

If you can print to your printer without a PPD file, simply leave off that option. In my case, that causes the printer to spit pages of Postscript. Your mileage may vary.