Perforce Python Script Collection.

rajeshkumar created the topic: Perforce Python Script Collection.

Implement a script that will do following:

1. Read config file. This file will contain following settings:
a. For mail delivery (SMTP)
b. For access to perforce server
2. Get from perforce a list of changes made since last script run time and get all updated files
3. Invoke script that will ‘build’ the changes – it will be located in the working folder of the
script(build.bat/build.sh). Script itself should come from perforce as well during step 2.
4. If running of build script is successful, add/update contents of folder named ‘bin’ in the perforce
repository (it is expected that build script will put there a product of its work)
5. In case of error of invocation, send out an email with the list of changes retrieved in p.2 and all outputs of
build script (both stdout/stderr), in which case contents of ‘bin’ folder should not be updated to perforce

Solution
Script details:
master.py – This file is the main file which should be excuted to get the all desired output as per the task
build.bat – This is a Build file which will be executing during compilation phase in master.py. config.ini: Following key should be modified as the environment specification

Sender
Receivers
Message
Host
p4port
p4user
p4client
p4passwd
Scenario to create fail Build:
Remove comment line from “REM mkdir raj” in build.bat

How to use?
Change the config.ini file appropriately and fire master.py script. If you find any issues, please follow the log error message accordingly.

File is as attached

File Attachment:
File Name: build.bat.txt
File Size:0 KB

File Attachment:
File Name: config.ini.txt
File Size:0 KB

File Attachment:
File Name: Index.txt
File Size:0 KB

File Attachment:
File Name: master.txt
File Size:4 KB
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

Tagged :

Remove Control ^M from files

tpatil created the topic: Remove Control ^M from files

Single file method

perl -pi -e "s/\r//" filename.txt

Multiple File Method

find . -type f -exec perl -pi -e "s/\r//" {} \;

rajeshkumar replied the topic: Re:Remove Control ^M from files
I used to do in shell using following command

> 1,$s/^M//g

Correct me if I am wrong
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

tpatil replied the topic: Re:Remove Control ^M from files

Yes, this is also correct command if you want to remove ^M from single file in VI edit mode.

Tagged :

I need to a perl script

rajeshkumar created the topic: i need to a perl script
Hi ,

There is a file called test.txt what are all the different ways

BEGIN:
test 1
test 2 %%%%%%%%%% TEST TEST TEST
test 3
END:

need to grab all contents in between BEGIN and END:
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

rajeshkumar replied the topic: Re:i need to a perl script

Solution could be …..

#!/usr/bin/perl -w
$file=open(f, "test.txt");
$str="";
while() {$str.=$_;}
close(f);
$str =~ s/BEGIN:(.*)END:/$1/egs;
print $str

Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

venu.madhav48@gmail.com replied the topic: Re:i need to a perl script

Please answer the below questions

1.What standard Perl modules have you made use of, and why did you use them instead of the equivalent built-in functions?

2.Write a statement that checks to make sure there are at least two command line arguments and exits with an error if not.

3.How do you find the number of elements in an array?

4.When an array is defined, PERL automatically numbers each element in the array
beginning with zero

venu.madhav48@gmail.com replied the topic: Re:i need to a perl script
Dear Rajesh,

Can u please help in answering the above questions

rajeshkumar replied the topic: Re:i need to a perl script

Hi Venu,

i will post this solution today evening…
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

venu.madhav48@gmail.com replied the topic: Re:i need to a perl script
Waiting for your post….

Tagged :

The difference between my and local

rajeshkumar created the topic: The difference between my and local

There is a subtle difference.

In the example below, $::a refers to $a in the ‘global’ namespace.
‘local’ temporarily changes the value of the variable, but only within the scope it exists in.
$a = 3.14159;
{
local $a = 3;
print “In block, \$a = $a\n”;
print “In block, \$::a = $::a\n”;
}

print “Outside block, \$a = $a\n”;
print “Outside block, \$::a = $::a\n”;

# This outputs In block,

# This outputs
In block, $a = 3
In block, $::a = 3
Outside block, $a = 3.14159
Outside block, $::a = 3.14159

‘my’ has no effect on the global $a, even inside the block.

$a = 3.14159;
{
my $a = 3;
print “In block, \$a = $a\n”;
print “In block, \$::a = $::a\n”;
}
print “Outside block, \$a = $a\n”;
print “Outside block, \$::a = $::a\n”;

# This outputs
In block, $a = 3
In block, $::a = 3.14159
Outside block, $a = 3.14159
Outside block, $::a = 3.14159

Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

scmuser replied the topic: Re: The difference between my and local

With more explanation…

Both of them are used to declare local variables.
The variables declared with “my” can live only within the block it was defined and cannot get its visibility inherited functions called within that block, but one defined with “local” can live within the block and have its visibility in the functions called within that block.

Tagged :

Question Regarding to Eval Function

scmuser created the topic: question regarding to eval function

I have one question regarding to eval function. I know eval function is use for error checking but I am not able to understand below line.

eval \'exec perl -S $0 ${1+\"$@\"}\' if 0; $0

for script name $@ set if error occur

Tagged :

Create a flat file database using perl

scmuser created the topic: Create a flat file database using perl

How to create a flat file database as shown below

s.no name age city phone
0 hema 22 Calcutta 4312542
1 hema 21 Bangalore 2344345
2 ganesh 25 delhi 2445454
3 kartik 45 pune 4312121
4 santosh 25 Hyderabad 2254231
5 kumar 25 mysore 2344567
6 gita 34 mangalore 6532123
7 gita 32 pune 2213456

Q1.print the details of the person who r from bangalore

Q2.Replace the city name managlore to pune

Q3.prints no of person having name gita and hema

Q4.print how many are of age 25

Tagged :