diff --git a/util.py b/util.py deleted file mode 100644 index 5c15afc8b..000000000 --- a/util.py +++ /dev/null @@ -1,69 +0,0 @@ -import os -import sys - -def fatal(msg): - print >> sys.stderr, msg - sys.exit(2) - -def get_list_from_file(file_path, list_name): - '''Looks for a Python list called list_name in the file specified - by file_path and returns it. - - If the file or list name aren't found, this function will return - an empty list. - - ''' - - list = [] - - # Read in the file if it exists. - if os.path.exists(file_path): - file_in = open(file_path, "r") - - # Look for the list. - list_string = "" - parsing_multiline_list = False - for line in file_in: - if list_name in line or parsing_multiline_list: - list_string += line - - # Handle multiline lists. - if ']' not in list_string: - parsing_multiline_list = True - else: - # Evaluate the list once its end is reached. - # Make the split function only split it once. - list = eval(list_string.split('=', 1)[1].strip()) - break - - # Close the file - file_in.close() - - return list - -def read_config_file(): - '''Reads the NS-3 configuration file and returns a list of enabled modules. - - This function first looks for the ns3 configuration file (.ns3rc) - in the current working directory and then looks in the ~ - directory. - - ''' - - # See if the ns3 configuration file exists in the current working - # directory and then look for it in the ~ directory. - dot_ns3rc_name = '.ns3rc' - dot_ns3rc_path = dot_ns3rc_name - if not os.path.exists(dot_ns3rc_path): - dot_ns3rc_path = os.path.expanduser('~/') + dot_ns3rc_name - if not os.path.exists(dot_ns3rc_path): - # Enable all modules if the .ns3rc file can't be found. - return ['all_modules'] - - # Read in the ns3 configuration file. - modules_enabled = get_list_from_file(dot_ns3rc_path, 'modules_enabled') - if not modules_enabled: - # Enable all modules if the modules_enabled line can't be found. - return ['all_modules'] - - return modules_enabled diff --git a/wscript b/wscript index 4657d66d3..653454a3c 100644 --- a/wscript +++ b/wscript @@ -28,7 +28,7 @@ import Build import Configure import Scripting -from util import read_config_file +from wutils import read_config_file # By default, all modules will be enabled. modules_enabled = ['all_modules'] diff --git a/wutils.py b/wutils.py index 465fd284b..7aee55257 100644 --- a/wutils.py +++ b/wutils.py @@ -233,3 +233,66 @@ def run_python_program(program_string, env, visualize=False): return run_argv([env['PYTHON']] + execvec, env, cwd=cwd) +def get_list_from_file(file_path, list_name): + '''Looks for a Python list called list_name in the file specified + by file_path and returns it. + + If the file or list name aren't found, this function will return + an empty list. + + ''' + + list = [] + + # Read in the file if it exists. + if os.path.exists(file_path): + file_in = open(file_path, "r") + + # Look for the list. + list_string = "" + parsing_multiline_list = False + for line in file_in: + if list_name in line or parsing_multiline_list: + list_string += line + + # Handle multiline lists. + if ']' not in list_string: + parsing_multiline_list = True + else: + # Evaluate the list once its end is reached. + # Make the split function only split it once. + list = eval(list_string.split('=', 1)[1].strip()) + break + + # Close the file + file_in.close() + + return list + + +def read_config_file(): + '''Reads the NS-3 configuration file and returns a list of enabled modules. + + This function first looks for the ns3 configuration file (.ns3rc) + in the current working directory and then looks in the ~ + directory. + + ''' + + # See if the ns3 configuration file exists in the current working + # directory and then look for it in the ~ directory. + dot_ns3rc_name = '.ns3rc' + dot_ns3rc_path = dot_ns3rc_name + if not os.path.exists(dot_ns3rc_path): + dot_ns3rc_path = os.path.expanduser('~/') + dot_ns3rc_name + if not os.path.exists(dot_ns3rc_path): + # Enable all modules if the .ns3rc file can't be found. + return ['all_modules'] + + # Read in the ns3 configuration file. + modules_enabled = get_list_from_file(dot_ns3rc_path, 'modules_enabled') + if not modules_enabled: + # Enable all modules if the modules_enabled line can't be found. + return ['all_modules'] + + return modules_enabled