Tag Archives: Perl

Progress report and a happy surprise

Since the last blog post most of my work has been less milestone oriented.

  • Full multilingual support for human readable nodes, nodes which show up in UIs
  • Preliminary support for Option XMLs
  • Two fixes for the XML schema to bring it upto date
  • Creation of a script wrapping XMLint and foomatics XML schema XSDes
  • Clean up of the OpenPrinting front page

I felt the the XML schema was important because my Perl module, the one replacing the C programs, is very forgiving. Robustness is of course a desirable trait in production software but Foomatic still needs something to enforce consistency. I knew we had XML XSDes but we were missing a simply script to run them. Once I had my new script in place two bugs in the printer schema came up. After I fixed that a rerun uncovered four XMLs that needed fixing.

When I started writing support for overviews (a massive data structure containing every printer and its drivers) I uncovered a bug, see if you can spot it:

# This variable holds the current time #
my $now = time;
my $Parser = xmlParse->new('en','0');
my @allPrinters
foreach my $xml (<../printer/*.xml>) {
   my$perlData = $Parser->parsePrinter($xml);
   print Dumper($perlData);

# Calculate runtime
$runtime = time - $now;

I hope you didn’t look too hard, the bug is way too easy to be obvious. This is from scaffolding.pl, a script I use to run xmlParse.pl through its paces. Its a throw away script that exists only for testing. Part of this testing is keeping an eye on runtime, and this is where the bug was.

Notice that our runtime calculation includes Dumper(A helper function that outputs Perl data structures in human readable form), when I wrote the script my assumption was that dumping the data structure was trivial. I was very wrong about this. We can read and parse an XML in one third the time it takes Dumper to print it. Every single printer XML can be read and parsed in under four seconds. Parsing every single Driver we get a runtime of 0:00, the one second resolution of the crude runtime calculator is insufficient! Fixing this bug also reduces the runtime of the C programs, but because the data structures are the same the cost of dumping is constant between the two parsing implementations. Thus the Perl implementation’s relative runtime advantage is even greater than I originally thought.

Definitely good news to report for the next OpenPrinting teleconn.

Prototype completed

The first week of my project was scheduled as  “April 25: Write a perl script capable of parsing a specific XML, extrapolate results to determine relativity to our performance requirements.”.

That week is over and the original goals of the prototype have been completed. In fact I sort of got carried away and the prototype is now nearly feature complete, for printer xml parsing. It turned out to be so fast that I simply have it parse ALL of the printer xmls when ever I want to test it. How fast? About twice as fast as the C program. Since this is a prototype the results are only preliminary, but I expect the final implementation to be at least on par with the C program. This speed was unexpected, my expectation was for the Perl to be linearly slower than the C, and  hoped it wasn’t exponentially slower, yet it is actually faster! This bodes well for the other three fourths of this portion of the project; driver xml, options xml, and overview.

Thanks to this unexpected computational speed I will be focusing on simplicitly in the implementation, since maintainability was the primarly goal of this portion of the project. I will keep an eye out for improvements but now primarily for the opportunity to simplify the code base.

Loging the #openprinting irc channel

The IRC channel is nice in theory for team wide casual communication. Unfortunately you need critical mass for it to do this task well. Often #openprinting will only have me and Till in it. Occasionally others will be present and only very occasionally will conversation occur. Since I’m new to the project I want to intercept as much inter-team communication as possible. Thus I’ve setup my home server with the irc client Irssi which logs all communication, then a perl script to clean the log and FTP it to my site. Finally one line of php to print it out on it’s own page.

Truthfully I wrote it up on a whime, but I do look forward to not missing out on chats.

Reusable code in DB.pm for import/export to/from DB

After asking Till some guestions I’ve figured out what’s left to write.

DB.pm already has:
Perl -> XML
SQL -> Perl (For printers and drivers)
XML -> Perl (For printers and drivers)

That only leaves me to write:
Perl -> SQL
SQL -> Perl (For options)
XML -> Perl (For options)

Functionality wise a good majority of hte code is already there. I also already have a function for create the tables from schema. After this I need to create a function to import a single XML and then a second function which calls the first function on all the XMLs.