Mercurial > hg > foxridge-archiver
annotate makemeta-lib.pl @ 35:e27d097a9d87
still issues with "while read"
author | casties |
---|---|
date | Fri, 23 Jun 2006 11:40:12 +0200 |
parents | ae8b0506498a |
children | 27f273329930 |
rev | line source |
---|---|
12
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
1 #!/usr/local/bin/perl -w |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
2 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
3 use strict; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
4 use XML::LibXML; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
5 |
22 | 6 use lib '/usr/local/mpiwg/archive'; |
12
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
7 use MPIWGStor; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
8 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
9 # make output unbuffered |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
10 $|=1; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
11 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
12 # program version |
30 | 13 my $version = "0.2.5 (9.6.2006 ROC)"; |
16 | 14 my $help = |
15 "use: makemeta-lib [options] file.xml | |
16 options: | |
17 -debug show debugging info | |
18 -dry-run simulate, dont'do anything | |
17
6c5c7743acb1
new version with new -onlinne-mode for online/permanent.
casties
parents:
16
diff
changeset
|
19 -online-mode mode for creating online/permanent files |
30 | 20 -online-base=dir base directory for online ids (for online mode) |
17
6c5c7743acb1
new version with new -onlinne-mode for online/permanent.
casties
parents:
16
diff
changeset
|
21 -cw-mode mode for copying einstein_cw archive documents |
16 | 22 -digifiles-mode mode for copying files from digifiles |
23 -map-file=mapfile.xml digilib mapping file (for digifiles mode) | |
29 | 24 -access=free adds free access tag (use access=mpiwg for restricted access) |
16 | 25 "; |
12
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
26 logger("INFO", "makemeta-lib $version"); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
27 |
13 | 28 ########################################### |
12
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
29 # mappings |
13 | 30 |
12
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
31 # generic mappings at top level |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
32 my %gen_map = ( |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
33 'Device' => 'meta/image-acquisition/device', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
34 'Image_Type' => 'meta/image-acquisition/image-type', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
35 'Production_Comment' => 'meta/image-acquisition/production-comment', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
36 'Postproduction' => 'meta/image-acquisition/production-comment', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
37 'Language' => 'meta/lang' |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
38 ); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
39 # sub type switch tag |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
40 my %type_map = ( |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
41 'Reference_Type' => 'meta/bib@type' |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
42 ); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
43 # sub type mappings |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
44 my %subtype_map = ( |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
45 'Book' => { |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
46 '_name' => 'book', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
47 'Author' => 'meta/bib/author', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
48 'Title' => 'meta/bib/title', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
49 'Year' => 'meta/bib/year', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
50 'Place_Published' => 'meta/bib/city', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
51 'Publisher' => 'meta/bib/publisher', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
52 'Edition' => 'meta/bib/edition' |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
53 }, |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
54 'Journal Article' => { |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
55 '_name' => 'journal-article', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
56 'Author' => 'meta/bib/author', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
57 'Title' => 'meta/bib/title', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
58 'Year' => 'meta/bib/year', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
59 'Secondary_Title' => 'meta/bib/journal', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
60 'Volume' => 'meta/bib/volume', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
61 'Number' => 'meta/bib/issue', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
62 'Pages' => 'meta/bib/pages' |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
63 }, |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
64 'In Book' => { |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
65 '_name' => 'inbook', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
66 'Author' => 'meta/bib/author', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
67 'Title' => 'meta/bib/title', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
68 'Year' => 'meta/bib/year', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
69 'Secondary_Title' => 'meta/bib/book-title', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
70 'Pages' => 'meta/bib/pages' |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
71 }, |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
72 'Newspaper Article' => { |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
73 '_name' => 'newspaper-article', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
74 'Author' => 'meta/bib/author', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
75 'Title' => 'meta/bib/title', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
76 'Year' => 'meta/bib/year', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
77 'Secondary_Title' => 'meta/bib/newspaper', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
78 'Place_Published' => 'meta/bib/city', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
79 'Number' => 'meta/bib/issue-date', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
80 'Pages' => 'meta/bib/pages' |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
81 }, |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
82 'Edited Book' => { |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
83 '_name' => 'edited-book', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
84 'Author' => 'meta/bib/editor', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
85 'Title' => 'meta/bib/title', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
86 'Year' => 'meta/bib/year', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
87 'Place_Published' => 'meta/bib/city', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
88 'Publisher' => 'meta/bib/publisher', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
89 'Edition' => 'meta/bib/edition' |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
90 }, |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
91 'Manuscript' => { |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
92 '_name' => 'manuscript', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
93 'Author' => 'meta/bib/author', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
94 'Title' => 'meta/bib/title', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
95 'Year' => 'meta/bib/year', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
96 'Place_Published' => 'meta/bib/location', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
97 } |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
98 ); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
99 # language element |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
100 my $lang_field = 'Language'; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
101 # languages to iso codes |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
102 my %lang_map = ( |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
103 'German' => 'de', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
104 'English' => 'en', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
105 'Italian' => 'it', |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
106 'French' => 'fr', |
13 | 107 'Latin' => 'la', |
14 | 108 'Japanese' => 'ja', |
15
8d2f0586eca6
new helper script for calling archiver on many directories
casties
parents:
14
diff
changeset
|
109 'Dutch' => 'nl', |
32 | 110 'Spanish' => 'es', |
111 'Swedish' => 'sv' | |
12
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
112 ); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
113 # storage fields |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
114 my $arch_id_field = 'ID_Archive'; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
115 my $online_url_field = 'URL'; |
16 | 116 my $online_id_field = 'ID_OnlinePermanent'; |
12
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
117 |
13 | 118 ####################################################### |
119 # internal parameters | |
120 # | |
121 | |
122 # storage | |
12
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
123 my $lib_arch_dir = '/mpiwg/archive/data/library'; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
124 my $lib_online_dir = '/mpiwg/online/permanent'; |
16 | 125 my $lib_digilib_path = 'permanent'; |
126 my $digifiles_dir = "/net/digifiles.mpiwg-berlin.mpg.de/Volumes/raid"; | |
12
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
127 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
128 # read command line parameters |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
129 my $args = MPIWGStor::parseargs; |
16 | 130 if (! scalar(%$args)) { |
131 print $help, "\n"; | |
132 exit 1; | |
133 } | |
12
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
134 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
135 # debug level |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
136 $debug = (exists $$args{'debug'}) ? $$args{'debug'} : 0; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
137 |
16 | 138 # simulate action only |
139 my $dry_run = (exists $$args{'dry-run'}) ? $$args{'dry-run'} : 0; | |
140 logger('DEBUG', "dry-run: $dry_run"); | |
141 | |
17
6c5c7743acb1
new version with new -onlinne-mode for online/permanent.
casties
parents:
16
diff
changeset
|
142 # use online mode |
6c5c7743acb1
new version with new -onlinne-mode for online/permanent.
casties
parents:
16
diff
changeset
|
143 my $online_mode = (exists $$args{'online-mode'}) ? $$args{'online-mode'} : 0; |
6c5c7743acb1
new version with new -onlinne-mode for online/permanent.
casties
parents:
16
diff
changeset
|
144 logger('DEBUG', "online_mode: $online_mode"); |
30 | 145 # online base dir |
146 my $online_base_dir = (exists $$args{'online-base'}) ? $$args{'online-base'} : ""; | |
147 logger('DEBUG', "online_base_dir: $online_base_dir"); | |
17
6c5c7743acb1
new version with new -onlinne-mode for online/permanent.
casties
parents:
16
diff
changeset
|
148 |
12
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
149 # use einstein-cw mode |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
150 my $cw_mode = (exists $$args{'cw-mode'}) ? $$args{'cw-mode'} : 0; |
16 | 151 logger('DEBUG', "cw_mode: $cw_mode"); |
152 | |
153 # use digifiles mode | |
154 my $digifiles_mode = (exists $$args{'digifiles-mode'}) ? $$args{'digifiles-mode'} : 0; | |
155 logger('DEBUG', "digifiles_mode: $digifiles_mode"); | |
156 # digilib mapping file | |
157 my $map_file_name = (exists $$args{'map-file'}) ? $$args{'map-file'} : ""; | |
158 logger('DEBUG', "map_file_name: $map_file_name"); | |
159 my $mapping_doc; | |
160 my $mapping_root; | |
12
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
161 |
29 | 162 # access type |
163 my $access_type = (exists $$args{'access'}) ? $$args{'access'} : ""; | |
164 | |
12
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
165 # index.meta namespace (not really implemented!) |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
166 my $namespace = ""; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
167 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
168 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
169 my $xml_changed = 0; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
170 my $errcnt = 0; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
171 my $warncnt = 0; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
172 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
173 ####################################################### |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
174 # check parameters that were passed to the program |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
175 # |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
176 my $infile = $$args{'path'}; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
177 if (! $infile) { |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
178 logger("ABORT", "no input file given!"); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
179 exit 1; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
180 } |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
181 # strip double slashes |
30 | 182 $infile = sstrip($infile, 1); |
12
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
183 if (! -f $infile) { |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
184 logger("ABORT", "input file \'$infile\' doesn't exist!"); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
185 exit 1; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
186 } |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
187 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
188 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
189 ####################################################### |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
190 # subroutines |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
191 # |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
192 |
16 | 193 |
194 sub add_digilib_mapping { | |
195 my ($src_dir, $dest_dir) = @_; | |
196 my $elem = $mapping_root->addNewChild($namespace, 'mapping'); | |
197 $elem->addChild($mapping_doc->createAttributeNS($namespace, 'link', $src_dir)); | |
198 $elem->addChild($mapping_doc->createAttributeNS($namespace, 'dir', $dest_dir)); | |
199 if ($map_file_name) { | |
200 write_xml($mapping_doc, $map_file_name); | |
201 } else { | |
202 logger('ABORT', "unable to write mapping file!"); | |
203 exit 1; | |
204 } | |
205 } | |
206 | |
207 sub find_digifiles_dir { | |
208 my ($input_node) = @_; | |
209 my $digifiles_base = '/net/digifiles.mpiwg-berlin.mpg.de/Volumes/raid'; | |
210 my $src_dir = find_online_dir($input_node, $digifiles_base, ''); | |
211 if (! $src_dir) { | |
212 logger('ERROR', "no online directory for digifiles entry"); | |
213 $errcnt++; | |
214 return; | |
215 } | |
216 my $dest_id = sstrip($input_node->findvalue("fm:$online_id_field")); | |
217 if (! $dest_id) { | |
218 logger('ERROR', "no ID field for digifiles entry"); | |
219 $errcnt++; | |
220 return; | |
221 } | |
222 my $dir = "$lib_online_dir/library/$dest_id"; | |
223 my $map_dir = "$lib_digilib_path/library/$dest_id"; | |
224 if ($dry_run) { | |
225 logger('DEBUG', "would move $digifiles_base/$src_dir to $dir"); | |
226 add_digilib_mapping($src_dir, "$map_dir/pageimg"); | |
227 return $dir; | |
228 } else { | |
229 logger('INFO', "moving $digifiles_base/$src_dir to $dir"); | |
230 logger('DEBUG', "mkdir $dir/pageimg"); | |
231 if (system("mkdir -p $dir/pageimg && chmod -R 0775 $dir") == 0) { | |
232 logger('DEBUG', "cp $digifiles_base/$src_dir $dir/pageimg"); | |
233 if (system("cp -rp $digifiles_base/$src_dir/* $dir/pageimg/") == 0) { | |
234 if (-d "$dir/pageimg") { | |
235 logger('DEBUG', "directory $dir OK"); | |
236 add_digilib_mapping($src_dir, "$map_dir/pageimg"); | |
237 if (system("rm -rf $digifiles_base/$src_dir/* && rm -rf $digifiles_base/$src_dir") == 0) { | |
238 logger('DEBUG', "directory $digifiles_base/$src_dir removed"); | |
239 return $dir; | |
240 } else { | |
241 logger('ERROR', "unable to remove source directory $digifiles_base/$src_dir!"); | |
242 $errcnt++; | |
243 return $dir; | |
244 } | |
245 } | |
246 } | |
247 } | |
248 logger('ABORT', "unable to copy directory $src_dir to $dir!"); | |
249 exit 1; | |
250 } | |
251 return; | |
252 } | |
253 | |
12
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
254 sub find_cw_dir { |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
255 my ($input_node) = @_; |
16 | 256 my $cw_base = '/mpiwg/archive/data/library/inbox/zwischen_backup'; |
257 my $src_dir = find_online_dir($input_node, $cw_base, 'pageimg'); | |
258 my $dest_id = sstrip($input_node->findvalue("fm:$arch_id_field")); | |
12
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
259 if (! $dest_id) { |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
260 logger('ERROR', "no ID field for einstein-cw entry"); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
261 $errcnt++; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
262 return; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
263 } |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
264 my $dir = "$lib_arch_dir/$dest_id"; |
16 | 265 if ($dry_run) { |
266 logger('DEBUG', "would move $cw_base/$src_dir to $dir"); | |
267 return $dir; | |
268 } else { | |
269 logger('DEBUG', "moving $cw_base/$src_dir to $dir"); | |
270 if (rename "$cw_base/$src_dir", $dir) { | |
271 if (-d $dir) { | |
272 logger('DEBUG', "directory $dir OK"); | |
273 return $dir; | |
274 } | |
275 } else { | |
276 logger('ABORT', "unable to rename directory $cw_base/$src_dir to $dir!"); | |
277 exit 1; | |
12
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
278 } |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
279 } |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
280 return; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
281 } |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
282 |
17
6c5c7743acb1
new version with new -onlinne-mode for online/permanent.
casties
parents:
16
diff
changeset
|
283 sub find_permanent_dir { |
6c5c7743acb1
new version with new -onlinne-mode for online/permanent.
casties
parents:
16
diff
changeset
|
284 my ($input_node) = @_; |
30 | 285 my $online_id = sstrip($input_node->findvalue("fm:$online_id_field")); |
286 # try online_base_dir + online_id first | |
287 if (($online_base_dir)&&($online_id)) { | |
288 my $dir = sstrip("$online_base_dir/$online_id", 1); | |
289 return $dir; | |
290 } | |
291 # then online_url | |
17
6c5c7743acb1
new version with new -onlinne-mode for online/permanent.
casties
parents:
16
diff
changeset
|
292 my $online_base = '/mpiwg/online/permanent'; |
30 | 293 my $online_dir = find_online_dir($input_node, $online_base, 'pageimg'); |
294 if ((! $online_dir)) { | |
295 logger('ERROR', "no ID or URL for online permanent entry"); | |
17
6c5c7743acb1
new version with new -onlinne-mode for online/permanent.
casties
parents:
16
diff
changeset
|
296 $errcnt++; |
6c5c7743acb1
new version with new -onlinne-mode for online/permanent.
casties
parents:
16
diff
changeset
|
297 return; |
6c5c7743acb1
new version with new -onlinne-mode for online/permanent.
casties
parents:
16
diff
changeset
|
298 } |
30 | 299 my $dir = sstrip("$online_base/$online_dir", 1); |
17
6c5c7743acb1
new version with new -onlinne-mode for online/permanent.
casties
parents:
16
diff
changeset
|
300 return $dir; |
6c5c7743acb1
new version with new -onlinne-mode for online/permanent.
casties
parents:
16
diff
changeset
|
301 } |
6c5c7743acb1
new version with new -onlinne-mode for online/permanent.
casties
parents:
16
diff
changeset
|
302 |
16 | 303 # |
304 # $dir = find_online_dir($input_node, $base_dir, $page_dir) | |
305 # | |
306 # Takes the path from the $online_url_field of the $input_node document | |
307 # and looks in the directory $base_dir for it. Strips $page_dir from the end. | |
308 # Returns the directory path sans $base_dir if it exists | |
309 # | |
12
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
310 sub find_online_dir { |
16 | 311 my ($input_node, $base_dir, $page_dir) = @_; |
12
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
312 $base_dir = $lib_online_dir unless ($base_dir); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
313 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
314 my $online_url = $input_node->findvalue("fm:$online_url_field"); |
16 | 315 logger('DEBUG', "checking URL: $online_url"); |
316 my $online_dir; | |
317 if ($online_url =~ /fn=permanent\/(.+)/) { | |
318 # new style digilib URL | |
319 $online_dir = $1; | |
320 } elsif ($online_url =~ /\?([^\+]+)\+/) { | |
321 # old style digilib URL | |
322 $online_dir = $1; | |
323 } | |
324 #logger('DEBUG', "online_dir1: $online_dir"); | |
325 if ($online_dir) { | |
17
6c5c7743acb1
new version with new -onlinne-mode for online/permanent.
casties
parents:
16
diff
changeset
|
326 $online_dir =~ s/\/$//; # strip ending slashes |
16 | 327 if ($page_dir) { |
30 | 328 # strip page_dir |
329 $online_dir =~ s/\/${page_dir}$//; | |
16 | 330 } |
12
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
331 #logger("DEBUG", "dir: $base_dir/$online_dir"); |
16 | 332 if (-d "$base_dir/$online_dir") { |
17
6c5c7743acb1
new version with new -onlinne-mode for online/permanent.
casties
parents:
16
diff
changeset
|
333 logger('DEBUG', "directory $base_dir/$online_dir exists"); |
16 | 334 return $online_dir; |
12
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
335 } |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
336 } |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
337 return; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
338 } |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
339 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
340 sub find_arch_dir { |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
341 my ($input_node) = @_; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
342 my $dir = ""; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
343 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
344 my $bib_dir = $input_node->findvalue("fm:$arch_id_field"); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
345 #logger('DEBUG', "bibdir: $bib_dir"); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
346 if ($bib_dir) { |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
347 $dir = "$lib_arch_dir/$bib_dir"; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
348 if (-d $dir) { |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
349 logger('DEBUG', "directory $dir exists"); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
350 return $dir; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
351 } |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
352 } |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
353 return; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
354 } |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
355 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
356 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
357 sub convert_bib { |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
358 my ($input_node, $index_root, $index_doc) = @_; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
359 my $cnt = 0; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
360 my $type = ""; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
361 my $type_path = ""; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
362 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
363 # process general stuff first |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
364 foreach my $n ($input_node->getChildNodes()) { |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
365 my $name = $n->nodeName(); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
366 my $val = $n->textContent(); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
367 #logger('DEBUG', " NODE: $name = '$val'"); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
368 if (exists $gen_map{$name}) { |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
369 # is a general field |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
370 if ($name eq $lang_field) { |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
371 # language field -> convert to iso code |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
372 if (exists $lang_map{$val}) { |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
373 $val = $lang_map{$val}; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
374 } else { |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
375 logger('ERROR', "unknown language: $val! skipping..."); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
376 $errcnt++; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
377 return 0; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
378 } |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
379 } |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
380 create_element_path($gen_map{$name}, $index_root, $namespace) |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
381 ->appendTextNode($val); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
382 $cnt++; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
383 } elsif (exists $type_map{$name}) { |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
384 # is a type field |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
385 $type_path = $type_map{$name}; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
386 $type = $val; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
387 # check with known types |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
388 if (exists $subtype_map{$val}) { |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
389 my $indextype = $subtype_map{$val}->{'_name'}; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
390 create_element_path("$type_path=$indextype", $index_root, $namespace); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
391 $cnt++; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
392 } else { |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
393 logger('ERROR', 'unknown bib type $val! skipping...'); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
394 $errcnt++; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
395 return 0; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
396 } |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
397 } |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
398 } |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
399 # process sub type fields |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
400 if ($type) { |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
401 foreach my $n ($input_node->getChildNodes()) { |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
402 my $name = $n->nodeName(); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
403 my $val = $n->textContent(); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
404 #logger('DEBUG', " NODE: $name = '$val'"); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
405 if (exists $subtype_map{$type}->{$name}) { |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
406 create_element_path($subtype_map{$type}->{$name}, $index_root, $namespace) |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
407 ->appendTextNode($val); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
408 $cnt++; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
409 } |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
410 } |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
411 } |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
412 return $cnt; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
413 } |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
414 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
415 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
416 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
417 sub process_all_fm_entries { |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
418 my ($input_root) = @_; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
419 my $cnt = 0; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
420 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
421 foreach my $n ($input_root->findnodes('fm:ROW')) { |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
422 logger('INFO', "processing entry $cnt ..."); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
423 process_fm_entry($n); |
16 | 424 $cnt++; |
12
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
425 } |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
426 } |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
427 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
428 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
429 sub process_fm_entry { |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
430 my ($input_node) = @_; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
431 my $index_doc = XML::LibXML::Document->createDocument('1.0', 'UTF-8'); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
432 my $index_root = $index_doc->createElementNS($namespace, 'resource'); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
433 $index_root->addChild($index_doc->createAttributeNS($namespace, 'version', '1.1')); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
434 $index_root->addChild($index_doc->createAttributeNS($namespace, 'type', 'MPIWG')); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
435 $index_doc->setDocumentElement($index_root); |
28 | 436 my $derived_from = ""; |
12
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
437 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
438 # try to find the document directory |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
439 my $doc_dir = ""; |
17
6c5c7743acb1
new version with new -onlinne-mode for online/permanent.
casties
parents:
16
diff
changeset
|
440 if ($online_mode) { |
6c5c7743acb1
new version with new -onlinne-mode for online/permanent.
casties
parents:
16
diff
changeset
|
441 $doc_dir = find_permanent_dir($input_node); |
28 | 442 $derived_from = find_arch_dir($input_node); |
17
6c5c7743acb1
new version with new -onlinne-mode for online/permanent.
casties
parents:
16
diff
changeset
|
443 } elsif ($cw_mode) { |
12
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
444 $doc_dir = find_cw_dir($input_node); |
16 | 445 } elsif ($digifiles_mode) { |
446 $doc_dir = find_digifiles_dir($input_node); | |
12
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
447 } else { |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
448 $doc_dir = find_arch_dir($input_node); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
449 } |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
450 if (! $doc_dir) { |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
451 logger('ERROR', "document directory not found! skipping..."); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
452 $errcnt++; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
453 return; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
454 } |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
455 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
456 # add standard stuff to index.meta |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
457 my ($docname, $docpath) = split_file_path($doc_dir); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
458 # name and date |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
459 create_text_path('name', $docname, $index_root, $namespace); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
460 create_text_path('archive-path', $doc_dir, $index_root, $namespace); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
461 create_text_path('archive-creation-date', stime(time), $index_root, $namespace); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
462 create_text_path('creator', 'digigroup', $index_root, $namespace); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
463 create_text_path('description', 'a scanned document', $index_root, $namespace); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
464 # acquisition |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
465 create_text_path('meta/acquisition/date', stime(time), $index_root, $namespace); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
466 create_text_path('meta/acquisition/provider/provider-id', 'digigroup', $index_root, $namespace); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
467 create_text_path('meta/acquisition/provider/address', 'Max Planck Institute for the History of Science', $index_root, $namespace); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
468 # media |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
469 create_text_path('media-type', 'image', $index_root, $namespace); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
470 create_text_path('meta/content-type', 'scanned document', $index_root, $namespace); |
28 | 471 # derived-from |
472 if ($derived_from) { | |
473 create_text_path('derived-from/archive-path', $derived_from, $index_root, $namespace); | |
29 | 474 } |
475 # access | |
476 if ($access_type) { | |
477 if ($access_type eq "free") { | |
478 create_element_path('access-conditions/access@type=free', $index_root, $namespace); | |
479 } else { | |
480 my $acc_tag = create_element_path('access-conditions/access@type=institution', $index_root, $namespace); | |
481 create_text_path('name', $access_type, $acc_tag, $namespace); | |
482 } | |
483 } | |
12
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
484 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
485 # convert bib entries |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
486 my $cnt = convert_bib($input_node, $index_root, $index_doc); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
487 if ($cnt == 0) { |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
488 # error or nothing to convert |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
489 logger('ERROR', "no bibliographic metadata!"); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
490 $errcnt++; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
491 return; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
492 } |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
493 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
494 # write new index.meta file |
16 | 495 if ($dry_run) { |
496 logger('DEBUG', "would write $doc_dir/index.meta"); | |
497 logger('DEBUG', $index_doc->toString(1)); | |
498 } else { | |
499 write_xml($index_doc, "$doc_dir/index.meta"); | |
500 } | |
12
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
501 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
502 } |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
503 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
504 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
505 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
506 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
507 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
508 ####################################################### |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
509 # Main |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
510 # |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
511 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
512 # load filemaker xml dump |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
513 my ($input_doc, $input_root) = read_xml($infile); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
514 # set namespace prefix |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
515 my $fm_namespace = $input_root->namespaceURI(); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
516 $input_root->setNamespace($fm_namespace, 'fm', 1); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
517 |
16 | 518 # create digilib mapping file for digifiles mode |
519 if ($digifiles_mode) { | |
520 $mapping_doc = XML::LibXML::Document->createDocument('1.0', 'UTF-8'); | |
521 $mapping_root = $mapping_doc->createElementNS($namespace, 'digilib-aliases'); | |
522 $mapping_doc->setDocumentElement($mapping_root); | |
523 #<mapping link="exp1/archimedes_image_repository/archimedes_large/achil_propo_087_la_1545" dir="permanent/archimedes_repository/large/achil_propo_087_la_1545"/> | |
524 | |
525 } | |
526 | |
12
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
527 process_all_fm_entries($input_root); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
528 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
529 |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
530 logger("INFO", "$warncnt warnings"); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
531 logger("INFO", "$errcnt errors"); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
532 if ($errcnt > 0) { |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
533 logger("ABORT", "there were errors!"); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
534 exit 1; |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
535 } else { |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
536 logger("DONE", "done something successfully!"); |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
537 } |
620aad237f57
new tool makemeta-lib.pl to create index meta entries from the libraries online sources database
casties
parents:
diff
changeset
|
538 |