Exemplo n.º 1
0
 def __init__(self, configuration, application_file):
     """
     """
     if configuration is None:
         raise ValueError(
             'Parameter "configuration": a simulation' ' configuration object expected but "None" value' " given!"
         )
     if application_file is None:
         raise ValueError(
             'Parameter "application": a name of an' ' application file expected but "None" value' " given!"
         )
     environment = dict()
     environment["time"] = Time()
     if "logger_level" in configuration:
         self.__logger = logger.create_logger(environment["time"], configuration["logger_level"])
     else:
         self.__logger = logger.create_logger(environment["time"])
     self.__logger.info(project_information())
     self.__logger.info("Initializing the simulation environment")
     for name in Sim2Net.__CONFIGURATION_VALUES:
         environment[name] = self.__get_value(name, configuration)
     environment["time"].setup(environment["simulation_frequency"])
     environment["area"] = self.__get_element("area", configuration, environment)
     environment["initial_coordinates"] = self.__get_element("placement", configuration, environment).get_placement()
     for name in Sim2Net.__CONFIGURATION_LISTS:
         environment[name] = self.__get_element(name, configuration, environment, environment["nodes_number"])
     for name in Sim2Net.__CONFIGURATION_OBJECTS:
         environment[name] = self.__get_element(name, configuration, environment)
     environment["application"] = self.__get_application_class(application_file)
     self.__total_simulation_steps = environment["total_simulation_steps"]
     self.__network = Network(environment)
Exemplo n.º 2
0
def main():
    """
    The entry point for the ``sim2net`` console command.
    """
    parser = argparse.ArgumentParser(
        prog='sim2net',
        usage=\
            'sim2net [-h | -d | -v | -i DIRECTORY] CONFIGURATION APPLICATION',
        description='%s' % project_information())
    group = parser.add_mutually_exclusive_group()
    group.add_argument(
        '-d', '--description',
        action='store_true',
        help='show description message and exit')
    group.add_argument(
        '-i', '--initialize',
        metavar='DIRECTORY',
        nargs=1,
        type=str,
        help='write configuration and application files to given directory')
    group.add_argument(
        '-v', '--version',
        action='store_true',
        help='show version message and exit')
    parser.add_argument(
        'configuration',
        metavar='CONFIGURATION',
        nargs='?',
        type=str,
        default=None,
        help='simulation configuration file')
    parser.add_argument(
        'application',
        metavar='APPLICATION',
        nargs='?',
        type=str,
        default=None,
        help='simulation application file')
    if len(argv) == 1:
        parser.print_help()
        exit(__POSIX_EXIT_FAILURE)
    args = parser.parse_args()
    if args.description:
        print __DESCRIPTION
        exit(__POSIX_EXIT_SUCCESS)
    if args.initialize:
        try:
            base_path = split(realpath(__file__))[0]
            copy(join(base_path, '_configuration_template.py'),
                 join(vars(args)['initialize'][0], 'configuration.py'))
            copy(join(base_path, '_application_template.py'),
                 join(vars(args)['initialize'][0], 'application.py'))
            exit(__POSIX_EXIT_SUCCESS)
        except Exception, err:
            print '***  [sim2net] CRITICAL - cannot write the files:\n'
            if __debug__:
                print_exc(file=stdout)
            else:
                print err
            exit(__POSIX_EXIT_FAILURE)
Exemplo n.º 3
0
def main():
    """
    The entry point for the ``sim2net`` console command.
    """
    parser = argparse.ArgumentParser(
        prog='sim2net',
        usage=\
            'sim2net [-h | -d | -v | -i DIRECTORY] CONFIGURATION APPLICATION',
        description='%s' % project_information())
    group = parser.add_mutually_exclusive_group()
    group.add_argument('-d',
                       '--description',
                       action='store_true',
                       help='show description message and exit')
    group.add_argument(
        '-i',
        '--initialize',
        metavar='DIRECTORY',
        nargs=1,
        type=str,
        help='write configuration and application files to given directory')
    group.add_argument('-v',
                       '--version',
                       action='store_true',
                       help='show version message and exit')
    parser.add_argument('configuration',
                        metavar='CONFIGURATION',
                        nargs='?',
                        type=str,
                        default=None,
                        help='simulation configuration file')
    parser.add_argument('application',
                        metavar='APPLICATION',
                        nargs='?',
                        type=str,
                        default=None,
                        help='simulation application file')
    if len(argv) == 1:
        parser.print_help()
        exit(__POSIX_EXIT_FAILURE)
    args = parser.parse_args()
    if args.description:
        print __DESCRIPTION
        exit(__POSIX_EXIT_SUCCESS)
    if args.initialize:
        try:
            base_path = split(realpath(__file__))[0]
            copy(join(base_path, '_configuration_template.py'),
                 join(vars(args)['initialize'][0], 'configuration.py'))
            copy(join(base_path, '_application_template.py'),
                 join(vars(args)['initialize'][0], 'application.py'))
            exit(__POSIX_EXIT_SUCCESS)
        except Exception, err:
            print '***  [sim2net] CRITICAL - cannot write the files:\n'
            if __debug__:
                print_exc(file=stdout)
            else:
                print err
            exit(__POSIX_EXIT_FAILURE)
