Some time ago I submitted a feature request ( + patch ) for ttree.

> tttee has the capability of copying files. That's nice, but with large
> files (think MP3, AVI, FLV, ...) it's rather disk consuming to
> maintain multiple, identical copies of the big files.
>
> So I've added a 'link' capability. It is similar to 'copy', but links
> instead. Should the link fail, copy is used as fallback.

Attached is the patch updated to version 2.24. It fits smoothly, doesn't
affect any existing code, even contains docmentation ;)

Any chance to get this included in the official version?

-- Johan

*** Template-Toolkit-2.24/bin/ttree~	2011-12-20 08:41:35.000000000 +0100
--- Template-Toolkit-2.24/bin/ttree	2012-02-08 10:00:49.000000000 +0100
***************
*** 71,76 ****
--- 71,77 ----
  my $libdir   = $config->lib;
  my $ignore   = $config->ignore;
  my $copy     = $config->copy;
+ my $link     = $config->link;
  my $accept   = $config->accept;
  my $absolute = $config->absolute;
  my $relative = $config->relative;
***************
*** 78,84 ****
  my $binmode  = $config->binmode;
  my $depends  = $config->depend;
  my $depsfile = $config->depend_file;
! my ($n_proc, $n_unmod, $n_skip, $n_copy, $n_mkdir) = (0) x 5;
  
  my $srcdir   = $config->src
      || die "Source directory not set (-s)\n";
--- 79,85 ----
  my $binmode  = $config->binmode;
  my $depends  = $config->depend;
  my $depsfile = $config->depend_file;
! my ($n_proc, $n_unmod, $n_skip, $n_copy, $n_link, $n_mkdir) = (0) x 6;
  
  my $srcdir   = $config->src
      || die "Source directory not set (-s)\n";
***************
*** 193,198 ****
--- 194,200 ----
            "Include Path: [ @$libdir ]\n",
            "      Ignore: [ @$ignore ]\n",
            "        Copy: [ @$copy ]\n",
+           "        Link: [ @$link ]\n",
            "      Accept: [ @$accept ]\n",
            "      Suffix: [ $sfx ]\n");
      print("      Module: $ttmodule ", $ttmodule->module_version(), "\n")
***************
*** 244,249 ****
--- 246,252 ----
          $dryrun ? red("This was a dry run.  Nothing was actually done\n") : "\n",
          green(sprintf($format, $n_proc,  $n_proc  == 1 ? 'file' : 'files', 'processed')),
          green(sprintf($format, $n_copy,  $n_copy  == 1 ? 'file' : 'files', 'copied')),
+         green(sprintf($format, $n_link,  $n_link  == 1 ? 'file' : 'files', 'linked')),
          green(sprintf($format, $n_mkdir, $n_mkdir == 1 ? 'directory' : 'directories', 'created')),
          yellow(sprintf($format, $n_unmod, $n_unmod == 1 ? 'file' : 'files', 'skipped (not modified)')),
          yellow(sprintf($format, $n_skip,  $n_skip  == 1 ? 'file' : 'files', 'skipped (ignored)'))
***************
*** 353,358 ****
--- 356,362 ----
      my ($old_suffix, $new_suffix);
      my $is_dep = 0;
      my $copy_file = 0;
+     my $link_file = 0;
  
      $absfile ||= $file;
      $filename = basename($file);
***************
*** 371,385 ****
                     
  #    print "proc $file => $dest\n";
      
!     # check against copy list
!     foreach my $copy_pattern (@$copy) {
!         if ($filename =~ /$copy_pattern/) {
!             $copy_file = 1;
!             $check = $copy_pattern;
              last;
          }
      }
  
      # stat the source file unconditionally, so we can preserve
      # mode and ownership
      ( undef, undef, $mode, undef, $uid, $gid, undef, 
--- 375,400 ----
                     
  #    print "proc $file => $dest\n";
      
!     # check against link list
!     foreach my $link_pattern (@$link) {
!         if ($filename =~ /$link_pattern/) {
!             $link_file = $copy_file = 1;
!             $check = $link_pattern;
              last;
          }
      }
  
+     unless ( $copy_file ) {
+ 	# check against copy list
+ 	foreach my $copy_pattern (@$copy) {
+ 	    if ($filename =~ /$copy_pattern/) {
+ 		$copy_file = 1;
+ 		$check = $copy_pattern;
+ 		last;
+ 	    }
+ 	}
+     }
+ 
      # stat the source file unconditionally, so we can preserve
      # mode and ownership
      ( undef, undef, $mode, undef, $uid, $gid, undef, 
***************
*** 405,410 ****
--- 420,444 ----
          }
      }
      
