Changeset 21


Ignore:
Timestamp:
Jul 31, 2007, 11:52:24 AM (12 years ago)
Author:
bruno
Message:

Add syntax, control of traces, debug level ...
Much Nicer output now

Location:
devel/pb
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • devel/pb/bin/pb.pl

    r20 r21  
    2121use POSIX qw(strftime);
    2222
    23 use vars qw (%defpkgdir %extpkgdir %version %confparam %filteredfiles);
     23use vars qw (%defpkgdir %extpkgdir %version %confparam %filteredfiles $debug);
    2424%extpkgdir = ();
    2525%filteredfiles = ();
     26$debug = 0;                 # Debug level
    2627use lib qw (lib);
    2728use common qw (env_init);
     
    4243my $pbdate = strftime("%Y-%m-%d", @date);
    4344
    44 getopts('p:t',\%opts);
    45 
     45getopts('hp:qtv',\%opts);
     46
     47if (defined $opts{'h'}) {
     48    syntax();
     49    exit(0);
     50}
     51if (defined $opts{'v'}) {
     52    $debug++;
     53}
     54if (defined $opts{'q'}) {
     55    $debug=-1;
     56}
    4657# Handles project name if any
    4758if (defined $opts{'p'}) {
     
    5970# Get Action
    6071$action = shift @ARGV;
    61 die "Syntax: pb [-p project] <action> [<params>...]" if (not defined $action);
    62 
    63 print "Project $ENV{'PBPROJ'}\n";
    64 #print "Action: $action - ARGV:".Dumper(\@ARGV);
     72die syntax() if (not defined $action);
     73
     74print "Project $ENV{'PBPROJ'}\n" if ($debug >= 0);
     75print "Action: $action\n" if ($debug >= 0);
    6576
    6677# Act depending on action
    6778if ($action =~ /^cms2build$/) {
    68     print "Action: cms2build\n";
    6979    # Get packages list
    7080    if (not defined $ARGV[0]) {
     
    8191        @pkgs = @ARGV;
    8292    }
    83     print "Packages:\n";
    84     print Dumper(@pkgs);
     93    print "Packages: ".join(',',@pkgs)."\n" if ($debug >= 0);
    8594    cms_init();
    8695
     
    105114        }
    106115        $pbrev = $ENV{'PBREVISION'};
    107         print "Management of $pkg $pbver-$pbtag (rev $pbrev)\n";
     116        print "\n" if ($debug >= 0);
     117        print "Management of $pkg $pbver-$pbtag (rev $pbrev)\n" if ($debug >= 0);
    108118        die "Unable to get env var PBDESTDIR" if (not defined $ENV{'PBDESTDIR'});
    109119        # Clean up dest if necessary. The export will recreate it
     
    114124        # And generate some additional files
    115125        $OUTPUT_AUTOFLUSH=1;
    116         print "$ENV{'PBCMSEXP'} of $pkg...";
     126        print "$ENV{'PBCMSEXP'} of $pkg..." if ($debug >= 0);
    117127        # computes in which dir we have to work
    118128        my $dir = $defpkgdir{$pkg};
     
    120130        system("$ENV{'PBCMSEXP'} $option $ENV{'PBROOT'}/$dir $dest 1>/dev/null");
    121131        if ($? == -1) {
    122             print "failed to execute: $!\n";
     132            print "failed to execute: $!\n" if ($debug >= 0);
    123133        } elsif ($? & 127) {
    124             printf "child died with signal %d, %s coredump\n", ($? & 127),  ($? & 128) ? 'with' : 'without';
    125         } else {
    126             print " Done under $dest\n";
     134            printf "child died with signal %d, %s coredump\n", ($? & 127),  ($? & 128) ? 'with' : 'without' if ($debug >= 0);
     135        } else {
     136            print " OK\n" if ($debug >= 0);
    127137        }
    128138
     
    134144        # Extract cms log history and store it
    135145        system("$ENV{'PBCMSLOG'} $option $ENV{'PBROOT'}/$dir > $dest/$ENV{'PBCMSLOGFILE'}");
    136         print "$ENV{'PBCMSLOG'} of $pkg...";
     146        print "$ENV{'PBCMSLOG'} of $pkg..." if ($debug >= 0);
    137147        if ($? == -1) {
    138             print "failed to execute: $!\n";
     148            print "failed to execute: $!\n" if ($debug >= 0);
    139149        } elsif ($? & 127) {
    140             printf "child died with signal %d, %s coredump\n", ($? & 127),  ($? & 128) ? 'with' : 'without';
    141         } else {
    142             print " OK\n";
    143         }
     150            printf "child died with signal %d, %s coredump\n", ($? & 127),  ($? & 128) ? 'with' : 'without' if ($debug >= 0);
     151        } else {
     152            print " OK\n" if ($debug >= 0);
     153        }
     154        my %build;
    144155        open(D,"$ENV{'PBCONF'}/DISTROS") || die "Unable to find $ENV{'PBCONF'}/DISTROS\n";
    145156        while (<D>) {
     
    147158            my ($dir,$ver) = split(/_/,$d);
    148159            chomp($ver);
    149             print "Generating build files for $dir ($ver)\n";
    150160            my ($ddir, $dver, $dfam, $dtype, $dsuf) = distro_init($dir,$ver);
    151             #print Dumper($ddir, $dver, $dfam, $dtype, $dsuf);
    152             #print "Filtering DDD => $pbdate, TTT => $pbtag, RRR => $pbtag$dsuf, VVV => $pbver\n";
     161            print "DEBUG: distro tuple: ".Dumper($ddir, $dver, $dfam, $dtype, $dsuf)."\n" if ($debug >= 1);
     162            print "DEBUG Filtering PBDATE => $pbdate, PBTAG => $pbtag, PBVER => $pbver\n" if ($debug >= 1);
    153163
    154164            # Filter build files from the less precise up to the most with overloading
     
    157167            # Find all build files first relatively to PBROOT
    158168            my %bfiles;
    159             #print "dir: $ENV{'PBCONF'}/$pkg\n";
     169            print "DEBUG dir: $ENV{'PBCONF'}/$pkg\n" if ($debug >= 1);
     170            $build{"$ddir-$dver"} = "yes";
    160171            if (-d "$ENV{'PBCONF'}/$pkg/$dtype") {
    161172                opendir(BDIR,"$ENV{'PBCONF'}/$pkg/$dtype" || die "Unable to open dir $ENV{'PBCONF'}/$pkg/$dtype: $!");
     
    191202                closedir(BDIR);
    192203            } else {
    193                 print "No Build Files found for $ddir-$dver\n";
     204                $build{"$ddir-$dver"} = "no";
    194205                next;
    195206            }
    196             print "bfiles: ".Dumper(\%bfiles)."\n";
     207            print "DEBUG bfiles: ".Dumper(\%bfiles)."\n" if ($debug >= 1);
    197208
    198209            # Get all filters to apply
     
    222233            my $ptr;
    223234            if (@ffiles) {
    224                 print "ffiles: ".Dumper(\@ffiles)."\n";
     235                print "DEBUG ffiles: ".Dumper(\@ffiles)."\n" if ($debug >= 1);
    225236                $config->file(@ffiles);
    226237                $ptr = $config->get("filter");
    227                 print "f:".Dumper($ptr)."\n";
     238                print "DEBUG f:".Dumper($ptr)."\n" if ($debug >= 1);
    228239            } else {
    229240                $ptr = { };
     
    242253            }
    243254        }
     255        if ($debug >= 0) {
     256            my @found;
     257            my @notfound;
     258            foreach my $b (keys %build) {
     259                push @found,$b if ($build{$b} =~ /yes/);
     260                push @notfound,$b if ($build{$b} =~ /no/);
     261            }
     262            print "Build files generated for ".join(',',@found)."\n";
     263            print "No Build files found for ".join(',',@notfound)."\n";
     264        }
    244265        close(D);
    245266        # Prepare the dest directory for archive
     
    247268            system("cd $dest ; $ENV{'PBCONF'}/$pkg/pbinit");
    248269            if ($? == -1) {
    249                 print "failed to execute: $!\n";
     270                print "failed to execute: $!\n" if ($debug >= 0);
    250271            } elsif ($? & 127) {
    251                 printf "child died with signal %d, %s coredump\n", ($? & 127),  ($? & 128) ? 'with' : 'without';
     272                printf "child died with signal %d, %s coredump\n", ($? & 127),  ($? & 128) ? 'with' : 'without' if ($debug >= 0);
    252273            } else {
    253                 print " $dest\n";
     274                print " $dest\n" if ($debug >= 0);
    254275            }
    255276        }
    256277        # Archive dest dir
    257278        chdir "$dest/..";
    258         print "Creating $pkg tar files (gzip... ";
     279        print "Creating $pkg tar files (gzip... " if ($debug >= 0);
    259280        system("tar cfphz $pkg-$pbver.tar.gz $pkg-$pbver");
    260281        if ($? == -1) {
    261             print "failed to execute: $!\n";
     282            print "failed to execute: $!\n" if ($debug >= 0);
    262283        } elsif ($? & 127) {
    263             printf "child died with signal %d, %s coredump\n", ($? & 127),  ($? & 128) ? 'with' : 'without';
    264         } else {
    265             print " OK)\n";
    266             print "Under $dest/../$pkg-$pbver.tar.gz\n";
     284            printf "child died with signal %d, %s coredump\n", ($? & 127),  ($? & 128) ? 'with' : 'without' if ($debug >= 0);
     285        } else {
     286            print " OK)\n" if ($debug >= 0);
     287            print "Under $dest/../$pkg-$pbver.tar.gz\n" if ($debug >= 0);
    267288        }
    268289    }
    269290} else {
    270291    print "'$action' is not available\n";
    271     print "Available actions are:\n";
    272     print "    cms2build\n";
     292    syntax();
    273293}
    274294
     
    284304my $dsuf=shift;
    285305
    286 print "From $f to $destfile\n";
     306print "DEBUG: From $f to $destfile\n" if ($debug >= 1);
    287307pbmkdir_p(dirname($destfile)) if (! -d dirname($destfile));
    288308open(DEST,"> $destfile") || die "Unable to create $destfile";
     
    292312    foreach my $s (keys %filter) {
    293313        # Process single variables
    294         #print "debug: $filter{$s}\n";
     314        print "DEBUG filter{$s}: $filter{$s}\n" if ($debug > 1);
    295315        my $tmp = $filter{$s};
    296316        next if (not defined $tmp);
     
    312332close(DEST);
    313333}
     334
     335sub syntax {
     336
     337    print "Syntax: pb [-vhqt][-p project] <action> [<params>...]\n";
     338    print "\n";
     339    print "-h : This help file\n";
     340    print "-q : Quiet mode\n";
     341    print "-t : Test mode (not done yet)\n";
     342    print "-v : Verbose mode\n";
     343    print "\n";
     344    print "-p project : Name of the project you're working on\n";
     345    print "             (or use the env variable PBPROJ)     \n";
     346    print "\n";
     347    print "<action> can be:\n";
     348    print "\n";
     349    print "\tcms2build: Create a tar file of the project under your CMS\n";
     350    print "\t           CMS supported are SVN and CVS\n";
     351    print "\n";
     352    print "\tbuild2pkg: Create packages for your running distribution  \n";
     353    print "\n";
     354    print "\n";
     355}
  • devel/pb/lib/changelog.pm

    r20 r21  
    3434my $chglog = "$ENV{'PBROOT'}/$path/ChangeLog";
    3535if (! -f $chglog) {
    36     print "Unable to find the ChangeLog file ($chglog) for $pkg\n";
     36    print "Unable to find the ChangeLog file ($chglog) for $pkg\n" if ($debug >= 0);
    3737    return("\n");
    3838}
  • devel/pb/lib/pb.pm

    r19 r21  
    1414my $conffile = shift;
    1515my $ptr;
     16my $trace;
     17
     18if ($debug >= 0) {
     19    $trace = 1;
     20} else {
     21    $trace = 0;
     22}
    1623
    1724my $config = AppConfig->new({
    1825                            # Auto Create variables mentioned in Conf file
    1926                            CREATE => 1,
    20                             DEBUG => 1,
     27                            DEBUG => $trace,
    2128                            GLOBAL => {
    2229                                # Each conf item is a hash
     
    3441$ptr = $config->get("confparam") || die "Unable to find confparam in $conffile";
    3542%confparam = %$ptr;
    36 print "confparam: ".Dumper($ptr)."\n";
     43print "DEBUG: confparam: ".Dumper($ptr)."\n" if ($debug >= 1);
    3744
    3845# List of pkg to build by default (mandatory)
    3946$ptr = $config->get("defpkgdir") || die "Unable to find defpkgdir in $conffile";
    4047%defpkgdir = %$ptr;
    41 print "defpkgdir: ".Dumper($ptr)."\n";
     48print "DEBUG: defpkgdir: ".Dumper($ptr)."\n" if ($debug >= 1);
    4249
    4350# List of additional pkg to build when all is called (optional)
    4451$ptr = $config->get("extpkgdir");
    45 print "extpkgdir1: ".Dumper($ptr)."\n";
     52print "DEBUG: extpkgdir1: ".Dumper($ptr)."\n" if ($debug >= 1);
    4653if (not defined $ptr) {
    4754    %extpkgdir = ();
     
    4956    %extpkgdir = %$ptr;
    5057}
    51 print "extpkgdir: ".Dumper(\%extpkgdir)."\n";
     58print "DEBUG: extpkgdir: ".Dumper(\%extpkgdir)."\n" if ($debug >= 1);
    5259
    5360# Valid version names (optional)
     
    5865    %version = %$ptr;
    5966}
    60 print "version: ".Dumper(\%version)."\n";
     67print "DEBUG: version: ".Dumper(\%version)."\n" if ($debug >= 1);
    6168
    6269# List of files to filter (optional)
     
    6774    %filteredfiles = %$ptr;
    6875}
    69 print "filteredfiles: ".Dumper(\%filteredfiles)."\n";
     76print "DEBUG: filteredfiles: ".Dumper(\%filteredfiles)."\n" if ($debug >= 1);
    7077
    7178}
Note: See TracChangeset for help on using the changeset viewer.