#!/usr/bin/python

import sys, os
from os.path import getsize
import argparse, itertools

from insulaudit import lib
from insulaudit.log import logger
import logging
logging.basicConfig(stream=sys.stdout)
logger.setLevel(logging.DEBUG)

from pprint import pprint, pformat

CHUNK_SIZE = 64

def get_opts():
  parser = argparse.ArgumentParser( )
  parser.add_argument(
    'input', nargs='+', help="Input files")
  return parser

def get_raw_handle(pathish):
  logger.info('opening %s' % (pathish))
  handle = open(pathish)
  return handle

def hex_dump_data(data):
  print lib.hexdump(bytearray(data))

def read_chunk(handle):
  logger.info('start reading: %s' % handle.tell( ))
  return bytearray(handle.read(64))

def do_chunk(handle):
  chunk = read_chunk(handle)
  hex_dump_data(chunk)

def do_input(pathish):
  handle = get_raw_handle(pathish)
  pos  = handle.tell( )
  size = getsize(pathish)
  logger.info('opening %s (%s bytes)' % (pathish, size))

  for i in itertools.count( ):
    if pos < size:
      logger.info('chunk: %s' % i)
      do_chunk(handle)
      pos = handle.tell( )
    else:
      break




def main(*args):
  parser = get_opts( )
  opts = parser.parse_args( )
  logger.info('opening %s' % (opts.input))

  for item in opts.input:
    do_input(item)


  


if __name__ == '__main__':
  main(sys.argv )


@@ -279,17 +279,49 @@
 _SIZE = 
-6
+32%0APROLOG_SIZE = 192 + 64 - 24 + 
 4%0A%0Adef g
@@ -392,16 +392,282 @@
 gument(%0A
+    '--chunk', dest='chunk', type=int,%0A    default=CHUNK_SIZE, help=%22Default chunksize: %25s%22 %25 CHUNK_SIZE)%0A  parser.add_argument(%0A    '--prolog', dest='prolog', type=int,%0A    default=PROLOG_SIZE, help=%22Default prologue size: %25s%22 %25 PROLOG_SIZE)%0A  parser.add_argument(%0A
     'inp
@@ -945,23 +945,58 @@
  reading
-: %25s' %25
+ (bytes %25s) from offset %25s' %25 (CHUNK_SIZE,
  handle.
@@ -1003,16 +1003,17 @@
 tell( ))
+)
 %0A  retur
@@ -1036,18 +1036,26 @@
 le.read(
-64
+CHUNK_SIZE
 ))%0A%0Adef 
@@ -1287,24 +1287,122 @@
 sh, size))%0A%0A
+  logger.info('reading prologue (%25s bytes)' %25 (PROLOG_SIZE))%0A  prolog = handle.read(PROLOG_SIZE)%0A%0A
   for i in i
@@ -1547,19 +1547,16 @@
  break%0A%0A
-%0A%0A%0A
 def main
@@ -1564,16 +1564,49 @@
 *args):%0A
+  global CHUNK_SIZE, PROLOG_SIZE%0A
   parser
@@ -1650,16 +1650,242 @@
 args( )%0A
+  #logger.info('opts: %25s' %25 (pformat(sys.argv)))%0A  CHUNK_SIZE = opts.chunk%0A  PROLOG_SIZE = opts.prolog%0A  cmdline = %5B sys.argv%5B0%5D,%0A    '--chunk %25s' %25 (CHUNK_SIZE),%0A    '--prolog %25s' %25 (PROLOG_SIZE) %5D%0A  print ' '.join(cmdline)%0A%0A
   logger
@@ -1970,14 +1970,8 @@
 m)%0A%0A
-%0A  %0A%0A%0A
 if _
@@ -2012,8 +2012,20 @@
 argv )%0A%0A
+#####%0A# EOF%0A

tweak opt parsing