remove the separate method contains(), it does not offer enough sugar, just duplicatd...
[rersyncrecent.git] / bin / rrr-news
blob2a44976cb13da7b171d0caf967be016cc66963d5
1 #!/usr/bin/perl -- -*- mode: cperl -*-
3 =head1 NAME
5 rrr-news - list files added to the dataset
7 =head1 SYNOPSIS
9 rrr-news [options]
11 =head1 OPTIONS
13 =over 8
15 =cut
17 my $optpod = <<'=back';
19 =item B<--after=s>
21 List all new files after this point in time. The format of the
22 timestamp is the unix epoch in floating point notation as used by
23 recentfiles in general.
25 =item B<--before=s>
27 List all new files before this point in time. The format of the
28 timestamp is the unix epoch in floating point notation as used by
29 recentfiles in general.
31 =item B<--dry-run!>
33 (TBD) Do not really run the command, ...
35 =item B<--help|h>
37 Prints a brief message and exists.
39 =item B<--local=s>
41 Specifies a local principal file. Nothing is mirrored, the list is
42 constructed from local resources. Cannot be combined with the
43 C<--remote> option.
45 =item B<--localroot=s>
47 Specifies the local root directory. C<--remote> must also be specified
48 and mirroring is happening implicitly. If missing, a temporary
49 directory is created to hold the data before constructing the list
50 (but this is inefficient in case the program is called again later
51 because the temporary directory is not persistent).
53 =item B<--max=i>
55 Limit the list to at max this many items.
57 =item B<--remote=s>
59 Specifies the remote principal file in rsync notation. This implies
60 that the necessary remote files will be mirrored before constructing
61 the list.
63 =item B<--rsync_options|rsync=s@>
65 Multiple options in the form of key=value pairs. E.g.
67 --rsync=compress=1 --rsync=links=1
69 The options are passed to the underlying L<File::Rsync> objects.
71 =item B<--skip-deletes!>
73 Boolean. If true then delete events are skipped.
75 =item B<--verbose|v+>
77 More feedback.
79 =back
81 =head1 DESCRIPTION
83 rersyncrecent is a project to get speedy rsync operation on large
84 trees over multiple hosts. It maintains a collection of files with
85 metadata (so called recentfiles) that represent adjacent overlapping
86 timespans of file change events.
88 rrr-news extracts from the recentfiles the new files added or
89 modified. The remote-principal-file is the rsync-notation for the
90 remote recentfile. The second argument is the path to the local mirror
91 directory. If you omit the second argument, a temporary directory is
92 taken instead.
94 =cut
97 use strict;
98 use warnings;
100 use File::Rsync::Mirror::Recent;
101 use Getopt::Long;
102 use Pod::Usage qw(pod2usage);
104 our %Opt;
105 my @opt = $optpod =~ /B<--(\S+)>/g;
107 GetOptions(\%Opt,
108 @opt,
109 ) or pod2usage(2);
111 if ($Opt{help}) {
112 pod2usage(0);
115 if (@ARGV) {
116 pod2usage(2);
119 if ($Opt{'dry-run'}) {
120 die "FIXME: not yet implemented";
123 my @constr;
124 for my $opt (qw(local remote localroot)) {
125 if (defined $Opt{$opt}) {
126 push @constr, $opt => $Opt{$opt};
129 my $rf = File::Rsync::Mirror::Recent->new
131 @constr,
132 # stupid, need no rsync options when running wiht -local!
133 rsync_options => {
134 compress => 1,
135 links => 1,
136 times => 1,
137 checksum => 1,
140 if ($rf->remote) {
141 unless ($rf->localroot) {
142 require File::Temp;
143 my $ldir = File::Temp::tempdir(
144 "rrr-news-XXXXXX",
145 TMPDIR => 1,
147 $rf->localroot($ldir);
149 } elsif ($rf->local) {
150 } else {
151 die "need either --local option or both of --remote and --localroot";
153 for my $passthrough (
154 "locktimeout",
155 "verbose",
157 if (my $x = $Opt{$passthrough}) {
158 $rf->$passthrough($x);
162 my %rsopt;
163 for my $rsopt (@{$Opt{rsync_options}||[]}) {
164 my($key,$value) = $rsopt =~ /([^=]+)=(.+)/s;
165 $rsopt{$key} = $value;
167 $rf->rsync_options(\%rsopt);
169 my @nopt;
170 for my $opt (qw(after before max skip-deletes)) {
171 if (defined $Opt{$opt}) {
172 push @nopt, $opt => $Opt{$opt}
175 print map { sprintf "%-20s %s\n", scalar localtime($_->{epoch}), substr($_->{path},8) } @{ $rf->news(@nopt) };
177 __END__
180 # Local Variables:
181 # mode: cperl
182 # coding: utf-8
183 # cperl-indent-level: 4
184 # End: