Move util.py functions into wutils.py
authorMitch Watrous <watrous@u.washington.edu>
Tue, 08 Mar 2011 16:03:45 -0800
changeset 6884 b7518424f22d
parent 6883 ec325f025373
child 6885 1bd1c1e8d7d3
child 6886 690b7a78bbd0
Move util.py functions into wutils.py
util.py
wscript
wutils.py
--- a/util.py	Tue Mar 08 14:57:45 2011 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -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
--- a/wscript	Tue Mar 08 14:57:45 2011 -0800
+++ b/wscript	Tue Mar 08 16:03:45 2011 -0800
@@ -28,7 +28,7 @@
 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']
--- a/wutils.py	Tue Mar 08 14:57:45 2011 -0800
+++ b/wutils.py	Tue Mar 08 16:03:45 2011 -0800
@@ -233,3 +233,66 @@
     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