#!/usr/bin/python
"""
 Copyright (C) 2010 David Francos Cuartero
         This program is free software; you can redistribute it and/or
        modify it under the terms of the GNU General Public License
        as published by the Free Software Foundation; either version 2
        of the License, or (at your option) any later version.

        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        GNU General Public License for more details.

        You should have received a copy of the GNU General Public License
        along with this program; if not, write to the Free Software
        Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

"""
from Digenpy_ import *
import sys, Digenpy_, types

if len(sys.argv) < 2:
     print 'Usage: %s Country Company [Year] [Mac] [ESSID]\n %s Country To see al contrys available, and\n %s Country Company to see some company specific usage\n' %(sys.argv[0], sys.argv[0], sys.argv[0])
     sys.exit(1)

if len(sys.argv) == 2:
    print 'Available countries:'
    for i in Digenpy_.__all__:
        print i
        mod=getattr(Digenpy_, i)
        for a in dir(mod):
            if isinstance(getattr(mod, a, None), types.ClassType):
                help_=getattr(mod, a)('').dictionary
                if help_:
                    if len(a) > 9: b="\t"
                    else: b="\t\t"
                    print '\t%s%s%s' %(a, b, help_)
                        
    sys.exit(1)

def printer(a_print):
    if __name__ == "__main__":
        if a_print.__class__ is types.ListType:
            for a in a_print: print a
        else:
            print a_print

z=[]
module=getattr(Digenpy_, sys.argv[1])
[z.append(getattr(module, sys.argv[2])) for a in dir(module)\
    if isinstance(getattr(module, a, None), types.ClassType) and a in sys.argv[2].split(',') ]
[printer(i(sys.argv[2:]).dictionary) for i in z]

