Changeset 1485 in ProjectBuilder for projects/casparbuster/devel/bin/cbusterize
- Timestamp:
- Apr 23, 2012, 11:04:02 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
projects/casparbuster/devel/bin/cbusterize
r1470 r1485 13 13 --help |-h brief help message 14 14 --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) 16 18 --machine|-m <machine> machine to consider in the subtree 17 19 … … 41 43 =item B<--source> I<path> 42 44 43 Specify the path to the source file or directory to manage with CasparBuster. 45 Specify 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 49 Specify the name of the plugin to manage with CasparBuster. Multiple plugins can be specified separated by ','. 50 A 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. 44 51 45 52 =back … … 102 109 use CasparBuster::Version; 103 110 use CasparBuster::Env; 111 use CasparBuster::Plugin; 104 112 #use Cwd 'realpath'; 105 113 use File::Find; … … 124 132 my $plugin = undef; 125 133 my $quiet = undef; 134 my $force = undef; 126 135 my $log = undef; 127 136 my $LOG = undef; … … 141 150 'help|h' => \$help, 142 151 'quiet|q' => \$quiet, 152 'force|f' => \$force, 143 153 'man' => \$man, 144 'log -files|l=s' => \$log,154 'logfile|l=s' => \$log, 145 155 'source|s=s' => \$source, 146 156 'plugin|p=s' => \$plugin, … … 176 186 my %cb; 177 187 my $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"); 179 189 pb_log(2,"%cb: ",Dumper($cb)); 180 190 … … 184 194 185 195 if (defined $plugin) { 186 # Load plugin conf 196 # Load plugins 197 cb_plugin_load(); 187 198 } 188 199 … … 190 201 eval { $basedir =~ s/(\$ENV.+\})/$1/eeg }; 191 202 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)); 203 pb_log(1, "DEBUG MODE, not doing anything, just printing\nDEBUG: basedir = $basedir\n"); 204 pb_log(1, "DEBUG: source = $source\n") if (defined $source); 205 pb_log(1, "DEBUG: machine = $machine\n") if (defined $machine); 206 207 # Use potentially a remote account if defined 208 my $account = undef; 209 my $remote = $machine; 210 ($account) = pb_conf_get_if("cbaccount") if (defined $machine); 211 $remote = $account->{$machine}."@".$machine if ((defined $account) && (defined $account->{$machine})); 212 pb_log(1, "DEBUG: remote = $remote\n") if (defined $remote); 194 213 195 214 # Create basedir if it doesn't exist … … 198 217 pb_log(1, "DEBUG: Creating recursively directory $basedir\n"); 199 218 } 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 223 if (defined $source) { 224 foreach my $f (split(/,/,$source)) { 225 cb_busterize($f); 226 } 227 } 228 229 # Now handle plugins if any 230 my $cbp = (); 231 232 if (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 243 sub cb_busterize { 244 245 my $source = shift; 246 247 pb_log(2,"Entering cb_busterize source: $source\n"); 204 248 # Is the source a file or a dir ? Split the source parameter in 2 205 249 my $srcdir = undef; 206 250 my $srcfile = undef; 207 # TODO: That should be remote !! 208 if (-d $source) { 209 $srcdir = $source; 251 my $cmd = undef; 252 253 if (not defined $machine) { 254 if (-d $source) { 255 $srcdir = $source; 256 } else { 257 $srcdir = dirname($source); 258 $srcfile = basename($source); 259 } 210 260 } 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 } 214 273 215 274 pb_log(1,"DEBUG: Found srcdir = $srcdir\n"); … … 230 289 $target = basename($target) if ((not defined $srcfile) && (-d $target)); 231 290 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 292 if ((not -d $target) && (defined $srcfile)) { 234 293 if ($debug) { 235 294 pb_log(1,"DEBUG: Creating recursively directory $target\n"); 236 295 } else { 237 pb_mkdir_p($target) || die "Unable to recursively create $target ";296 pb_mkdir_p($target) || die "Unable to recursively create $target: $!"; 238 297 pb_vcs_add($scheme,$target); 239 298 pb_log(0,"INFO: Created $target and added it to your $scheme system\n"); … … 242 301 243 302 # We need to know where to get the content from 244 my $cmd;245 303 my $cmdopt = ""; 246 304 … … 249 307 250 308 if (defined $machine) { 251 $cmd = "scp -p -q $cmdopt $ machine:$source $target";309 $cmd = "scp -p -q $cmdopt $remote:$source $target"; 252 310 } else { 253 311 $cmd = "cp -p $cmdopt $source $target"; … … 257 315 if (defined $srcfile) { 258 316 # File case 259 if ( ! -f "$target/$srcfile"){317 if ((! -f "$target/$srcfile") || (defined $force)){ 260 318 if ($debug) { 261 319 pb_log(1,"DEBUG: launching $cmd\n"); … … 270 328 } else { 271 329 # Directory case 272 # TODO: if targetlocal dir alredy exists, take the parent273 330 if ($debug) { 274 331 pb_log(1,"DEBUG: launching $cmd\n"); … … 279 336 } 280 337 } 338 pb_log(2,"Exiting cb_busterize\n"); 339 }
Note:
See TracChangeset
for help on using the changeset viewer.