Changeset 1123


Ignore:
Timestamp:
08/18/12 17:26:01 (12 years ago)
Author:
nanardon
Message:

Support an encoding parameter for Unix files base

Location:
trunk/LATMOS-Accounts
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Unix.pm

    r1071 r1123  
    88use LATMOS::Accounts::Log; 
    99use Fcntl qw(:flock); 
     10use Encode; 
    1011 
    1112our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0]; 
     
    7677sub _load_unix_file { 
    7778    my ($self, $file, $callback) = @_; 
     79    my $enc = find_encoding($self->config('encoding') || 'iso-8859-14') 
     80        or do { 
     81        $self->log(LA_ERROR, "Cannot find encoding %s", $self->config('encoding') || 'iso-8859-15'); 
     82        return; 
     83    }; 
    7884    open(my $handle, '<', $file) or do { 
    7985        $self->log(LA_ERR, "Cannot open unix file `%s' for reading (%s)", $file, $!); 
     
    8490    while (my $line = <$handle>) { 
    8591        chomp($line); 
     92        $line = encode('utf-8', $line); 
    8693        my @ch = split(':', $line); 
    8794        $callback->(@ch); 
     
    195202sub _save_unix_file { 
    196203    my ($self, $file, @data) = @_; 
     204    my $enc = find_encoding($self->config('encoding') || 'iso-8859-14') 
     205        or do { 
     206        $self->log(LA_ERROR, "Cannot find encoding %s", $self->config('encoding') || 'iso-8859-15'); 
     207        return; 
     208    }; 
    197209    open(my $handle, '>>', $file) or do { 
    198210        la_log(LA_ERR, "Cannot open unix file `%s' for writing (%s)", $file, $!); 
     
    202214    truncate($handle, 0); 
    203215    foreach my $line (@data) { 
    204         print $handle join(':', map { my $f = $_; $f =~ s/:/;/g; $f } map { defined($_) ? $_ : '' } @$line) . "\n"; 
     216        my $string = join(':', map { my $f = $_; $f =~ s/:/;/g; $f } map { defined($_) ? $_ : '' } @$line) . "\n"; 
     217        $string = decode('utf8', $string); 
     218        print $handle $string; 
    205219    } 
    206220    close($handle); 
  • trunk/LATMOS-Accounts/man/man8/latmos-accounts-base-unix.pod

    r1111 r1123  
    6161    group_1:500:x,dd,ee,ff 
    6262 
     63=item encoding 
     64 
     65Specify the encoding of the file. Default is C<iso-8859-15>. 
     66 
    6367=back 
  • trunk/LATMOS-Accounts/man/man8/latmos-accounts-changes.pod

    r1078 r1123  
    11=head1 3.0.1 
    22 
     3    - add support for various encoding for UNIX file 
    34    - add description attribute to aliases and revaliases object 
    45    - add user attributes to nethost to store poeple using the computer if it is 
Note: See TracChangeset for help on using the changeset viewer.