Pasar código de PERL a Python 3
Budget: $10 – $30 USD
Buenas. Tengo un script en perl que necesito transformarlo a Python 3
use Net::Telnet ();
use Data::Dumper;
use strict;
(my $path = $0) =~ s/\/?[^\/]*\z//; # directorio donde reside el script
sub new
{
my ($class, $args) = @_;
my $hdt = "A001";
my $host = "123.456.789";
my $opcuser = "user_123";
my $opcpass = "pass_123";
my $hdtuser = 'csvsys';
my $hdtpass = 'csv_sys';
my $timeout = 30;
my $t = new Net::Telnet (
Timeout => $timeout
, Binmode => 0
, Errmode => 'die' #\&terror
, Prompt => '/>$/' );
my $fninput = "$path/log/input_$opcuser.log";
my $fhinput = $t->input_log($fninput);
$t->open($host);
# Login OPC
$t->waitfor('/login: ?$/i');
$t->print($opcuser);
$t->waitfor('/password: ?$/i');
$t->print($opcpass);
# Login HDT
#$t->waitfor(Match => '/enter user name$/i', Timeout => $timeout*3);
#$t->waitfor('/>$/');
$t->waitfor(Match => '/>$/', Timeout => $timeout*3);
$t->print($hdtuser);
#$t->waitfor('/enter password$/i');
$t->waitfor('/>$/');
$t->print($hdtpass);
# Going to CI mode
$t->waitfor(Match => '/MORE\.\.\./', Timeout => $timeout*3);
$t->print(chr(13)); # enter
$t->waitfor('/>$/');
$t->print('quit all');
$t->waitfor('/>$/');
return bless {
hdt => $hdt
, host => $host
, opcuser => $opcuser
, telnet => $t
, fhinput => $fhinput
, timeout => $timeout
}, $class;
}
sub check
{
my $self = shift;
my $hdt = $self->{hdt};
my $opcuser = $self->{opcuser};
my $t = $self->{telnet};
my $fhinput = $self->{fhinput};
my $timeout = $self->{timeout};
my $vplevels = [];
my $key;
my $value;
# QUERYDMC
#
$t->print('cornerstone;cveqpt;cvprov;cvpath');
$t->waitfor('/>$/');
$t->print("querycp");
my ($pmatch, $match) = $t->waitfor (
Match => '/>$/',
Timeout => $timeout*3
);
my $salida = ($pmatch =~ s/querycp//r);
my @mi_matriz = obtener_matriz_campos($salida);
leer_matriz( @mi_matriz );
return $vplevels;
}
sub DESTROY
{
my $self = shift;
my $t = $self->{telnet};
my $fhinput = $self->{fhinput};
# Logout
$t->print('logout');
$t->waitfor('/press return to exit\.$/i');
$t->print(chr(13)); # enter
close $fhinput;
}
sub terror # telnet error
{
my $msg = shift;
die "telnet error - $msg\n";
}
return 1;
# vi: ts=4 sw=4
Solo personas que hayan trabajado con conexiones telnet Perl y Python 3
Solo mirare propuesta que coloquen al prinicipio "HELLO - 12-10-2021"
Gracias.
use Net::Telnet ();
use Data::Dumper;
use strict;
(my $path = $0) =~ s/\/?[^\/]*\z//; # directorio donde reside el script
sub new
{
my ($class, $args) = @_;
my $hdt = "A001";
my $host = "123.456.789";
my $opcuser = "user_123";
my $opcpass = "pass_123";
my $hdtuser = 'csvsys';
my $hdtpass = 'csv_sys';
my $timeout = 30;
my $t = new Net::Telnet (
Timeout => $timeout
, Binmode => 0
, Errmode => 'die' #\&terror
, Prompt => '/>$/' );
my $fninput = "$path/log/input_$opcuser.log";
my $fhinput = $t->input_log($fninput);
$t->open($host);
# Login OPC
$t->waitfor('/login: ?$/i');
$t->print($opcuser);
$t->waitfor('/password: ?$/i');
$t->print($opcpass);
# Login HDT
#$t->waitfor(Match => '/enter user name$/i', Timeout => $timeout*3);
#$t->waitfor('/>$/');
$t->waitfor(Match => '/>$/', Timeout => $timeout*3);
$t->print($hdtuser);
#$t->waitfor('/enter password$/i');
$t->waitfor('/>$/');
$t->print($hdtpass);
# Going to CI mode
$t->waitfor(Match => '/MORE\.\.\./', Timeout => $timeout*3);
$t->print(chr(13)); # enter
$t->waitfor('/>$/');
$t->print('quit all');
$t->waitfor('/>$/');
return bless {
hdt => $hdt
, host => $host
, opcuser => $opcuser
, telnet => $t
, fhinput => $fhinput
, timeout => $timeout
}, $class;
}
sub check
{
my $self = shift;
my $hdt = $self->{hdt};
my $opcuser = $self->{opcuser};
my $t = $self->{telnet};
my $fhinput = $self->{fhinput};
my $timeout = $self->{timeout};
my $vplevels = [];
my $key;
my $value;
# QUERYDMC
#
$t->print('cornerstone;cveqpt;cvprov;cvpath');
$t->waitfor('/>$/');
$t->print("querycp");
my ($pmatch, $match) = $t->waitfor (
Match => '/>$/',
Timeout => $timeout*3
);
my $salida = ($pmatch =~ s/querycp//r);
my @mi_matriz = obtener_matriz_campos($salida);
leer_matriz( @mi_matriz );
return $vplevels;
}
sub DESTROY
{
my $self = shift;
my $t = $self->{telnet};
my $fhinput = $self->{fhinput};
# Logout
$t->print('logout');
$t->waitfor('/press return to exit\.$/i');
$t->print(chr(13)); # enter
close $fhinput;
}
sub terror # telnet error
{
my $msg = shift;
die "telnet error - $msg\n";
}
return 1;
# vi: ts=4 sw=4
Solo personas que hayan trabajado con conexiones telnet Perl y Python 3
Solo mirare propuesta que coloquen al prinicipio "HELLO - 12-10-2021"
Gracias.