summaryrefslogtreecommitdiff
path: root/Master/tlpkg/TeXLive/TeXCatalogue.pm
diff options
context:
space:
mode:
authorNorbert Preining <preining@logic.at>2007-07-12 09:38:09 +0000
committerNorbert Preining <preining@logic.at>2007-07-12 09:38:09 +0000
commit2559ab32acfcf160257c8a7c85c968e7dd58b589 (patch)
tree96c6dfb1847833fd69bf0b03305a22f6119e5cc7 /Master/tlpkg/TeXLive/TeXCatalogue.pm
parentfb899d343bd98cff4dfa012ef1e5cb7f851e69f4 (diff)
the road to new texdoc handling:
- allow tags "details" and "language" for docfiles - allow catalogue-* keys in a TLPOBJ file - TLPOBJ.pm: add update_from_catalogue which updates some information - adapt the tlpsrc2tlpdb script to take another argument -catalogue in which case the database is build with catalogue information included git-svn-id: svn://tug.org/texlive/trunk@4568 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/tlpkg/TeXLive/TeXCatalogue.pm')
-rw-r--r--Master/tlpkg/TeXLive/TeXCatalogue.pm177
1 files changed, 171 insertions, 6 deletions
diff --git a/Master/tlpkg/TeXLive/TeXCatalogue.pm b/Master/tlpkg/TeXLive/TeXCatalogue.pm
index 25aae3074d9..33ef33e6a7d 100644
--- a/Master/tlpkg/TeXLive/TeXCatalogue.pm
+++ b/Master/tlpkg/TeXLive/TeXCatalogue.pm
@@ -1,21 +1,168 @@
# $Id$
# TeXLive::TeXCatalogue - module for accessing the TeX Catalogue
+#
# Copyright 2007 Norbert Preining
#
+# Loads of code is taken from the catalogue checking script of Robin Fairbairns
+#
# This file is licensed under the GNU General Public Licence version 2
# or any later version.
-die "THIS MODULE IS NOT EVEN CLOSE TO BE FINISHED\n";
+use XML::DOM;
-package TeXLive::TeXCatalogue;
+package TeXLive::TeXCatalogue::Entry;
-use XML::Parser;
+sub new {
+ my $class = shift;
+ my %params = @_;
+ my $self = {
+ xmlfile => $params{'xmlfile'},
+ entry => defined($params{'entry'}) ? $params{'entry'} : {},
+ docs => defined($params{'docs'}) ? $params{'docs'} : {},
+ name => $params{'name'},
+ caption => $params{'caption'},
+ ctan => $params{'ctan'},
+ texlive => $params{'texlive'},
+ version => $params{'version'},
+ url => $params{'url'},
+ };
+ bless $self, $class;
+ if (defined($self->{'xmlfile'})) {
+ $self->initialize();
+ }
+ return $self;
+}
+
+sub initialize {
+ my $self = shift;
+ my $parser = new XML::DOM::Parser;
+ # parse all the files
+ my $cat = $parser->parsefile ($self->{'xmlfile'}) ||
+ die "Failed to parse ", $self->{'xmlfile'};
+ # there's almost always only one, but...
+ my $entryset = $cat -> getElementsByTagName ("entry");
+ my $entry = $entryset->item(0);
+ # entry attributes
+ my $entryid = $entry->getAttributeNode("id");
+ $self->{'entry'}{'id'} = $entryid->getValue;
+ my $entrydate = $entry->getAttributeNode("datestamp");
+ if ($entrydate) {
+ $self->{'entry'}{'date'} = $entrydate->getValue;
+ }
+ my $entrymodder = $entry->getAttributeNode("modifier");
+ if ($entrymodder) {
+ $self->{'entry'}{'modder'} = $entrymodder->getValue;
+ }
+ # parse the rest of the entries
+ # only the first name and caption is allowed
+ # description CANNOT be parsed like this since it contains more childs!!
+ # (<tt> <xref> etc elements
+ foreach my $k qw/name caption/ {
+ $self->{$k} = $cat->getElementsByTagName($k)->item(0)->getFirstChild->toString;
+ }
+ $self->{'license'} = $cat->getElementsByTagName("license")->item(0)->getAttributeNode("type")->getValue;
+ my $versnode = $cat->getElementsByTagName("version")->item(0);
+ if ($versnode) {
+ my $numnode = $versnode->getAttributeNode("number");
+ if ($numnode) {
+ $self->{'version'} = $numnode->getValue;
+ }
+ }
+ my $urlnode = $cat->getElementsByTagName("home")->item(0);
+ if ($urlnode) {
+ $self->{'url'} = $urlnode->getAttributeNode("href")->getValue;
+ }
+ $ctannode = $cat->getElementsByTagName("ctan")->item(0);
+ if ($ctannode) {
+ $self->{'ctan'} = $ctannode->getAttributeNode("path")->getValue;
+ }
+ my $tlnode = $cat->getElementsByTagName("texlive")->item(0);
+ if ($tlnode) {
+ $self->{'texlive'} = $tlnode->getAttributeNode("location")->getValue;
+ }
+ # parse the documentation entries
+ my $doc = $cat->getElementsByTagName ("documentation");
+ for (my $i=0; $i < $doc->getLength; $i++ ) {
+ my $node = $doc->item($i);
+ my $docfile = $node->getAttributeNode("href")->getValue;
+ my $detailsnode = $node->getAttributeNode("details");
+ if ($detailsnode) { $details = $detailsnode->getValue; }
+ my $languagenode = $node->getAttributeNode("language");
+ if ($languagenode) { $language = $languagenode->getValue; }
+ $self->{'docs'}{$docfile}{'available'} = 1;
+ if ($details) { $self->{'docs'}{$docfile}{'details'} = $details; }
+ if ($language) { $self->{'docs'}{$docfile}{'language'} = $language; }
+ }
+ $cat->dispose;
+}
+
+sub xmlfile {
+ my $self = shift;
+ if (@_) { $self->{'xmlfile'} = shift }
+ return $self->{'xmlfile'};
+}
+sub name {
+ my $self = shift;
+ if (@_) { $self->{'name'} = shift }
+ return $self->{'name'};
+}
+sub license {
+ my $self = shift;
+ if (@_) { $self->{'license'} = shift }
+ return $self->{'license'};
+}
+sub version {
+ my $self = shift;
+ if (@_) { $self->{'version'} = shift }
+ return $self->{'version'};
+}
+sub caption {
+ my $self = shift;
+ if (@_) { $self->{'caption'} = shift }
+ return $self->{'caption'};
+}
+sub url {
+ my $self = shift;
+ if (@_) { $self->{'url'} = shift }
+ return $self->{'url'};
+}
+sub ctan {
+ my $self = shift;
+ if (@_) { $self->{'ctan'} = shift }
+ return $self->{'ctan'};
+}
+sub texlive {
+ my $self = shift;
+ if (@_) { $self->{'texlive'} = shift }
+ return $self->{'texlive'};
+}
+sub docs {
+ my $self = shift;
+ my %newdocs = @_;
+ if (@_) { $self->{'docs'} = \%newdocs }
+ return $self->{'docs'};
+}
+sub entry {
+ my $self = shift;
+ my %newentry = @_;
+ if (@_) { $self->{'entry'} = \%newentry }
+ return $self->{'entry'};
+}
+
+
+################################################################
+#
+# TeXLive::TeXCatalogue
+#
+################################################################
+package TeXLive::TeXCatalogue;
sub new {
my $class = shift;
my %params = @_;
my $self = {
location => $params{'location'},
+ entries => defined($params{'entries'}) ? $params{'entries'} : {},
};
bless $self, $class;
if (defined($self->{'location'})) {
@@ -25,10 +172,26 @@ sub new {
}
sub initialize {
- my $class = shift;
- die "Not done yet ...\n";
+ my $self = shift;
+ my $parser = new XML::DOM::Parser;
+ # parse all the files
+ foreach (glob($self->{'location'} . "/entries/?/*.xml")) {
+ my $tce = TeXLive::TeXCatalogue::Entry->new( 'xmlfile' => "$_" );
+ $self->{'entries'}{$tce->name} = $tce;
+ }
}
+sub location {
+ my $self = shift;
+ if (@_) { $self->{'location'} = shift }
+ return $self->{'location'};
+}
+sub entries {
+ my $self = shift;
+ my %newentries = @_;
+ if (@_) { $self->{'entries'} = \%newentries }
+ return $self->{'entries'};
+}
1;
@@ -48,6 +211,8 @@ missing
The L<TeXLive::TeXCatalogue> module provides access to the data stored
in the TeX Catalogue.
+DOCUMENTATION MISSING, SORRY!!!
+
=head1 AUTHORS AND COPYRIGHT
This script and its documentation were written for the TeX Live
@@ -61,4 +226,4 @@ GNU General Public License Version 2 or later.
### tab-width: 2
### indent-tabs-mode: nil
### End:
-# vim:set tabstop=2: #
+# vim:set tabstop=2 expandtab: #