1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
6 from twisted.python import usage
7 from twisted.application import app
8 from twisted.persisted import sob
11 class ConvertOptions(usage.Options):
12 synopsis = "Usage: tapconvert [options]"
14 ['in', 'i', None, "The filename of the tap to read from"],
15 ['out', 'o', None, "A filename to write the tap to"],
16 ['typein', 'f', 'guess',
17 "The format to use; this can be 'guess', 'python', "
18 "'pickle', 'xml', or 'source'."],
19 ['typeout', 't', 'source',
20 "The output format to use; this can be 'pickle', 'xml', or 'source'."],
24 ['decrypt', 'd', "The specified tap/aos/xml file is encrypted."],
25 ['encrypt', 'e', "Encrypt file before writing"]
28 compData = usage.Completions(
29 optActions={"typein": usage.CompleteList(["guess", "python", "pickle",
31 "typeout": usage.CompleteList(["pickle", "xml", "source"]),
32 "in": usage.CompleteFiles(descr="tap file to read from"),
33 "out": usage.CompleteFiles(descr="tap file to write to"),
37 def postOptions(self):
38 if self['in'] is None:
39 raise usage.UsageError("%s\nYou must specify the input filename."
41 if self["typein"] == "guess":
43 self["typein"] = sob.guessType(self["in"])
45 raise usage.UsageError("Could not guess type for '%s'" %
49 options = ConvertOptions()
51 options.parseOptions(sys.argv[1:])
52 except usage.UsageError, e:
55 app.convertStyle(options["in"], options["typein"],
56 options.opts['decrypt'] or getpass.getpass('Passphrase: '),
57 options["out"], options['typeout'], options["encrypt"])