Changeset 963

Show
Ignore:
Timestamp:
08/18/08 04:09:46 (3 months ago)
Author:
breese
Message:

modified export-ts to properly copy static files if they are present. added support for a --static parameter to indicate where static files are stored

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tools/export-ts/export-ts

    r951 r963  
    1818sub usage { 
    1919    return qq{--blog=<blog_id> --name=<TS name> [--version=<TS version>] 
    20         [--id=<TS ID>] [--key=<TS key>]}; 
     20        [--id=<TS ID>] [--key=<TS key>] [--static=<dir>]}; 
    2121} 
    2222 
     
    3434                    the resulting plugin. (optional) 
    3535 
     36        --static    The path to the directory containing your mt-static 
     37                    files for this template set. It must be a relative  
     38                    path from your mt-static folder. 
     39 
    3640        --id        The ID of the resulting template set. (optional) 
    3741 
     
    4246} 
    4347 
    44 my ( $BLOG_ID, $TS_NAME, $TS_ID, $TS_KEY, $TS_VERSION, $VERBOSE, $BASE_DIR ); 
     48my ( $BLOG_ID, $TS_NAME, $TS_ID, $TS_KEY, $TS_VERSION, $VERBOSE, $BASE_DIR, $STATIC ); 
    4549$TS_NAME    = 'My Template Set'; 
    46 $TS_VERSION = '1.0'; 
     50$TS_VERSION = '1.01'; 
    4751 
    4852sub options { 
     
    5054        'blog=i'    => \$BLOG_ID, 
    5155        'name=s'    => \$TS_NAME, 
     56        'static=s'  => \$STATIC, 
    5257        'id=s'      => \$TS_ID, 
    5358        'key=s'     => \$TS_KEY, 
     
    6267use File::Path; 
    6368use MT::Util qw( dirify ); 
     69use MT; 
     70use File::Copy::Recursive qw(dircopy); 
    6471 
    6572sub main { 
     
    7077    $TS_ID  ||= dirify($TS_NAME); 
    7178    $TS_KEY ||= dirify($TS_NAME); 
     79    $STATIC ||= File::Spec->catdir( 'plugins', $TS_KEY ); 
    7280 
    7381    $BASE_DIR = $TS_KEY . "-" . $TS_VERSION; 
    7482    mkpath( File::Spec->catdir( $BASE_DIR, 'plugins', $TS_KEY, 'templates' ) ); 
    75     mkpath( File::Spec->catdir( $BASE_DIR, 'mt-static', 'plugins', $TS_KEY ) ); 
    76  
    77     debug( 'Exporting templaes from blog #' . $BLOG_ID ); 
     83 
     84    my $mt = MT->new() or die MT->errstr; 
     85    my $from = File::Spec->catdir( _static_file_path($mt) , $STATIC ); 
     86    if (-e $from) {  
     87        my $to   = File::Spec->catdir( $BASE_DIR, 'mt-static', $STATIC ); 
     88        debug( 'Copying static files from ' . $from . ' to ' . $to ); 
     89        mkpath( $to ); 
     90        dircopy( $from, $to ); 
     91    } 
     92 
     93    debug( 'Exporting templates from blog #' . $BLOG_ID ); 
    7894    my @tmpls; 
    7995    my $yaml = YAML::Tiny->new; 
     
    184200} 
    185201 
     202sub _static_file_path { 
     203    my ($ctx) = @_; 
     204    my $cfg = $ctx->{cfg}; 
     205    my $path = $cfg->StaticFilePath; 
     206    if (!$path) { 
     207        $path = $ctx->{mt_dir}; 
     208        $path .= '/' unless $path =~ m!/$!; 
     209        $path .= 'mt-static/'; 
     210    } 
     211    $path .= '/' unless $path =~ m!/$!; 
     212    return $path; 
     213} 
     214 
    186215__PACKAGE__->main() unless caller; 
    187216