#!/usr/bin/perl

use XML::Simple;
use Data::Dumper;

# get the file name
$filename = "directory.xml";
# slurp in the xml file noisily
$ref = XMLin($filename, KeyAttr => [id]);
# dump it to the screen for debugging only
#print Dumper($ref);

print "ccdbcmd mkdir /calib\n";

$hashref = $ref->{directory};

foreach $id (keys %$hashref) {
    $name = $ref->{directory}->{$id}->{name};
    $parentId = $ref->{directory}->{$id}->{parentId};
    if (! $parentId) {
	print "ccdbcmd mkdir /calib/$name\n";
    } else {
	print "ccdbcmd mkdir /calib/$ref->{directory}->{$parentId}->{name}/$name\n";
    }
}

exit;
