| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
from twisted.python import usage |
|---|
| 5 |
from twisted.application import app |
|---|
| 6 |
from twisted.persisted import sob |
|---|
| 7 |
import sys, getpass |
|---|
| 8 |
|
|---|
| 9 |
class 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 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 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 |
|
|---|
| 44 |
def 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"]) |
|---|