[6320] | 1 | """ |
---|
| 2 | ------------------------------------------------------------------------------ |
---|
| 3 | Mango 802.11 Reference Design - Experiments Framework - Log File Version Updater |
---|
| 4 | ------------------------------------------------------------------------------ |
---|
| 5 | License: Copyright 2014-2019, Mango Communications. All rights reserved. |
---|
| 6 | Distributed under the WARP license (http://warpproject.org/license) |
---|
| 7 | ------------------------------------------------------------------------------ |
---|
| 8 | This script uses the WLAN Exp Log framework to update version information |
---|
| 9 | in a given hdf5 log file that contains data assocated with an experiment |
---|
| 10 | utilizing the 802.11 reference design and WLAN Exp. |
---|
| 11 | |
---|
| 12 | Hardware Setup: |
---|
| 13 | - None. Updating log version information can be done completely off-line |
---|
| 14 | |
---|
| 15 | Required Script Changes: |
---|
| 16 | - None. Script requires filename of file to be anonymized to be |
---|
| 17 | passed in on the command line. |
---|
| 18 | |
---|
| 19 | Description: |
---|
| 20 | This script parses the log file and updates any WLAN Exp / 802.11 |
---|
| 21 | version information and write the resulting log data to a new file. |
---|
| 22 | ------------------------------------------------------------------------------ |
---|
| 23 | """ |
---|
| 24 | import sys |
---|
| 25 | import os |
---|
| 26 | |
---|
| 27 | import wlan_exp.log.util as log_util |
---|
| 28 | import wlan_exp.log.util_hdf as hdf_util |
---|
| 29 | |
---|
| 30 | |
---|
| 31 | #----------------------------------------------------------------------------- |
---|
| 32 | # Functions |
---|
| 33 | #----------------------------------------------------------------------------- |
---|
| 34 | |
---|
| 35 | def log_file_update(filename): |
---|
| 36 | """Update the log file.""" |
---|
| 37 | |
---|
| 38 | #--------------------------------------------------------------------- |
---|
| 39 | # Read input file |
---|
| 40 | # |
---|
| 41 | |
---|
| 42 | # Get the log_data from the file |
---|
| 43 | log_bytes = bytearray(hdf_util.hdf5_to_log_data(filename=filename)) |
---|
| 44 | |
---|
| 45 | # Get the raw_log_index from the file |
---|
| 46 | raw_log_index = hdf_util.hdf5_to_log_index(filename=filename) |
---|
| 47 | |
---|
| 48 | # Get the user attributes from the file |
---|
| 49 | log_attr_dict = hdf_util.hdf5_to_attr_dict(filename=filename) |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | #--------------------------------------------------------------------- |
---|
| 53 | # Print information about the file |
---|
| 54 | # |
---|
| 55 | |
---|
| 56 | log_util.print_log_index_summary(raw_log_index, "Log Index Summary:") |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | #--------------------------------------------------------------------- |
---|
| 60 | # Write output file |
---|
| 61 | # |
---|
| 62 | |
---|
| 63 | # Write the log to a new HDF5 file |
---|
| 64 | (fn_fldr, fn_file) = os.path.split(filename) |
---|
| 65 | |
---|
| 66 | # Find the last '.' in the file name and classify everything after that as the <ext> |
---|
| 67 | ext_i = fn_file.rfind('.') |
---|
| 68 | if (ext_i != -1): |
---|
| 69 | # Remember the original file extension |
---|
| 70 | fn_ext = fn_file[ext_i:] |
---|
| 71 | fn_base = fn_file[0:ext_i] |
---|
| 72 | else: |
---|
| 73 | fn_ext = '' |
---|
| 74 | fn_base = fn_file |
---|
| 75 | |
---|
| 76 | newfilename = os.path.join(fn_fldr, fn_base + "_update" + fn_ext) |
---|
| 77 | |
---|
| 78 | print("Writing new file {0} ...".format(newfilename)) |
---|
| 79 | |
---|
| 80 | # Copy any user attributes to the new file |
---|
| 81 | hdf_util.log_data_to_hdf5(log_bytes, newfilename, attr_dict=log_attr_dict) |
---|
| 82 | |
---|
| 83 | return |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | #----------------------------------------------------------------------------- |
---|
| 87 | # Main |
---|
| 88 | #----------------------------------------------------------------------------- |
---|
| 89 | |
---|
| 90 | if __name__ == '__main__': |
---|
| 91 | if(len(sys.argv) < 2): |
---|
| 92 | print("ERROR: must provide at least one log file input") |
---|
| 93 | sys.exit() |
---|
| 94 | else: |
---|
| 95 | for filename in sys.argv[1:]: |
---|
| 96 | # Ensure the log file actually exists; Print an error and continue to the next file. |
---|
| 97 | if(not os.path.isfile(filename)): |
---|
| 98 | print("\nERROR: File {0} not found".format(filename)) |
---|
| 99 | else: |
---|
| 100 | print("\nUpdating file '{0}' ({1:5.1f} MB)\n".format(filename, (os.path.getsize(filename)/1E6))) |
---|
| 101 | log_file_update(filename) |
---|
| 102 | |
---|