Changeset 201

Show
Ignore:
Timestamp:
05/23/05 13:30:25 (4 years ago)
Author:
ged
Message:

- Cleaned up command-line error-handling

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/simplest-thing/tools/convertWikiPage.rb

    r200 r201  
    11#!/usr/bin/ruby 
     2# 
     3#  A quick hack of a program to convert TWiki-ish formatted pages from the 
     4#  docs.FaerieMUD.org site into Trac-style pages. 
     5# 
     6#   $Id$ 
     7# 
     8# = Usage 
     9# 
     10#   convertWikiPage.rb [OPTIONS] <Project> <PageFile> [<PageFile>+] 
     11# 
     12# Run with '--help' for a list of options. 
     13# 
    214 
    315require 'optparse' 
    416require 'tempfile' 
    5  
    6 # 
    7 #  A quick hack of a program to convert TWiki-ish formatted pages from the 
    8 #  docs.FaerieMUD.org site into Trac-style pages. 
    9 # 
    1017require 'pathname' 
    1118require 'diff/lcs' 
    1219require 'pp' 
     20 
    1321 
    1422TracAdmin = '/usr/local/bin/trac-admin' 
     
    6371    project = args.shift or raise "No project specified" 
    6472 
     73    project = File::join( ProjectRoot, project ) unless 
     74        File::directory?( project ) 
     75    projectPath = Pathname::new( project ) 
     76    raise "No such project '%s'" % [projectPath] unless 
     77        projectPath.exist? 
     78    debugMsg "Targetting project at %s" % [projectPath] 
     79 
     80    raise "No pages to convert" if args.empty? 
     81    debugMsg "%d pages to convert" % [args.nitems] 
     82 
    6583    args.collect {|arg| Pathname::new(arg) }.each do |path| 
    6684         
     
    87105        $deferr.puts "OK" 
    88106    end 
     107rescue RuntimeError => err 
     108    $deferr.puts "Error: %s" % err.message 
     109    exit!( 1 ) 
    89110end 
    90111 
     
    285306### Invoked trac-admin to import the transformed page +content+ with the 
    286307### specified +pageName+. 
    287 def importWikiPage( project, pageName, content, dryrun ) 
    288     projectPath = File::join( ProjectRoot, project ) 
    289  
     308def importWikiPage( projectPath, pageName, content, dryrun ) 
    290309    if dryrun 
    291310        debugMsg "Would have imported new content to %s: %s:" %