Showing posts with label eclipse. Show all posts
Showing posts with label eclipse. Show all posts

Friday, July 17, 2009

Post builder script for CGI development in Eclipse

Hi,

In CGI development it may be a lot of help to have some sort of a post builder script. The primary aim of this script should be updating the cgi scenario(s) and modules when you build your perl project under Eclipse.

So I have come up with the following post_builder_script.pl:


#!/usr/bin/perl -w

use strict;

# append "/" to the target path if required
my $target_path = $ARGV[0];
if (not( $target_path =~ m/\/$/)) {
$target_path .= "/";
}

# copy cgi script: what, from where, to where
my $file = "uni_search.cgi";
my $copy_base_path = "../";
my $copy_from = $copy_base_path.$file;
my $copy_to = $target_path.$file;

copy($copy_from, $copy_to);

# copy Perl modules
my @modules = ("Module1.pm", "Module2.pm", "Module3.pm");
my $modules_path = "some_path/";
$copy_base_path = "./";
my $target_copy_base_path = $target_path.$modules_path;

foreach my $module(@modules) {
copy($copy_base_path.$module,
$target_copy_base_path.$module);
}

sub copy
{
my $copy_from = shift;
my $copy_to = shift;

my $result;

# chmod'ing
$result = system("echo ".[your_sudo_password_here].
" | sudo -S chmod +w ".$copy_to);
print "Changing write rights: ".$result."\n";

# updates / copies the cgi script to server
$result = system("sudo cp ".$copy_from." ".$copy_to);
if ($result == 0) {
print "Result of copying the ".$copy_from.
" to server's cgi-bin: ".$result."\n\n";
}
}



It is easy to add a builder which will call the script. In Perl perspective go to Project->Properties->Builders. Select "New..." on the right. Choose "Program" in the popup window. Configure the program by choosing what to launch, where and command line arguments:




There you go. After the builder has been successfully configured, edit your code and do full rebuild (select the root node of your project and Project->Build Project), when you want to deploy your cgi script set to your web server.