TiddlyWiki.org

Changeset 1104

Show
Ignore:
Timestamp:
06/12/06 17:34:57 (2 years ago)
Author:
JeremyRuston
Message:

Added support for destination directory for Ginsu (ticket #22)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Trunk/tools/cooker/cook.rb

    r1086 r1104  
    1111class Optparse 
    1212        def self.parse(args) 
     13                version = "Version: #{$VERSION} (#{$BUILD.gsub('$', '').strip})" 
     14                 
    1315                options = OpenStruct.new 
     16                options.help = "" 
    1417                options.dest = "" 
    1518                options.hashid = false 
    1619                 
    1720                opts = OptionParser.new do |opts| 
    18                         opts.banner = "Cooker Build: " + $BUILD + ", Version: " + $VERSION + "\nUsage: cook.rb recipename [options]" 
     21                        opts.banner = "Cook #{version}\n" 
     22                        opts.banner += "Usage: cook.rb recipename [...] [options]" 
    1923                        opts.separator "" 
    2024                        opts.separator "Specific options:" 
    2125                         
    22                         opts.on("-d", "--dest [DESTINATION]", "Destination directory") do |dest| 
     26                        opts.on("-d", "--dest DESTINATION", "Destination directory") do |dest| 
    2327                                if(!File.exist?(dest)) 
    24                                         STDERR.puts("Error: destination directory: " + dest + " does not exist.") 
     28                                        STDERR.puts("ERROR - Destination directory '#{dest}' does not exist.") 
    2529                                        exit 
    2630                                end 
     
    3236                        end 
    3337                         
    34                         # No argument, shows at tail. This will print an options summary. 
    35                         # Try it and see! 
     38                        options.help = opts 
     39                         
    3640                        opts.on_tail("-h", "--help", "Show this message") do 
    37                                 puts opts 
     41                                puts options.help 
     42                                exit 64 
     43                        end 
     44                         
     45                        opts.on_tail("--version", "Show version") do 
     46                                puts version 
    3847                                exit 64 
    3948                        end 
     
    4655options = Optparse.parse(ARGV) 
    4756 
     57if(ARGV.empty?) 
     58        puts options.help 
     59        exit 
     60end 
     61 
    4862ARGV.each do |file| 
    4963        if(!File.exist?(file)) 
    50                 STDERR.puts("ERROR, File: " + file + " Does not exist.") 
     64                STDERR.puts("ERROR - File '#{file}' does not exist.") 
    5165                exit 
    5266        end 
  • Trunk/tools/cooker/ginsu.rb

    r1086 r1104  
    1111class Optparse 
    1212        def self.parse(args) 
     13                version = "Version: #{$VERSION} (#{$BUILD.gsub('$', '').strip})" 
     14                 
    1315                options = OpenStruct.new 
     16                options.help = "" 
    1417                options.dest = "" 
    1518                 
    1619                opts = OptionParser.new do |opts| 
    17                         opts.banner = "Ginsu Build: " + $BUILD + ", Version: " + $VERSION + "\nUsage: ginsu.rb [tiddlywikiname]" 
     20                        opts.banner = "Ginsu #{version}\n" 
     21                        opts.banner += "Usage: ginsu.rb tiddlywikiname [...] [options]" 
    1822                        opts.separator "" 
    1923                        opts.separator "Specific options:" 
    2024                         
    21                         # No argument, shows at tail. This will print an options summary. 
    22                         # Try it and see! 
     25                        opts.on("-d", "--dest DESTINATION", "Destination directory") do |dest| 
     26                                if(!File.exist?(dest)) 
     27                                        STDERR.puts("ERROR - Destination directory '#{dest}' does not exist.") 
     28                                        exit 
     29                                end 
     30                                options.dest = dest 
     31                        end 
     32                         
     33                        options.help = opts 
     34                         
    2335                        opts.on_tail("-h", "--help", "Show this message") do 
    24                                 puts opts 
     36                                puts options.help 
     37                                exit 64 
     38                        end 
     39                         
     40                        opts.on_tail("--version", "Show version") do 
     41                                puts version 
    2542                                exit 64 
    2643                        end 
     
    3350options = Optparse.parse(ARGV) 
    3451 
     52if(ARGV.empty?) 
     53        puts options.help 
     54        exit 
     55end 
     56 
    3557ARGV.each do |file| 
    3658        if(!File.exist?(file)) 
    37                 STDERR.puts("ERROR: File: " + file + " Does not exist.") 
     59                STDERR.puts("ERROR - File '#{file}' does not exist.") 
    3860                exit 
    3961        end 
     
    4163 
    4264ARGV.each do |file| 
    43         splitter = Splitter.new(file
     65        splitter = Splitter.new(file, options.dest
    4466        splitter.split 
    4567end 
  • Trunk/tools/cooker/splitter.rb

    r1103 r1104  
    44 
    55class Splitter 
    6         def initialize(filename
     6        def initialize(filename, outdir=nil
    77                @filename = filename 
    88                dirset = false 
    99                dirnum = 0; 
     10                dirname = outdir.nil? || outdir.empty? ? @filename : File.join(outdir, File.basename(@filename)) 
    1011                while !dirset do 
    11                         targetdir = @filename + "." + dirnum.to_s 
    12                         if !File.exists?(targetdir) 
    13                                 @dirname = targetdir 
     12                        @dirname = dirname + "." + dirnum.to_s 
     13                        if !File.exists?(@dirname) 
    1414                                Dir.mkdir(@dirname) 
    1515                                dirset = true 
     
    3838                end 
    3939                if(tiddlerCount == 0) 
    40                         puts "#{@filename} does not contain any tiddlers" 
     40                        puts "'#{@filename}' does not contain any tiddlers" 
    4141                else 
    42                         puts "\n#{@filename} processed, #{tiddlerCount.to_s} tiddlers written to #{@dirname}/
     42                        puts "\n'#{@filename}' processed, #{tiddlerCount.to_s} tiddlers written to '#{@dirname}'
    4343                end 
    4444        end