@@ -7,249 +7,85 @@ use File::stat;
77use Time::localtime ;
88use File::Basename;
99use DateTime::Format::Strptime;
10- # use Memoize;
1110
1211with ' BioX::Workflow::Command::Utils::Files::TrackChanges' ;
1312
1413=head3 files
1514
1615Files just for this rule
1716
17+ ##TODO Make this a hash?
1818=cut
1919
20- has ' files' => (
21- traits => [' Hash' ],
22- is => ' rw' ,
23- isa => ' HashRef' ,
24- default => sub { {} },
25- handles => {
26- files_pairs => ' kv' ,
27- clear_files => ' clear' ,
28- },
29- );
20+ # has 'files' => (
21+ # traits => ['Hash'],
22+ # is => 'rw',
23+ # isa => 'HashRef',
24+ # default => sub { {} },
25+ # handles => {
26+ # files_pairs => 'kv',
27+ # clear_files => 'clear',
28+ # },
29+ # );
3030
31-
32- # TODO Update this
33- # No longer seen_modify - since we are not checking for timestamps anymore
34- has ' seen_modify' => (
35- traits => [' Hash' ],
31+ has ' files' => (
32+ traits => [' Array' ],
3633 is => ' rw' ,
37- isa => ' HashRef ' ,
38- default => sub { {} },
34+ isa => ' ArrayRef ' ,
35+ default => sub { [] },
3936 handles => {
40- seen_modify_pairs => ' kv' ,
41- clear_seen_modify => ' clear' ,
37+ has_files => ' count' ,
38+ all_files => ' elements' ,
39+ push_files => ' push' ,
40+ sort_files => ' sort_in_place' ,
41+ uniq_files => ' uniq' ,
4242 },
43+ clearer => ' clear_files' ,
4344);
4445
4546sub walk_FILES {
4647 my $self = shift ;
4748 my $attr = shift ;
4849
49- $self -> seen_modify-> {local } = {};
50-
51- # my $mod_input = $self->pre_FILES( $attr, 'INPUT' );
5250 $self -> pre_FILES( $attr , ' INPUT' );
5351 $self -> add_graph(' INPUT' );
5452 $self -> clear_files;
5553
56- # $self->app_log->info('Between checks...');
57- # my $mod_output = $self->pre_FILES( $attr, 'OUTPUT' );
58- $self -> pre_FILES($attr , ' OUTPUT' );
54+ $self -> pre_FILES( $attr , ' OUTPUT' );
5955 $self -> add_graph(' OUTPUT' );
6056 $self -> clear_files;
61- # $self->local_attr->{_modified} = 1 if $mod_input;
62-
63- # TODO add check for when we have actually modified the output
6457}
6558
6659sub pre_FILES {
6760 my $self = shift ;
6861 my $attr = shift ;
6962 my $cond = shift ;
7063
71- # $self->app_log->info( 'Beginning modification checks for ' . $cond );
72- # REF check?
7364 walk {
7465 wanted => sub { $self -> walk_INPUT(@_ ) }
7566 },
7667 $attr -> $cond ;
77-
78- # Once we get to the input we want to see if we are processing a new file or no
79- # my $modify = $self->iterate_FILES;
80- $self -> iterate_FILES;
81-
82- # return $modify;
68+ $self -> uniq_files;
69+ $self -> sort_files;
8370}
8471
85- sub iterate_FILES {
86- my $self = shift ;
72+ =head3 walk_INPUT
8773
88- # my $modify = 0;
89- for my $pair ( $self -> files_pairs ) {
90- my $file = $pair -> [0];
91- $self -> seen_modify-> {local }-> {$file } = 1;
92- # if ( $self->seen_modify->{all}->{$file} ) {
93- # my $tmodify = $self->seen_modify->{all}->{$file};
94- # $modify = 1 if $tmodify;
95- # $self->update_seen( $file, $modify );
96- # next;
97- # }
98- # elsif ( !-e $file ) {
99- # $self->update_seen( $file, 1 );
100- # $modify = 1;
101- # next;
102- # }
103- #
104- # if ( $self->process_file($file) ) {
105- # $modify = 1;
106- # }
107- }
108-
109- # return $modify;
110- }
111-
112- =head3 process_file
74+ walk the INPUT/OUTPUT and catch all Path::Tiny references
11375
11476=cut
11577
116- # sub process_file {
117- # my $self = shift;
118- # my $file = shift;
119- #
120- # $self->seen_modify->{local}->{$file} = 1;
121- # # my $details = File::Details->new($file);
122- # # my $mtime = ctime( stat($file)->mtime );
123- # #
124- # # if ( exists $self->track_files->{$file}->{mtime} ) {
125- # #
126- # # # Check to see if we have a difference
127- # # my $p_mtime = $self->track_files->{$file}->{mtime};
128- # # if ( compare_mtimes( $p_mtime, $mtime ) ) {
129- # # # $self->flag_for_process( $file, $p_mtime, $mtime );
130- # # $self->update_seen( $file, 1 );
131- # #
132- # # return 1;
133- # # }
134- # # else {
135- # # # This is the only time we should return 0
136- # # $self->update_seen( $file, 0 );
137- # # return 0;
138- # # }
139- # # }
140- # # else {
141- # # $self->update_seen( $file, 1 );
142- # # return 1;
143- # # }
144- # }
145-
146- # This is really more of a sanity check
147- sub flag_for_process {
148- my $self = shift ;
149- my $file = shift ;
150- my $p_mtime = shift ;
151- my $mtime = shift ;
152-
153- my $basename = basename($file );
154-
155- # #TO LOG OR NOT TO LOG
156- # $self->app_log->warn(
157- # 'File ' . $file . ' has been modified since your last analysis.' );
158- # $self->app_log->warn( $basename
159- # . ":\n\tLast Recorded Modification:\t"
160- # . $p_mtime
161- # . "\n\tMost Recent Modification:\t"
162- # . $mtime );
163-
164- # TODO We only want this in run...
165- # TODO Add an override here
166- # if ( !$self->check_select && !$self->use_timestamps ) {
167- # $self->app_log->warn( 'You have selected to skip rule '
168- # . $self->rule_name
169- # . ', but this file has changed since last your last analysis.' );
170- #
171- # }
172- }
173-
17478sub walk_INPUT {
17579 my $self = shift ;
17680 my $ref = shift ;
17781
178- return if ref ($ref );
17982 return unless $ref ;
18083
181- if ( !exists $self -> files-> {$ref } ) {
182- $self -> files-> {$ref } = 1;
183- }
184- }
185-
186- # memoize('compare_mtimes');
187- # sub compare_mtimes {
188- # my $pmtime = shift;
189- # my $mtime = shift;
190- #
191- # my $strp = DateTime::Format::Strptime->new(
192- # pattern => '%a %b %e %T %Y',
193- # time_zone => 'local',
194- # );
195- #
196- # my $dt1 = $strp->parse_datetime($pmtime);
197- # my $dt2 = $strp->parse_datetime($mtime);
198- #
199- # #For reasons unknown there is something off by 1 second either way
200- # #my $cmp = DateTime->compare( $dt1, $dt2 );
201- # my $dur = $dt2->subtract_datetime($dt1);
202- #
203- # # TODO Add this formatting to HPC::Runner
204- # my ( $days, $hours, $minutes, $seconds ) =
205- # $dur->in_units( 'days', 'hours', 'minutes', 'seconds' );
206- #
207- # if ( $days >= 1 || $hours >= 1 || $minutes >= 1 ) {
208- # return 1;
209- # }
210- # elsif ( $seconds >= 2 ) {
211- # return 1;
212- # }
213- # else {
214- # return 0;
215- # }
216- # }
217- #
218- # sub update_seen {
219- # my $self = shift;
220- # my $file = shift;
221- # my $update = shift;
222- #
223- # # $self->seen_modify->{all}->{$file} = $update;
224- # $self->seen_modify->{local}->{$file} = $update;
225- # }
226-
227- sub write_file_log {
228- my $self = shift ;
84+ my $ref_name = ref ($ref );
85+ return unless $ref_name ;
86+ return unless $ref_name eq ' Path::Tiny' ;
22987
230- my $text = " " ;
231- my @files = keys %{ $self -> seen_modify-> {local } };
232- @files = sort @files ;
233-
234- $self -> seen_modify-> {local } = {};
235-
236- if (@files ) {
237- $text = <<EOF ;
238- ; \\
239- biox file_log \\
240- \t --exit_code `echo \$\? ` \\
241- EOF
242- }
243-
244- my $last = pop (@files );
245- foreach my $file (@files ) {
246- $text .= <<EOF ;
247- \t --file $file \\
248- EOF
249- }
250- $text .= " \t --file $last \n\n " if $last ;
251-
252- return $text ;
88+ $self -> push_files( $ref -> absolute );
25389}
25490
255911;
0 commit comments