Changeset 379 for trunk/project-meta


Ignore:
Timestamp:
Nov 28, 2018, 12:05:51 AM (5 years ago)
Author:
g7moreau
Message:
  • Update project-meta to Dublin Core. Add an upgrade command
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/project-meta/project-meta

    r220 r379  
    88use strict;
    99use warnings;
    10 use version; our $VERSION = version->declare('0.0.12');
     10use version; our $VERSION = version->declare('0.1.1');
    1111
    1212use File::Copy qw(copy);   
     
    1717use Archive::Zip qw(:ERROR_CODES :CONSTANTS);
    1818
     19our $CFG_VERSION = 2;
    1920
    2021my ($verbose);
     
    3637   'make-file-license'     => \&cmd_make_file_license,
    3738   'list-license'          => \&cmd_list_license,
     39   'upgrade'               => \&cmd_upgrade,
    3840   );
    3941
     
    7577   $folderdb->{$folder}++;
    7678   return addfolder2list($folderdb, $folder);
     79   }
     80
     81################################################################
     82
     83sub 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
     111sub 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;
    77125   }
    78126
     
    96144 project-meta make-file-author
    97145 project-meta make-file-copyright
     146 project-meta upgrade
    98147END
    99148   }
     
    107156################################################################
    108157
     158sub 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
    109177sub 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'};
    113181   my $current_dir = Cwd::getcwd();
    114182   my $dap_folder  = $meta->{'public-dap'}{'dap-folder'};
    115183
    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_/]+};
    117185   print_ok 'public-dap/dap-folder',            $dap_folder ne '' and $dap_folder =~ m{^/};
    118186   print_ok 'dap-folder not match current_dir', $dap_folder !~ m{$current_dir};
     
    124192
    125193sub cmd_dap_publish {
    126    my $meta = YAML::Syck::LoadFile("PROJECT-META.yml");
     194   my $meta = load_metadata();
    127195   my $current_dir = Cwd::getcwd();
    128    my $acronym     = $meta->{'project'}{'acronym'};
     196   my $acronym     = $meta->{'project'}{'identifier'}{'acronym'};
    129197   my $dap_folder  = $meta->{'public-dap'}{'dap-folder'};
    130198   my $data_set    = $meta->{'public-dap'}{'data-set'};
     
    169237
    170238sub cmd_dap_unpublish {
    171    my $meta = YAML::Syck::LoadFile("PROJECT-META.yml");
     239   my $meta = load_metadata();
    172240   my $current_dir = Cwd::getcwd();
    173    my $acronym     = $meta->{'project'}{'acronym'};
     241   my $acronym     = $meta->{'project'}{'identifier'}{'acronym'};
    174242   my $dap_folder  = $meta->{'public-dap'}{'dap-folder'};
    175243
     
    184252
    185253sub cmd_make_zip {
    186    my $meta = YAML::Syck::LoadFile("PROJECT-META.yml");
     254   my $meta = load_metadata();
    187255   my $current_dir = Cwd::getcwd();
    188256   my $data_set    = $meta->{'public-dap'}{'data-set'};
    189    my $acronym     = $meta->{'project'}{'acronym'};
     257   my $acronym     = $meta->{'project'}{'identifier'}{'acronym'};
    190258
    191259   push @{$data_set}, 'AUTHORS.txt', 'COPYRIGHT.txt', 'LICENSE.txt';
     
    236304
    237305sub cmd_make_file_author {
    238    my $meta = YAML::Syck::LoadFile("PROJECT-META.yml");
     306   my $meta = load_metadata();
    239307
    240308   my $current_dir = Cwd::getcwd();
    241309
    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'};
    244312
    245313   if (-f "$current_dir/AUTHORS.txt") {
     
    277345
    278346sub cmd_make_file_license {
    279    my $meta = YAML::Syck::LoadFile("PROJECT-META.yml");
     347   my $meta = load_metadata();
    280348
    281349   my $current_dir = Cwd::getcwd();
     
    286354      }
    287355
    288    my $license = $meta->{'public-dap'}{'data-license'};
     356   my $license = $meta->{'project'}{'rights'};
    289357
    290358   if (not -f "/usr/share/project-meta/license.d/$license.txt") {
     
    303371
    304372sub cmd_make_file_copyright {
    305    my $meta = YAML::Syck::LoadFile("PROJECT-META.yml");
     373   my $meta = load_metadata();
    306374
    307375   my $current_dir = Cwd::getcwd();
     
    330398      );
    331399   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      }
    332406   $tt->process('COPYRIGHT.tt',
    333407      {
    334408         title       => $meta->{'project'}{'title'},
    335          acronym     => $meta->{'project'}{'acronym'},
    336          authorlist  => $meta->{'project'}{'authors'},
    337          description => $meta->{'project'}{'short-description'},
    338          license     => $meta->{'public-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,
    340414      }, \$msg_format) || die $tt->error;
    341415
     
    385459 project-meta make-file-author
    386460 project-meta make-file-copyright
     461 project-meta upgrade
    387462
    388463
     
    426501=over
    427502
    428 =item * C<project/acronym>: the project short acronym, add to the OpeNDAP root folder
     503=item * C<project/identifier/acronym>: the project short acronym, add to the OpeNDAP root folder
    429504
    430505=item * C<public-dap/dap-folder>: the OpeNDAP root folder
     
    462537=over
    463538
    464 =item * C<project/acronym>: the project short acronym, use as root folder
     539=item * C<project/identifier/acronym>: the project short acronym, use as root folder
    465540
    466541=item * C<public-dap/data-set>: a list of files or folder to push
     
    542617Create or update the F<COPYRIGHT.txt> file at the current folder.
    543618Authors, license and copyright data are extracted from the C<PROJECT-META.yml> file.
     619
     620=head2 upgrade
     621
     622 project-meta upgrade
     623
     624Upgrade config file to last version.
     625Create a file F<PROJECT-META-vVERSION.yml> in the current directory if it's not exists, error otherwise.
     626Please maually verify this autogenerated config file before rename and using it.
    544627
    545628
Note: See TracChangeset for help on using the changeset viewer.