Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   CVS access via PERL (http://www.velocityreviews.com/forums/t885996-cvs-access-via-perl.html)

Holger Biebinger 04-19-2004 04:09 PM

CVS access via PERL
 
Hi NG,
I would like to access a CVS Server which provides pserverv access. I
tried to access via
cvs [Directory here] login
After that i get a login prompt. Can I enter my password with PERL? I am
a beginner in using the PERL language.
I would appreciate any help.

Holger


Paul Lalli 04-19-2004 04:58 PM

Re: CVS access via PERL
 
On Mon, 19 Apr 2004, Holger Biebinger wrote:

> Hi NG,
> I would like to access a CVS Server which provides pserverv access. I
> tried to access via
> cvs [Directory here] login
> After that i get a login prompt. Can I enter my password with PERL? I am
> a beginner in using the PERL language.
> I would appreciate any help.
>


The first help you'll get is a bunch of people telling you the language's
name is "Perl" not "PERL". Please follow that advice.

The second piece of advice I'll give is that you may want to check out the
CVS module at http://search.cpan.org/~rsoliv/Cvs-0.06/lib/Cvs.pm

The third piece of advice is that you should read the Posting Guidelines
which are posted regularly to the group. Specifically in this case,
please pay attention to the bit that tells you to "Speak Perl, not
English". That is, what do you mean when you said "I tried to access via
cvs [Directory here] login". Did you execute a system command? Are you
redirecting your Perl script to or from the CVS command? Show us what
you're doing.

Paul Lalli

Holger Biebinger 04-19-2004 05:33 PM

Re: CVS access via PERL
 
Hi,

Paul Lalli wrote:

> On Mon, 19 Apr 2004, Holger Biebinger wrote:
>
>>I would like to access a CVS Server which provides pserverv access. I
>>tried to access via
>>cvs [Directory here] login
>>After that i get a login prompt. Can I enter my password with PERL? I am
>>a beginner in using the PERL language.
>>I would appreciate any help.
>>

>
> The first help you'll get is a bunch of people telling you the language's
> name is "Perl" not "PERL". Please follow that advice.
>

Ok thanks. I will follow that advice.

> The second piece of advice I'll give is that you may want to check out the
> CVS module at http://search.cpan.org/~rsoliv/Cvs-0.06/lib/Cvs.pm
>

I will have a look at it. Thanks for that hint. :-)

> The third piece of advice is that you should read the Posting Guidelines
> which are posted regularly to the group. Specifically in this case,
> please pay attention to the bit that tells you to "Speak Perl, not
> English". That is, what do you mean when you said "I tried to access via
> cvs [Directory here] login". Did you execute a system command? Are you
> redirecting your Perl script to or from the CVS command? Show us what
> you're doing.
>


Ok, let me try to speak Perl. I'm afraid I have quite a bad accent ;-) I
have a config file with the CVS access data and i want to connect to the
cvs server for a checkout:

test.cfg (the config file)
# CVS Variables
CVS_SERVER = 192.168.0.1
CVS_DIR = /usr/cvs
CVS_RSH = pserver

CVS_USERNAME = holger
CVS_PASSWORD = test

# webEdition Revision Variables
PROJECT = testproject
RELEASE = REL_0_1

test.pl
#!/usr/bin/perl -w

# I don't exactly know if I need all those packages
use File::Find;
use File::Path;
use File::Basename;
use File::Copy;
use File::Spec;
use File::DosGlob 'glob'; # TinyPerl only seems to work with DosGlob :-/
use FileHandle;
use Getopt::Std;
use Config;

%config = (
);

$scriptbase = dirname($0);
$configfile = "$scriptbase/testfile.cfg" unless $configfile;
parse_cfg($configfile);

my $cvs ="cvs -d
:$config{'CVS_RSH'}:$config{'CVS_USERNAME'}"."@"." $config{'CVS_SERVER'}:"."$config{'CVS_DIR'}";
my $release = $config{'RELEASE'};
my $project = $config{'PROJECT'};
my $checkoutdir = $config{'CHECKOUTDIR'};

system "$cvs login";
#how can I enter the password?
system "$cvs co $project";

sub parse_cfg {
my $inifile = shift;
my ($var, $val);

open(CONFIG, $configfile) || die ("Error opening $configfile !");
print("Config File opened!\n");
while(<CONFIG>) {
next if /^\s*#/;
next unless /(\w+)\s*=\s*(.+)/;

($var, $val) = ($1, $2);

$config{$var} = $val;
}
close(CONFIG);
}

Thanks again.
Holger


Paul Lalli 04-19-2004 06:04 PM

Re: CVS access via PERL
 
On Mon, 19 Apr 2004, Holger Biebinger wrote:

> Ok, let me try to speak Perl. I'm afraid I have quite a bad accent ;-) I
> have a config file with the CVS access data and i want to connect to the
> cvs server for a checkout:
>
> test.pl
> #!/usr/bin/perl -w
>
> # I don't exactly know if I need all those packages
> use File::Find;
> use File::Path;
> use File::Basename;
> use File::Copy;
> use File::Spec;
> use File::DosGlob 'glob'; # TinyPerl only seems to work with DosGlob :-/
> use FileHandle;
> use Getopt::Std;
> use Config;