+     # check against link list
+     if ( $link_file ) {
+         unless ($dryrun) {
+ 	    if ( link($absfile, $dest) == 1 ) {
+ 		$copy_file = 0;
+ 	    }
+ 	    else {
+ 		warn red("Could not link ($absfile to $dest) : $!\n");
+ 	    }
+         }
+ 
+ 	unless ( $copy_file ) {
+ 	    $n_link++;
+ 	    printf green("  > %-32s (linked, matches /$check/)\n"), $file
+ 	      if $verbose;
+ 	    return;
+ 	}
+     }
+ 
      # check against copy list
      if ($copy_file) {
          $n_copy++;
***************
*** 579,584 ****
--- 613,619 ----
          'binmode=s',
          'ignore=s@',
          'copy=s@',
+         'link=s@',
          'accept=s@',
          'depend=s%',
          'depend_debug|depdbg',
***************
*** 696,701 ****
--- 731,739 ----
  copy = \\.png\$ 
  copy = \\.gif\$ 
  
+ # ditto for things that should be linked rather than copied / processed.
+ # link = \\.flv\$ 
+ 
  # by default, everything not ignored or copied is accepted; add 'accept'
  # lines if you want to filter further. e.g.
  #
***************
*** 774,779 ****
--- 812,818 ----
  File search specifications (all may appear multiple times):
     --ignore=REGEX           Ignore files matching REGEX
     --copy=REGEX             Copy files matching REGEX
+    --link=REGEX             Link files matching REGEX
     --accept=REGEX           Process only files matching REGEX 
  
  File Dependencies Options:
***************
*** 873,883 ****
      /home/abw/.ttreerc created.  Please edit accordingly and re-run ttree
  
  The purpose of this file is to set any I<global> configuration options
! that you want applied I<every> time F<ttree> is run.  For example, you
! can use the C<ignore> and C<copy> option to provide regular expressions
! that specify which files should be ignored and which should be copied 
! rather than being processed as templates.  You may also want to set 
! flags like C<verbose> and C<recurse> according to your preference.
  
  A minimal F<.ttreerc>:
  
--- 912,923 ----
      /home/abw/.ttreerc created.  Please edit accordingly and re-run ttree
  
  The purpose of this file is to set any I<global> configuration options
! that you want applied I<every> time F<ttree> is run. For example, you
! can use the C<ignore> and C<copy> / C<link> options to provide regular
! expressions that specify which files should be ignored and which
! should be copied or linked rather than being processed as templates.
! You may also want to set flags like C<verbose> and C<recurse>
! according to your preference.
  
  A minimal F<.ttreerc>:
  
***************
*** 1010,1023 ****
  
  =head2 File Options
  
! The C<ignore>, C<copy> and C<accept> options are used to specify Perl
! regexen to filter file names.  Files that match any of the C<ignore>
! options will not be processed.  Remaining files that match any of the
! C<copy> regexen will be copied to the destination directory.  Remaining
! files that then match any of the C<accept> criteria are then processed
! via the Template Toolkit.  If no C<accept> parameter is specified then 
! all files will be accepted for processing if not already copied or
! ignored.
  
      # ignore these files
      ignore = \b(CVS|RCS)\b
--- 1050,1063 ----
  
  =head2 File Options
  
! The C<ignore>, C<copy>, C<link> and C<accept> options are used to
! specify Perl regexen to filter file names. Files that match any of the
! C<ignore> options will not be processed. Remaining files that match
! any of the C<copy> or C<link> regexen will be copied or linked to the
! destination directory. Remaining files that then match any of the
! C<accept> criteria are then processed via the Template Toolkit. If no
! C<accept> parameter is specified then all files will be accepted for
! processing if not already copied or ignored.
  
      # ignore these files
      ignore = \b(CVS|RCS)\b
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to