Changeset 1494 in ProjectBuilder


Ignore:
Timestamp:
Apr 30, 2012, 2:58:47 AM (12 years ago)
Author:
Bruno Cornec
Message:
  • Add support for cbplugindirsandfiles. This param provides support for direstories and all their children, whereas cbplugindirs is restricted to the directory alone. Usefull for named support
  • Add named plugin
  • cbusterize wworks now mostly for named (access to root owned file is still aproblem to solve)
  • cb also supports the new cbplugindirsandfiles param
Location:
projects/casparbuster/devel
Files:
1 added
3 edited

Legend:

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

    r1490 r1494  
    257257        $cbp = cb_plugin_get($p,$cbp);
    258258        # Adds mtime info to the plugin structure
    259         foreach my $type ('files','dirs') {
     259        foreach my $type ('files','dirs','dirsandfiles') {
    260260            foreach my $f (keys %{$cbp->{$p}->{$type}}) {
    261261                my $tdir = $dest;
     
    282282    my $type = 'files';
    283283    if (-d $fullsource) {
    284         $type = 'dirs';
     284        $type = 'dirsandfiles';
    285285    }
    286286    die "ERROR: Only able to handle files or dirs with option --source\n" if ((! -d $fullsource) && (! -f $fullsource));
     
    321321    # Check what in cbp is in the DB and deploy only if necessary
    322322    foreach my $k (keys %{$cbp}) {
    323         foreach my $type ('files','dirs') {
     323        foreach my $type ('files','dirs','dirsandfiles') {
    324324            foreach my $o (keys %{$cbp->{$k}->{$type}}) {
    325325                # Compare with info from DB
     
    353353my $curdate = time();
    354354foreach my $k (keys %{$cbp}) {
    355     foreach my $type ('files','dirs') {
     355    foreach my $type ('files','dirs','dirsandfiles') {
     356        # TODO: for dirs we may remove the files below ?
    356357        foreach my $o ((keys %{$cbp->{$k}->{$type}})) {
    357358            if (not defined $cbp->{$k}->{$type}->{$o}->{'deleted'}) {
     
    426427
    427428foreach my $k (keys %{$cbp}) {
    428     foreach my $type ('files','dirs') {
     429    foreach my $type ('files','dirs','dirsandfiles') {
     430        # TODO: do we act recursively for dirsandfiles at least for uid/gid ?
    429431        foreach my $o ((keys %{$cbp->{$k}->{$type}})) {
    430432            if (not defined $cbp->{$k}->{$type}->{$o}->{'deleted'}) {
     
    441443    if (defined $cbp->{$k}->{'reloadscript'}) {
    442444        if ($debug) {
    443             pb_log(1,"INFO: Executing (on $mac) sudo $cbp->{$k}->{'reloadscript'}\n");
     445            pb_log(1,"INFO: Executing (on $mac) $cbp->{$k}->{'reloadscript'}\n");
    444446        } else {
    445             &$func("sudo $cbp->{$k}->{'reloadscript'}");
     447            &$func("$cbp->{$k}->{'reloadscript'}");
    446448        }
    447449    }
  • projects/casparbuster/devel/bin/cbusterize

    r1487 r1494  
    115115use Pod::Usage;
    116116use Data::Dumper;
     117use Net::SSH2;
    117118use ProjectBuilder::Base;
    118119use ProjectBuilder::Conf;
     
    202203# Use potentially a remote account if defined
    203204my $account = undef;
    204 my $remote = $machine;
     205my $remote = undef;
    205206($account) = pb_conf_get_if("cbaccount") if (defined $machine);
    206 $remote = $account->{$machine}."@".$machine if ((defined $account) && (defined $account->{$machine}));
    207 pb_log(1, "DEBUG: remote = $remote\n") if (defined $remote);
     207$remote = $account->{$machine} if ((defined $account) && (defined $machine) && (defined $account->{$machine}));
     208pb_log(1, "DEBUG: remote account1 = $remote\n") if (defined $remote);
     209$remote = getpwuid($<) if (not defined $remote);
     210pb_log(1, "DEBUG: remote account2 = $remote\n");
    208211
    209212# Create basedir if it doesn't exist
     
    218221if (defined $source) {
    219222    foreach my $f (split(/,/,$source)) {   
    220         cb_busterize($f);
     223        cb_busterize($f,"true");
    221224    }
    222225}
     
    230233        $cbp = cb_plugin_get($p,$cbp);
    231234        pb_log(2,"cbp: ".Dumper($cbp)."\n");
    232         foreach my $k ((keys %{$cbp->{$plugin}->{'files'}}),(keys %{$cbp->{$plugin}->{'dirs'}})) {
    233             cb_busterize($k);
     235        foreach my $k (keys %{$cbp->{$plugin}->{'dirsandfiles'}}) {
     236            cb_busterize($k,"true");
     237        }
     238        foreach my $k ((keys %{$cbp->{$plugin}->{'dirs'}}),(keys %{$cbp->{$plugin}->{'files'}})) {
     239            cb_busterize($k,"false");
    234240        }
    235241    }
     
    239245
    240246my $source = shift;
     247my $recur = shift;
    241248
    242249pb_log(2,"Entering cb_busterize source: $source\n");
     
    245252my $srcfile = undef;
    246253my $cmd = undef;
     254my $ssh2;
     255my $sftp;
    247256
    248257if (not defined $machine) {
     
    254263    }
    255264} else {
    256     $cmd = "ssh -q $remote \'echo \"if [ -d $source ]; then exit 0; else exit -1; fi\" | sudo bash\'";
    257     my $res = pb_system($cmd,"","quiet");
    258     pb_log(2,"DEBUG: Found res = $res\n");
    259     if ($res == 0) {
    260         $srcdir = $source;
    261         pb_log(1,"DEBUG: Found remote dir = $source\n");
    262     } else {
    263         $srcdir = dirname($source);
    264         $srcfile = basename($source);
    265         pb_log(1,"DEBUG: Found remote file = $source\n");
     265    $ssh2 = Net::SSH2->new();
     266    $ssh2->connect($machine);
     267    my $hdir = (getpwnam(getpwuid($<)))[7];
     268    if ($ssh2->auth_publickey($remote,"$hdir/.ssh/id_dsa.pub","$hdir/.ssh/id_dsa")) {
     269        $sftp = $ssh2->sftp;
     270        my %dirs = $sftp->stat("$source/.");
     271        my $res = 0;
     272        $res = -1 if (not defined $dirs{'mode'});
     273        pb_log(2,"DEBUG: Found res = $res\n");
     274        if ($res == 0) {
     275            $srcdir = $source;
     276            pb_log(1,"DEBUG: Found remote dir = $source\n");
     277        } else {
     278            $srcdir = dirname($source);
     279            $srcfile = basename($source);
     280            pb_log(1,"DEBUG: Found remote file = $source\n");
     281        }
    266282    }
    267283}
     
    284300$target = basename($target) if ((not defined $srcfile) && (-d $target));
    285301
    286 # Create target if it doesn't exist when we have to copy a file
    287 if ((not -d $target) && (defined $srcfile)) {
     302# Create target if it doesn't exist
     303if (not -d $target) {
    288304    if ($debug) {
    289305        pb_log(1,"DEBUG: Creating recursively directory $target\n");
    290306    } else {
    291307        pb_mkdir_p($target) || die "Unable to recursively create $target: $!";
    292         pb_vcs_add($scheme,$target);
    293         pb_log(0,"INFO: Created $target and added it to your $scheme system\n");
     308    }
     309    # Add all the dirs in it to VCS (in reverse order)
     310    my $tdir = $target;
     311    my @tab = ();
     312    while ($tdir ne $basedir) {
     313        push(@tab,$tdir);
     314        $tdir = dirname($tdir);
     315        pb_log(3,"tdir is now $tdir\n");
     316    }
     317    if ($debug) {
     318        pb_log(0,"INFO: Added to your $scheme system the dirs: ".join(' ',reverse(@tab))."\n");
     319    } else {
     320        pb_vcs_add($scheme,reverse(@tab));
    294321    }
    295322}
     
    302329
    303330if (defined $machine) {
    304     $cmd = "scp -p -q $cmdopt $remote:$source $target";
     331    $cmd = "scp -p -q $cmdopt $remote\@$machine:\'$source\' $target";
    305332} else {
    306333    $cmd = "cp -p $cmdopt $source $target";
     
    310337if (defined $srcfile) {
    311338    # File case
    312     if ((! -f "$target/$srcfile") || (defined $force)){
     339    if ((! -f "$target/$srcfile") || (defined $force)) {
    313340        if ($debug) {
    314341            pb_log(1,"DEBUG: launching $cmd\n");
     
    324351    # Directory case
    325352    if ($debug) {
    326         pb_log(1,"DEBUG: launching $cmd\n");
    327     } else {
    328         pb_system($cmd);
     353        if ($recur eq "true") {
     354            pb_log(1,"DEBUG: launching $cmd\n");
     355        } else {
     356            pb_log(1,"DEBUG: mkdir -p $target\n");
     357        }
     358    } else {
     359        if ($recur eq "true") {
     360            pb_system($cmd);
     361        }
    329362        pb_vcs_add($scheme,"$target");
    330363        pb_log(0,"INFO: Created $target and added it to your $scheme system\n");
    331364    }
    332365}
     366$ssh2->disconnect() if (defined $machine);
    333367pb_log(2,"Exiting cb_busterize\n");
    334368}
  • projects/casparbuster/devel/lib/CasparBuster/Plugin.pm

    r1490 r1494  
    7878
    7979pb_log(2,"Entering cb_plugin_get for plugin $plugin\n");
    80 my ($flist,$dlist,$slist) = pb_conf_get_if("cbpluginfiles","cbplugindirs","cbpluginreload");
     80my ($flist,$dlist,$dflist,$slist) = pb_conf_get_if("cbpluginfiles","cbplugindirs","cbplugindirsandfiles","cbpluginreload");
    8181if ((defined $flist) && (defined $flist->{$plugin}) && ($flist->{$plugin} !~ /^\s*$/)) {
    8282    foreach my $block (split(/;/,$flist->{$plugin})) {
     
    9393    }
    9494}
     95if ((defined $dflist) && (defined $dflist->{$plugin}) && ($dflist->{$plugin} !~ /^\s*$/)) {
     96    foreach my $block (split(/;/,$dflist->{$plugin})) {
     97        pb_log(3,"block : $block\n");
     98        my ($name,$tmp) = split(/\|/,$block);
     99        ($cbp->{$plugin}->{'dirsandfiles'}->{$name}->{'uid'},$cbp->{$plugin}->{'dirsandfiles'}->{$name}->{'gid'},$cbp->{$plugin}->{'dirsandfiles'}->{$name}->{'mode'}) = split(/\,/,$tmp);
     100    }
     101}
    95102if ((defined $slist) && (defined $slist->{$plugin})) {
    96103    $cbp->{$plugin}->{'reloadscript'} = $slist->{$plugin};
Note: See TracChangeset for help on using the changeset viewer.