1 2=head1 NAME 3 4Devscripts::Uscan::Config - uscan configuration object 5 6=head1 SYNOPSIS 7 8 use Devscripts::Uscan::Config; 9 my $config = Devscripts::Uscan::Config->new->parse; 10 11=head1 DESCRIPTION 12 13Uscan configuration object. It can scan configuration files 14(B</etc/devscripts.conf> and B<~/.devscripts>) and command line arguments. 15 16=cut 17 18package Devscripts::Uscan::Config; 19 20use strict; 21 22use Devscripts::Uscan::Output; 23use Exporter 'import'; 24use Moo; 25 26extends 'Devscripts::Config'; 27 28our $CURRENT_WATCHFILE_VERSION = 4; 29 30use constant default_user_agent => "Debian uscan" 31 . ($main::uscan_version ? " $main::uscan_version" : ''); 32 33our @EXPORT = (qw($CURRENT_WATCHFILE_VERSION)); 34 35# I - ACCESSORS 36 37# Options + default values 38 39has bare => (is => 'rw'); 40has check_dirname_level => (is => 'rw'); 41has check_dirname_regex => (is => 'rw'); 42has compression => (is => 'rw'); 43has copyright_file => (is => 'rw'); 44has destdir => (is => 'rw'); 45has download => (is => 'rw'); 46has download_current_version => (is => 'rw'); 47has download_debversion => (is => 'rw'); 48has download_version => (is => 'rw'); 49has exclusion => (is => 'rw'); 50has log => (is => 'rw'); 51has orig => (is => 'rw'); 52has package => (is => 'rw'); 53has pasv => (is => 'rw'); 54has http_header => (is => 'rw', default => sub { {} }); 55 56# repack to .tar.$zsuffix if 1 57has repack => (is => 'rw'); 58has safe => (is => 'rw'); 59has signature => (is => 'rw'); 60has symlink => (is => 'rw'); 61has timeout => (is => 'rw'); 62has user_agent => (is => 'rw'); 63has uversion => (is => 'rw'); 64has watchfile => (is => 'rw'); 65 66# II - Options 67 68use constant keys => [ 69 # 2.1 - Simple parameters that can be set in ~/.devscripts and command line 70 [ 71 'check-dirname-level=s', 'DEVSCRIPTS_CHECK_DIRNAME_LEVEL', 72 qr/^[012]$/, 1 73 ], 74 [ 75 'check-dirname-regex=s', 'DEVSCRIPTS_CHECK_DIRNAME_REGEX', 76 undef, 'PACKAGE(-.+)?' 77 ], 78 ['dehs!', 'USCAN_DEHS_OUTPUT', sub { $dehs = $_[1]; 1 }], 79 [ 80 'destdir=s', 81 'USCAN_DESTDIR', 82 sub { 83 if (-d $_[1]) { 84 $_[0]->destdir($_[1]) if (-d $_[1]); 85 return 1; 86 } 87 return (0, 88 "The directory to store downloaded files(\$destdir): $_[1]"); 89 }, 90 '..' 91 ], 92 ['exclusion!', 'USCAN_EXCLUSION', 'bool', 1], 93 ['timeout=i', 'USCAN_TIMEOUT', qr/^\d+$/, 20], 94 [ 95 'user-agent|useragent=s', 96 'USCAN_USER_AGENT', 97 qr/\w/, 98 sub { 99 default_user_agent; 100 } 101 ], 102 ['repack', 'USCAN_REPACK', 'bool'], 103 # 2.2 - Simple command line args 104 ['bare', undef, 'bool', 0], 105 ['compression=s'], 106 ['copyright-file=s'], 107 ['download-current-version', undef, 'bool'], 108 ['download-version=s'], 109 ['download-debversion|dversion=s'], 110 ['log', undef, 'bool'], 111 ['package=s'], 112 ['uversion|upstream-version=s'], 113 ['watchfile=s'], 114 # 2.3 - More complex options 115 # http headers (#955268) 116 ['http-header=s', 'USCAN_HTTP_HEADER', undef, sub { {} }], 117 118 # "download" and its aliases 119 [ 120 undef, 121 'USCAN_DOWNLOAD', 122 sub { 123 return (1, 'Bad USCAN_DOWNLOAD value, skipping') 124 unless ($_[1] =~ /^(?:yes|(no))$/i); 125 $_[0]->download(0) if $1; 126 return 1; 127 } 128 ], 129 [ 130 'download|d+', 131 undef, 132 sub { 133 $_[1] =~ s/^yes$/1/i; 134 $_[1] =~ s/^no$/0/i; 135 return (0, "Wrong number of -d") 136 unless ($_[1] =~ /^[0123]$/); 137 $_[0]->download($_[1]); 138 return 1; 139 }, 140 1 141 ], 142 [ 143 'force-download', 144 undef, 145 sub { 146 $_[0]->download(2); 147 } 148 ], 149 ['no-download', undef, sub { $_[0]->download(0); return 1; }], 150 ['overwrite-download', undef, sub { $_[0]->download(3) }], 151 152 # "pasv" 153 [ 154 'pasv|passive', 155 'USCAN_PASV', 156 sub { 157 return $_[0]->pasv('default') 158 unless ($_[1] =~ /^(yes|0|1|no)$/); 159 $_[0]->pasv({ 160 yes => 1, 161 1 => 1, 162 no => 0, 163 0 => 0, 164 }->{$1}); 165 return 1; 166 }, 167 0 168 ], 169 170 # "safe" and "symlink" and their aliases 171 ['safe|report', 'USCAN_SAFE', 'bool', 0], 172 [ 173 'report-status', 174 undef, 175 sub { 176 $_[0]->safe(1); 177 $verbose ||= 1; 178 } 179 ], 180 ['copy', undef, sub { $_[0]->symlink('copy') }], 181 ['rename', undef, sub { $_[0]->symlink('rename') if ($_[1]); 1; }], 182 [ 183 'symlink!', 184 'USCAN_SYMLINK', 185 sub { 186 $_[0]->symlink( 187 $_[1] =~ /^(no|0|rename)$/ ? $1 188 : $_[1] =~ /^(yes|1|symlink)$/ ? 'symlink' 189 : 'no' 190 ); 191 return 1; 192 }, 193 'symlink' 194 ], 195 # "signature" and its aliases 196 ['signature!', undef, 'bool', 1], 197 ['skipsignature|skip-signature', undef, sub { $_[0]->signature(-1) }], 198 # "verbose" and its aliases 199 ['debug', undef, sub { $verbose = 2 }], 200 ['extra-debug', undef, sub { $verbose = 3 }], 201 ['no-verbose', undef, sub { $verbose = 0; return 1; }], 202 [ 203 'verbose|v+', 204 'USCAN_VERBOSE', 205 sub { 206 $verbose = ($_[1] =~ /^yes$/i ? 1 : $_[1] =~ /^(\d)$/ ? $1 : 0); 207 return 1; 208 } 209 ], 210 # Display version 211 [ 212 'version', 213 undef, 214 sub { 215 if ($_[1]) { $_[0]->version; exit 0 } 216 } 217 ]]; 218 219use constant rules => [ 220 sub { 221 my $self = shift; 222 if ($self->package) { 223 $self->download(0) 224 unless ($self->download > 1); # compatibility 225 return (0, 226"The --package option requires to set the --watchfile option, too." 227 ) unless defined $self->watchfile; 228 } 229 $self->download(0) if ($self->safe == 1 and $self->download == 1); 230 return 1; 231 }, 232 # $signature: -1 = no downloading signature and no verifying signature, 233 # 0 = no downloading signature but verifying signature, 234 # 1 = downloading signature and verifying signature 235 sub { 236 my $self = shift; 237 $self->signature(-1) 238 if $self->download == 0; # Change default 1 -> -1 239 return 1; 240 }, 241 sub { 242 if (defined $_[0]->watchfile and @ARGV) { 243 return (0, "Can't have directory arguments if using --watchfile"); 244 } 245 return 1; 246 }, 247]; 248 249# help methods 250sub usage { 251 my ($self) = @_; 252 print <<"EOF"; 253Usage: $progname [options] [dir ...] 254 Process watch files in all .../debian/ subdirs of those listed (or the 255 current directory if none listed) to check for upstream releases. 256Options: 257 --no-conf, --noconf 258 Don\'t read devscripts config files; 259 must be the first option given 260 --no-verbose Don\'t report verbose information. 261 --verbose, -v Report verbose information. 262 --debug, -vv Report verbose information including the downloaded 263 web pages as processed to STDERR for debugging. 264 --extra-debug, -vvv Report also remote content during "search" step 265 --dehs Send DEHS style output (XML-type) to STDOUT, while 266 send all other uscan output to STDERR. 267 --no-dehs Use only traditional uscan output format (default) 268 --download, -d 269 Download the new upstream release (default) 270 --force-download, -dd 271 Download the new upstream release, even if up-to-date 272 (may not overwrite the local file) 273 --overwrite-download, -ddd 274 Download the new upstream release, even if up-to-date 275 (may overwrite the local file) 276 --no-download, --nodownload 277 Don\'t download and report information. 278 Previously downloaded tarballs may be used. 279 Change default to --skip-signature. 280 --signature Download signature and verify (default) 281 --no-signature Don\'t download signature but verify if already downloaded. 282 --skip-signature 283 Don\'t bother download signature nor verify it. 284 --safe, --report 285 avoid running unsafe scripts by skipping both the repacking 286 of the downloaded package and the updating of the new 287 source tree. Change default to --no-download and 288 --skip-signature. 289 --report-status (= --safe --verbose) 290 --download-version VERSION 291 Specify the version which the upstream release must 292 match in order to be considered, rather than using the 293 release with the highest version 294 --download-debversion VERSION 295 Specify the Debian package version to download the 296 corresponding upstream release version. The 297 dversionmangle and uversionmangle rules are 298 considered. 299 --download-current-version 300 Download the currently packaged version 301 --check-dirname-level N 302 Check parent directory name? 303 N=0 never check parent directory name 304 N=1 only when $progname changes directory (default) 305 N=2 always check parent directory name 306 --check-dirname-regex REGEX 307 What constitutes a matching directory name; REGEX is 308 a Perl regular expression; the string \`PACKAGE\' will 309 be replaced by the package name; see manpage for details 310 (default: 'PACKAGE(-.+)?') 311 --destdir Path of directory to which to download. 312 --package PACKAGE 313 Specify the package name rather than examining 314 debian/changelog; must use --upstream-version and 315 --watchfile with this option, no directory traversing 316 will be performed, no actions (even downloading) will be 317 carried out 318 --upstream-version VERSION 319 Specify the current upstream version in use rather than 320 parsing debian/changelog to determine this 321 --watchfile FILE 322 Specify the watch file rather than using debian/watch; 323 no directory traversing will be done in this case 324 --bare Disable all site specific special case codes to perform URL 325 redirections and page content alterations. 326 --no-exclusion Disable automatic exclusion of files mentioned in 327 debian/copyright field Files-Excluded and Files-Excluded-* 328 --pasv Use PASV mode for FTP connections 329 --no-pasv Don\'t use PASV mode for FTP connections (default) 330 --no-symlink Don\'t rename nor repack upstream tarball 331 --timeout N Specifies how much time, in seconds, we give remote 332 servers to respond (default 20 seconds) 333 --user-agent, --useragent 334 Override the default user agent string 335 --log Record md5sum changes of repackaging 336 --help Show this message 337 --version Show version information 338 339Options passed on to mk-origtargz: 340 --symlink Create a correctly named symlink to downloaded file (default) 341 --rename Rename instead of symlinking 342 --copy Copy instead of symlinking 343 --repack Repack downloaded archives to change compression 344 --compression [ gzip | bzip2 | lzma | xz ] 345 When the upstream sources are repacked, use compression COMP 346 for the resulting tarball (default: gzip) 347 --copyright-file FILE 348 Remove files matching the patterns found in FILE 349 350Default settings modified by devscripts configuration files: 351$self->{modified_conf_msg} 352EOF 353} 354 355sub version { 356 print <<"EOF"; 357This is $progname, from the Debian devscripts package, version $main::uscan_version 358This code is copyright 1999-2006 by Julian Gilbey and 2018 by Xavier Guimard, 359all rights reserved. 360Original code by Christoph Lameter. 361This program comes with ABSOLUTELY NO WARRANTY. 362You are free to redistribute this code under the terms of the 363GNU General Public License, version 2 or later. 364EOF 365} 366 3671; 368__END__ 369=head1 SEE ALSO 370 371L<uscan>, L<Devscripts::Config> 372 373=head1 AUTHOR 374 375B<uscan> was originally written by Christoph Lameter 376E<lt>clameter@debian.orgE<gt> (I believe), modified by Julian Gilbey 377E<lt>jdg@debian.orgE<gt>. HTTP support was added by Piotr Roszatycki 378E<lt>dexter@debian.orgE<gt>. B<uscan> was rewritten in Perl by Julian Gilbey. 379Xavier Guimard E<lt>yadd@debian.orgE<gt> rewrote uscan in object 380oriented Perl. 381 382=head1 COPYRIGHT AND LICENSE 383 384Copyright 2002-2006 by Julian Gilbey <jdg@debian.org>, 3852018 by Xavier Guimard <yadd@debian.org> 386 387This program is free software; you can redistribute it and/or modify 388it under the terms of the GNU General Public License as published by 389the Free Software Foundation; either version 2 of the License, or 390(at your option) any later version. 391 392=cut 393