File: query.py

package info (click to toggle)
ecflow 5.15.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 51,868 kB
  • sloc: cpp: 269,341; python: 22,756; sh: 3,609; perl: 770; xml: 333; f90: 204; ansic: 141; makefile: 70
file content (50 lines) | stat: -rw-r--r-- 2,099 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
# Name        :
# Author      : Avi
# Revision    : $Revision: #10 $
#
# Copyright 2009- ECMWF.
# This software is licensed under the terms of the Apache Licence version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.
#////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
import ecflow
import argparse # for argument parsing  
import sys  
import os
    
if __name__ == "__main__":
    DESC = """query node state
              Usage:
                   query.py --host cca --port 4141 --path /ecflow/regenerate
            """    
    PARSER = argparse.ArgumentParser(description=DESC,  
                                formatter_class=argparse.RawDescriptionHelpFormatter)
    PARSER.add_argument('--host', default=os.getenv("ECF_HOST","localhost"),   
                        help="The name of the host machine, defaults to 'localhost'")
    PARSER.add_argument('--port', default=os.getenv("ECF_PORT","3141"),   
                        help="The port on the host, defaults to 3141")
    PARSER.add_argument('--path', default="/",   
                        help="The path to the node. i.e /suite/family/task")
    ARGS = PARSER.parse_args()
    
    CL = ecflow.Client(ARGS.host, ARGS.port)
    try:
        CL.sync_local()
        defs = CL.get_defs()        
        if len(defs) == 0 :
            print("No suites found, exiting...")
            sys.exit(0) 
        if ARGS.path == "/":
            print(defs.get_state())
        else:
            node = defs.find_abs_node(ARGS.path)
            if node is None:  
                print("No node found at path " + ARGS.path)
            else:
                print(node.get_state())
    except RuntimeError as ex:
        print("Error: " + str(ex))
        print("Check host and port number are correct.")