~patrickas/ensoft-sextant/add_dev_script

« back to all changes in this revision

Viewing changes to src/sextant/__main__.py

  • Committer: Tarmac
  • Author(s): patrickas at co, James Harkin
  • Date: 2014-09-01 16:00:59 UTC
  • mfrom: (3.1.10 minor_bugfixes)
  • Revision ID: tarmac-20140901160059-nx4l6bw5jc297i10
Make Sextant Web a lot less chatty.

Show diffs side-by-side

added added

removed removed

Lines of Context:
82
82
            st = ('Program {progname} with {numfuncs} functions '
83
83
                  'uploaded by {uploader} (id {uploaderid}) on {date}.')
84
84
            print(st.format(progname=program.program_name,
85
 
                            numfuncs=program.number,
 
85
                            numfuncs=program.number_of_funcs,
86
86
                            uploader=program.uploader,
87
87
                            uploaderid=program.uploader_id,
88
88
                            date=program.date))
164
164
 
165
165
    """
166
166
 
167
 
    argumentparser = argparse.ArgumentParser(description="Invoke part of the SEXTANT program")
 
167
    argumentparser = argparse.ArgumentParser(prog='sextant', usage='sextant', description="Invoke part of the SEXTANT program")
168
168
    subparsers = argumentparser.add_subparsers(title="subcommands")
169
169
 
170
170
    #set what will be defined as a "common function"
368
368
 
369
369
 
370
370
def _is_localhost(host, port):
371
 
    """Checks whether a host is an alias to localhost."""
372
 
    return socket.getaddrinfo(host, port)[0][4][0] in ('127.0.0.1', '::1')
 
371
    """
 
372
    Checks whether a host is an alias to localhost.
 
373
 
 
374
    Raises socket.gaierror if the host was not found.
 
375
 
 
376
    """
 
377
 
 
378
    addr = socket.getaddrinfo(host, port)[0][4][0]
 
379
 
 
380
    return addr in ('127.0.0.1', '::1')
373
381
 
374
382
 
375
383
def main():
380
388
 
381
389
        remotehost, remoteport = _get_host_and_port(args.remote_neo4j)
382
390
 
383
 
        if _is_localhost(remotehost, remoteport):
 
391
        try:
 
392
            is_loc = _is_localhost(remotehost, remoteport)
 
393
        except socket.gaierror:
 
394
            logging.error('Server {} not found.'.format(remotehost))
 
395
            return
 
396
 
 
397
        if is_loc:
384
398
            # we are attempting to connect to localhost anyway, so we won't
385
399
            # bother to SSH to it.
386
400
            # There may be some ways the user can trick us into trying to SSH