#!/usr/bin/env python
from __future__ import absolute_import
# -*- coding: utf8 -*-
"""
	Rebuild python source code from binary file (.pyc)
"""
import sys, marshal
from reblok import Parser, Reblok


if __name__ == '__main__':
	if len(sys.argv) < 2:
		print "Usage: %s file.pyc" % sys.argv[0]; sys.exit(1);

	if not sys.argv[1].endswith('.pyc'):
		print "file %s does not seems to be a python bytecode file. Exiting..." % sys.argv[1]

	with open(sys.argv[1], 'r') as f:
		f.seek(8)
		bytecode = marshal.load(f)

	tree  = Parser().walk(bytecode)
	Reblok().run(tree)
