Changeset 379 for trunk/project-meta
- Timestamp:
- Nov 28, 2018, 12:05:51 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/project-meta/project-meta
r220 r379 8 8 use strict; 9 9 use warnings; 10 use version; our $VERSION = version->declare('0. 0.12');10 use version; our $VERSION = version->declare('0.1.1'); 11 11 12 12 use File::Copy qw(copy); … … 17 17 use Archive::Zip qw(:ERROR_CODES :CONSTANTS); 18 18 19 our $CFG_VERSION = 2; 19 20 20 21 my ($verbose); … … 36 37 'make-file-license' => \&cmd_make_file_license, 37 38 'list-license' => \&cmd_list_license, 39 'upgrade' => \&cmd_upgrade, 38 40 ); 39 41 … … 75 77 $folderdb->{$folder}++; 76 78 return addfolder2list($folderdb, $folder); 79 } 80 81 ################################################################ 82 83 sub upgrade_version_1_to_2 { 84 my $meta = shift; 85 86 $meta->{'project'}{'identifier'} ||= {}; 87 $meta->{'project'}{'identifier'}{'acronym'} = $meta->{'project'}{'acronym'}; 88 delete $meta->{'project'}{'acronym'}; 89 90 $meta->{'project'}{'creator'} = $meta->{'project'}{'authors'}; 91 delete $meta->{'project'}{'authors'}; 92 93 $meta->{'project'}{'description'} = $meta->{'project'}{'short-description'}; 94 delete $meta->{'project'}{'short-description'}; 95 96 $meta->{'project'}{'rights'} = $meta->{'public-dap'}{'data-license'}; 97 delete $meta->{'public-dap'}{'data-license'}; 98 99 $meta->{'project'}{'relation'} ||= []; 100 for my $doi (@{$meta->{'publication'}{'doi'}}) { 101 push @{$meta->{'project'}{'relation'}}, {doi => $doi}; 102 } 103 delete $meta->{'publication'}{'doi'}; 104 105 $meta->{'version'} = 2; 106 return $meta; 107 } 108 109 ################################################################ 110 111 sub load_metadata { 112 my $meta = YAML::Syck::LoadFile("PROJECT-META.yml"); 113 114 my $initial_version = $meta->{'version'}; 115 if ($initial_version < $CFG_VERSION) { 116 print "Warning: upgrade config file from version $initial_version to last version $CFG_VERSION\n"; 117 my $upgrade = 'upgrade_version_' . ($CFG_VERSION - 1) . '_to_' . $CFG_VERSION; 118 &{$upgrade}($meta); 119 } 120 elsif ($initial_version < $CFG_VERSION) { 121 die "Error: config file at future version $meta->{'version'}, program only at $CFG_VERSION\n" 122 } 123 124 return wantarray ? ($meta, $version) : $meta; 77 125 } 78 126 … … 96 144 project-meta make-file-author 97 145 project-meta make-file-copyright 146 project-meta upgrade 98 147 END 99 148 } … … 107 156 ################################################################ 108 157 158 sub cmd_upgrade { 159 my ($meta, $initial_version) = load_metadata(); 160 161 if ($initial_version < $meta->{'version'}) { 162 my $next_config = "PROJECT-META-v$meta->{'version'}.yml"; 163 if (-e $next_config) { 164 die "Error: upgrade propose config file $next_config already exists\n"; 165 } 166 167 print "Warning: create new config file $next_config, please verify before using it\n"; 168 YAML::Syck::SaveFile($next_config, $meta); 169 } 170 else ($initial_version == $CFG_VERSION) { 171 print "Warning: nothing to do, config file already at version $CFG_VERSION\n" 172 }; 173 } 174 175 ################################################################ 176 109 177 sub cmd_check { 110 my $meta = YAML::Syck::LoadFile("PROJECT-META.yml");111 112 my $acronym = $meta->{'project'}{' acronym'};178 my $meta = load_metadata(); 179 180 my $acronym = $meta->{'project'}{'identifier'}{'acronym'}; 113 181 my $current_dir = Cwd::getcwd(); 114 182 my $dap_folder = $meta->{'public-dap'}{'dap-folder'}; 115 183 116 print_ok 'project/ acronym',$acronym =~ m{\d\d\w[\w\d_/]+};184 print_ok 'project/identifier/acronym', $acronym =~ m{\d\d\w[\w\d_/]+}; 117 185 print_ok 'public-dap/dap-folder', $dap_folder ne '' and $dap_folder =~ m{^/}; 118 186 print_ok 'dap-folder not match current_dir', $dap_folder !~ m{$current_dir}; … … 124 192 125 193 sub cmd_dap_publish { 126 my $meta = YAML::Syck::LoadFile("PROJECT-META.yml");194 my $meta = load_metadata(); 127 195 my $current_dir = Cwd::getcwd(); 128 my $acronym = $meta->{'project'}{' acronym'};196 my $acronym = $meta->{'project'}{'identifier'}{'acronym'}; 129 197 my $dap_folder = $meta->{'public-dap'}{'dap-folder'}; 130 198 my $data_set = $meta->{'public-dap'}{'data-set'}; … … 169 237 170 238 sub cmd_dap_unpublish { 171 my $meta = YAML::Syck::LoadFile("PROJECT-META.yml");239 my $meta = load_metadata(); 172 240 my $current_dir = Cwd::getcwd(); 173 my $acronym = $meta->{'project'}{' acronym'};241 my $acronym = $meta->{'project'}{'identifier'}{'acronym'}; 174 242 my $dap_folder = $meta->{'public-dap'}{'dap-folder'}; 175 243 … … 184 252 185 253 sub cmd_make_zip { 186 my $meta = YAML::Syck::LoadFile("PROJECT-META.yml");254 my $meta = load_metadata(); 187 255 my $current_dir = Cwd::getcwd(); 188 256 my $data_set = $meta->{'public-dap'}{'data-set'}; 189 my $acronym = $meta->{'project'}{' acronym'};257 my $acronym = $meta->{'project'}{'identifier'}{'acronym'}; 190 258 191 259 push @{$data_set}, 'AUTHORS.txt', 'COPYRIGHT.txt', 'LICENSE.txt'; … … 236 304 237 305 sub cmd_make_file_author { 238 my $meta = YAML::Syck::LoadFile("PROJECT-META.yml");306 my $meta = load_metadata(); 239 307 240 308 my $current_dir = Cwd::getcwd(); 241 309 242 my $acronym = $meta->{'project'}{' acronym'};243 my $authors_list = $meta->{'project'}{' authors'};310 my $acronym = $meta->{'project'}{'identifier'}{'acronym'}; 311 my $authors_list = $meta->{'project'}{'creator'}; 244 312 245 313 if (-f "$current_dir/AUTHORS.txt") { … … 277 345 278 346 sub cmd_make_file_license { 279 my $meta = YAML::Syck::LoadFile("PROJECT-META.yml");347 my $meta = load_metadata(); 280 348 281 349 my $current_dir = Cwd::getcwd(); … … 286 354 } 287 355 288 my $license = $meta->{'p ublic-dap'}{'data-license'};356 my $license = $meta->{'project'}{'rights'}; 289 357 290 358 if (not -f "/usr/share/project-meta/license.d/$license.txt") { … … 303 371 304 372 sub cmd_make_file_copyright { 305 my $meta = YAML::Syck::LoadFile("PROJECT-META.yml");373 my $meta = load_metadata(); 306 374 307 375 my $current_dir = Cwd::getcwd(); … … 330 398 ); 331 399 my $msg_format = ''; 400 my $doi_first; 401 for my $doi (@{$meta->{'project'}{'relation'}) { 402 next if not exists $doi->{'doi'}; 403 $doi_first = $doi->{'doi'}; 404 last; 405 } 332 406 $tt->process('COPYRIGHT.tt', 333 407 { 334 408 title => $meta->{'project'}{'title'}, 335 acronym => $meta->{'project'}{' acronym'},336 authorlist => $meta->{'project'}{' authors'},337 description => $meta->{'project'}{' short-description'},338 license => $meta->{'p ublic-dap'}{'data-license'},339 doi => $ meta->{'publication'}{'doi'},409 acronym => $meta->{'project'}{'identifier'}{'acronym'}, 410 authorlist => $meta->{'project'}{'creator'}, 411 description => $meta->{'project'}{'description'}, 412 license => $meta->{'project'}{'rights'}, 413 doi => $ doi_first, 340 414 }, \$msg_format) || die $tt->error; 341 415 … … 385 459 project-meta make-file-author 386 460 project-meta make-file-copyright 461 project-meta upgrade 387 462 388 463 … … 426 501 =over 427 502 428 =item * C<project/ acronym>: the project short acronym, add to the OpeNDAP root folder503 =item * C<project/identifier/acronym>: the project short acronym, add to the OpeNDAP root folder 429 504 430 505 =item * C<public-dap/dap-folder>: the OpeNDAP root folder … … 462 537 =over 463 538 464 =item * C<project/ acronym>: the project short acronym, use as root folder539 =item * C<project/identifier/acronym>: the project short acronym, use as root folder 465 540 466 541 =item * C<public-dap/data-set>: a list of files or folder to push … … 542 617 Create or update the F<COPYRIGHT.txt> file at the current folder. 543 618 Authors, license and copyright data are extracted from the C<PROJECT-META.yml> file. 619 620 =head2 upgrade 621 622 project-meta upgrade 623 624 Upgrade config file to last version. 625 Create a file F<PROJECT-META-vVERSION.yml> in the current directory if it's not exists, error otherwise. 626 Please maually verify this autogenerated config file before rename and using it. 544 627 545 628
Note: See TracChangeset
for help on using the changeset viewer.