GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: a ruby-to-pyc compiler
Clone URL: git://github.com/why/unholy.git
why (author)
Mon May 05 02:34:41 -0700 2008
commit  ef3799c41bcd58e74b876fa03f1ef28cbd02a8b6
tree    a4d799b1f5a03fa068968e6999475627e24ddc53
parent  77363ecf78ed1b2eaf1d27b6cdb15503366f60f1
unholy / decompyle / scripts / decompyle
100755 98 lines (84 sloc) 3.051 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/python
# Mode: -*- python -*-
#
# Copyright (c) 2000-2002 by hartmut Goebel <hartmut@goebel.noris.de>
#
"""
Usage: decompyle [OPTIONS]... [ FILE | DIR]...
 
Examples:
decompyle foo.pyc bar.pyc # decompyle foo.pyc, bar.pyc to stdout
decompyle -o . foo.pyc bar.pyc # decompyle to ./foo.dis and ./bar.dis
decompyle -o /tmp /usr/lib/python1.5 # decompyle whole library
 
Options:
-o <path> output decompyled files to this path:
if multiple input files are decompyled, the common prefix
is stripped from these names and the remainder appended to
<path>
decompyle -o /tmp bla/fasel.pyc bla/foo.pyc
-> /tmp/fasel.dis, /tmp/foo.dis
decompyle -o /tmp bla/fasel.pyc bar/foo.pyc
-> /tmp/bla/fasel.dis, /tmp/bar/foo.dis
decompyle -o /tmp /usr/lib/python1.5
-> /tmp/smtplib.dis ... /tmp/lib-tk/FixTk.dis
--verify compare generated source with input byte-code
(requires -o)
--help show this message
 
Debugging Options:
--showasm include byte-code (disables --verify)
--showast include AST (abstract syntax tree) (disables --verify)
 
Extensions of generated files:
'.dis' successfully decompyled (and verified if --verify)
'.dis_unverified' successfully decompyled but --verify failed
'.nodis' decompyle failed (contact author for enhancement)
"""
 
Usage_short = \
"decomyple [--help] [--verify] [--showasm] [--showast] [-o <path>] FILE|DIR..."
 
import sys, os, getopt
from decompyle import main, verify
import time
 
showasm = showast = do_verify = 0
outfile = '-'
out_base = None
 
opts, files = getopt.getopt(sys.argv[1:], 'ho:',
                           ['help', 'verify', 'showast', 'showasm'])
for opt, val in opts:
    if opt in ('-h', '--help'):
        print __doc__
        sys.exit(0)
    elif opt == '--verify':
        do_verify = 1
    elif opt == '--showasm':
        showasm = 1
        do_verify = 0
    elif opt == '--showast':
        showast = 1
        do_verify = 0
    elif opt == '-o':
        outfile = val
    else:
        print Usage_short
        sys.exit(1)
 
# argl, commonprefix works on strings, not on path parts,
# thus we must handle the case with files in 'some/classes'
# and 'some/cmds'
src_base = os.path.commonprefix(files)
if src_base[-1:] != os.sep:
    src_base = os.path.dirname(src_base)
if src_base:
    sb_len = len( os.path.join(src_base, '') )
    files = map(lambda f: f[sb_len:], files)
    del sb_len
    
if outfile == '-':
    outfile = None # use stdout
elif outfile and os.path.isdir(outfile):
    out_base = outfile; outfile = None
elif outfile and len(files) > 1:
    out_base = outfile; outfile = None
 
print time.ctime() #, args[0]
 
try:
    main(src_base, out_base, files, outfile, showasm, showast, do_verify)
except KeyboardInterrupt, OSError:
    pass
except verify.VerifyCmpError:
    raise
 
print time.ctime()