The only one I see you using here are File::Basename (for dirname()). I
would recommend getting rid of the rest (and if the interpreter gives you
an error, then you know you should add it back. :-) )

>
> %config = (
> );
>
> $scriptbase = dirname($0);
> $configfile = "$scriptbase/testfile.cfg" unless $configfile;
> parse_cfg($configfile);
>
> my $cvs ="cvs -d
> :$config{'CVS_RSH'}:$config{'CVS_USERNAME'}"."@"." $config{'CVS_SERVER'}:"."$config{'CVS_DIR'}";


Gahh. That looks rather messy. You might want to take advantage of the
hashkey property of barewords, not to mention escaping @ characters:

my $cvs ="cvs -d :$config{CVS_RSH}:$config{CVS_USERNAME}\@$config{C VS_SERVER}:$config{CVS_DIR}";

Well. It's mildly better anyway.

> my $release = $config{'RELEASE'};
> my $project = $config{'PROJECT'};
> my $checkoutdir = $config{'CHECKOUTDIR'};
>
> system "$cvs login";
> #how can I enter the password?
> system "$cvs co $project";
>


Okay. Now I understand. The simple answer is that you can't, at least not
like this. What you're trying to do is called "bidirectional interprocess
communication". That is, both getting input from and sending output to a
process. This is more complicated than you might imagine. For more
details, read:
perldoc -q pipe

That documentation will refer you to the IPC::Open2 module. However,
since you are trying to do something very specific with your bidirectional
pipe - something that many people before you have wanted to do - there
already exists a module specifically for it. I therefore refer you back
to the CVS module from CPAN that I posted in my previous message.


Paul Lalli

> sub parse_cfg {
> my $inifile = shift;
> my ($var, $val);
>
> open(CONFIG, $configfile) || die ("Error opening $configfile !");
> print("Config File opened!\n");
> while(<CONFIG>) {
> next if /^\s*#/;
> next unless /(\w+)\s*=\s*(.+)/;
>
> ($var, $val) = ($1, $2);
>
> $config{$var} = $val;
> }
> close(CONFIG);
> }
>
> Thanks again.
> Holger
>
>


Holger Biebinger 04-20-2004 09:09 AM

Re: CVS access via PERL
 
Hi,

Paul Lalli wrote:

> On Mon, 19 Apr 2004, Holger Biebinger wrote:
>
>
>>Ok, let me try to speak Perl. I'm afraid I have quite a bad accent ;-) I
>>have a config file with the CVS access data and i want to connect to the
>>cvs server for a checkout:
>>
>>test.pl
>>#!/usr/bin/perl -w
>>
>># I don't exactly know if I need all those packages
>>use File::Find;
>>use File::Path;
>>use File::Basename;
>>use File::Copy;
>>use File::Spec;
>>use File::DosGlob 'glob'; # TinyPerl only seems to work with DosGlob :-/
>>use FileHandle;
>>use Getopt::Std;
>>use Config;

>
>
> The only one I see you using here are File::Basename (for dirname()). I
> would recommend getting rid of the rest (and if the interpreter gives you
> an error, then you know you should add it back. :-) )
>
>

Ok you were right. It was the only one needed.

>>%config = (
>>);
>>
>>$scriptbase = dirname($0);
>>$configfile = "$scriptbase/testfile.cfg" unless $configfile;
>>parse_cfg($configfile);
>>
>>my $cvs ="cvs -d
>>:$config{'CVS_RSH'}:$config{'CVS_USERNAME'}"."@" ."$config{'CVS_SERVER'}:"."$config{'CVS_DIR'}";

>
>
> Gahh. That looks rather messy. You might want to take advantage of the
> hashkey property of barewords, not to mention escaping @ characters:
>
> my $cvs ="cvs -d :$config{CVS_RSH}:$config{CVS_USERNAME}\@$config{C VS_SERVER}:$config{CVS_DIR}";
>
> Well. It's mildly better anyway.
>

Really, its better. Thanks for that hint.

>
>>my $release = $config{'RELEASE'};
>>my $project = $config{'PROJECT'};
>>my $checkoutdir = $config{'CHECKOUTDIR'};
>>
>>system "$cvs login";
>>#how can I enter the password?
>>system "$cvs co $project";
>>

>
>
> Okay. Now I understand. The simple answer is that you can't, at least not
> like this. What you're trying to do is called "bidirectional interprocess
> communication". That is, both getting input from and sending output to a
> process. This is more complicated than you might imagine. For more
> details, read:
> perldoc -q pipe
>

OK. it is not quite easy ;-) It was the humble try of a beginner.

> That documentation will refer you to the IPC::Open2 module. However,
> since you are trying to do something very specific with your bidirectional
> pipe - something that many people before you have wanted to do - there
> already exists a module specifically for it. I therefore refer you back
> to the CVS module from CPAN that I posted in my previous message.
>

I tried it out and it seems to work for my purposes. Great. Next time I
will first have a look if anyone else has already done the work for me
;-) Now I know where to search.

Holger



All times are GMT. The time now is 03:12 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.