Changeset 1985 for trunk/LATMOS-Accounts/lib
- Timestamp:
- 04/20/17 18:30:00 (7 years ago)
- Location:
- trunk/LATMOS-Accounts/lib/LATMOS/Accounts
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/OCHelper.pm
r1023 r1985 112 112 } 113 113 114 =head2 $ochelper->Automate($info) 115 116 Try to create object from C<$info> w/o interacting with user. 117 If given infomation does not allow to create object, it failed. 118 119 Return 1 on success. 120 121 =cut 122 123 sub Automate { 124 my ($self, $info) = @_; 125 126 for (my $count = 0; $count < 3; $count++) { 127 my $status; 128 ($status, $info) = $self->step($info); 129 if ($status eq 'CREATED') { 130 return 1; 131 } elsif ($status eq 'ERROR') { 132 return; 133 } 134 } 135 } 136 114 137 1; 115 138 -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Utils.pm
r1984 r1985 9 9 use File::Temp qw(tempfile); 10 10 use Crypt::Cracklib; 11 use Text::CSV; 11 12 12 13 our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0]; … … 21 22 22 23 @ISA = qw(Exporter); 23 @EXPORT = qw(to_ascii exec_command switch_user run_via_sudo buildLogin yesno);24 @EXPORT_OK = qw(to_ascii exec_command switch_user run_via_sudo buildLogin yesno);24 @EXPORT = qw(to_ascii exec_command switch_user run_via_sudo buildLogin loadCSV yesno); 25 @EXPORT_OK = qw(to_ascii exec_command switch_user run_via_sudo buildLogin loadCSV yesno); 25 26 26 27 =head2 to_ascii($text) … … 175 176 } 176 177 178 =head2 loadCSV($fh, $callback, $initcallback) 179 180 Parse CVS files and return an array for each parsed line. 181 182 If defined call C<$callback> for parsed line. 183 184 C<$initcallback>, if defined, is called just after the first line. 185 186 =cut 187 188 sub loadCSV { 189 my ($fh, $cb, $initcb) = @_; 190 191 my $csv = Text::CSV->new({ 192 blank_is_undef => 1, 193 binary => 1, 194 }); 195 196 binmode($fh, ":encoding(UTF-8)"); 197 198 # First line contains attribute 199 my $columns = $csv->getline( $fh ); 200 201 $csv->column_names($columns); 202 203 if ($initcb) { 204 $initcb->($csv); 205 } 206 207 my $all = []; 208 my $linecount = 1; 209 while ( my $row = $csv->getline_hr( $fh ) ) { 210 $linecount++; 211 if ($cb) { 212 if (! $cb->($row, $linecount)) { 213 return; 214 } 215 } 216 push(@{ $all }, $row); 217 } 218 $csv->eof () or do { 219 return; 220 }; 221 222 return $all; 223 } 224 177 225 =head2 check_oid_validity($name) 178 226
Note: See TracChangeset
for help on using the changeset viewer.