Changeset 397 in ProjectBuilder


Ignore:
Timestamp:
Apr 19, 2008, 1:03:02 AM (16 years ago)
Author:
Bruno Cornec
Message:
  • pb_syntax is now shared
  • creation of 2 new shared functions pb_syntax_init and pb_temp_init
Location:
devel/pb
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • devel/pb/bin/pb

    r395 r397  
    1212use strict 'vars';
    1313use Getopt::Long qw(:config auto_abbrev no_ignore_case);
    14 use Pod::Usage;
    1514use Data::Dumper;
    1615use English;
    1716use File::Basename;
    1817use File::Copy;
    19 use File::Path;
    2018use File::stat;
    2119use File::Temp qw(tempdir);
    2220use Date::Manip;
    23 use Time::localtime qw(localtime);
    2421use POSIX qw(strftime);
    25 
    26 
    27 # Global variables
    2822use lib qw (lib);
    2923use ProjectBuilder::Distribution;
     
    3125use ProjectBuilder::Base;
    3226
     27# Global variables
    3328my %opts;                   # CLI Options
    3429my $action;                 # action to realize
     
    304299
    305300my ($projectbuilderver,$projectbuilderrev) = pb_version_init();
     301
     302# Initialize the syntax string
     303
     304pb_syntax_init("pb (aka project-builder.org) Version $projectbuilderver-$projectbuilderrev\n");
    306305
    307306GetOptions("help|?|h" => \$opts{'h'},
     
    16371636}
    16381637
    1639 sub pb_syntax {
    1640 
    1641 my $exit_status = shift || -1;
    1642 my $verbose_level = shift || 0;
    1643 
    1644 my $filehandle = \*STDERR;
    1645 
    1646 $filehandle = \*STDOUT if ($exit_status == 0);
    1647 
    1648 pod2usage( { -message => "pb (aka project-builder.org) Version $projectbuilderver-$projectbuilderrev\n",
    1649              -exitval => $exit_status  ,
    1650              -verbose => $verbose_level,
    1651              -output  => $filehandle } );
    1652 }
    1653 
    16541638sub pb_env_init {
    16551639
     
    17891773
    17901774pb_log(2,"PBBUILDDIR: $ENV{'PBBUILDDIR'}\n");
    1791 #
    1792 # Set temp directory
    1793 #
    1794 if (not defined $ENV{'TMPDIR'}) {
    1795     $ENV{'TMPDIR'}="/tmp";
    1796 }
    1797 $ENV{'PBTMP'} = tempdir( "pb.XXXXXXXXXX", DIR => $ENV{'TMPDIR'}, CLEANUP => 1 );
     1775
     1776pb_temp_init();
    17981777pb_log(2,"PBTMP: $ENV{'PBTMP'}\n");
    17991778
     
    31993178# If we don't need to do it, or don't have it fake something
    32003179if (((not defined $chglog) || (! -f $chglog)) && ($doit ne "yes")) {
    3201     my @date=(localtime->sec(), localtime->min(), localtime->hour(), localtime->mday(), localtime->mon(), localtime->year(), localtime->wday(), localtime->yday(), localtime->isdst());
     3180    my @date = pb_get_date();
    32023181    $date = strftime("%Y-%m-%d", @date);
    32033182    $ndate = UnixDate($date,"%a", "%b", "%d", "%Y");
  • devel/pb/lib/ProjectBuilder/Base.pm

    r396 r397  
    1818use Data::Dumper;
    1919use Time::localtime qw(localtime);
     20use Pod::Usage;
    2021use English;
    2122
     
    2728# any code which uses this module.
    2829 
    29 our $debug = 0;
    30 our $LOG = \*STDOUT;
     30our $debug = 0;         # Global debug level
     31our $LOG = \*STDOUT;    # File descriptor of the log file
     32our $synmsg = "Error";  # Global error message
    3133
    3234our @ISA = qw(Exporter);
     
    341343=cut
    342344
    343 # get content of a file in a variable
    344345sub pb_get_content {
    345346
     
    356357}
    357358
     359=item B<pb_syntax_init>
     360
     361This function initializes the global variable used by the pb_syntax function.
     362
     363The parameter is the message string which will be printed when calling pb_syntax
     364
     365=cut
     366
     367sub pb_syntax_init {
     368
     369$synmsg = shift || "Error";
     370}
     371
     372=item B<pb_syntax>
     373
     374This function prints the syntax expected by the application, based on pod2usage, and exits.
     375The first parameter is the return value of the exit.
     376The second parameter is the verbosity as expected by pod2usage.
     377
     378Cf: man Pod::Usage
     379
     380=cut
     381
     382sub pb_syntax {
     383
     384my $exit_status = shift || -1;
     385my $verbose_level = shift || 0;
     386
     387my $filehandle = \*STDERR;
     388
     389$filehandle = \*STDOUT if ($exit_status == 0);
     390
     391pod2usage( { -message => $synmsg,
     392             -exitval => $exit_status  ,
     393             -verbose => $verbose_level,
     394             -output  => $filehandle } );
     395}
     396
     397=item B<pb_temp_init>
     398
     399This function initializes the environemnt variable PBTMP to a random value. This directory can be safely used during the whole program, it will be removed at the end automatically.
     400
     401=cut
     402
     403sub pb_temp_init {
     404
     405if (not defined $ENV{'TMPDIR'}) {
     406    $ENV{'TMPDIR'}="/tmp";
     407}
     408$ENV{'PBTMP'} = tempdir( "pb.XXXXXXXXXX", DIR => $ENV{'TMPDIR'}, CLEANUP => 1 );
     409}
     410
     411=back
     412
     413=head1 WEB SITES
     414
     415The main Web site of the project is available at L<http://www.project-builder.org/>. Bug reports should be filled using the trac instance of the project at L<http://trac.project-builder.org/>.
     416
     417=head1 USER MAILING LIST
     418
     419None exists for the moment.
     420
     421=head1 AUTHORS
     422
     423The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
     424
     425=head1 COPYRIGHT
     426
     427Project-Builder.org is distributed under the GPL v2.0 license
     428described in the file C<COPYING> included with the distribution.
     429
     430=cut
     431
    3584321;
Note: See TracChangeset for help on using the changeset viewer.