Commit f923fad2 authored by smoretti's avatar smoretti

Add support for a local DESCRIPTION file

parent 88055c25
#!/usr/bin/env perl
# Perl embedded modules
use strict;
use warnings;
use diagnostics;
# Sebastien Moretti from the Vital-IT (http://www.vital-it.ch) Center
# for high-performance computing of the SIB Swiss Institute of Bioinformatics.
my $VERSION = '0.1.2';
my $VERSION = '0.1.4';
use Cwd 'abs_path';
use DateTime;
use File::Copy;
use File::Slurp;
use Getopt::Long;
use List::MoreUtils qw(uniq);
......@@ -30,63 +31,82 @@ my %url = ('bioc' => 'http://bioconductor.org/packages/__RELEAS
my ($package, $R_version, $R_package, $B_version) = ('', 0, 0, 'release');
my ($debug) = (0);
my ($debug) = (0);
my ($infile) = ('');
my %opts = ('debug' => \$debug, # more verbose
'package=s' => \$package, # Package name
'R_version=s' => \$R_version,
'R_package=s' => \$R_package,
'B_version=s' => \$B_version,
'file=s' => \$infile,
);
# Check arguments
my $test_options = Getopt::Long::GetOptions(%opts);
if ( !$test_options || $package eq '' || $R_version eq '0' ){
print "\n\tInvalid or missing argument:
\te.g. $0 -package=<PACKAGE NAME> -R_version=<VERSION OF R> [-R_package=<R PACKAGE VERSION> -B_version=<Bioconductor version> -debug]
if ( !$test_options || ($package eq '' && $infile eq '') || ($package ne '' && $infile ne '') || $R_version eq '0' ){
warn "\n\tInvalid or missing argument:
\te.g. $0 -package=<PACKAGE NAME> -R_version=<VERSION OF R> [-R_package=<R PACKAGE VERSION> -B_version=<Bioconductor version> -debug]
\t\t OR with a LOCAL file:
\te.g. $0 -file=<DESCRIPTION file> -R_version=<VERSION OF R> [-R_package=<R PACKAGE VERSION> -B_version=<Bioconductor version> -debug]
\t-package Package name e.g. SRAdb
\t-R_version Version of R e.g. 3.2.2
\t-R_package Version of R package e.g. 322 (by default R_version without dots)
\t-B_version Version of Bioconductor (by default last release)
\t-debug More verbose
\t-file Read a local R DESCRIPTION file
\n";
exit 1;
}
if ( $infile ne '' ){
if ( !-e $infile || !-r $infile || -z $infile ){
die "Cannot read file [$infile]\n";
}
$infile = abs_path($infile);
}
if ( $R_package==0 ){
$R_package = $R_version;
$R_package =~ s{\.}{}g;
}
if ( get_R_base_package($package) ){
die "$package is already available with base R libraries";
if ( !$infile && get_R_base_package($package) ){
die "$package is already available with base R libraries\n";
}
mkdir $temp_dir;
chdir $temp_dir;
binmode STDOUT, ':utf8';
# Try to get package description file from different sources, in order
my $Source = '';
URL:
for my $url ( sort keys %url ){ # Luckyly respect package source frequencies
if ( $url eq 'cran' ){
$url{$url} .= "$package/$desc_file";
}
else {
$url{$url} =~ s{__RELEASE__}{$B_version};
}
if ( $infile ){
# Copy in $temp_dir where we are!
copy("$infile", "./$desc_file");
$Source = 'LOCAL';
}
else {
URL:
for my $url ( sort keys %url ){ # Luckyly sorting respect package source frequencies
if ( $url eq 'cran' ){
$url{$url} .= "$package/$desc_file";
}
else {
$url{$url} =~ s{__RELEASE__}{$B_version};
}
my $content = get("$url{$url}");
if ( defined $content && $content ne '' ){
if ( $content =~ /Package: $package\n/ ){
$Source = $url;
# Shorten file
$content =~ s{^.*?Package: $package\n}{Package: $package\n}sm;
$content =~ s{\n\n.*$}{\n}sm;
write_file("$desc_file", $content);
last;
my $content = get("$url{$url}");
if ( defined $content && $content ne '' ){
if ( $content =~ /Package: $package\n/ ){
$Source = $url;
# Shorten file
$content =~ s{^.*?Package: $package\n}{Package: $package\n}sm;
$content =~ s{\n\n.*$}{\n}sm;
write_file("$desc_file", $content);
last;
}
}
}
}
......@@ -128,6 +148,9 @@ if ( -e "$desc_file" && -s "$desc_file" ){
if ( $line =~ /^Package:\s*(.+)/ ){
$Name = trim($1);
if ( $Source eq 'LOCAL' ){
$package = $Name;
}
die "Description name and provided package name do not match: [$package]-[$Name]\n" if ( $package ne $Name );
}
elsif ( $line =~ /^Title:\s*(.+)/ ){
......@@ -175,8 +198,8 @@ if ( -e "$desc_file" && -s "$desc_file" ){
"http://bioconductor.org/packages/$B_version/data/annotation/src/contrib/PACKAGES",
"http://bioconductor.org/packages/$B_version/data/experiment/src/contrib/PACKAGES",
# "http://bioconductor.org/packages/$B_version/extra/src/contrib/PACKAGES",
# Do not use Bioconductor extra here because soem packages are duplicated with CRAN,
# and mor up-to-date in CRAN
# Do not use Bioconductor extra here because some packages are duplicated with CRAN,
# and more up-to-date in CRAN
);
for my $url ( @Bioc_urls ){
my $content = get("$url");
......@@ -206,11 +229,11 @@ exit 0;
sub trim {
my ($string) = @_;
my ($string) = @_;
$string =~ s{^\s+}{}m;
$string =~ s{\s+$}{}m;
return $string;
$string =~ s{^\s+}{}m;
$string =~ s{\s+$}{}m;
return $string;
}
sub format_license {
......@@ -313,6 +336,7 @@ sub get_template {
: $Source eq 'data-annotation' ? "R$R_package-Bioconductor-%{_realname}"
: $Source eq 'data-experiment' ? "R$R_package-Bioconductor-%{_realname}"
: $Source eq 'extra' ? "R$R_package-Bioconductor-%{_realname}"
: $Source eq 'LOCAL' ? "R$R_package-%{_realname}"
: '';
my $URL = $Source eq 'bioc' ? 'http://www.bioconductor.org/packages/__RELEASE__/bioc/html/%{_realname}.html'
......@@ -320,6 +344,7 @@ sub get_template {
: $Source eq 'data-annotation' ? 'http://www.bioconductor.org/packages/__RELEASE__/data/annotation/html/%{_realname}.html'
: $Source eq 'data-experiment' ? 'http://www.bioconductor.org/packages/__RELEASE__/data/experiment/html/%{_realname}.html'
: $Source eq 'extra' ? 'http://www.bioconductor.org/packages/__RELEASE__/extra/html/%{_realname}.html'
: $Source eq 'LOCAL' ? 'TODO:LOCAL'
: '';
my $Source0 = $Source eq 'bioc' ? 'http://www.bioconductor.org/packages/__RELEASE__/bioc/src/contrib/%{_realname}_%{version}.tar.gz'
......@@ -327,6 +352,7 @@ sub get_template {
: $Source eq 'data-annotation' ? 'http://www.bioconductor.org/packages/__RELEASE__/data/annotation/src/contrib/%{_realname}_%{version}.tar.gz'
: $Source eq 'data-experiment' ? 'http://www.bioconductor.org/packages/__RELEASE__/data/experiment/src/contrib/%{_realname}_%{version}.tar.gz'
: $Source eq 'extra' ? 'http://www.bioconductor.org/packages/__RELEASE__/extra/src/contrib/%{_realname}_%{version}.tar.gz'
: $Source eq 'LOCAL' ? 'TODO:LOCAL'
: '';
$URL =~ s{__RELEASE__}{$B_version};
......@@ -391,7 +417,8 @@ sub get_template {
# Build template
my $template = "%define _R_version $R_version
my $template = "# Define R version and package prefix
%define _R_version $R_version
%define _prefix $R_path/R/%{_R_version}
%define _realname $package
......@@ -440,7 +467,7 @@ find \$RPM_BUILD_ROOT%{_libdir}/R/library/ -type f -name INDEX -exec chmod -x
%files
%defattr(-, root, root, -)
%dir %{_libdir}/R/library/
%{_libdir}/R/library/*
%{_libdir}/R/library/%{_realname}
%changelog
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment