1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
package Devscripts::Uscan;
use strict;
use warnings;
use Cwd qw/cwd/;
use Exporter 'import';
use Devscripts::Uscan::Config;
use Devscripts::Uscan::FindFiles;
use Devscripts::Uscan::Output;
use Devscripts::Uscan::WatchFile;
our @EXPORT = (qw(uscan process_watchfile));
sub uscan {
# Reset global variables
%Devscripts::Uscan::WatchLine::already_downloaded = ();
Devscripts::Uscan::Output::reset();
# Initialize configuration
my $config = Devscripts::Uscan::Config->new->parse;
if ($dehs) {
uscan_verbose "The --dehs option enabled.\n"
. " STDOUT = XML output for use by other programs\n"
. " STDERR = plain text output for human\n"
. " Use the redirection of STDOUT to a file to get the clean XML data";
}
my $res = 0;
# Search for watchfiles
my @wf = find_watch_files($config);
return (1, $found) unless @wf;
foreach (@wf) {
# Read watchfiles
my ($tmp) = process_watchfile($config, @$_);
$res ||= $tmp;
# Are there any warnings to give if we're using dehs?
dehs_output if ($dehs);
}
uscan_verbose "Scan finished";
return ($res, $found);
}
sub process_watchfile {
my ($config, $pkg_dir, $package, $version, $watchfile) = @_;
my $opwd = cwd();
chdir $pkg_dir;
my $wf = Devscripts::Uscan::WatchFile->new({
config => $config,
package => $package,
pkg_dir => $pkg_dir,
pkg_version => $version,
watchfile => $watchfile,
});
return ($wf->status, $found) if ($wf->status);
my $res = $wf->process_lines;
chdir $opwd;
return ($res, $found);
}
1;
__END__
=head1 NAME
Devscripts::Uscan - Main L<uscan> library
=head1 SYNOPSIS
use Devscripts::Uscan;
my ($res, $found) = uscan();
exit($res ? $res : $found ? 0 : 1);
=head1 DESCRIPTION
Devscripts::Uscan is the main library called by L<uscan>
=head2 EXPORT
This functions are automatically imported:
=head3 B<uscan()>
Parse watch files and return two values:
=over
=item * B<$res>: the exit code. 0 if nothing wrong happened.
=item * B<$found>: return the number of new upstream found.
=back
=head3 B<process_watchfile($config, $pkg_dir, $package, $version, $watchfile)>
Read given watch file and does L<uscan> job.
=head4 Arguments
=over
=item * B<$config>: a L<Devscripts::Uscan::Config> object
=item * B<$pkg_dir>: root of the Debian source directory
=item * B<$package>: name of the package
=item * B<$version>: current Debian version of the package
=item * B<$watchfile>: path to the watch file
=back
=head4 Returned values
B<process_watchfile()> returns 2 values:
=over
=item * B<$res>: the exit status. 0 if nothing wrong happened.
=item * B<$found>: number of upstream updates found.
B<Important>: this value is a cumulative one. If you want to call
B<process_watchfile()> more than one time and want to check this value for
the current watch file, you have to reset it using the global B<$found>
variable provided by L<Devscripts::Uscan::Output>:
use Devscripts::Uscan::Output;
# Loop
my $res;
while (XX) {
# ...
$found = 0;
$res = process_watchfile(@arguments);
if($found) {
#...
}
}
=back
=head1 SEE ALSO
L<uscan(1)>, L<Devscripts::Uscan::WatchFile(3pm)>
=head1 AUTHOR
Xavier Guimard <yadd@debian.org>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2021 by Xavier Guimard
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.32.1 or,
at your option, any later version of Perl 5 you may have available.
=cut
|