|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +BSD 3-Clause License |
| 4 | +
|
| 5 | +Copyright (c) 2025, University of Southern California |
| 6 | +All rights reserved. |
| 7 | +
|
| 8 | +Redistribution and use in source and binary forms, with or without |
| 9 | +modification, are permitted provided that the following conditions are met: |
| 10 | +
|
| 11 | +1. Redistributions of source code must retain the above copyright notice, this |
| 12 | + list of conditions and the following disclaimer. |
| 13 | +
|
| 14 | +2. Redistributions in binary form must reproduce the above copyright notice, |
| 15 | + this list of conditions and the following disclaimer in the documentation |
| 16 | + and/or other materials provided with the distribution. |
| 17 | +
|
| 18 | +3. Neither the name of the copyright holder nor the names of its |
| 19 | + contributors may be used to endorse or promote products derived from |
| 20 | + this software without specific prior written permission. |
| 21 | +
|
| 22 | +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 23 | +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 24 | +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 25 | +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 26 | +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 27 | +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 28 | +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 29 | +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 30 | +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 31 | +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 | +
|
| 33 | +Program to validate the BBP station file provided by the Quakeworx gateway |
| 34 | +""" |
| 35 | +from __future__ import division, print_function |
| 36 | + |
| 37 | +# Works for both Python 2 and 3 |
| 38 | +try: input = raw_input |
| 39 | +except NameError: pass |
| 40 | + |
| 41 | +# Import Python modules |
| 42 | +import os |
| 43 | +import sys |
| 44 | +import optparse |
| 45 | + |
| 46 | +# Import Broadband modules |
| 47 | +import bband_utils |
| 48 | +from station_list import StationList |
| 49 | + |
| 50 | +STL_MAX_FILE_SIZE_KB = 10 |
| 51 | + |
| 52 | +def main(): |
| 53 | + """ |
| 54 | + Parse command line options and create the needed files/directories |
| 55 | + """ |
| 56 | + prog_base = os.path.basename(sys.argv[0]) |
| 57 | + usage = "usage: %s [options]" % (prog_base) |
| 58 | + parser = optparse.OptionParser(usage) |
| 59 | + parser.add_option("-i", "--input-file", type="string", action="store", |
| 60 | + dest="input_file", |
| 61 | + help="Input file") |
| 62 | + parser.add_option("-o", "--output-file", type="string", action="store", |
| 63 | + dest="output_file", |
| 64 | + help="Output file") |
| 65 | + (options, _) = parser.parse_args() |
| 66 | + |
| 67 | + input_file = options.input_file |
| 68 | + output_file = options.output_file |
| 69 | + |
| 70 | + # Check file size |
| 71 | + try: |
| 72 | + file_size = os.path.getsize(input_file) |
| 73 | + # Convert from bytes to kb |
| 74 | + file_size = file_size / 1024 |
| 75 | + if file_size > STL_MAX_FILE_SIZE_KB: |
| 76 | + raise bband_utils.ParameterError("Input station file larger than %d Kb!" % (STL_MAX_FILE_SIZE_KB)) |
| 77 | + except OSError as e: |
| 78 | + raise bband_utils.ProcessingError("Cannot get size for file %s!" % (input_file)) |
| 79 | + |
| 80 | + # Parse input file |
| 81 | + station_list_object = StationList(input_file) |
| 82 | + site_list = station_list_object.get_station_list() |
| 83 | + station_list_object.build(site_list, output_file) |
| 84 | + |
| 85 | +if __name__ == "__main__": |
| 86 | + main() |
0 commit comments