1"""globaling.py module with global constants
2
3"""
4
5
6import sys
7import math
8import re
9from collections import namedtuple
10
11from ..aid.sixing import *  # Python2to3 support
12
13#Globals
14#Constant Definitions
15
16#FlowScript build reporting indentations
17INDENT_ADD = '      '
18INDENT_CREATE = '     '
19
20#Task generator control values
21STOP = 0
22START = 1
23RUN = 2
24ABORT = 3
25READY =  4
26ControlNames = { STOP : 'Stop', START : 'Start', RUN : 'Run', ABORT : 'Abort', READY : 'Ready',}
27
28#Task generator operational status
29STOPPED = STOP
30STARTED = START
31RUNNING = RUN
32ABORTED = ABORT
33READIED = READY
34StatusNames = { STOPPED : 'Stopped', STARTED : 'Started', RUNNING : 'Running', ABORTED : 'Aborted', READIED : 'Readied', }
35StatusValues = { 'Stopped' : STOPPED, 'Started' :  STARTED, 'Running' : RUNNING, 'Aborted' : ABORTED, 'Readied' : READIED,}
36
37#log rule values
38NEVER = 0
39ONCE = 1
40ALWAYS = 2
41UPDATE = 3
42CHANGE = 4
43STREAK = 5
44DECK = 6
45LogRuleNames = {NEVER : 'Never', ONCE : 'Once', ALWAYS : 'Always',
46                UPDATE : 'Update', CHANGE : 'Change', STREAK : 'Streak', DECK: 'Deck',}
47LogRuleValues = {'Never' : NEVER, 'Once' : ONCE,  'Always' : ALWAYS,
48                 'Update' : UPDATE, 'Change' : CHANGE, 'Streak' : STREAK, 'Deck' : DECK,}
49
50#Task schedule context
51INACTIVE = 0
52ACTIVE = 1
53AUX = 2
54SLAVE = 3
55MOOT = 4
56ScheduleNames = { INACTIVE : 'inactive',
57                  ACTIVE : 'active',
58                  AUX : 'aux',
59                  SLAVE : 'slave',
60                  MOOT : 'moot'}
61ScheduleValues = { 'inactive': INACTIVE ,
62                   'active':  ACTIVE,
63                   'aux': AUX,
64                   'slave': SLAVE,
65                   'moot': MOOT}
66
67#Task ordering
68MID = 0
69FRONT = 1
70BACK = 2
71
72OrderNames = { MID : 'mid', FRONT : 'front', BACK : 'back'}
73OrderValues = { 'mid': MID , 'front':  FRONT, 'back': BACK}
74
75# Frame action contexts  should change these to enums
76NATIVE = 0
77ENTER = 1
78RECUR = 2
79PRECUR = 3
80EXIT = 4
81RENTER = 5
82REXIT = 6
83BENTER = 7
84TRANSIT = 8
85
86ActionContextValues = { 'native': NATIVE , 'enter':  ENTER, 'recur': RECUR,
87                        'precur': PRECUR, 'exit': EXIT, 'renter': RENTER,
88                        'rexit': REXIT, 'benter': BENTER}
89ActionContextNames = { NATIVE : 'native', ENTER : 'enter', RECUR : 'recur',
90                       PRECUR : 'precur', EXIT : 'exit', RENTER : 'renter',
91                       REXIT : 'rexit', BENTER : 'benter'}
92
93ActionSubContextValues = {'transit': TRANSIT}
94ActionSubContextNames = { TRANSIT : 'transit'}
95
96
97
98#Precompile re match objects
99
100#regular expression objects to quickly determine if string is valid python identifier
101#Usage: REO_Identifier.match('Hello') returns match object if match otherwise None
102REO_Identifier = re.compile(r'^[a-zA-Z_]\w*$') #valid python identifier
103REO_IdentPub = re.compile(r'^[a-zA-Z]\w*$') #valid python public identifier ie no leading underscore
104
105# regex objects to determine if string is valid store path
106# to use
107#if REO_Path.match(s):
108#  then s is valid path
109
110REO_RelPath = re.compile(r'^([a-zA-Z_]\w*)+([.][a-zA-Z_]\w*)*$')  # not start with dot
111REO_DotPath = re.compile(r'^([.][a-zA-Z_]\w*)+$')  # starts with dot
112REO_Path = re.compile(r'^([a-zA-Z_]\w*)+([.][a-zA-Z_]\w*)*$|^([.][a-zA-Z_]\w*)+$')  # dotpath or relpath
113REO_PathDotPath = re.compile(r'^([a-zA-Z_]\w*)+([.][a-zA-Z_]\w*)+$|^([.][a-zA-Z_]\w*)+$') # at least one dot
114
115# allows path to end in dot or not for node paths
116REO_RelPathNode = re.compile(r'^([a-zA-Z_]\w*)+(([.][a-zA-Z_]\w*)*$|([.][a-zA-Z_]\w*)*[.]$)')  # not start with dot
117REO_DotPathNode = re.compile(r'^([.][a-zA-Z_]\w*)+$|^([.][a-zA-Z_]\w*)+[.]$')  # starts with dot
118REO_PathNode = re.compile(r'^([a-zA-Z_]\w*)+(([.][a-zA-Z_]\w*)*$|([.][a-zA-Z_]\w*)*[.]$)|^([.][a-zA-Z_]\w*)+$|^([.][a-zA-Z_]\w*)+[.]$')
119
120#regex object to split hafscript command line
121#REO_Chunks = re.compile(r'#.*|[^ "]+|"[^"]*"')
122REO_Chunks = re.compile(r"""#.*|[^ "']+|"[^"]*"|'[^']*'""")
123# Usage
124# chunks = REO_Chunks.findall(s)
125
126# to match each part
127REO_Quoted = re.compile(r'^"[^"]*"$')
128REO_QuotedSingle = re.compile(r"^'[^']*'$")
129REO_Comment = re.compile(r'^#.*$')
130REO_Plain = re.compile(r'^[^ "]+$')
131#Usage
132# if REO_Quoted.match(s):
133#    s.strip('"')
134
135#regex object determine if lat or lon is in human readable form
136#REO_LATLONPOS = re.compile(r'^([0-9]+)[N,E,n,e]([0-9]+\.[0-9]+)$')
137REO_LatLonNE = re.compile(r'^(\d+)[N,E,n,e](\d+\.\d+)$')
138REO_LatLonSW = re.compile(r'^(\d+)[S,W,s,w](\d+\.\d+)$')
139#Usage
140# ll = REO_LatLonNE.findall(s) #returns list of tuples of groups [(deg,min)]
141# if ll:
142#   deg = float(ll[0][0])
143#   min = float(ll[0][1])
144#   fracdeg = deg + min/60.0
145
146
147#  Various Point namedtuple objects
148Pxy = namedtuple('Pxy', 'x y')  # Cartesian
149Pxyz = namedtuple('Pxyz', 'x y z')  # Cartesian right hand order
150Pne = namedtuple('Pne', 'n e')  # World mapping North East
151Pned = namedtuple('Pned', 'n e d')  # World mapping North East Down right hand order
152Pfs = namedtuple('Pfs', 'f s')  # Body Forward Starboard
153Pfsb = namedtuple('Pfsb', 'f s b')  # Body Forward Starboard Below right hand order
154
155REO_PointXY = re.compile(r'^([-+]?\d+\.\d*|[-+]?\d+)?[X,x]([-+]?\d+\.\d*|[-+]?\d+)[Y,y]$')
156REO_PointXYZ = re.compile(r'^([-+]?\d+\.\d*|[-+]?\d+)[X,x]([-+]?\d+\.\d*|[-+]?\d+)[Y,y]([-+]?\d+\.\d*|[-+]?\d+)[Z,z]$')
157
158REO_PointNE = re.compile(r'^([-+]?\d+\.\d*|[-+]?\d+)[N,n]([-+]?\d+\.\d*|[-+]?\d+)[E,e]$')
159REO_PointNED = re.compile(r'^([-+]?\d+\.\d*|[-+]?\d+)[N,n]([-+]?\d+\.\d*|[-+]?\d+)[E,e]([-+]?\d+\.\d*|[-+]?\d+)[D,d]$')
160
161REO_PointFS = re.compile(r'^([-+]?\d+\.\d*|[-+]?\d+)[F,f]([-+]?\d+\.\d*|[-+]?\d+)[S,s]$')
162REO_PointFSB = re.compile(r'^([-+]?\d+\.\d*|[-+]?\d+)[F,f]([-+]?\d+\.\d*|[-+]?\d+)[S,s]([-+]?\d+\.\d*|[-+]?\d+)[B,b]$')
163