Changeset 108 for devel/pb/bin/pb


Ignore:
Timestamp:
Sep 6, 2007, 2:18:18 AM (12 years ago)
Author:
bruno
Message:

Lots of changes to prepare the dev of the VMs support.
No more global variables
Support $ENV{'HOME'} in pbrc for pbrc keyword (allows portability across accounts and share of .pbrc)
Fixes on pb_cms_export for SVN in order to be called externally
pn_env_init retunrs now a lot of params in a list
pb_get_pkg needs params and is simplified by consequence
pbinit is called with a simple system. pb_system has isues with cascading stdout/stderr redirections
pb_send2ssh now supports sending to VM + launch of a pbscript if it exists and it should bring back packages from VM in the future and it now supports more parameters.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/pb/bin/pb

    r107 r108  
    2121
    2222# Global variables
    23 use vars qw (%defpkgdir %extpkgdir %filteredfiles %pbrc $debug $LOG);
    24 
    2523use lib qw (lib);
    2624use ProjectBuilder::Distribution qw (pb_distro_init);
     
    4139my @date=(localtime->sec(), localtime->min(), localtime->hour(), localtime->mday(), localtime->mon(), localtime->year(), localtime->wday(), localtime->yday(), localtime->isdst());
    4240my $pbdate = strftime("%Y-%m-%d", @date);
     41my $debug = 0;
     42my $LOG = \*STDOUT;
    4343
    4444getopts('hl:m:p:qr:tv',\%opts);
     
    6767}
    6868
     69# Handle root of the project if defined
     70if (defined $opts{'r'}) {
     71    $ENV{'PBROOT'} = $opts{'r'};
     72}
     73# Handle virtual machines if any
     74if (defined $opts{'m'}) {
     75    $ENV{'PBVM'} = $opts{'m'};
     76}
     77
    6978# Get Action
    7079$action = shift @ARGV;
    7180die pb_syntax() if (not defined $action);
    7281
    73 # Handle root of the project if defined
    74 if (defined $opts{'r'}) {
    75     $ENV{'PBROOT'} = $opts{'r'};
    76 }
    77 # Handle virtual machines if any
    78 if (defined $opts{'m'}) {
    79     $ENV{'PBVM'} = $opts{'m'};
    80 }
     82my ($pbrc, $filteredfiles, $defpkgdir, $extpkgdir);
     83
    8184# Handles project name if any
     85# And get global params
    8286if (defined $opts{'p'}) {
    8387    ($ENV{'PBPROJ'},$debug,$LOG, $pbrc, $filteredfiles, $defpkgdir, $extpkgdir)
     
    8791    = pb_env_init();
    8892}
    89 
    90 print $LOG "Project $ENV{'PBPROJ'}\n" if ($debug >= 0);
     93my %pbrc = %$pbrc;
     94my %filteredfiles = %$filteredfiles;
     95my %defpkgdir = %$defpkgdir;
     96my %extpkgdir = %$extpkgdir;
     97
     98print $LOG "Project: $ENV{'PBPROJ'}\n" if ($debug >= 0);
    9199print $LOG "Action: $action\n" if ($debug >= 0);
    92100
     
    125133sub pb_cms2build {
    126134
    127     my $ptr = pb_get_pkg();
     135    my $ptr = pb_get_pkg(\%defpkgdir,\%extpkgdir);
    128136    @pkgs = @$ptr;
    129137    my $cms=pb_cms_init($ENV{'PBPROJ'},$pbdate);
     
    224232            if (defined $ptr) {
    225233                foreach my $f (values %bfiles) {
    226                     pb_filter_file_pb("$ENV{'PBROOT'}/$f",$ptr,"$dest/pbconf/$ddir-$dver/".basename($f),$dtype,$pbsuf,$pbpkg,$pbver,$pbtag,$pbrev,$pbdate);
     234                    pb_filter_file_pb("$ENV{'PBROOT'}/$f",$ptr,"$dest/pbconf/$ddir-$dver/".basename($f),$dtype,$pbsuf,$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,\%defpkgdir,\%extpkgdir);
    227235                }
    228236                if (defined $filteredfiles{$pbpkg}) {
     
    245253        # Prepare the dest directory for archive
    246254        if (-x "$ENV{'PBCONF'}/$pbpkg/pbinit") {
    247             pb_system("cd $dest ; $ENV{'PBCONF'}/$pbpkg/pbinit","Executing init script $ENV{'PBCONF'}/$pbpkg/pbinit");
     255            #pb_system("cd $dest ; $ENV{'PBCONF'}/$pbpkg/pbinit","Executing init script $ENV{'PBCONF'}/$pbpkg/pbinit");
     256            print $LOG "Executing init script $ENV{'PBCONF'}/$pbpkg/pbinit\n";
     257            system("cd $dest ; $ENV{'PBCONF'}/$pbpkg/pbinit");
    248258        }
    249259
     
    283293
    284294    # Get list of packages to build
    285     my $ptr = pb_get_pkg();
     295    my $ptr = pb_get_pkg(\%defpkgdir,\%extpkgdir);
    286296    @pkgs = @$ptr;
    287297
     
    343353}
    344354
     355# By default deliver to the the public site hosting the
     356# ftp structure (or whatever) or a VM
    345357sub pb_send2ssh {
    346358
    347359    my $cmt = shift;
     360    my $host = shift || "sshhost";
     361    my $login = shift || "sshlogin";
     362    my $dir = shift || "sshdir";
     363    my $port = shift || "sshport";
    348364
    349365    my @src;
    350366
    351367    # Get list of packages to build
    352     my $ptr = pb_get_pkg();
     368    my $ptr = pb_get_pkg(\%defpkgdir,\%extpkgdir);
    353369    @pkgs = @$ptr;
    354370
     
    370386        if ($cmt eq "Sources") {
    371387            $src="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz";
     388        } elsif ($cmt eq "VMs") {
     389            $src="$ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz $ENV{'PBDESTDIR'}/pbscript $ENV{'PBETC'}";
    372390        } elsif ($cmt eq "Packages") {
    373391            if ($dtype eq "rpm") {
     
    383401                die "Unknown dtype format $dtype";
    384402            }
     403            # Also make a pbscript to generate yum/urpmi/apt bases
     404            # $src = "$src $ENV{'PBDESTDIR'}/pbscript"
    385405        }
    386406        print $LOG "$cmt: $src\n" if ($debug >= 0);
    387407        push @src, $src;
    388408    }
    389     my ($sshhost,$sshlogin,$sshdir) = pb_conf_get("sshhost", "sshlogin", "sshdir");
     409    my ($sshhost,$sshlogin,$sshdir,$sshport) = pb_conf_get($host,$login,$dir,$port);
    390410    my $mac = "$sshlogin->{$ENV{'PBPROJ'}}\@$sshhost->{$ENV{'PBPROJ'}}";
    391     my $dir;
     411    my $tdir;
    392412    if ($cmt eq "Sources") {
    393         $dir = "$sshdir->{$ENV{'PBPROJ'}}/src";
     413        $tdir = "$sshdir->{$ENV{'PBPROJ'}}/src";
     414    } elsif ($cmt eq "VMs") {
     415        $tdir = "$sshdir->{$ENV{'PBPROJ'}}";
    394416    } elsif ($cmt eq "Packages") {
    395         $dir = "$sshdir->{$ENV{'PBPROJ'}}/$ddir/$dver";
     417        $tdir = "$sshdir->{$ENV{'PBPROJ'}}/$ddir/$dver";
    396418    } else {
    397419        return;
    398420    }
    399421    $src = join(' ',@src);
    400     pb_system("ssh -q $mac \"mkdir -p $dir ; cd $dir ; rm -f $src\"","Preparing $dir on $mac");
    401     pb_system("scp -p $src $mac:$dir","$cmt delivery in $dir on $mac");
     422    pb_system("ssh -q $mac \"mkdir -p $tdir ; cd $tdir ; rm -f $src\"","Preparing $tdir on $mac");
     423    pb_system("scp -p -P $sshport $src $mac:$tdir","$cmt delivery in $tdir on $mac");
     424    pb_system("ssh -q $mac \"cd $tdir ; if [-f pbscript]; then chmod 755 ./pbscript ; ./pbscript\"","Executing pbscript on $mac");
     425    if ($cmt eq "VMs") {
     426        pb_system("scp -p -P $sshport $mac:$tdir/.... ...","Package recovery in $tdir from $mac");
     427    }
    402428}
    403429
     
    405431    my ($vm,$all) = pb_get_vm();
    406432
     433    # Prepare the script to be executed on the VM
     434    # in $ENV{'PBDESTDIR'}/pbscript
     435    # Launch the VM
     436    # Gather all required files to send them to the VM
     437    pb_send2ssh("VMs","vmhost","vmlogin","vmdir","vmport");
     438   
    407439    # Send tar files when we do a global generation
    408440    pb_build2ssh() if ($all == 1);
     
    412444
    413445my @pkgs;
     446my $defpkgdir = shift;
     447my $extpkgdir = shift;
     448
     449my %defpkgdir = %$defpkgdir;
     450my %extpkgdir = %$extpkgdir;
    414451
    415452# Get packages list
     
    418455} elsif ($ARGV[0] =~ /^all$/) {
    419456    @pkgs = keys %defpkgdir;
    420     if (defined %extpkgdir) {
    421         my $k = keys %extpkgdir;
    422         if (defined $k) {
    423             push(@pkgs, keys %extpkgdir);
    424         }
    425     }
     457    push(@pkgs, keys %extpkgdir);
    426458} else {
    427459    @pkgs = @ARGV;
     
    443475# Get VM list
    444476if ((not defined $ENV{'PBVM'}) || ($ENV{'PBVM'} =~ /^all$/)) {
    445     my $ptr = pb_conf_get("vmlist");
     477    my ($ptr) = pb_conf_get("vmlist");
    446478    $ENV{'PBVM'} = $ptr->{$ENV{'PBPROJ'}};
    447479    $all = 1;
    448480}
    449481@vm = split(/,/,$ENV{'PBVM'});
    450 print $LOG "VMs: ".join(',',@vm)."\n" if ($debug >= 0);
     482print $LOG "VMs: ".join(',',@vm)."\n";
    451483return(\@vm,$all);
    452484}
Note: See TracChangeset for help on using the changeset viewer.