root/trunk/twisted/scripts/tapconvert.py

Revision 13232, 2.0 KB (checked in by teratorn, 5 years ago)

zsh annotations for twisted commands

Line 
1# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
2# See LICENSE for details.
3
4from twisted.python import usage
5from twisted.application import app
6from twisted.persisted import sob
7import sys, getpass
8
9class ConvertOptions(usage.Options):
10    synopsis = "Usage: tapconvert [options]"
11    optParameters = [
12        ['in',      'i', None,     "The filename of the tap to read from"],
13        ['out',     'o', None,     "A filename to write the tap to"],
14        ['typein''f', 'guess',
15         "The  format to use; this can be 'guess', 'python', "
16         "'pickle', 'xml', or 'source'."],
17        ['typeout', 't', 'source',
18         "The output format to use; this can be 'pickle', 'xml', or 'source'."],
19        ]
20
21    optFlags = [
22        ['decrypt', 'd', "The specified tap/aos/xml file is encrypted."],
23        ['encrypt', 'e', "Encrypt file before writing"]
24        ]
25    #zsh_altArgDescr = {"foo":"use this description for foo instead"}
26    #zsh_multiUse = ["foo", "bar"]
27    #zsh_mutuallyExclusive = [("foo", "bar"), ("bar", "baz")]
28    zsh_actions = {"typein":"(guess python pickle xml source)",
29                   "typeout":"(pickle xml source)"}
30    zsh_actionDescr = {"in":"tap file to read from",
31                       "out":"tap file to write to"}
32   
33    def postOptions(self):
34        if self['in'] is None:
35            raise usage.UsageError("%s\nYou must specify the input filename."
36                                   % self)
37        if self["typein"] == "guess":
38            try:
39                self["typein"] = sob.guessType(self["in"])
40            except KeyError:
41                raise usage.UsageError("Could not guess type for '%s'" %
42                                       self["typein"])
43
44def run():
45    options = ConvertOptions()
46    try:
47        options.parseOptions(sys.argv[1:])
48    except usage.UsageError, e:
49        print e
50    else:
51        app.convertStyle(options["in"], options["typein"],
52                     options.opts['decrypt'] or getpass.getpass('Passphrase: '),
53                     options["out"], options['typeout'], options["encrypt"])
Note: See TracBrowser for help on using the browser.