/[pxelator]/lib/PXElator/log.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/PXElator/log.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 71 by dpavlin, Thu Jul 30 00:08:21 2009 UTC revision 72 by dpavlin, Thu Jul 30 23:57:19 2009 UTC
# Line 14  foreach ( glob("$dir/pxelator.*.log") ) Line 14  foreach ( glob("$dir/pxelator.*.log") )
14          unlink $_;          unlink $_;
15  }  }
16    
17    my $mac_dir = "$dir/mac";
18    mkdir $mac_dir unless -e $mac_dir;
19    
20    use Time::HiRes qw/time/;
21    my $start_t = time();
22    
23    sub mac {
24            my ( $mac, $message ) = @_;
25            print "MAC $mac $message\n";
26            open(my $fh, '>>', "$mac_dir/$mac");
27            print $fh time() - $start_t, "\t$message\n";
28            close($fh);
29    }
30    
31    our $mac_pos;
32    
33    use File::Slurp;
34    
35    sub mac_changes {
36            my $mac = shift;
37    
38            my @changes;
39    
40            foreach my $mac_path ( sort glob("$mac_dir/*") ) {
41    
42                    open(my $fh, '<', $mac_path);
43    
44                    my $pos = $mac_path;
45                    $pos =~ s{/([^/]+$)}{/\.$1\.pos};
46                    my $mac = uc($1);
47                    $mac =~ s{(..)}{$1:}g;
48                    $mac =~ s{:$}{};
49                    seek $fh, read_file($pos), 0 if -e $pos;
50    
51                    while(<$fh>) {
52                            chomp;
53                            push @changes, "$_\t$mac";
54                    }
55    
56                    warn "pos $pos ",tell($fh);
57                    write_file $pos, tell($fh);
58            }
59    
60            return @changes;
61    }
62    
63  1;  1;

Legend:
Removed from v.71  
changed lines
  Added in v.72

  ViewVC Help
Powered by ViewVC 1.1.26