Changeset 1485 in ProjectBuilder for projects/casparbuster/devel/bin/cbusterize


Ignore:
Timestamp:
Apr 23, 2012, 11:04:02 AM (12 years ago)
Author:
Bruno Cornec
Message:
  • Adds a Plugin module to support plugin management
  • cbusterize now works with both -s and -p options
  • One plugin example added (dhcpd)

-cb script started. Not working now

File:
1 edited

Legend:

Unmodified
Added
Removed
  • projects/casparbuster/devel/bin/cbusterize

    r1470 r1485  
    1313   --help   |-h         brief help message
    1414   --man            full documentation
    15    --source |-s <file/dir>  directory or file to copy in the CasparBuster tree
     15   --force   |-f            force copy of files, even if they exist
     16   --source |-s <file/dir>  directory or files to copy in the CasparBuster tree (',' separated if many)
     17   --plugin |-p <plugin name>   plugin defining what to copy in the CasparBuster tree (',' separated if many)
    1618   --machine|-m <machine>   machine to consider in the subtree
    1719
     
    4143=item B<--source> I<path>
    4244
    43 Specify the path to the source file or directory to manage with CasparBuster.
     45Specify the path to the source file or directory to manage with CasparBuster. Multiple paths can be specified separated by ','.
     46
     47=item B<--plugin> I<name>
     48
     49Specify the name of the plugin to manage with CasparBuster. Multiple plugins can be specified separated by ','.
     50A plugin defines a set of files (with their mode and owner), a set of directories (with their mode and owner) and a set of scripts to launch once the files are copied remotely.
    4451
    4552=back
     
    102109use CasparBuster::Version;
    103110use CasparBuster::Env;
     111use CasparBuster::Plugin;
    104112#use Cwd 'realpath';
    105113use File::Find;
     
    124132my $plugin = undef;
    125133my $quiet = undef;
     134my $force = undef;
    126135my $log = undef;
    127136my $LOG = undef;
     
    141150    'help|h'      => \$help,
    142151    'quiet|q'     => \$quiet,
     152    'force|f'     => \$force,
    143153    'man'         => \$man,
    144     'log-files|l=s' => \$log,
     154    'logfile|l=s' => \$log,
    145155    'source|s=s'  => \$source,
    146156    'plugin|p=s'  => \$plugin,
     
    176186my %cb;
    177187my $cb = \%cb;
    178 ($cb->{'basedir'},$cb->{'database'},$cb->{'usemachines'},$cb->{'pluginsdir'},$cb->{'cms'}) = pb_conf_get("cbbasedir","cbdatabase","cbusemachines","cbpluginssubdir","cbcms");
     188($cb->{'basedir'},$cb->{'usemachines'},$cb->{'cms'}) = pb_conf_get("cbbasedir","cbusemachines","cbcms");
    179189pb_log(2,"%cb: ",Dumper($cb));
    180190
     
    184194
    185195if (defined $plugin) {
    186     # Load plugin conf
     196    # Load plugins
     197    cb_plugin_load();
    187198}
    188199
     
    190201eval { $basedir =~ s/(\$ENV.+\})/$1/eeg };
    191202
    192 pb_log(1, "DEBUG MODE, not doing anything, just printing\nDEBUG: basedir = $basedir\nDEBUG: source  = $source\n");
    193 pb_log(1, "DEBUG: machine = $machine\n") if (defined ($machine));
     203pb_log(1, "DEBUG MODE, not doing anything, just printing\nDEBUG: basedir = $basedir\n");
     204pb_log(1, "DEBUG: source = $source\n") if (defined $source);
     205pb_log(1, "DEBUG: machine = $machine\n") if (defined $machine);
     206
     207# Use potentially a remote account if defined
     208my $account = undef;
     209my $remote = $machine;
     210($account) = pb_conf_get_if("cbaccount") if (defined $machine);
     211$remote = $account->{$machine}."@".$machine if ((defined $account) && (defined $account->{$machine}));
     212pb_log(1, "DEBUG: remote = $remote\n") if (defined $remote);
    194213
    195214# Create basedir if it doesn't exist
     
    198217        pb_log(1, "DEBUG: Creating recursively directory $basedir\n");
    199218    } else {
    200         pb_mkdir_p($basedir) || die "Unable to recursively create $basedir";
    201     }
    202 }
    203 
     219        pb_mkdir_p($basedir) || die "Unable to recursively create $basedir: $!";
     220    }
     221}
     222
     223if (defined $source) {
     224    foreach my $f (split(/,/,$source)) {   
     225        cb_busterize($f);
     226    }
     227}
     228
     229# Now handle plugins if any
     230my $cbp = ();
     231
     232if (defined $plugin) {
     233    foreach my $p (split(/,/,$plugin)) {   
     234        pb_log(1,"Getting context for plugin $p\n");
     235        $cbp = cb_plugin_get($p,$cbp);
     236        pb_log(2,"cbp: ".Dumper($cbp)."\n");
     237        foreach my $k ((keys %{$cbp->{$plugin}->{'files'}}),(keys %{$cbp->{$plugin}->{'dirs'}})) {
     238            cb_busterize($k);
     239        }
     240    }
     241}
     242
     243sub cb_busterize {
     244
     245my $source = shift;
     246
     247pb_log(2,"Entering cb_busterize source: $source\n");
    204248# Is the source a file or a dir ? Split the source parameter in 2
    205249my $srcdir = undef;
    206250my $srcfile = undef;
    207 # TODO: That should be remote !!
    208 if (-d $source) {
    209     $srcdir = $source;
     251my $cmd = undef;
     252
     253if (not defined $machine) {
     254    if (-d $source) {
     255        $srcdir = $source;
     256    } else {
     257        $srcdir = dirname($source);
     258        $srcfile = basename($source);
     259    }
    210260} else {
    211     $srcdir = dirname($source);
    212     $srcfile = basename($source);
    213     }
     261    $cmd = "ssh -q $remote \'echo \"if [ -d $source ]; then exit 0; else exit -1; fi\" | sudo bash\'";
     262    my $res = pb_system($cmd,"","quiet");
     263    pb_log(2,"DEBUG: Found res = $res\n");
     264    if ($res == 0) {
     265        $srcdir = $source;
     266        pb_log(1,"DEBUG: Found remote dir = $source\n");
     267    } else {
     268        $srcdir = dirname($source);
     269        $srcfile = basename($source);
     270        pb_log(1,"DEBUG: Found remote file = $source\n");
     271    }
     272}
    214273
    215274pb_log(1,"DEBUG: Found srcdir = $srcdir\n");
     
    230289$target = basename($target) if ((not defined $srcfile) && (-d $target));
    231290
    232 # Create target if it doesn't exist
    233 if (not -d $target) {
     291# Create target if it doesn't exist when we have to copy a file
     292if ((not -d $target) && (defined $srcfile)) {
    234293    if ($debug) {
    235294        pb_log(1,"DEBUG: Creating recursively directory $target\n");
    236295    } else {
    237         pb_mkdir_p($target) || die "Unable to recursively create $target";
     296        pb_mkdir_p($target) || die "Unable to recursively create $target: $!";
    238297        pb_vcs_add($scheme,$target);
    239298        pb_log(0,"INFO: Created $target and added it to your $scheme system\n");
     
    242301
    243302# We need to know where to get the content from
    244 my $cmd;
    245303my $cmdopt = "";
    246304
     
    249307
    250308if (defined $machine) {
    251     $cmd = "scp -p -q $cmdopt $machine:$source $target";
     309    $cmd = "scp -p -q $cmdopt $remote:$source $target";
    252310} else {
    253311    $cmd = "cp -p $cmdopt $source $target";
     
    257315if (defined $srcfile) {
    258316    # File case
    259     if (! -f "$target/$srcfile") {
     317    if ((! -f "$target/$srcfile") || (defined $force)){
    260318        if ($debug) {
    261319            pb_log(1,"DEBUG: launching $cmd\n");
     
    270328} else {
    271329    # Directory case
    272     # TODO: if targetlocal dir alredy exists, take the parent
    273330    if ($debug) {
    274331        pb_log(1,"DEBUG: launching $cmd\n");
     
    279336    }
    280337}
     338pb_log(2,"Exiting cb_busterize\n");
     339}
Note: See TracChangeset for help on using the changeset viewer.