Exemplo n.º 4
0
 def __init__(self, configuration, application_file):
     """
     """
     if configuration is None:
         raise ValueError('Parameter "configuration": a simulation'
                          ' configuration object expected but "None" value'
                          ' given!')
     if application_file is None:
         raise ValueError('Parameter "application": a name of an'
                          ' application file expected but "None" value'
                          ' given!')
     environment = dict()
     environment['time'] = Time()
     if 'logger_level' in configuration:
         self.__logger = \
             logger.create_logger(environment['time'],
                                  configuration['logger_level'])
     else:
         self.__logger = logger.create_logger(environment['time'])
     self.__logger.info(project_information())
     self.__logger.info('Initializing the simulation environment')
     for name in Sim2Net.__CONFIGURATION_VALUES:
         environment[name] = self.__get_value(name, configuration)
     environment['time'].setup(environment['simulation_frequency'])
     environment['area'] = \
         self.__get_element('area', configuration, environment)
     environment['initial_coordinates'] = \
         self.__get_element('placement', configuration,
                            environment).get_placement()
     for name in Sim2Net.__CONFIGURATION_LISTS:
         environment[name] = \
             self.__get_element(name, configuration, environment,
                                environment['nodes_number'])
     for name in Sim2Net.__CONFIGURATION_OBJECTS:
         environment[name] = self.__get_element(name, configuration,
                                                environment)
     environment['application'] = \
         self.__get_application_class(application_file)
     self.__total_simulation_steps = environment['total_simulation_steps']
     self.__network = Network(environment)
Exemplo n.º 5
0
__POSIX_EXIT_FAILURE = 1

#: The POSIX exit status to signal success.
__POSIX_EXIT_SUCCESS = 0

#: The description string.
__DESCRIPTION = """%s

Copyright (c) 2012-2014  Michal Kalewski  <mkalewski at cs.put.poznan.pl>

This program comes with ABSOLUTELY NO WARRANTY.
THIS IS FREE SOFTWARE, AND YOU ARE WELCOME TO REDISTRIBUTE IT UNDER THE TERMS
AND CONDITIONS OF THE MIT LICENSE.  YOU SHOULD HAVE RECEIVED A COPY OF THE
LICENSE ALONG WITH THIS SOFTWARE; IF NOT, YOU CAN DOWNLOAD A COPY FROM
HTTP://WWW.OPENSOURCE.ORG.
""" % project_information()


def main():
    """
    The entry point for the ``sim2net`` console command.
    """
    parser = argparse.ArgumentParser(
        prog='sim2net',
        usage=\
            'sim2net [-h | -d | -v | -i DIRECTORY] CONFIGURATION APPLICATION',
        description='%s' % project_information())
    group = parser.add_mutually_exclusive_group()
    group.add_argument('-d',
                       '--description',
                       action='store_true',
Exemplo n.º 6
0
__POSIX_EXIT_FAILURE = 1

#: The POSIX exit status to signal success.
__POSIX_EXIT_SUCCESS = 0

#: The description string.
__DESCRIPTION = """%s

Copyright (c) 2012-2014  Michal Kalewski  <mkalewski at cs.put.poznan.pl>

This program comes with ABSOLUTELY NO WARRANTY.
THIS IS FREE SOFTWARE, AND YOU ARE WELCOME TO REDISTRIBUTE IT UNDER THE TERMS
AND CONDITIONS OF THE MIT LICENSE.  YOU SHOULD HAVE RECEIVED A COPY OF THE
LICENSE ALONG WITH THIS SOFTWARE; IF NOT, YOU CAN DOWNLOAD A COPY FROM
HTTP://WWW.OPENSOURCE.ORG.
""" % project_information()


def main():
    """
    The entry point for the ``sim2net`` console command.
    """
    parser = argparse.ArgumentParser(
        prog='sim2net',
        usage=\
            'sim2net [-h | -d | -v | -i DIRECTORY] CONFIGURATION APPLICATION',
        description='%s' % project_information())
    group = parser.add_mutually_exclusive_group()
    group.add_argument(
        '-d', '--description',
        action='store_true',