# -*- coding: utf-8 -*- """Module allowing to call av_home, with the adequate configuration""" import sys import os import av_home class av_home_caller: """AV HOME caller""" def __init__(self): from optparse import OptionParser usage = """ %prog master [conf_file] Run the master script for AV HOME test %prog slave [conf_file] Run the slave script for AV HOME test %prog report Generate the AV HOME report""" self._commands = dict((n[4:], getattr(self, n)) for n in dir(self) if n.startswith('run_')) self._parser = OptionParser(usage = usage) self._parser.add_option ("-m", "--plug-mac-addr", action="store", type="string", dest="plug_mac", help="MAC address of the plug") self._parser.add_option ("-p", "--peer-mac-addr", action="store", type="string", dest="peer_mac", help="MAC address of the peer plug") self._parser.add_option ("-s", "--source-mac-addr", action="store", type="string", dest="source_mac", help="MAC address of PC") self._parser.add_option ("-i", "--iface", action="store", type="string", dest="iface", help="Name of the network interface (e.g eth0)") self._parser.add_option ("-a", "--ip-addr", action="store", type="string", dest="addr", help="IP address of the peer PC") self._parser.add_option ("-d", "--output-directory", action="store", type="string", dest="output_dir", help="Output directory suffix") self._parser.add_option ("-l", "--scammer-path", action="store", type="string", dest="scammer_path", help="Path to Lib Scammer directory") def run(self, args, prefix): (options, args) = self._parser.parse_args() if args[1]: av_home.parse_config (args[1]) av_home.set_opts(options, prefix) av_home.check_params () if args[0] in self._commands: getattr(self, 'run_' + args[0])() else: print (args[0] + ' is not a supported command') self._parser.print_help() sys.exit(1) def run_master(self): av_home.master_script(); def run_slave(self): av_home.slave_script(); def run_report(self): av_home.report(); if __name__ == "__main__": prefix = os.path.dirname (sys.argv[0]) av_home_caller().run(sys.argv[1:], prefix)