示例#1
0
    def setStatus(self, status='secondary'):
        """Set PAGER status ('primary' will transfer, 'secondary' will not.)

        :param status:
          PAGER status ('primary' will transfer products, 'secondary' will not.)
        :returns:
          PAGER status set
        """
        config = read_config()
        config_file = get_config_file()
        lines = open(config_file, 'rt').readlines()
        if 'status' not in config:
            lines.append('status : %s\n' % status)
        else:
            newlines = []
            for line in lines:
                parts = line.split(':')
                if parts[0].strip() == 'status':
                    line = 'status : %s\n' % status
                else:
                    pass
                newlines.append(line)
        f = open(config_file, 'wt')
        f.writelines(newlines)
        return status
示例#2
0
    def getStatus(self):
        """Get the PAGER status ('primary' will transfer products, 'secondary' will not.)

        :returns:
          PAGER status
        """
        config = read_config()
        status = 'secondary'
        if 'status' in config and config['status'] == 'primary':
            return 'primary'
        return status
示例#3
0
def main(args):
    # read global config file
    config = read_config()

    # figure out where the output data goes
    pager_folder = config['output_folder']

    # figure out where the archive folder is
    archive_folder = config['archive_folder']

    admin = PagerAdmin(pager_folder, archive_folder)
    event_folder = admin.getEventFolder(args.eventid)
    vnumbers = admin.getVersionNumbers(event_folder)
    version_folder = os.path.join(event_folder, 'version.%03i' % vnumbers[-1])
    json_folder = os.path.join(version_folder, 'json')
    eventfile = os.path.join(json_folder, 'event.json')
    eventdict = json.load(open(eventfile, 'rt'))

    arguments = OrderedDict()
    arguments['eventid'] = args.eventid
    arguments['directory'] = version_folder
    arguments['type'] = 'losspager'
    if eventdict['shakemap']['shake_type'] == 'SCENARIO':
        arguments['type'] = 'losspager-scenario'
    eventid = eventdict['shakemap']['shake_id']
    source = eventdict['shakemap']['shake_source']
    code = eventid.replace(source, '')
    arguments['code'] = code
    arguments['source'] = source
    arguments['status'] = 'ACTION'
    arguments['action'] = 'UPDATE'
    arguments['preferred-latitude'] = '%.4f' % eventdict['event']['lat']
    arguments['preferred-longitude'] = '%.4f' % eventdict['event']['lon']
    arguments['preferred-depth'] = '%.1f' % eventdict['event']['depth']
    arguments['preferred-magnitude'] = '%.1f' % eventdict['event']['mag']
    etimestr = eventdict['event']['time'].replace(' ', 'T') + '.000Z'
    arguments['preferred-eventtime'] = etimestr
    argstr = ' '.join(
        ['--' + key + '=' + value for key, value in arguments.items()])
    cmd = 'emailpager %s' % argstr
    print(cmd)
    if args.run:
        print('Calling emailpager: "%s"' % cmd)
        res, stdout, stderr = get_command_output(cmd)
        if res:
            print('Successful.')
        else:
            print('Failure - "%s".' % stderr)
示例#4
0
 def setStatus(self,status='secondary'):
     config = read_config()
     config_file = get_config_file()
     lines = open(config_file,'rt').readlines()
     if 'status' not in config:
         lines.append('status : %s\n' % status)
     else:
         newlines = []
         for line in lines:
             parts = line.split(':')
             if parts[0].strip() == 'status':
                 line = 'status : %s\n' % status
             else:
                 pass
             newlines.append(line)
     f = open(config_file,'wt')
     f.writelines(newlines)
     return status
示例#5
0
def test_pager_main():
    # if we're on a system where config file does not exist, don't run the test.
    # means we won't be able to test in CI scenario
    if get_config_file() is None:
        print(
            "We're not running on a system with PAGER data installed. Exiting this test."
        )
        return True
    thisdir = pathlib.Path(__file__).parent
    gridfile = (
        thisdir / ".." / "data" / "eventdata" / "northridge" / "northridge_grid.xml"
    )
    args = Args(
        gridfile=gridfile,
        debug=True,
        release=False,
        cancel=False,
        tsunami=False,
        elapsed=False,
    )
    config = read_config()
    main(args, config)
示例#6
0
 def getStatus(self):
     config = read_config()
     status = 'secondary'
     if 'status' in config and config['status'] == 'primary':
         return 'primary'
     return status