python-adfs

changeset 39:47c724665e5e

Added fallback support for getopt. Tidied up the version display and changed the URL for the tool's home page.
author David Boddie <david@boddie.org.uk>
date Tue Apr 15 16:19:44 2003 +0200
parents ff2377de5265
children edbb8aea6b29
files ADF2INF.py
diffstat 1 files changed, 93 insertions(+), 26 deletions(-) [+]
line diff
     1.1 --- a/ADF2INF.py	Tue Apr 15 02:07:36 2003 +0200
     1.2 +++ b/ADF2INF.py	Tue Apr 15 16:19:44 2003 +0200
     1.3 @@ -3,40 +3,34 @@
     1.4      Name        : ADF2INF.py
     1.5      Author      : David Boddie
     1.6      Created     : Wed 18th October 2000
     1.7 -    Updated     : Mon 24th March 2003
     1.8 +    Updated     : Tue 15th April 2003
     1.9      Purpose     : Convert ADFS disc images (ADF) to INF files
    1.10 -    WWW         : http://david.boddie.org.uk/Projects/Emulation/T2Tools
    1.11 +    WWW         : http://david.boddie.org.uk/Projects/Python/ADFSlib
    1.12  """
    1.13  
    1.14  
    1.15  import os, sys
    1.16 -import ADFSlib, cmdsyntax
    1.17 +import ADFSlib
    1.18  
    1.19 +try:
    1.20  
    1.21 -__version__ = "0.31c (Wed 26th March 2003)"
    1.22 +    import cmdsyntax
    1.23 +    use_getopt = 0
    1.24  
    1.25 +except ImportError:
    1.26  
    1.27 -if __name__ == "__main__":
    1.28 -    
    1.29 -    syntax = """
    1.30 -    (
    1.31 -        (-l | --list) [-t | --file-types] <ADF file>
    1.32 -    ) |
    1.33 -    (
    1.34 -        [-d | --create-directory]
    1.35 -        [(-t | --file-types) [(-s separator) | --separator=character]]
    1.36 -        <ADF file> <destination path>
    1.37 -    ) |
    1.38 -    (
    1.39 -        (-v | --verify) <ADF file>
    1.40 -    )
    1.41 -    """
    1.42 -    
    1.43 -    version = __version__
    1.44 -    
    1.45 +    import getopt
    1.46 +    use_getopt = 1
    1.47 +
    1.48 +
    1.49 +__version__ = "0.32c (Tue 15th April 2003)"
    1.50 +
    1.51 +
    1.52 +def read_cmdsyntax_input(argv, syntax):
    1.53 +
    1.54      syntax_obj = cmdsyntax.Syntax(syntax)
    1.55      
    1.56 -    matches, failed = syntax_obj.get_args(sys.argv[1:], return_failed = 1)
    1.57 +    matches, failed = syntax_obj.get_args(argv[1:], return_failed = 1)
    1.58      
    1.59      if len(matches) != 1 and cmdsyntax.use_GUI() != None:
    1.60      
    1.61 @@ -53,11 +47,85 @@
    1.62      
    1.63          match = None
    1.64      
    1.65 +    return match
    1.66 +
    1.67 +
    1.68 +def read_getopt_input(argv):
    1.69 +
    1.70 +    opts, args = getopt.getopt(argv[1:], "ldts:v")
    1.71 +
    1.72 +    match = {}
    1.73 +    
    1.74 +    opt_dict = {"-l": "list", "-d": "directory", "-t": "file-types", "-s": "separator",
    1.75 +                "-v": "verify"}
    1.76 +    arg_list = ["ADF file", "destination path"]
    1.77 +    
    1.78 +    # Read the options specified.
    1.79 +    
    1.80 +    for opt, value in opts:
    1.81 +    
    1.82 +        if opt_dict.has_key(opt):
    1.83 +        
    1.84 +            match[opt_dict[opt]] = value or '1'
    1.85 +        
    1.86 +        else:
    1.87 +        
    1.88 +            return None
    1.89 +    
    1.90 +    # Read the remaining arguments: there should be two of these.
    1.91 +    
    1.92 +    if match.has_key("list") and len(args) != 1:
    1.93 +    
    1.94 +        return None
    1.95 +    
    1.96 +    elif not match.has_key("list") and len(args) != 2:
    1.97 +    
    1.98 +        return None
    1.99 +    
   1.100 +    else:
   1.101 +    
   1.102 +        i = 0
   1.103 +        for arg in args:
   1.104 +        
   1.105 +            match[arg_list[i]] = arg
   1.106 +            i = i + 1
   1.107 +    
   1.108 +    if match == {}: match = None
   1.109 +    
   1.110 +    return match
   1.111 +
   1.112 +
   1.113 +if __name__ == "__main__":
   1.114 +    
   1.115 +    if use_getopt == 0:
   1.116 +    
   1.117 +        syntax = """
   1.118 +        \r(
   1.119 +        \r    (-l | --list) [-t | --file-types] <ADF file>
   1.120 +        \r) |
   1.121 +        \r(
   1.122 +        \r    [-d | --create-directory]
   1.123 +        \r    [(-t | --file-types) [(-s separator) | --separator=character]]
   1.124 +        \r    <ADF file> <destination path>
   1.125 +        \r) |
   1.126 +        \r(
   1.127 +        \r    (-v | --verify) <ADF file>
   1.128 +        \r)
   1.129 +        """
   1.130 +        
   1.131 +        match = read_cmdsyntax_input(sys.argv, syntax)
   1.132 +    
   1.133 +    else:
   1.134 +    
   1.135 +        syntax = "[-l] [-d] [-t] [-s separator] [-v]" + \
   1.136 +                 "<ADF file> <destination path>"
   1.137 +        match = read_getopt_input(sys.argv)
   1.138 +    
   1.139      if match == {} or match is None:
   1.140      
   1.141 -        print "Syntax: ADF2INF.py "+syntax
   1.142 +        print "Syntax: ADF2INF.py " + syntax
   1.143          print
   1.144 -        print 'ADF2INF version '+version
   1.145 +        print 'ADF2INF version ' + __version__
   1.146          print
   1.147          print 'Take the files stored in the directory given and store them as files with'
   1.148          print 'corresponding INF files.'
   1.149 @@ -82,7 +150,6 @@
   1.150      
   1.151      # Determine whether the file is to be listed
   1.152      
   1.153 -    
   1.154      listing = match.has_key("l") or match.has_key("list")
   1.155      use_name = match.has_key("d") or match.has_key("create-directory")
   1.156      filetypes = match.has_key("t") or match.has_key("file-types")