Changeset 963
- Timestamp:
- 08/18/08 04:09:46 (3 months ago)
- Files:
-
- trunk/tools/export-ts/export-ts (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/tools/export-ts/export-ts
r951 r963 18 18 sub usage { 19 19 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>]}; 21 21 } 22 22 … … 34 34 the resulting plugin. (optional) 35 35 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 36 40 --id The ID of the resulting template set. (optional) 37 41 … … 42 46 } 43 47 44 my ( $BLOG_ID, $TS_NAME, $TS_ID, $TS_KEY, $TS_VERSION, $VERBOSE, $BASE_DIR );48 my ( $BLOG_ID, $TS_NAME, $TS_ID, $TS_KEY, $TS_VERSION, $VERBOSE, $BASE_DIR, $STATIC ); 45 49 $TS_NAME = 'My Template Set'; 46 $TS_VERSION = '1.0 ';50 $TS_VERSION = '1.01'; 47 51 48 52 sub options { … … 50 54 'blog=i' => \$BLOG_ID, 51 55 'name=s' => \$TS_NAME, 56 'static=s' => \$STATIC, 52 57 'id=s' => \$TS_ID, 53 58 'key=s' => \$TS_KEY, … … 62 67 use File::Path; 63 68 use MT::Util qw( dirify ); 69 use MT; 70 use File::Copy::Recursive qw(dircopy); 64 71 65 72 sub main { … … 70 77 $TS_ID ||= dirify($TS_NAME); 71 78 $TS_KEY ||= dirify($TS_NAME); 79 $STATIC ||= File::Spec->catdir( 'plugins', $TS_KEY ); 72 80 73 81 $BASE_DIR = $TS_KEY . "-" . $TS_VERSION; 74 82 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 ); 78 94 my @tmpls; 79 95 my $yaml = YAML::Tiny->new; … … 184 200 } 185 201 202 sub _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 186 215 __PACKAGE__->main() unless caller; 187 216
