source: trunk/gsdl3/bin/script/convert_coll_from_gs2.pl@ 3688

Last change on this file since 3688 was 3688, checked in by kjdon, 21 years ago

gs2 compatible building/conversion scripts

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 KB
Line 
1#!/usr/bin/perl -w
2
3BEGIN {
4 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
5 die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
6 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
7 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan");
8 #unshift (@INC, "$ENV{'GSDLHOME'}/perllib/plugins");
9 # unshift (@INC, "$ENV{'GSDLHOME'}/perllib/classify");
10}
11
12#use arcinfo;
13use colcfg;
14#use plugin;
15use docprint;
16use util;
17use parsargv;
18use FileHandle;
19use XML::Writer;
20
21&main();
22sub print_usage() {
23 print STDOUT "Usage: convert_coll_from_gs2.pl [options] coll-name\n";
24 print STDOUT "options:\n";
25
26}
27
28sub main {
29
30 my ($collectdir);
31 # note that no defaults are passed for most options as they're set
32 # later (after we check the collect.cfg file)
33 if (!parsargv::parse(\@ARGV,
34 'verbosity/\d+/', \$verbosity,
35 'collectdir/.*/', \$collectdir,
36 'faillog/.*/', \$faillog)) {
37 &print_usage();
38 die "\n";
39 }
40
41 # get and check the collection name
42 if (($collection = &util::use_collection(@ARGV, $collectdir)) eq "") {
43 &print_usage();
44 die "\n";
45 }
46
47 $collconfigfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "etc", "collect.cfg");
48 my $collectcfg;
49 if (-e $collconfigfilename) {
50 $collectcfg = &colcfg::read_collect_cfg ($collconfigfilename);
51
52 }
53 $buildconfigfilename = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "building", "build.cfg");
54 my $buildcfg;
55 if (-e $buildconfigfilename) {
56 $buildcfg = &colcfg::read_build_cfg ($buildconfigfilename);
57
58 }
59
60 my $outfile = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, "building", "buildConfig.xml");
61 if (-e $outfile) {
62 print STDOUT "buildConfig file already exists! overwriting it!\n";
63
64 }
65
66 my $buildtype;
67 if (defined $collectcfg->{'buildtype'}) {
68 $buildtype = $collectcfg->{'buildtype'};
69 } else {
70 $buildtype = 'mg';
71 }
72
73 my $output = new IO::File(">$outfile");
74 my $writer = new XML::Writer(OUTPUT => $output);
75
76 $writer->startTag('buildConfig');
77
78 if (defined $collectcfg->{'collectionmeta'}) {
79 my $collmeta = $collectcfg->{'collectionmeta'};
80 $writer->startTag('metadataList');
81 #just do collname for now
82 my $collnames = $collmeta->{'collectionname'};
83 foreach $lang (keys %$collnames) {
84 my $short_lang;
85 if ($lang eq 'default') {
86 $short_lang = 'en';
87 } else {
88 ($short_lang) = $lang =~ /^\[l=(..)\]/;
89 }
90 $writer->startTag('metadata', 'lang'=>$short_lang, 'name'=>'collName');
91 $writer->characters($collnames->{$lang});
92 $writer->endTag('metadata');
93 }
94 my $collabouts = $collmeta->{'collectionextra'};
95 foreach $lang (keys %$collabouts) {
96 my $short_lang;
97 if ($lang eq 'default') {
98 $short_lang = 'en';
99 } else {
100 ($short_lang) = $lang =~ /^\[l=(..)\]/;
101 }
102 $writer->startTag('metadata', 'lang'=>$short_lang, 'name'=>'collDescript');
103 $writer->characters($collabouts->{$lang});
104 $writer->endTag('metadata');
105 }
106 $writer->endTag('metadataList');
107 }
108 $writer->startTag('serviceRackList');
109
110 if ($buildtype =~ /^mg/) {
111 if ($buildtype eq 'mgpp') {
112 #for each level
113 my @levels = ('Document');
114 my $defaultlevel = 'Document';
115 if (defined $collectcfg->{'levels'}) {
116 push @levels, @{$collectcfg->{'levels'}};
117
118 foreach $l(@levels){
119 $defaultlevel = 'Section' if $l eq 'Section';
120 }
121 }
122
123 $writer->startTag('serviceRack', 'name'=>'GS2MGPPRetrieve');
124 $writer->emptyTag('defaultLevel', 'name'=>$defaultlevel);
125 $writer->endTag('serviceRack');
126
127 $writer->startTag('serviceRack', 'name'=>'GS2MGPPSearch');
128 $writer->emptyTag('defaultLevel', 'name'=>$defaultlevel);
129 $writer->startTag('levelList');
130 foreach $level (@levels) {
131 $writer->emptyTag('level', 'name'=>$level);
132 }
133 $writer->endTag('levelList');
134
135 #fieldlist
136
137 } elsif ($buildtype eq 'mg') {
138 $writer->emptyTag('serviceRack', 'name'=>'GS2MGRetrieve');
139 $writer->startTag('serviceRack', 'name'=>'GS2MGSearch');
140 }
141
142 #indexes
143 my $indexmap = {};
144 if (defined $buildcfg->{'indexmap'}) {
145 $indexmap_t = $buildcfg->{'indexmap'};
146 foreach $i (@$indexmap_t) {
147 my ($k, $v) = $i =~ /^(.*)\-\>(.*)$/;
148 $indexmap->{$k} = $v;
149 }
150 } else {
151 print STDERR "indexmap not defined";
152 }
153 my $defaultindex;
154 if (defined $collectcfg->{'defaultindex'}) {
155 $defaultindex = $collectcfg->{'defaultindex'};
156 } else {
157 print STDERR "defaultindex not defined";
158 }
159 $defaultindex = $indexmap->{$defaultindex};
160 $writer->emptyTag('defaultIndex', 'name'=>$defaultindex);
161 $writer->startTag('indexList');
162 #for each index
163 foreach $i (keys %$indexmap) {
164 $index = $indexmap->{$i};
165 $writer->emptyTag('index', 'name'=>$index);
166 }
167 $writer->endTag('indexList');
168
169 $writer->endTag('serviceRack');
170 }
171
172 #my $classifiers = {};
173 my $count = 1;
174 my $phind = 0;
175 my $started_classifiers = 0;
176 if (defined $collectcfg->{'classify'}) {
177 my $classifiers = $collectcfg->{'classify'};
178 foreach $cl (@$classifiers) {
179 print STDERR "cl=$cl\n";
180 $name = "CL$count";
181 $count++;
182 my ($classname) = @$cl[0];
183 if ($classname eq "Phind") {
184 $phind=1;
185 next;
186 }
187
188 if (not $started_classifiers) {
189 $writer->startTag('serviceRack', 'name'=>'GS2Browse');
190 $writer->startTag('classifierList');
191 $started_classifiers = 1;
192 }
193 my $title = ''; #use buttonname if defined, otherwise use metadata
194
195 for ($i=0; $i<scalar(@$cl); $i++) {
196 $arg = @$cl[$i];
197 if ($arg eq "-buttonname") {
198 $title = @$cl[$i+1];
199 last;
200 }
201 if ($arg eq "-metadata") {
202 $title = @$cl[$i+1];
203 }
204 }
205
206 $writer->startTag('classifier', 'name'=>$name);
207 $writer->startTag('metadataList');
208 #title meta
209 $writer->startTag('metadata', 'name'=>'Title');
210 $writer->characters($title);
211 $writer->endTag('metadata');
212 $writer->endTag('metadataList');
213 $writer->endTag('classifier');
214
215
216 } #foreach classifier
217 if ($started_classifiers) {
218 # end the classifiers
219 $writer->endTag('classifierList');
220 $writer->endTag('serviceRack');
221 }
222 if ($phind) {
223 # if phind classifier
224 $writer->emptyTag('serviceRack', 'name'=>'PhindPhraseBrowse');
225 }
226
227 }
228 $writer->endTag('serviceRackList');
229 $writer->endTag('buildConfig');
230 $writer->end();
231 $output->close();
232
233}
234
235#$writer->startTag('');
236#$writer->endTag('');
237#$writer->characters();
238#$writer->emptyTag('');
239
2401;
Note: See TracBrowser for help on using the repository browser.