use
5.012;
{
$App::Magpie::Action::Update::VERSION
=
'2.000'
;
}
sub
run {
my
(
$self
) =
@_
;
my
$specdir
= dir(
"SPECS"
);
-e
$specdir
or
$self
->log_fatal(
"cannot find a SPECS directory, aborting"
);
my
@specfiles
=
grep
{ /\.spec$/ }
$specdir
->children;
scalar
(
@specfiles
) > 0
or
$self
->log_fatal(
"could not find a spec file, aborting"
);
scalar
(
@specfiles
) < 2
or
$self
->log_fatal(
"more than one spec file found, aborting"
);
my
$specfile
=
shift
@specfiles
;
my
$spec
=
$specfile
->slurp;
my
$pkgname
=
$specfile
->basename;
$pkgname
=~ s/\.spec$//;
$self
->
log
(
"updating $pkgname"
);
my
(
$distname
) = (
$spec
=~ /^
%define
\s+upstream_name\s+(.*)$/m );
my
(
$distvers
) = (
$spec
=~ /^
%define
\s+upstream_version\s+(.*)$/m );
defined
(
$distname
) or
$self
->log_fatal(
"package does not use %upstream_name"
);
defined
(
$distvers
) or
$self
->log_fatal(
"package does not use %upstream_version"
);
$self
->log_debug(
"perl distribution to update: $distname v$distvers"
);
my
$cpanmconf
= CPAN::Mini->config_file;
defined
(
$cpanmconf
)
or
$self
->log_fatal(
"no minicpan installation found, aborting"
);
my
%config
= CPAN::Mini->read_config( {
quiet
=>1} );
my
$cpanmdir
= dir(
$config
{
local
} );
$self
->log_debug(
"found a minicpan installation in $cpanmdir"
);
$self
->log_debug(
"parsing 02packages.details.txt.gz"
);
my
$modgz
=
$cpanmdir
->file(
"modules"
,
"02packages.details.txt.gz"
);
my
$p
= Parse::CPAN::Packages::Fast->new(
$modgz
->stringify );
my
$dist
=
$p
->latest_distribution(
$distname
);
my
$newvers
=
$dist
->version;
version->new(
$newvers
) > version->new(
$distvers
)
or
$self
->log_fatal(
"no new version found"
);
$self
->
log
(
"new version found: $newvers"
);
my
$cpantarball
=
$cpanmdir
->file(
"authors"
,
"id"
,
$dist
->prefix );
my
$tarball
=
$dist
->filename;
$self
->log_debug(
"copying $tarball to SOURCES"
);
copy(
$cpantarball
->stringify,
"SOURCES"
)
or
$self
->log_fatal(
"could not copy $cpantarball to SOURCES: $!"
);
my
$suffix
=
$tarball
;
$suffix
=~ s/.
*$newvers
\.//g;
$self
->
log
(
"new suffix: $suffix"
);
$self
->log_debug(
"updating spec file $specfile"
);
$spec
=~ s/
%mkrel
\d+/
%mkrel
1/;
$spec
=~ s/^(
%define
\s+upstream_version)\s+.*/$1
$newvers
/m;
$spec
=~ s/^(source.
*upstream_version
[^.]*)\..*/$1.
$suffix
/mi;
my
$specfh
=
$specfile
->openw;
$specfh
->
print
(
$spec
);
$specfh
->
close
;
my
$script
= file(
"refresh"
);
my
$fh
=
$script
->openw;
$fh
->
print
(
<<EOF);
#!/bin/bash
magpie fix -v && \\
bm -l && \\
mgarepo sync && \\
svn ci -m "update to $newvers" && \\
mgarepo submit && \\
rm \$0
EOF
$fh
->
close
;
chmod
0755,
$script
;
App::Magpie::Action::FixSpec->new->run;
$self
->
log
(
"trying to build package locally"
);
$self
->run_command(
"bm -l"
);
$self
->
log
(
"committing changes"
);
$self
->run_command(
"mgarepo sync"
);
$self
->run_command(
"svn ci -m 'update to $newvers'"
);
App::Magpie::Action::BSWait->new->run;
$self
->
log
(
"submitting package"
);
$self
->run_command(
"mgarepo submit"
);
$script
->remove;
}
1;