Changeset 331 in ProjectBuilder for devel/pb/bin/pb


Ignore:
Timestamp:
Mar 2, 2008, 12:25:28 AM (16 years ago)
Author:
Bruno Cornec
Message:
  • Improvements for CMS support in 0.9.x serie (lots on CVS)
  • Use pod for pb documentation (modules to be done)
  • Use Getopt::Long and support now long options
  • pb_syntax now uses pod2usage
File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/pb/bin/pb

    r329 r331  
    1111
    1212use strict 'vars';
    13 use Getopt::Std;
     13use Getopt::Long qw(:config auto_abbrev no_ignore_case);
     14use Pod::Usage;
    1415use Data::Dumper;
    1516use English;
     
    4041my $pbport;                 # Port to use to connect to the VM
    4142my $newver;                 # New version to create
    42 my $iso;                    # ISO iage for the VM to create
     43my $iso;                    # ISO image for the VM to create
    4344
    4445my @date = pb_get_date();
    4546my $pbdate = strftime("%Y-%m-%d", @date);
    4647
    47 getopts('a:fhi:l:m:P:p:qr:s:tvV:',\%opts);
     48# ---------------------------------------------------------------------------
     49
     50=pod
     51
     52=head1 NAME
     53
     54pb, aka project-builder.org - builds packages for your projects
     55
     56=head1 DESCRIPTION
     57
     58pb helps you build various packages directly from your project sources.
     59Those sources could be handled by a CMS (Configuration Management System)
     60such as Subversion, CVS, ... or being a simple reference to a compressed tar file.
     61It's based on a set of configuration files, a set of provided macros to help
     62you keeping build files as generic as possible. For example, a single .spec
     63file should be required to generate for all rpm based distributions, even
     64if you could also have multiple .spec files if required.
     65
     66=head1 SYNOPSIS
     67
     68pb [-vhq][-r pbroot][-p project][[-s script -a account -P port] -m \"mach-1[,...]\"][-i iso] <action> [<pkg1> ...]
     69
     70pb [--verbose][--help][--man][--quiet][--revision pbroot][--project project][[--script script --account account --port port] --machine \"mach-1[,...]\"][--iso iso] <action> [<pkg1> ...]
     71
     72=head1 OPTIONS
     73
     74=over 4
     75
     76=item B<-v|--verbose>
     77
     78Print a brief help message and exits.
     79
     80=item B<-q|--quiet>
     81
     82Do not print any output.
     83
     84=item B<-h|--help>
     85
     86Print a brief help message and exits.
     87
     88=item B<--man>
     89
     90Prints the manual page and exits.
     91
     92=item B<-m|--machine machine1[,machine2,...]>
     93
     94Name of the Virtual Machines (VM) or Virtual Environments (VE) you want to build on (coma separated).
     95All if none precised (or use the env variable PBV).
     96
     97=item B<-s|--script script>
     98
     99Name of the script you want to execute on the related VMs or VEs.
     100
     101=item B<-i|--iso iso_image>
     102
     103Name of the ISO image of the distribution you want to install on the related VMs.
     104
     105=item B<-a|--account account>
     106
     107Name of the account to use to connect on the related VMs.
     108
     109=item B<-P|--port port_number>
     110
     111Port number to use to connect on the related VMs.\n";
     112
     113=item B<-p|--project project_name>
     114
     115Name of the project you're working on (or use the env variable PBPROJ)
     116
     117=item B<-r|--revision revision>
     118
     119Path Name of the project revision under the CMS (or use the env variable PBROOT)
     120
     121=item B<-V|--version new_version>
     122
     123New version of the project to create based on the current one.
     124
     125=back
     126
     127=head1 ARGUMENTS
     128
     129<action> can be:
     130
     131=over 4
     132
     133=item B<cms2build>
     134
     135Create tar files for the project under your CMS.
     136CMS supported are SVN and CVS
     137parameters are packages to build
     138if not using default list
     139
     140=item B<build2pkg>
     141
     142Create packages for your running distribution
     143
     144=item B<cms2pkg>
     145
     146cms2build + build2pkg
     147
     148=item B<build2ssh>
     149
     150Send the tar files to a SSH host
     151
     152=item B<cms2ssh>
     153
     154cms2build + build2ssh
     155
     156=item B<pkg2ssh>
     157
     158Send the packages built to a SSH host
     159
     160=item B<build2vm>
     161
     162Create packages in VMs, launching them if needed
     163and send those packages to a SSH host once built
     164VM type supported are QEMU
     165
     166=item B<build2ve>
     167
     168Create packages in VEs, creating it if needed
     169and send those packages to a SSH host once built
     170
     171=item B<cms2vm>
     172
     173cms2build + build2vm
     174
     175=item B<cms2ve>
     176
     177cms2build + build2ve
     178
     179=item B<launchvm>
     180
     181Launch one virtual machine
     182
     183=item B<launchve>
     184
     185Launch one virtual environment
     186
     187=item B<script2vm>
     188
     189Launch one virtual machine if needed
     190and executes a script on it
     191
     192=item B<script2ve>
     193
     194Execute a script in a virtual environment
     195
     196=item B<newvm>
     197
     198Create a new virtual machine
     199
     200=item B<newve>
     201
     202Create a new virtual environment
     203
     204=item B<newver>
     205
     206Create a new version of the project derived
     207from the current one
     208
     209=item B<newproj>
     210
     211Create a new project and a template set of
     212configuration files under pbconf
     213
     214=back
     215
     216<pkgs> can be a list of packages, the keyword 'all' or nothing, in which case the default list of packages is taken (corresponding to the defpkgdir list of arguments in the configuration file).
     217
     218=head1 WEB SITES
     219
     220The 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/>.
     221
     222=head1 USER MAILING LIST
     223
     224None exists for the moment.
     225
     226=head1 CONFIGURATION FILES
     227
     228Each pb user may have a configuration in F<$HOME/.pbrc>. The values in this file may overwrite any other configuration file value.
     229
     230Here is an example of such a configuration file:
     231
     232 #
     233 # Define for each project the URL of its pbconf repository
     234 # No default option allowed here as they need to be all different
     235 #
     236 # URL of the pbconf content
     237 # This is the format of a classical URL with the extension of additional schema such as
     238 # svn+ssh, cvs+ssh, ...
     239 #
     240 pbconfurl linuxcoe = cvs+ssh://:ext:bcornec@linuxcoe.cvs.sourceforge.net:/cvsroot/linuxcoe/pbconf
     241
     242 # This is normaly defined in the project's configuration file
     243 # Url of the project
     244 #
     245 pburl linuxcoe = cvs+ssh://:ext:bcornec@linuxcoe.cvs.sourceforge.net:/cvsroot/linuxcoe
     246 
     247 # All these URLs needs to be defined here as the are the entry point
     248 # for how to build packages for the project
     249 #
     250 pbconfurl pb = svn+ssh://svn.project-builder.org/mondo/svn/pb/pbconf
     251 pbconfurl mondorescue = svn+ssh://svn.project-builder.org/mondo/svn/project-builder/mondorescue/pbconf
     252 pbconfurl collectl = svn+ssh://bruno@svn.mondorescue.org/mondo/svn/project-builder/collectl/pbconf
     253 pbconfurl netperf = svn+ssh://svn.mondorescue.org/mondo/svn/project-builder/netperf/pbconf
     254 
     255 # Under that dir will take place everything related to pb
     256 # If you want to use VMs/chroot/..., then use $ENV{'HOME'} to make it portable
     257 # to your VMs/chroot/...
     258 # if not defined then /var/cache
     259 pbdefdir default = $ENV{'HOME'}/project-builder
     260 pbdefdir pb = $ENV{'HOME'}
     261 pbdefdir linuxcoe = $ENV{'HOME'}/LinuxCOE/cvs
     262 pbdefdir mondorescue = $ENV{'HOME'}/mondo/svn
     263 
     264 # pbconfdir points to the directory where the CMS content of the pbconfurl is checked out
     265 # If not defined, pbconfdir is under pbdefdir/pbproj/pbconf
     266 pbconfdir linuxcoe = $ENV{'HOME'}/LinuxCOE/cvs/pbconf
     267 pbconfdir mondorescue = $ENV{'HOME'}/mondo/svn/pbconf
     268 
     269 # pbdir points to the directory where the CMS content of the pburl is checked out
     270 # If not defined, pbdir is under pbdefdir/pbproj
     271 # Only defined if we have access to the dev of the project
     272 pbdir linuxcoe = $ENV{'HOME'}/LinuxCOE/cvs
     273 pbdir mondorescue = $ENV{'HOME'}/mondo/svn
     274 
     275 # -daemonize doesn't work with qemu 0.8.2
     276 vmopt default = -m 384
     277
     278=head1 AUTHORS
     279
     280The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
     281
     282=head1 COPYRIGHT
     283
     284Project-Builder.org is distributed under the GPL v2.0 license
     285described in the file C<COPYING> included with the distribution.
     286
     287=cut
     288
     289# ---------------------------------------------------------------------------
     290
     291# Old syntax
     292#getopts('a:fhi:l:m:P:p:qr:s:vV:',\%opts);
    48293
    49294my ($projectbuilderver,$projectbuilderrev) = pb_version_init();
     295
     296GetOptions("help|?|h" => \$opts{'h'},
     297        "man" => \$opts{'man'},
     298        "verbose|v+" => \$opts{'v'},
     299        "quiet|q" => \$opts{'q'},
     300        "log-files|l=s" => \$opts{'l'},
     301        "force|f" => \$opts{'f'},
     302        "account|a=s" => \$opts{'a'},
     303        "revision|r=s" => \$opts{'r'},
     304        "script|s=s" => \$opts{'s'},
     305        "machines|mock|m=s" => \$opts{'m'},
     306        "port|P=i" => \$opts{'P'},
     307        "project|p=s" => \$opts{'p'},
     308        "iso|i=s" => \$opts{'i'},
     309        "version|V=s" => \$opts{'V'},
     310) || pb_syntax(-1,0);
     311
    50312if (defined $opts{'h'}) {
    51     pb_syntax();
    52     exit(0);
     313    pb_syntax(0,1);
     314}
     315if (defined $opts{'man'}) {
     316    pb_syntax(0,2);
    53317}
    54318if (defined $opts{'v'}) {
    55     $debug = 2;
    56     #$debug = $opts{'v'};
     319    $debug = $opts{'v'};
    57320    pb_log(0,"Debug value: $debug\n");
    58321}
     
    70333pb_log_init($debug, $LOG);
    71334
    72 # Handles test option
    73 if (defined $opts{'t'}) {
    74     $test = "TRUE";
    75     # Works only for SVN
    76     $option = "-r BASE";
    77 }
    78 
    79335# Handle root of the project if defined
    80336if (defined $opts{'r'}) {
     
    103359# Get Action
    104360$action = shift @ARGV;
    105 die pb_syntax() if (not defined $action);
     361die pb_syntax(-1,1) if (not defined $action);
    106362
    107363my ($filteredfiles, $supfiles, $defpkgdir, $extpkgdir);
     
    170426} else {
    171427    pb_log(0,"\'$action\' is not available\n");
    172     pb_syntax();
     428    pb_syntax(-2,1);
    173429}
    174430
     
    177433    my $ptr = pb_get_pkg($defpkgdir,$extpkgdir);
    178434    @pkgs = @$ptr;
    179     my ($scheme,$uri)=pb_cms_init($ENV{'PBPROJ'});
     435    my ($uri) = pb_conf_get("pburl");
     436    my ($scheme, $account, $host, $port, $path) = pb_get_uri($uri->{$ENV{'PBPROJ'}});
    180437
    181438    #
    182439    # Check project cms compliance
    183440    #
    184     pb_cms_compliant("pbdir",'PBDIR',"$ENV{'PBDEFDIR'}/$ENV{'PBPROJ'}",$uri,$pbinit);
     441    pb_cms_compliant("pbdir",'PBDIR',"$ENV{'PBDEFDIR'}/$ENV{'PBPROJ'}",$uri->{$ENV{'PBPROJ'}},$pbinit);
     442
     443    # Some variable initialization depending on CMS type
     444    pb_cms_init($scheme);
    185445
    186446    my ($pkgv, $pkgt) = pb_conf_get_if("pkgver","pkgtag");
     
    225485
    226486        # If it isn't a flat CMS, then we have the choice to export subdir
    227         #$dir = "$uri/$dir" if ($ENV{'PBREVISION'} ne "flat");
    228         pb_cms_export($uri,"$ENV{'PBDIR'}/$pbprojver/$dir",$dest);
     487        pb_cms_export($uri->{$ENV{'PBPROJ'}},"$ENV{'PBDIR'}/$pbprojver/$dir",$dest);
    229488
    230489        # Get project info on authors and log file
     
    9051164    my $res = pb_cms_isdiff($scheme);
    9061165    die "You need to have no differences before creating a new version" if ($res != 0);
    907     my $cmsurl = pb_cms_getinfo($scheme,$ENV{'PBROOT'},"URL:");
     1166    my $cmsurl = pb_cms_get_uri($scheme,$ENV{'PBROOT'});
    9081167    my $newurl = dirname($cmsurl)."/$newver";
    9091168    pb_cms_copy($scheme,$cmsurl,$newurl);
     
    11411400}
    11421401
     1402
    11431403sub pb_syntax {
    11441404
    1145     print "pb (aka project-builder) Version $projectbuilderver-$projectbuilderrev\n";
    1146     print "\n";
    1147     print "Syntax: pb [-vhqt][-r pbroot][-p project][[-s script -a account -P port] -m \"mach-1[,...]\"][-i iso] <action> [<pkg1> ...]\n";
    1148     print "\n";
    1149     print "-h: This help file\n";
    1150     print "-q: Quiet mode\n";
    1151     print "-t: Test mode (not done yet)\n";
    1152     print "-v: Verbose mode\n";
    1153     print "\n";
    1154     print "-m machine: Name of the Virtual Machines (VM) you want\n";
    1155     print "            to build on (coma separated). All if none precised\n";
    1156     print "            (or use the env variable PBV)       \n";
    1157     print "\n";
    1158     print "-s script:  Name of the script you want\n";
    1159     print "            to execute on the related VMs.\n";
    1160     print "\n";
    1161     print "-i iso:     Name of the ISO image of the distribution you want\n";
    1162     print "            to install on the related VMs.\n";
    1163     print "\n";
    1164     print "-a account: Name of the account to use\n";
    1165     print "            to connect on the related VMs.\n";
    1166     print "\n";
    1167     print "-P port:    Port number to use\n";
    1168     print "            to connect on the related VMs.\n";
    1169     print "\n";
    1170     print "-p project: Name of the project you're working on\n";
    1171     print "            (or use the env variable PBPROJ)     \n";
    1172     print "\n";
    1173     print "-r pbroot:  Path Name of project under the CMS \n";
    1174     print "            (or use the env variable PBROOT)   \n";
    1175     print "\n";
    1176     print "-V newver:  New version of the project to create\n";
    1177     print "            from the current one.              \n";
    1178     print "\n";
    1179     print "<action> can be:\n";
    1180     print "\n";
    1181     print "\tcms2build:    Create tar files for the project under your CMS\n";
    1182     print "\t              CMS supported are SVN and CVS\n";
    1183     print "\t              parameters are packages to build\n";
    1184     print "\t              if not using default list\n";
    1185     print "\n";
    1186     print "\tbuild2pkg:    Create packages for your running distribution  \n";
    1187     print "\n";
    1188     print "\tcms2pkg:      cms2build + build2pkg\n";
    1189     print "\n";
    1190     print "\tbuild2ssh:    Send the tar files to a SSH host               \n";
    1191     print "\n";
    1192     print "\tcms2ssh:      cms2build + build2ssh\n";
    1193     print "\n";
    1194     print "\tpkg2ssh:      Send the packages built to a SSH host          \n";
    1195     print "\n";
    1196     print "\tbuild2vm:     Create packages in VMs, launching them if needed\n";
    1197     print "\t              and send those packages to a SSH host once built\n";
    1198     print "\t              VM type supported are QEMU            \n";
    1199     print "\n";
    1200     print "\tbuild2ve:     Create packages in VEs, creating it if needed\n";
    1201     print "\t              and send those packages to a SSH host once built\n";
    1202     print "\n";
    1203     print "\tcms2vm:       cms2build + build2vm\n";
    1204     print "\n";
    1205     print "\tcms2ve:       cms2build + build2ve\n";
    1206     print "\n";
    1207     print "\tlaunchvm:     Launch one virtual machine\n";
    1208     print "\n";
    1209     print "\tlaunchve:     Launch one virtual environment\n";
    1210     print "\n";
    1211     print "\tscript2vm:    Launch one virtual machine if needed        \n";
    1212     print "\t              and executes a script on it                 \n";
    1213     print "\n";
    1214     print "\tscript2ve:    Execute a script in a virtual environment       \n";
    1215     print "\n";
    1216     print "\tnewvm:        Create a new virtual machine\n";
    1217     print "\n";
    1218     print "\tnewve:        Create a new virtual environment\n";
    1219     print "\n";
    1220     print "\tnewver:       Create a new version of the project derived \n";
    1221     print "\t              from the current one                        \n";
    1222     print "\n";
    1223     print "\tnewproj:      Create a new project and a template set of  \n";
    1224     print "\t              configuration files under pbconf            \n";
    1225     print "\n";
    1226 }
     1405my $exit_status = shift || -1;
     1406my $verbose_level = shift || 0;
     1407
     1408my $filehandle = \*STDERR;
     1409
     1410$filehandle = \*STDOUT if ($exit_status == 0);
     1411
     1412pod2usage( { -message => "pb (aka project-builder.org) Version $projectbuilderver-$projectbuilderrev\n",
     1413             -exitval => $exit_status  ,
     1414             -verbose => $verbose_level,
     1415             -output  => $filehandle } );
     1416}
     1417
     1418
Note: See TracChangeset for help on using the changeset viewer.