sequence
stringlengths 1.19k
35k
| code
stringlengths 75
8.58k
|
---|---|
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'join'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'ignore_errors'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '14', '18', '24', '43', '69', '78', '102', '113', '119', '173']}, {'id': '9', 'type': 'assert_statement', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': '_status_fn'}, {'id': '13', 'type': 'string', 'children': [], 'value': '"Asked to join a task which hasn\'t had any commands executed on it"'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'check_interval'}, {'id': '17', 'type': 'float', 'children': [], 'value': '0.2'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'status_fn'}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': '_status_fn'}; {'id': '24', 'type': 'if_statement', 'children': ['25', '35']}, {'id': '25', 'type': 'not_operator', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'wait_for_file'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'status_fn'}; {'id': '32', 'type': 'keyword_argument', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'max_wait_sec'}; {'id': '34', 'type': 'integer', 'children': [], 'value': '30'}, {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'log'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'string', 'children': [], 'value': 'f"Retrying waiting for {status_fn}"'}, {'id': '43', 'type': 'while_statement', 'children': ['44', '51']}; {'id': '44', 'type': 'not_operator', 'children': ['45']}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'exists'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'status_fn'}, {'id': '51', 'type': 'block', 'children': ['52', '59']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'log'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'string', 'children': [], 'value': 'f"Still waiting for {self._cmd}"'}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'wait_for_file'}; {'id': '64', 'type': 'argument_list', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'status_fn'}; {'id': '66', 'type': 'keyword_argument', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'max_wait_sec'}; {'id': '68', 'type': 'integer', 'children': [], 'value': '30'}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'contents'}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'status_fn'}; {'id': '78', 'type': 'if_statement', 'children': ['79', '85']}, {'id': '79', 'type': 'comparison_operator', 'children': ['80', '84'], 'value': '=='}; {'id': '80', 'type': 'call', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'contents'}; {'id': '84', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '85', 'type': 'block', 'children': ['86', '93']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'sleep'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'check_interval'}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'contents'}; {'id': '96', 'type': 'call', 'children': ['97', '100']}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'status_fn'}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'status'}, {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'call', 'children': ['109', '112']}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'contents'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '112', 'type': 'argument_list', 'children': []}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '118']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'last_status'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'status'}, {'id': '119', 'type': 'if_statement', 'children': ['120', '123']}; {'id': '120', 'type': 'comparison_operator', 'children': ['121', '122'], 'value': '!='}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '122', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '123', 'type': 'block', 'children': ['124', '131', '155']}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'extra_msg'}, {'id': '127', 'type': 'conditional_expression', 'children': ['128', '129', '130'], 'value': 'if'}; {'id': '128', 'type': 'string', 'children': [], 'value': "'(ignoring error)'"}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'ignore_errors'}; {'id': '130', 'type': 'string', 'children': [], 'value': "'(failing)'"}, {'id': '131', 'type': 'if_statement', 'children': ['132', '140']}; {'id': '132', 'type': 'boolean_operator', 'children': ['133', '139'], 'value': 'or'}, {'id': '133', 'type': 'call', 'children': ['134', '137']}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'util'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'is_set'}, {'id': '137', 'type': 'argument_list', 'children': ['138']}; {'id': '138', 'type': 'string', 'children': [], 'value': "'NCLUSTER_RUN_WITH_OUTPUT_ON_FAILURE'"}, {'id': '139', 'type': 'True', 'children': []}; {'id': '140', 'type': 'block', 'children': ['141', '148']}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'call', 'children': ['143', '146']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}, {'id': '147', 'type': 'string', 'children': [], 'value': 'f"Start failing output {extra_msg}: \\n{\'*\'*80}\\n\\n \'{self.read(self._out_fn)}\'"'}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'call', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'log'}, {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'string', 'children': [], 'value': 'f"\\n{\'*\'*80}\\nEnd failing output"'}, {'id': '155', 'type': 'if_statement', 'children': ['156', '158', '164']}; {'id': '156', 'type': 'not_operator', 'children': ['157']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'ignore_errors'}; {'id': '158', 'type': 'block', 'children': ['159']}, {'id': '159', 'type': 'raise_statement', 'children': ['160']}; {'id': '160', 'type': 'call', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}, {'id': '163', 'type': 'string', 'children': [], 'value': 'f"Command {self._cmd} returned status {status}"'}; {'id': '164', 'type': 'else_clause', 'children': ['165']}, {'id': '165', 'type': 'block', 'children': ['166']}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'call', 'children': ['168', '171']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'log'}, {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'string', 'children': [], 'value': 'f"Warning: command {self._cmd} returned status {status}"'}, {'id': '173', 'type': 'return_statement', 'children': ['174']} | def join(self, ignore_errors=False):
assert self._status_fn, "Asked to join a task which hasn't had any commands executed on it"
check_interval = 0.2
status_fn = self._status_fn
if not self.wait_for_file(status_fn, max_wait_sec=30):
self.log(f"Retrying waiting for {status_fn}")
while not self.exists(status_fn):
self.log(f"Still waiting for {self._cmd}")
self.wait_for_file(status_fn, max_wait_sec=30)
contents = self.read(status_fn)
if len(contents) == 0:
time.sleep(check_interval)
contents = self.read(status_fn)
status = int(contents.strip())
self.last_status = status
if status != 0:
extra_msg = '(ignoring error)' if ignore_errors else '(failing)'
if util.is_set('NCLUSTER_RUN_WITH_OUTPUT_ON_FAILURE') or True:
self.log(
f"Start failing output {extra_msg}: \n{'*'*80}\n\n '{self.read(self._out_fn)}'")
self.log(f"\n{'*'*80}\nEnd failing output")
if not ignore_errors:
raise RuntimeError(f"Command {self._cmd} returned status {status}")
else:
self.log(f"Warning: command {self._cmd} returned status {status}")
return status |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '22', '24']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_run_with_output_on_failure'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '19']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'non_blocking'}; {'id': '8', 'type': 'False', 'children': []}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'ignore_errors'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'max_wait_sec'}; {'id': '14', 'type': 'binary_operator', 'children': ['15', '18'], 'value': '*'}, {'id': '15', 'type': 'binary_operator', 'children': ['16', '17'], 'value': '*'}; {'id': '16', 'type': 'integer', 'children': [], 'value': '365'}, {'id': '17', 'type': 'integer', 'children': [], 'value': '24'}; {'id': '18', 'type': 'integer', 'children': [], 'value': '3600'}, {'id': '19', 'type': 'default_parameter', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'check_interval'}, {'id': '21', 'type': 'float', 'children': [], 'value': '0.2'}; {'id': '22', 'type': 'type', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '24', 'type': 'block', 'children': ['25', '34', '42', '50', '158', '179', '189', '233', '244', '270', '281', '287', '331']}, {'id': '25', 'type': 'if_statement', 'children': ['26', '30']}; {'id': '26', 'type': 'not_operator', 'children': ['27']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': '_can_run'}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'assert_statement', 'children': ['32', '33']}; {'id': '32', 'type': 'False', 'children': []}, {'id': '33', 'type': 'string', 'children': [], 'value': '"Using .run before initialization finished"'}; {'id': '34', 'type': 'if_statement', 'children': ['35', '38']}, {'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': 'in'}; {'id': '36', 'type': 'string', 'children': [], 'value': "'\\n'"}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '38', 'type': 'block', 'children': ['39']}, {'id': '39', 'type': 'assert_statement', 'children': ['40', '41']}; {'id': '40', 'type': 'False', 'children': []}, {'id': '41', 'type': 'string', 'children': [], 'value': '"Don\'t support multi-line for run2"'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '49', 'type': 'argument_list', 'children': []}; {'id': '50', 'type': 'if_statement', 'children': ['51', '54', '155']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '54', 'type': 'ERROR', 'children': ['55', '97', '111', '112', '154']}, {'id': '55', 'type': 'comparison_operator', 'children': ['56', '96'], 'value': 'not'}; {'id': '56', 'type': 'binary_operator', 'children': ['57', '62', '95'], 'value': '+'}, {'id': '57', 'type': 'attribute', 'children': ['58', '59', '61']}; {'id': '58', 'type': 'string', 'children': [], 'value': "'\n return '"}, {'id': '59', 'type': 'ERROR', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'run_counter'}; {'id': '62', 'type': 'ERROR', 'children': ['63', '64', '71', '74', '75', '78', '79', '82', '83', '86', '87', '88', '94']}, {'id': '63', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '64', 'type': 'call', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '68', 'type': 'argument_list', 'children': ['69', '70']}, {'id': '69', 'type': 'string', 'children': [], 'value': '"tmux> %s"'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': '_cmd'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': '_cmd_fn'}; {'id': '78', 'type': 'string', 'children': [], 'value': "f'{self.remote_scratch}/{self.run_counter}.cmd'"}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': '_status_fn'}; {'id': '82', 'type': 'string', 'children': [], 'value': "f'{self.remote_scratch}/{self.run_counter}.status'"}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': '_out_fn'}; {'id': '86', 'type': 'string', 'children': [], 'value': "f'{self.remote_scratch}/{self.run_counter}.out'"}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '88', 'type': 'call', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'util'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'shell_strip_comment'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'assert'}, {'id': '95', 'type': 'string', 'children': [], 'value': "'&'"}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '97', 'type': 'ERROR', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '104']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101', '103']}; {'id': '100', 'type': 'string', 'children': [], 'value': 'f"cmd {cmd} contains &, that breaks things"'}, {'id': '101', 'type': 'ERROR', 'children': ['102']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'file_write'}; {'id': '104', 'type': 'argument_list', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': '_cmd_fn'}; {'id': '108', 'type': 'binary_operator', 'children': ['109', '110'], 'value': '+'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '110', 'type': 'string', 'children': [], 'value': "'\\n'"}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'modified_cmd'}; {'id': '112', 'type': 'binary_operator', 'children': ['113', '136', '145'], 'value': '+'}, {'id': '113', 'type': 'binary_operator', 'children': ['114', '135'], 'value': '+'}; {'id': '114', 'type': 'attribute', 'children': ['115', '131', '134']}, {'id': '115', 'type': 'call', 'children': ['116', '130']}; {'id': '116', 'type': 'attribute', 'children': ['117', '126', '129']}, {'id': '117', 'type': 'call', 'children': ['118', '124']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120', '123']}, {'id': '119', 'type': 'string', 'children': [], 'value': "f'{cmd} > >(tee -a {self._out_fn}) 2> >(tee -a {self._out_fn} >&2); echo $? > {self._status_fn}'"}; {'id': '120', 'type': 'ERROR', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'modified_cmd'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'shlex'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'quote'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'modified_cmd'}; {'id': '126', 'type': 'ERROR', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'start_time'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '130', 'type': 'argument_list', 'children': []}, {'id': '131', 'type': 'ERROR', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'tmux_window'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'tmux_session'}, {'id': '135', 'type': 'string', 'children': [], 'value': "':'"}; {'id': '136', 'type': 'ERROR', 'children': ['137', '143', '144']}, {'id': '137', 'type': 'call', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'tmux_window_id'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'tmux_cmd'}; {'id': '144', 'type': 'string', 'children': [], 'value': 'f"tmux send-keys -t {tmux_window} {modified_cmd} Enter"'}, {'id': '145', 'type': 'call', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': '_run_raw'}, {'id': '149', 'type': 'argument_list', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'tmux_cmd'}, {'id': '151', 'type': 'keyword_argument', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'ignore_errors'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'ignore_errors'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'non_blocking'}, {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'return_statement', 'children': ['157']}, {'id': '157', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '158', 'type': 'if_statement', 'children': ['159', '171']}, {'id': '159', 'type': 'not_operator', 'children': ['160']}; {'id': '160', 'type': 'call', 'children': ['161', '164']}, {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'wait_for_file'}; {'id': '164', 'type': 'argument_list', 'children': ['165', '168']}, {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': '_status_fn'}; {'id': '168', 'type': 'keyword_argument', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'max_wait_sec'}; {'id': '170', 'type': 'integer', 'children': [], 'value': '60'}, {'id': '171', 'type': 'block', 'children': ['172']}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'call', 'children': ['174', '177']}; {'id': '174', 'type': 'attribute', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'log'}, {'id': '177', 'type': 'argument_list', 'children': ['178']}; {'id': '178', 'type': 'string', 'children': [], 'value': 'f"Retrying waiting for {self._status_fn}"'}, {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'elapsed_time'}; {'id': '182', 'type': 'binary_operator', 'children': ['183', '188'], 'value': '-'}, {'id': '183', 'type': 'call', 'children': ['184', '187']}; {'id': '184', 'type': 'attribute', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '187', 'type': 'argument_list', 'children': []}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'start_time'}, {'id': '189', 'type': 'while_statement', 'children': ['190', '203']}; {'id': '190', 'type': 'boolean_operator', 'children': ['191', '200'], 'value': 'and'}, {'id': '191', 'type': 'not_operator', 'children': ['192']}; {'id': '192', 'type': 'call', 'children': ['193', '196']}, {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '196', 'type': 'argument_list', 'children': ['197']}, {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': '_status_fn'}; {'id': '200', 'type': 'comparison_operator', 'children': ['201', '202'], 'value': '<'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'elapsed_time'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'max_wait_sec'}, {'id': '203', 'type': 'block', 'children': ['204', '211', '223']}; {'id': '204', 'type': 'expression_statement', 'children': ['205']}, {'id': '205', 'type': 'call', 'children': ['206', '209']}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'log'}, {'id': '209', 'type': 'argument_list', 'children': ['210']}; {'id': '210', 'type': 'string', 'children': [], 'value': 'f"Still waiting for {cmd}"'}, {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'call', 'children': ['213', '216']}, {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'wait_for_file'}; {'id': '216', 'type': 'argument_list', 'children': ['217', '220']}, {'id': '217', 'type': 'attribute', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': '_status_fn'}; {'id': '220', 'type': 'keyword_argument', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'max_wait_sec'}; {'id': '222', 'type': 'integer', 'children': [], 'value': '60'}, {'id': '223', 'type': 'expression_statement', 'children': ['224']}; {'id': '224', 'type': 'assignment', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'elapsed_time'}; {'id': '226', 'type': 'binary_operator', 'children': ['227', '232'], 'value': '-'}, {'id': '227', 'type': 'call', 'children': ['228', '231']}; {'id': '228', 'type': 'attribute', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '231', 'type': 'argument_list', 'children': []}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'start_time'}, {'id': '233', 'type': 'expression_statement', 'children': ['234']}; {'id': '234', 'type': 'assignment', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'contents'}; {'id': '236', 'type': 'call', 'children': ['237', '240']}, {'id': '237', 'type': 'attribute', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '240', 'type': 'argument_list', 'children': ['241']}, {'id': '241', 'type': 'attribute', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': '_status_fn'}; {'id': '244', 'type': 'if_statement', 'children': ['245', '251']}, {'id': '245', 'type': 'comparison_operator', 'children': ['246', '250'], 'value': '=='}; {'id': '246', 'type': 'call', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '248', 'type': 'argument_list', 'children': ['249']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'contents'}; {'id': '250', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '251', 'type': 'block', 'children': ['252', '259']}; {'id': '252', 'type': 'expression_statement', 'children': ['253']}, {'id': '253', 'type': 'call', 'children': ['254', '257']}; {'id': '254', 'type': 'attribute', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'sleep'}, {'id': '257', 'type': 'argument_list', 'children': ['258']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'check_interval'}, {'id': '259', 'type': 'expression_statement', 'children': ['260']}; {'id': '260', 'type': 'assignment', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'contents'}; {'id': '262', 'type': 'call', 'children': ['263', '266']}, {'id': '263', 'type': 'attribute', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '266', 'type': 'argument_list', 'children': ['267']}, {'id': '267', 'type': 'attribute', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': '_status_fn'}; {'id': '270', 'type': 'expression_statement', 'children': ['271']}, {'id': '271', 'type': 'assignment', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'status'}, {'id': '273', 'type': 'call', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '275', 'type': 'argument_list', 'children': ['276']}; {'id': '276', 'type': 'call', 'children': ['277', '280']}, {'id': '277', 'type': 'attribute', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'contents'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '280', 'type': 'argument_list', 'children': []}, {'id': '281', 'type': 'expression_statement', 'children': ['282']}; {'id': '282', 'type': 'assignment', 'children': ['283', '286']}, {'id': '283', 'type': 'attribute', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'last_status'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'status'}, {'id': '287', 'type': 'if_statement', 'children': ['288', '291']}; {'id': '288', 'type': 'comparison_operator', 'children': ['289', '290'], 'value': '!='}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '290', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '291', 'type': 'block', 'children': ['292', '299', '306', '313']}; {'id': '292', 'type': 'expression_statement', 'children': ['293']}, {'id': '293', 'type': 'assignment', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'extra_msg'}, {'id': '295', 'type': 'conditional_expression', 'children': ['296', '297', '298'], 'value': 'if'}; {'id': '296', 'type': 'string', 'children': [], 'value': "'(ignoring error)'"}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'ignore_errors'}; {'id': '298', 'type': 'string', 'children': [], 'value': "'(failing)'"}, {'id': '299', 'type': 'expression_statement', 'children': ['300']}; {'id': '300', 'type': 'call', 'children': ['301', '304']}, {'id': '301', 'type': 'attribute', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '304', 'type': 'argument_list', 'children': ['305']}, {'id': '305', 'type': 'string', 'children': [], 'value': 'f"Start failing output {extra_msg}: \\n{\'*\'*80}\\n\\n \'{self.read(self._out_fn)}\'"'}; {'id': '306', 'type': 'expression_statement', 'children': ['307']}, {'id': '307', 'type': 'call', 'children': ['308', '311']}; {'id': '308', 'type': 'attribute', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'log'}, {'id': '311', 'type': 'argument_list', 'children': ['312']}; {'id': '312', 'type': 'string', 'children': [], 'value': 'f"\\n{\'*\'*80}\\nEnd failing output"'}, {'id': '313', 'type': 'if_statement', 'children': ['314', '316', '322']}; {'id': '314', 'type': 'not_operator', 'children': ['315']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'ignore_errors'}; {'id': '316', 'type': 'block', 'children': ['317']}, {'id': '317', 'type': 'raise_statement', 'children': ['318']}; {'id': '318', 'type': 'call', 'children': ['319', '320']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'}; {'id': '320', 'type': 'argument_list', 'children': ['321']}, {'id': '321', 'type': 'string', 'children': [], 'value': 'f"Command {cmd} returned status {status}"'}; {'id': '322', 'type': 'else_clause', 'children': ['323']}, {'id': '323', 'type': 'block', 'children': ['324']}; {'id': '324', 'type': 'expression_statement', 'children': ['325']}, {'id': '325', 'type': 'call', 'children': ['326', '329']}; {'id': '326', 'type': 'attribute', 'children': ['327', '328']}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'log'}, {'id': '329', 'type': 'argument_list', 'children': ['330']}; {'id': '330', 'type': 'string', 'children': [], 'value': 'f"Warning: command {cmd} returned status {status}"'}, {'id': '331', 'type': 'return_statement', 'children': ['332']}; {'id': '332', 'type': 'call', 'children': ['333', '336']}, {'id': '333', 'type': 'attribute', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '336', 'type': 'argument_list', 'children': ['337']}, {'id': '337', 'type': 'attribute', 'children': ['338', '339']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '339', 'type': 'identifier', 'children': [], 'value': '_out_fn'} | def _run_with_output_on_failure(self, cmd, non_blocking=False,
ignore_errors=False,
max_wait_sec=365 * 24 * 3600,
check_interval=0.2) -> str:
if not self._can_run:
assert False, "Using .run before initialization finished"
if '\n' in cmd:
assert False, "Don't support multi-line for run2"
cmd = cmd.strip()
if cmd.startswith('
return ''
self.run_counter += 1
self.log("tmux> %s", cmd)
self._cmd = cmd
self._cmd_fn = f'{self.remote_scratch}/{self.run_counter}.cmd'
self._status_fn = f'{self.remote_scratch}/{self.run_counter}.status'
self._out_fn = f'{self.remote_scratch}/{self.run_counter}.out'
cmd = util.shell_strip_comment(cmd)
assert '&' not in cmd, f"cmd {cmd} contains &, that breaks things"
self.file_write(self._cmd_fn, cmd + '\n')
modified_cmd = f'{cmd} > >(tee -a {self._out_fn}) 2> >(tee -a {self._out_fn} >&2); echo $? > {self._status_fn}'
modified_cmd = shlex.quote(modified_cmd)
start_time = time.time()
tmux_window = self.tmux_session + ':' + str(self.tmux_window_id)
tmux_cmd = f"tmux send-keys -t {tmux_window} {modified_cmd} Enter"
self._run_raw(tmux_cmd, ignore_errors=ignore_errors)
if non_blocking:
return 0
if not self.wait_for_file(self._status_fn, max_wait_sec=60):
self.log(f"Retrying waiting for {self._status_fn}")
elapsed_time = time.time() - start_time
while not self.exists(self._status_fn) and elapsed_time < max_wait_sec:
self.log(f"Still waiting for {cmd}")
self.wait_for_file(self._status_fn, max_wait_sec=60)
elapsed_time = time.time() - start_time
contents = self.read(self._status_fn)
if len(contents) == 0:
time.sleep(check_interval)
contents = self.read(self._status_fn)
status = int(contents.strip())
self.last_status = status
if status != 0:
extra_msg = '(ignoring error)' if ignore_errors else '(failing)'
self.log(
f"Start failing output {extra_msg}: \n{'*'*80}\n\n '{self.read(self._out_fn)}'")
self.log(f"\n{'*'*80}\nEnd failing output")
if not ignore_errors:
raise RuntimeError(f"Command {cmd} returned status {status}")
else:
self.log(f"Warning: command {cmd} returned status {status}")
return self.read(self._out_fn) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19', '21']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'upload'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '9', '14']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'typed_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'local_fn'}, {'id': '7', 'type': 'type', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '9', 'type': 'typed_default_parameter', 'children': ['10', '11', '13']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'remote_fn'}, {'id': '11', 'type': 'type', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '13', 'type': 'string', 'children': [], 'value': "''"}; {'id': '14', 'type': 'typed_default_parameter', 'children': ['15', '16', '18']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'dont_overwrite'}; {'id': '16', 'type': 'type', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '18', 'type': 'False', 'children': []}, {'id': '19', 'type': 'type', 'children': ['20']}; {'id': '20', 'type': 'None', 'children': []}, {'id': '21', 'type': 'block', 'children': ['22', '44', '75', '121', '262', '277', '290', '302', '326', '347', '357']}; {'id': '22', 'type': 'if_statement', 'children': ['23', '26']}, {'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': 'in'}; {'id': '24', 'type': 'string', 'children': [], 'value': "'*'"}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'local_fn'}; {'id': '26', 'type': 'block', 'children': ['27', '43']}, {'id': '27', 'type': 'for_statement', 'children': ['28', '29', '35']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'local_subfn'}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'glob'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'local_fn'}, {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'upload'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'local_subfn'}, {'id': '43', 'type': 'return_statement', 'children': []}; {'id': '44', 'type': 'if_statement', 'children': ['45', '52', '53', '58']}, {'id': '45', 'type': 'ERROR', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'string', 'children': [], 'value': '"skipping backup file {local_fn}"'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'return'}, {'id': '53', 'type': 'ERROR', 'children': ['54']}; {'id': '54', 'type': 'not_operator', 'children': ['55']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'sftp'}; {'id': '58', 'type': 'block', 'children': ['59']}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'sftp'}; {'id': '64', 'type': 'call', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'u'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'call_with_retries'}; {'id': '68', 'type': 'argument_list', 'children': ['69', '74']}, {'id': '69', 'type': 'attribute', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'ssh_client'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'open_sftp'}; {'id': '74', 'type': 'string', 'children': [], 'value': "'self.ssh_client.open_sftp'"}, {'id': '75', 'type': 'function_definition', 'children': ['76', '77', '80']}; {'id': '76', 'type': 'function_name', 'children': [], 'value': 'maybe_fix_mode'}, {'id': '77', 'type': 'parameters', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'local_fn_'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'remote_fn_'}; {'id': '80', 'type': 'block', 'children': ['81', '102']}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '84', 'type': 'subscript', 'children': ['85', '98']}, {'id': '85', 'type': 'call', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'oct'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'subscript', 'children': ['89', '95']}, {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'stat'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'local_fn_'}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'stat'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'ST_MODE'}; {'id': '98', 'type': 'slice', 'children': ['99', '101']}, {'id': '99', 'type': 'unary_operator', 'children': ['100'], 'value': '-'}; {'id': '100', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '101', 'type': 'colon', 'children': []}; {'id': '102', 'type': 'if_statement', 'children': ['103', '106']}, {'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': 'in'}; {'id': '104', 'type': 'string', 'children': [], 'value': "'7'"}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '106', 'type': 'block', 'children': ['107', '114']}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'call', 'children': ['109', '112']}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'string', 'children': [], 'value': 'f"Making {remote_fn_} executable with mode {mode}"'}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'call', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': '_run_raw'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'string', 'children': [], 'value': 'f"chmod {mode} {remote_fn_}"'}, {'id': '121', 'type': 'function_definition', 'children': ['122', '123', '126']}; {'id': '122', 'type': 'function_name', 'children': [], 'value': '_put_dir'}, {'id': '123', 'type': 'parameters', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'source'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '126', 'type': 'block', 'children': ['127', '160', '169', '174']}, {'id': '127', 'type': 'function_definition', 'children': ['128', '129', '137']}; {'id': '128', 'type': 'function_name', 'children': [], 'value': '_safe_mkdir'}, {'id': '129', 'type': 'parameters', 'children': ['130', '131', '134']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '131', 'type': 'default_parameter', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'mode'}, {'id': '133', 'type': 'integer', 'children': [], 'value': '511'}; {'id': '134', 'type': 'default_parameter', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'ignore_existing'}; {'id': '136', 'type': 'True', 'children': []}, {'id': '137', 'type': 'block', 'children': ['138']}; {'id': '138', 'type': 'try_statement', 'children': ['139', '150']}, {'id': '139', 'type': 'block', 'children': ['140']}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'call', 'children': ['142', '147']}; {'id': '142', 'type': 'attribute', 'children': ['143', '146']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'sftp'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'mkdir'}, {'id': '147', 'type': 'argument_list', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'mode'}; {'id': '150', 'type': 'except_clause', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'IOError'}; {'id': '152', 'type': 'block', 'children': ['153']}, {'id': '153', 'type': 'if_statement', 'children': ['154', '155', '157']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'ignore_existing'}, {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'pass_statement', 'children': []}, {'id': '157', 'type': 'else_clause', 'children': ['158']}; {'id': '158', 'type': 'block', 'children': ['159']}, {'id': '159', 'type': 'raise_statement', 'children': []}; {'id': '160', 'type': 'assert_statement', 'children': ['161']}, {'id': '161', 'type': 'call', 'children': ['162', '167']}; {'id': '162', 'type': 'attribute', 'children': ['163', '166']}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'isdir'}, {'id': '167', 'type': 'argument_list', 'children': ['168']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'source'}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'call', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': '_safe_mkdir'}; {'id': '172', 'type': 'argument_list', 'children': ['173']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '174', 'type': 'for_statement', 'children': ['175', '176', '182']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '176', 'type': 'call', 'children': ['177', '180']}, {'id': '177', 'type': 'attribute', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'listdir'}; {'id': '180', 'type': 'argument_list', 'children': ['181']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '182', 'type': 'block', 'children': ['183']}, {'id': '183', 'type': 'if_statement', 'children': ['184', '200', '249']}; {'id': '184', 'type': 'call', 'children': ['185', '190']}, {'id': '185', 'type': 'attribute', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'isfile'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}, {'id': '191', 'type': 'call', 'children': ['192', '197']}; {'id': '192', 'type': 'attribute', 'children': ['193', '196']}, {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '197', 'type': 'argument_list', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'source'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '200', 'type': 'block', 'children': ['201', '227']}, {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'call', 'children': ['203', '208']}, {'id': '203', 'type': 'attribute', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'sftp'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'put'}; {'id': '208', 'type': 'argument_list', 'children': ['209', '218']}, {'id': '209', 'type': 'call', 'children': ['210', '215']}; {'id': '210', 'type': 'attribute', 'children': ['211', '214']}, {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '215', 'type': 'argument_list', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'source'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '218', 'type': 'call', 'children': ['219', '224']}, {'id': '219', 'type': 'attribute', 'children': ['220', '223']}; {'id': '220', 'type': 'attribute', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '224', 'type': 'argument_list', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'call', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'maybe_fix_mode'}; {'id': '230', 'type': 'argument_list', 'children': ['231', '240']}, {'id': '231', 'type': 'call', 'children': ['232', '237']}; {'id': '232', 'type': 'attribute', 'children': ['233', '236']}, {'id': '233', 'type': 'attribute', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '237', 'type': 'argument_list', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'source'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '240', 'type': 'call', 'children': ['241', '246']}, {'id': '241', 'type': 'attribute', 'children': ['242', '245']}; {'id': '242', 'type': 'attribute', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '246', 'type': 'argument_list', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '249', 'type': 'else_clause', 'children': ['250']}; {'id': '250', 'type': 'block', 'children': ['251', '256']}, {'id': '251', 'type': 'expression_statement', 'children': ['252']}; {'id': '252', 'type': 'call', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': '_safe_mkdir'}; {'id': '254', 'type': 'argument_list', 'children': ['255']}, {'id': '255', 'type': 'string', 'children': [], 'value': "f'{target}/{item}'"}; {'id': '256', 'type': 'expression_statement', 'children': ['257']}, {'id': '257', 'type': 'call', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': '_put_dir'}, {'id': '259', 'type': 'argument_list', 'children': ['260', '261']}; {'id': '260', 'type': 'string', 'children': [], 'value': "f'{source}/{item}'"}, {'id': '261', 'type': 'string', 'children': [], 'value': "f'{target}/{item}'"}; {'id': '262', 'type': 'if_statement', 'children': ['263', '265']}, {'id': '263', 'type': 'not_operator', 'children': ['264']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'remote_fn'}, {'id': '265', 'type': 'block', 'children': ['266']}; {'id': '266', 'type': 'expression_statement', 'children': ['267']}, {'id': '267', 'type': 'assignment', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'remote_fn'}, {'id': '269', 'type': 'call', 'children': ['270', '275']}; {'id': '270', 'type': 'attribute', 'children': ['271', '274']}, {'id': '271', 'type': 'attribute', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'basename'}, {'id': '275', 'type': 'argument_list', 'children': ['276']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'local_fn'}, {'id': '277', 'type': 'expression_statement', 'children': ['278']}; {'id': '278', 'type': 'call', 'children': ['279', '282']}, {'id': '279', 'type': 'attribute', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'log'}; {'id': '282', 'type': 'argument_list', 'children': ['283']}, {'id': '283', 'type': 'binary_operator', 'children': ['284', '289'], 'value': '+'}; {'id': '284', 'type': 'binary_operator', 'children': ['285', '288'], 'value': '+'}, {'id': '285', 'type': 'binary_operator', 'children': ['286', '287'], 'value': '+'}; {'id': '286', 'type': 'string', 'children': [], 'value': "'uploading '"}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'local_fn'}; {'id': '288', 'type': 'string', 'children': [], 'value': "' to '"}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'remote_fn'}; {'id': '290', 'type': 'expression_statement', 'children': ['291']}, {'id': '291', 'type': 'assignment', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'remote_fn'}, {'id': '293', 'type': 'call', 'children': ['294', '297']}; {'id': '294', 'type': 'attribute', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'remote_fn'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'replace'}, {'id': '297', 'type': 'argument_list', 'children': ['298', '299']}; {'id': '298', 'type': 'string', 'children': [], 'value': "'~'"}, {'id': '299', 'type': 'attribute', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'homedir'}; {'id': '302', 'type': 'if_statement', 'children': ['303', '306']}, {'id': '303', 'type': 'comparison_operator', 'children': ['304', '305'], 'value': 'in'}; {'id': '304', 'type': 'string', 'children': [], 'value': "'/'"}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'remote_fn'}; {'id': '306', 'type': 'block', 'children': ['307', '318']}, {'id': '307', 'type': 'expression_statement', 'children': ['308']}; {'id': '308', 'type': 'assignment', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'remote_dir'}; {'id': '310', 'type': 'call', 'children': ['311', '316']}, {'id': '311', 'type': 'attribute', 'children': ['312', '315']}; {'id': '312', 'type': 'attribute', 'children': ['313', '314']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'dirname'}; {'id': '316', 'type': 'argument_list', 'children': ['317']}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'remote_fn'}; {'id': '318', 'type': 'assert_statement', 'children': ['319', '325']}, {'id': '319', 'type': 'call', 'children': ['320', '323']}; {'id': '320', 'type': 'attribute', 'children': ['321', '322']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'exists'}, {'id': '323', 'type': 'argument_list', 'children': ['324']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'remote_dir'}, {'id': '325', 'type': 'string', 'children': [], 'value': 'f"Remote dir {remote_dir} doesn\'t exist"'}; {'id': '326', 'type': 'if_statement', 'children': ['327', '335']}, {'id': '327', 'type': 'boolean_operator', 'children': ['328', '329'], 'value': 'and'}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'dont_overwrite'}, {'id': '329', 'type': 'call', 'children': ['330', '333']}; {'id': '330', 'type': 'attribute', 'children': ['331', '332']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'exists'}, {'id': '333', 'type': 'argument_list', 'children': ['334']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'remote_fn'}, {'id': '335', 'type': 'block', 'children': ['336', '346']}; {'id': '336', 'type': 'expression_statement', 'children': ['337']}, {'id': '337', 'type': 'call', 'children': ['338', '341']}; {'id': '338', 'type': 'attribute', 'children': ['339', '340']}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'log'}, {'id': '341', 'type': 'argument_list', 'children': ['342']}; {'id': '342', 'type': 'binary_operator', 'children': ['343', '344'], 'value': '%'}, {'id': '343', 'type': 'string', 'children': [], 'value': '"Remote file %s exists, skipping"'}; {'id': '344', 'type': 'tuple', 'children': ['345']}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'remote_fn'}; {'id': '346', 'type': 'return_statement', 'children': []}, {'id': '347', 'type': 'assert_statement', 'children': ['348', '356']}; {'id': '348', 'type': 'call', 'children': ['349', '354']}, {'id': '349', 'type': 'attribute', 'children': ['350', '353']}; {'id': '350', 'type': 'attribute', 'children': ['351', '352']}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '354', 'type': 'argument_list', 'children': ['355']}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'local_fn'}; {'id': '356', 'type': 'string', 'children': [], 'value': 'f"{local_fn} not found"'}, {'id': '357', 'type': 'if_statement', 'children': ['358', '366', '373']}; {'id': '358', 'type': 'call', 'children': ['359', '364']}, {'id': '359', 'type': 'attribute', 'children': ['360', '363']}; {'id': '360', 'type': 'attribute', 'children': ['361', '362']}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '364', 'type': 'argument_list', 'children': ['365']}, {'id': '365', 'type': 'identifier', 'children': [], 'value': 'local_fn'}; {'id': '366', 'type': 'block', 'children': ['367']}, {'id': '367', 'type': 'expression_statement', 'children': ['368']}; {'id': '368', 'type': 'call', 'children': ['369', '370']}, {'id': '369', 'type': 'identifier', 'children': [], 'value': '_put_dir'}; {'id': '370', 'type': 'argument_list', 'children': ['371', '372']}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'local_fn'}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'remote_fn'}, {'id': '373', 'type': 'else_clause', 'children': ['374']}; {'id': '374', 'type': 'block', 'children': ['375', '388', '418', '432']}, {'id': '375', 'type': 'assert_statement', 'children': ['376', '384']}; {'id': '376', 'type': 'call', 'children': ['377', '382']}, {'id': '377', 'type': 'attribute', 'children': ['378', '381']}; {'id': '378', 'type': 'attribute', 'children': ['379', '380']}, {'id': '379', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '381', 'type': 'identifier', 'children': [], 'value': 'isfile'}; {'id': '382', 'type': 'argument_list', 'children': ['383']}, {'id': '383', 'type': 'identifier', 'children': [], 'value': 'local_fn'}; {'id': '384', 'type': 'binary_operator', 'children': ['385', '386'], 'value': '%'}, {'id': '385', 'type': 'string', 'children': [], 'value': '"%s is not a file"'}; {'id': '386', 'type': 'tuple', 'children': ['387']}, {'id': '387', 'type': 'identifier', 'children': [], 'value': 'local_fn'}; {'id': '388', 'type': 'if_statement', 'children': ['389', '402']}, {'id': '389', 'type': 'boolean_operator', 'children': ['390', '396'], 'value': 'and'}; {'id': '390', 'type': 'call', 'children': ['391', '394']}, {'id': '391', 'type': 'attribute', 'children': ['392', '393']}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '393', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '394', 'type': 'argument_list', 'children': ['395']}, {'id': '395', 'type': 'identifier', 'children': [], 'value': 'remote_fn'}; {'id': '396', 'type': 'call', 'children': ['397', '400']}, {'id': '397', 'type': 'attribute', 'children': ['398', '399']}; {'id': '398', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '399', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '400', 'type': 'argument_list', 'children': ['401']}, {'id': '401', 'type': 'identifier', 'children': [], 'value': 'remote_fn'}; {'id': '402', 'type': 'block', 'children': ['403']}, {'id': '403', 'type': 'expression_statement', 'children': ['404']}; {'id': '404', 'type': 'assignment', 'children': ['405', '406']}, {'id': '405', 'type': 'identifier', 'children': [], 'value': 'remote_fn'}; {'id': '406', 'type': 'binary_operator', 'children': ['407', '410'], 'value': '+'}, {'id': '407', 'type': 'binary_operator', 'children': ['408', '409'], 'value': '+'}; {'id': '408', 'type': 'identifier', 'children': [], 'value': 'remote_fn'}, {'id': '409', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '410', 'type': 'call', 'children': ['411', '416']}, {'id': '411', 'type': 'attribute', 'children': ['412', '415']}; {'id': '412', 'type': 'attribute', 'children': ['413', '414']}, {'id': '413', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '414', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '415', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '416', 'type': 'argument_list', 'children': ['417']}, {'id': '417', 'type': 'identifier', 'children': [], 'value': 'local_fn'}; {'id': '418', 'type': 'expression_statement', 'children': ['419']}, {'id': '419', 'type': 'call', 'children': ['420', '425']}; {'id': '420', 'type': 'attribute', 'children': ['421', '424']}, {'id': '421', 'type': 'attribute', 'children': ['422', '423']}; {'id': '422', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '423', 'type': 'identifier', 'children': [], 'value': 'sftp'}; {'id': '424', 'type': 'identifier', 'children': [], 'value': 'put'}, {'id': '425', 'type': 'argument_list', 'children': ['426', '429']}; {'id': '426', 'type': 'keyword_argument', 'children': ['427', '428']}, {'id': '427', 'type': 'identifier', 'children': [], 'value': 'localpath'}; {'id': '428', 'type': 'identifier', 'children': [], 'value': 'local_fn'}, {'id': '429', 'type': 'keyword_argument', 'children': ['430', '431']}; {'id': '430', 'type': 'identifier', 'children': [], 'value': 'remotepath'}, {'id': '431', 'type': 'identifier', 'children': [], 'value': 'remote_fn'}; {'id': '432', 'type': 'expression_statement', 'children': ['433']}, {'id': '433', 'type': 'call', 'children': ['434', '435']}; {'id': '434', 'type': 'identifier', 'children': [], 'value': 'maybe_fix_mode'}, {'id': '435', 'type': 'argument_list', 'children': ['436', '437']}; {'id': '436', 'type': 'identifier', 'children': [], 'value': 'local_fn'}, {'id': '437', 'type': 'identifier', 'children': [], 'value': 'remote_fn'} | def upload(self, local_fn: str, remote_fn: str = '',
dont_overwrite: bool = False) -> None:
if '*' in local_fn:
for local_subfn in glob.glob(local_fn):
self.upload(local_subfn)
return
if '
self.log("skipping backup file {local_fn}")
return
if not self.sftp:
self.sftp = u.call_with_retries(self.ssh_client.open_sftp,
'self.ssh_client.open_sftp')
def maybe_fix_mode(local_fn_, remote_fn_):
mode = oct(os.stat(local_fn_)[stat.ST_MODE])[-3:]
if '7' in mode:
self.log(f"Making {remote_fn_} executable with mode {mode}")
self._run_raw(f"chmod {mode} {remote_fn_}")
def _put_dir(source, target):
def _safe_mkdir(path, mode=511, ignore_existing=True):
try:
self.sftp.mkdir(path, mode)
except IOError:
if ignore_existing:
pass
else:
raise
assert os.path.isdir(source)
_safe_mkdir(target)
for item in os.listdir(source):
if os.path.isfile(os.path.join(source, item)):
self.sftp.put(os.path.join(source, item), os.path.join(target, item))
maybe_fix_mode(os.path.join(source, item), os.path.join(target, item))
else:
_safe_mkdir(f'{target}/{item}')
_put_dir(f'{source}/{item}', f'{target}/{item}')
if not remote_fn:
remote_fn = os.path.basename(local_fn)
self.log('uploading ' + local_fn + ' to ' + remote_fn)
remote_fn = remote_fn.replace('~', self.homedir)
if '/' in remote_fn:
remote_dir = os.path.dirname(remote_fn)
assert self.exists(
remote_dir), f"Remote dir {remote_dir} doesn't exist"
if dont_overwrite and self.exists(remote_fn):
self.log("Remote file %s exists, skipping" % (remote_fn,))
return
assert os.path.exists(local_fn), f"{local_fn} not found"
if os.path.isdir(local_fn):
_put_dir(local_fn, remote_fn)
else:
assert os.path.isfile(local_fn), "%s is not a file" % (local_fn,)
if self.exists(remote_fn) and self.isdir(remote_fn):
remote_fn = remote_fn + '/' + os.path.basename(local_fn)
self.sftp.put(localpath=local_fn, remotepath=remote_fn)
maybe_fix_mode(local_fn, remote_fn) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_child_fn'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'bases'}, {'id': '7', 'type': 'block', 'children': ['8', '51', '57', '83', '89', '105']}; {'id': '8', 'type': 'function_definition', 'children': ['9', '10', '13']}, {'id': '9', 'type': 'function_name', 'children': [], 'value': 'call_method'}; {'id': '10', 'type': 'parameters', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '13', 'type': 'block', 'children': ['14', '41']}; {'id': '14', 'type': 'if_statement', 'children': ['15', '20', '29']}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '17', 'type': 'argument_list', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '20', 'type': 'block', 'children': ['21', '25']}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '24', 'type': 'None', 'children': []}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'owner'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '29', 'type': 'else_clause', 'children': ['30']}; {'id': '30', 'type': 'block', 'children': ['31', '35']}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'owner'}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': '__class__'}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '50']}, {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': '__get__'}, {'id': '47', 'type': 'argument_list', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'instance'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'owner'}; {'id': '50', 'type': 'argument_list', 'children': []}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'default_name'}; {'id': '54', 'type': 'subscript', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '56', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '57', 'type': 'function_definition', 'children': ['58', '59', '61']}; {'id': '58', 'type': 'function_name', 'children': [], 'value': 'default_fn'}, {'id': '59', 'type': 'parameters', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'for_statement', 'children': ['63', '64', '65']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'bases'}, {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'if_statement', 'children': ['67', '72']}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '69', 'type': 'argument_list', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'default_name'}; {'id': '72', 'type': 'block', 'children': ['73']}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'call_method'}; {'id': '76', 'type': 'argument_list', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '78', 'type': 'call', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '80', 'type': 'argument_list', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'default_name'}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'default_fn'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'default_name'}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'fns'}; {'id': '92', 'type': 'list_comprehension', 'children': ['93', '98', '101']}, {'id': '93', 'type': 'tuple', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '95', 'type': 'subscript', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '98', 'type': 'for_in_clause', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'names'}, {'id': '101', 'type': 'if_clause', 'children': ['102']}; {'id': '102', 'type': 'comparison_operator', 'children': ['103', '104'], 'value': 'in'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'attrs'}, {'id': '105', 'type': 'if_statement', 'children': ['106', '112', '118', '153']}; {'id': '106', 'type': 'comparison_operator', 'children': ['107', '111'], 'value': '>'}, {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'fns'}, {'id': '111', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '112', 'type': 'block', 'children': ['113']}, {'id': '113', 'type': 'raise_statement', 'children': ['114']}; {'id': '114', 'type': 'call', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'}; {'id': '116', 'type': 'argument_list', 'children': ['117']}, {'id': '117', 'type': 'string', 'children': [], 'value': '"Cannot have more than one setup or teardown method per context (class or test)."'}; {'id': '118', 'type': 'elif_clause', 'children': ['119', '125']}, {'id': '119', 'type': 'comparison_operator', 'children': ['120', '124'], 'value': '=='}; {'id': '120', 'type': 'call', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'fns'}; {'id': '124', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '125', 'type': 'block', 'children': ['126', '134', '145', '151']}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}, {'id': '127', 'type': 'assignment', 'children': ['128', '131']}; {'id': '128', 'type': 'pattern_list', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'fn'}, {'id': '131', 'type': 'subscript', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'fns'}, {'id': '133', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '134', 'type': 'function_definition', 'children': ['135', '136', '138']}, {'id': '135', 'type': 'function_name', 'children': [], 'value': 'child_fn'}; {'id': '136', 'type': 'parameters', 'children': ['137']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '138', 'type': 'block', 'children': ['139']}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'call', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'call_method'}; {'id': '142', 'type': 'argument_list', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'fn'}, {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'assignment', 'children': ['147', '150']}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'child_fn'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '151', 'type': 'return_statement', 'children': ['152']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'child_fn'}, {'id': '153', 'type': 'else_clause', 'children': ['154']}; {'id': '154', 'type': 'block', 'children': ['155']}, {'id': '155', 'type': 'return_statement', 'children': ['156']} | def get_child_fn(attrs, names, bases):
def call_method(obj, method):
if isinstance(obj, type):
instance = None
owner = obj
else:
instance = obj
owner = obj.__class__
method.__get__(instance, owner)()
default_name = names[0]
def default_fn(obj):
for cls in bases:
if hasattr(cls, default_name):
call_method(obj, getattr(cls, default_name))
default_fn.__name__ = default_name
fns = [(name, attrs[name]) for name in names if name in attrs]
if len(fns) > 1:
raise RuntimeError("Cannot have more than one setup or teardown method per context (class or test).")
elif len(fns) == 1:
name, fn = fns[0]
def child_fn(obj):
call_method(obj, fn)
child_fn.__name__ = name
return child_fn
else:
return default_fn |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '20']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'authenticate'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'username'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'password'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'actions'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'authorization'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21', '60', '67', '92', '103', '116', '169', '366', '372']}, {'id': '21', 'type': 'if_statement', 'children': ['22', '25']}; {'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'is'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '24', 'type': 'None', 'children': []}, {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'with_statement', 'children': ['27', '34']}, {'id': '27', 'type': 'with_clause', 'children': ['28']}; {'id': '28', 'type': 'with_item', 'children': ['29']}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'warnings'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'catch_warnings'}, {'id': '33', 'type': 'argument_list', 'children': []}; {'id': '34', 'type': 'block', 'children': ['35', '40']}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': '_ignore_warnings'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '43', 'type': 'call', 'children': ['44', '51']}; {'id': '44', 'type': 'attribute', 'children': ['45', '50']}, {'id': '45', 'type': 'subscript', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': '_sessions'}, {'id': '49', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '51', 'type': 'argument_list', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': '_base_url'}, {'id': '55', 'type': 'keyword_argument', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'verify'}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': '_tlsverify'}; {'id': '60', 'type': 'if_statement', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'ok'}; {'id': '64', 'type': 'block', 'children': ['65']}, {'id': '65', 'type': 'return_statement', 'children': ['66']}; {'id': '66', 'type': 'None', 'children': []}, {'id': '67', 'type': 'if_statement', 'children': ['68', '77']}; {'id': '68', 'type': 'comparison_operator', 'children': ['69', '72'], 'value': '!='}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'response'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'status_code'}; {'id': '72', 'type': 'attribute', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'requests'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'codes'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'unauthorized'}, {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'raise_statement', 'children': ['79']}, {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'exceptions'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'DXFUnexpectedStatusCodeError'}, {'id': '83', 'type': 'argument_list', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'status_code'}, {'id': '87', 'type': 'attribute', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'requests'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'codes'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'unauthorized'}; {'id': '92', 'type': 'if_statement', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': '_insecure'}; {'id': '96', 'type': 'block', 'children': ['97']}, {'id': '97', 'type': 'raise_statement', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'exceptions'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'DXFAuthInsecureError'}; {'id': '102', 'type': 'argument_list', 'children': []}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'parsed'}; {'id': '106', 'type': 'call', 'children': ['107', '110']}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'www_authenticate'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'parse'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}, {'id': '111', 'type': 'subscript', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'headers'}, {'id': '115', 'type': 'string', 'children': [], 'value': "'www-authenticate'"}; {'id': '116', 'type': 'if_statement', 'children': ['117', '124', '151', '163']}, {'id': '117', 'type': 'boolean_operator', 'children': ['118', '121'], 'value': 'and'}; {'id': '118', 'type': 'comparison_operator', 'children': ['119', '120'], 'value': 'is'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'username'}; {'id': '120', 'type': 'None', 'children': []}, {'id': '121', 'type': 'comparison_operator', 'children': ['122', '123'], 'value': 'is'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'password'}, {'id': '123', 'type': 'None', 'children': []}; {'id': '124', 'type': 'block', 'children': ['125']}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'assignment', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '128', 'type': 'dictionary', 'children': ['129']}, {'id': '129', 'type': 'pair', 'children': ['130', '131']}; {'id': '130', 'type': 'string', 'children': [], 'value': "'Authorization'"}, {'id': '131', 'type': 'binary_operator', 'children': ['132', '133'], 'value': '+'}; {'id': '132', 'type': 'string', 'children': [], 'value': "'Basic '"}, {'id': '133', 'type': 'call', 'children': ['134', '149']}; {'id': '134', 'type': 'attribute', 'children': ['135', '148']}, {'id': '135', 'type': 'call', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'base64'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'b64encode'}, {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'call', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': '_to_bytes_2and3'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}, {'id': '143', 'type': 'binary_operator', 'children': ['144', '147'], 'value': '+'}; {'id': '144', 'type': 'binary_operator', 'children': ['145', '146'], 'value': '+'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'username'}; {'id': '146', 'type': 'string', 'children': [], 'value': "':'"}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'password'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'decode'}, {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'string', 'children': [], 'value': "'utf-8'"}, {'id': '151', 'type': 'elif_clause', 'children': ['152', '155']}; {'id': '152', 'type': 'comparison_operator', 'children': ['153', '154'], 'value': 'is'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'authorization'}; {'id': '154', 'type': 'None', 'children': []}, {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'assignment', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'headers'}, {'id': '159', 'type': 'dictionary', 'children': ['160']}; {'id': '160', 'type': 'pair', 'children': ['161', '162']}, {'id': '161', 'type': 'string', 'children': [], 'value': "'Authorization'"}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'authorization'}, {'id': '163', 'type': 'else_clause', 'children': ['164']}; {'id': '164', 'type': 'block', 'children': ['165']}, {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'assignment', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '168', 'type': 'dictionary', 'children': []}, {'id': '169', 'type': 'if_statement', 'children': ['170', '173']}; {'id': '170', 'type': 'comparison_operator', 'children': ['171', '172'], 'value': 'in'}, {'id': '171', 'type': 'string', 'children': [], 'value': "'bearer'"}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'parsed'}, {'id': '173', 'type': 'block', 'children': ['174', '180', '221', '235', '246', '261', '271', '277', '290', '299', '334', '339', '347', '362']}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}, {'id': '175', 'type': 'assignment', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '177', 'type': 'subscript', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'parsed'}, {'id': '179', 'type': 'string', 'children': [], 'value': "'bearer'"}; {'id': '180', 'type': 'if_statement', 'children': ['181', '186', '204', '215']}, {'id': '181', 'type': 'boolean_operator', 'children': ['182', '183'], 'value': 'and'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'actions'}, {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': '_repo'}; {'id': '186', 'type': 'block', 'children': ['187']}, {'id': '187', 'type': 'expression_statement', 'children': ['188']}; {'id': '188', 'type': 'assignment', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'scope'}; {'id': '190', 'type': 'binary_operator', 'children': ['191', '198'], 'value': '+'}, {'id': '191', 'type': 'binary_operator', 'children': ['192', '197'], 'value': '+'}; {'id': '192', 'type': 'binary_operator', 'children': ['193', '194'], 'value': '+'}, {'id': '193', 'type': 'string', 'children': [], 'value': "'repository:'"}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': '_repo'}, {'id': '197', 'type': 'string', 'children': [], 'value': "':'"}; {'id': '198', 'type': 'call', 'children': ['199', '202']}, {'id': '199', 'type': 'attribute', 'children': ['200', '201']}; {'id': '200', 'type': 'string', 'children': [], 'value': "','"}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '202', 'type': 'argument_list', 'children': ['203']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'actions'}; {'id': '204', 'type': 'elif_clause', 'children': ['205', '208']}, {'id': '205', 'type': 'comparison_operator', 'children': ['206', '207'], 'value': 'in'}; {'id': '206', 'type': 'string', 'children': [], 'value': "'scope'"}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '208', 'type': 'block', 'children': ['209']}, {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'assignment', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'scope'}; {'id': '212', 'type': 'subscript', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '214', 'type': 'string', 'children': [], 'value': "'scope'"}, {'id': '215', 'type': 'else_clause', 'children': ['216']}; {'id': '216', 'type': 'block', 'children': ['217']}, {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'assignment', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'scope'}; {'id': '220', 'type': 'string', 'children': [], 'value': "''"}, {'id': '221', 'type': 'expression_statement', 'children': ['222']}; {'id': '222', 'type': 'assignment', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'url_parts'}; {'id': '224', 'type': 'call', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '226', 'type': 'argument_list', 'children': ['227']}, {'id': '227', 'type': 'call', 'children': ['228', '231']}; {'id': '228', 'type': 'attribute', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'urlparse'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'urlparse'}, {'id': '231', 'type': 'argument_list', 'children': ['232']}; {'id': '232', 'type': 'subscript', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '234', 'type': 'string', 'children': [], 'value': "'realm'"}, {'id': '235', 'type': 'expression_statement', 'children': ['236']}; {'id': '236', 'type': 'assignment', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '238', 'type': 'call', 'children': ['239', '242']}, {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'urlparse'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'parse_qs'}; {'id': '242', 'type': 'argument_list', 'children': ['243']}, {'id': '243', 'type': 'subscript', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'url_parts'}, {'id': '245', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '246', 'type': 'expression_statement', 'children': ['247']}, {'id': '247', 'type': 'call', 'children': ['248', '251']}; {'id': '248', 'type': 'attribute', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '251', 'type': 'argument_list', 'children': ['252']}; {'id': '252', 'type': 'dictionary', 'children': ['253', '258']}, {'id': '253', 'type': 'pair', 'children': ['254', '255']}; {'id': '254', 'type': 'string', 'children': [], 'value': "'service'"}, {'id': '255', 'type': 'subscript', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '257', 'type': 'string', 'children': [], 'value': "'service'"}; {'id': '258', 'type': 'pair', 'children': ['259', '260']}, {'id': '259', 'type': 'string', 'children': [], 'value': "'scope'"}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'scope'}, {'id': '261', 'type': 'expression_statement', 'children': ['262']}; {'id': '262', 'type': 'assignment', 'children': ['263', '266']}, {'id': '263', 'type': 'subscript', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'url_parts'}, {'id': '265', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '266', 'type': 'call', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'urlencode'}; {'id': '268', 'type': 'argument_list', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '270', 'type': 'True', 'children': []}, {'id': '271', 'type': 'expression_statement', 'children': ['272']}; {'id': '272', 'type': 'assignment', 'children': ['273', '276']}, {'id': '273', 'type': 'subscript', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'url_parts'}, {'id': '275', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '276', 'type': 'string', 'children': [], 'value': "'https'"}, {'id': '277', 'type': 'if_statement', 'children': ['278', '281']}; {'id': '278', 'type': 'attribute', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': '_auth_host'}, {'id': '281', 'type': 'block', 'children': ['282']}; {'id': '282', 'type': 'expression_statement', 'children': ['283']}, {'id': '283', 'type': 'assignment', 'children': ['284', '287']}; {'id': '284', 'type': 'subscript', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'url_parts'}; {'id': '286', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '287', 'type': 'attribute', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '289', 'type': 'identifier', 'children': [], 'value': '_auth_host'}; {'id': '290', 'type': 'expression_statement', 'children': ['291']}, {'id': '291', 'type': 'assignment', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'auth_url'}, {'id': '293', 'type': 'call', 'children': ['294', '297']}; {'id': '294', 'type': 'attribute', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'urlparse'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'urlunparse'}, {'id': '297', 'type': 'argument_list', 'children': ['298']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'url_parts'}, {'id': '299', 'type': 'with_statement', 'children': ['300', '307']}; {'id': '300', 'type': 'with_clause', 'children': ['301']}, {'id': '301', 'type': 'with_item', 'children': ['302']}; {'id': '302', 'type': 'call', 'children': ['303', '306']}, {'id': '303', 'type': 'attribute', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'warnings'}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'catch_warnings'}; {'id': '306', 'type': 'argument_list', 'children': []}, {'id': '307', 'type': 'block', 'children': ['308', '313']}; {'id': '308', 'type': 'expression_statement', 'children': ['309']}, {'id': '309', 'type': 'call', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': '_ignore_warnings'}, {'id': '311', 'type': 'argument_list', 'children': ['312']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '313', 'type': 'expression_statement', 'children': ['314']}; {'id': '314', 'type': 'assignment', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '316', 'type': 'call', 'children': ['317', '324']}, {'id': '317', 'type': 'attribute', 'children': ['318', '323']}; {'id': '318', 'type': 'subscript', 'children': ['319', '322']}, {'id': '319', 'type': 'attribute', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '321', 'type': 'identifier', 'children': [], 'value': '_sessions'}; {'id': '322', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '324', 'type': 'argument_list', 'children': ['325', '326', '329']}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'auth_url'}; {'id': '326', 'type': 'keyword_argument', 'children': ['327', '328']}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'headers'}, {'id': '329', 'type': 'keyword_argument', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'verify'}, {'id': '331', 'type': 'attribute', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '333', 'type': 'identifier', 'children': [], 'value': '_tlsverify'}; {'id': '334', 'type': 'expression_statement', 'children': ['335']}, {'id': '335', 'type': 'call', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': '_raise_for_status'}, {'id': '337', 'type': 'argument_list', 'children': ['338']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '339', 'type': 'expression_statement', 'children': ['340']}; {'id': '340', 'type': 'assignment', 'children': ['341', '342']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'rjson'}; {'id': '342', 'type': 'call', 'children': ['343', '346']}, {'id': '343', 'type': 'attribute', 'children': ['344', '345']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '346', 'type': 'argument_list', 'children': []}, {'id': '347', 'type': 'expression_statement', 'children': ['348']}; {'id': '348', 'type': 'assignment', 'children': ['349', '352']}, {'id': '349', 'type': 'attribute', 'children': ['350', '351']}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '352', 'type': 'conditional_expression', 'children': ['353', '356', '359'], 'value': 'if'}, {'id': '353', 'type': 'subscript', 'children': ['354', '355']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'rjson'}, {'id': '355', 'type': 'string', 'children': [], 'value': "'access_token'"}; {'id': '356', 'type': 'comparison_operator', 'children': ['357', '358'], 'value': 'in'}, {'id': '357', 'type': 'string', 'children': [], 'value': "'access_token'"}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'rjson'}, {'id': '359', 'type': 'subscript', 'children': ['360', '361']}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'rjson'}, {'id': '361', 'type': 'string', 'children': [], 'value': "'token'"}; {'id': '362', 'type': 'return_statement', 'children': ['363']}, {'id': '363', 'type': 'attribute', 'children': ['364', '365']}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '365', 'type': 'identifier', 'children': [], 'value': '_token'}; {'id': '366', 'type': 'expression_statement', 'children': ['367']}, {'id': '367', 'type': 'assignment', 'children': ['368', '371']}; {'id': '368', 'type': 'attribute', 'children': ['369', '370']}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '370', 'type': 'identifier', 'children': [], 'value': '_headers'}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '372', 'type': 'return_statement', 'children': ['373']}, {'id': '373', 'type': 'None', 'children': []} | def authenticate(self,
username=None, password=None,
actions=None, response=None,
authorization=None):
if response is None:
with warnings.catch_warnings():
_ignore_warnings(self)
response = self._sessions[0].get(self._base_url, verify=self._tlsverify)
if response.ok:
return None
if response.status_code != requests.codes.unauthorized:
raise exceptions.DXFUnexpectedStatusCodeError(response.status_code,
requests.codes.unauthorized)
if self._insecure:
raise exceptions.DXFAuthInsecureError()
parsed = www_authenticate.parse(response.headers['www-authenticate'])
if username is not None and password is not None:
headers = {
'Authorization': 'Basic ' + base64.b64encode(_to_bytes_2and3(username + ':' + password)).decode('utf-8')
}
elif authorization is not None:
headers = {
'Authorization': authorization
}
else:
headers = {}
if 'bearer' in parsed:
info = parsed['bearer']
if actions and self._repo:
scope = 'repository:' + self._repo + ':' + ','.join(actions)
elif 'scope' in info:
scope = info['scope']
else:
scope = ''
url_parts = list(urlparse.urlparse(info['realm']))
query = urlparse.parse_qs(url_parts[4])
query.update({
'service': info['service'],
'scope': scope
})
url_parts[4] = urlencode(query, True)
url_parts[0] = 'https'
if self._auth_host:
url_parts[1] = self._auth_host
auth_url = urlparse.urlunparse(url_parts)
with warnings.catch_warnings():
_ignore_warnings(self)
r = self._sessions[0].get(auth_url, headers=headers, verify=self._tlsverify)
_raise_for_status(r)
rjson = r.json()
self.token = rjson['access_token'] if 'access_token' in rjson else rjson['token']
return self._token
self._headers = headers
return None |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'ddl'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'source_database'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '23', '34', '46', '59', '74', '84', '97', '229']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '16']}, {'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': 'is'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'ddl'}, {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': '_ddl'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'ddl'}, {'id': '23', 'type': 'if_statement', 'children': ['24', '27']}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': 'is'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'source_database'}; {'id': '26', 'type': 'None', 'children': []}, {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'source_database'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'source_database'}; {'id': '34', 'type': 'if_statement', 'children': ['35', '40']}, {'id': '35', 'type': 'comparison_operator', 'children': ['36', '39'], 'value': 'is'}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': '_ddl'}, {'id': '39', 'type': 'None', 'children': []}; {'id': '40', 'type': 'block', 'children': ['41']}, {'id': '41', 'type': 'raise_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'string', 'children': [], 'value': '"DDL is not specified"'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '49', 'type': 'call', 'children': ['50', '55']}; {'id': '50', 'type': 'attribute', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': '_DDL_PARSE_EXPR'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'parseString'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': '_ddl'}, {'id': '59', 'type': 'if_statement', 'children': ['60', '63']}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'in'}, {'id': '61', 'type': 'string', 'children': [], 'value': '"schema"'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '71']}; {'id': '66', 'type': 'attribute', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': '_table'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'schema'}, {'id': '71', 'type': 'subscript', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '73', 'type': 'string', 'children': [], 'value': '"schema"'}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '81']}; {'id': '76', 'type': 'attribute', 'children': ['77', '80']}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': '_table'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '81', 'type': 'subscript', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '83', 'type': 'string', 'children': [], 'value': '"table"'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '91']}; {'id': '86', 'type': 'attribute', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': '_table'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'is_temp'}, {'id': '91', 'type': 'conditional_expression', 'children': ['92', '93', '96'], 'value': 'if'}; {'id': '92', 'type': 'True', 'children': []}, {'id': '93', 'type': 'comparison_operator', 'children': ['94', '95'], 'value': 'in'}; {'id': '94', 'type': 'string', 'children': [], 'value': '"temp"'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '96', 'type': 'False', 'children': []}, {'id': '97', 'type': 'for_statement', 'children': ['98', '99', '102']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'ret_col'}, {'id': '99', 'type': 'subscript', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'ret'}, {'id': '101', 'type': 'string', 'children': [], 'value': '"columns"'}; {'id': '102', 'type': 'block', 'children': ['103']}, {'id': '103', 'type': 'if_statement', 'children': ['104', '111', '157']}; {'id': '104', 'type': 'comparison_operator', 'children': ['105', '110'], 'value': '=='}, {'id': '105', 'type': 'call', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'ret_col'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'getName'}, {'id': '109', 'type': 'argument_list', 'children': []}; {'id': '110', 'type': 'string', 'children': [], 'value': '"column"'}, {'id': '111', 'type': 'block', 'children': ['112', '144']}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'col'}, {'id': '115', 'type': 'call', 'children': ['116', '123']}; {'id': '116', 'type': 'attribute', 'children': ['117', '122']}, {'id': '117', 'type': 'attribute', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': '_table'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '123', 'type': 'argument_list', 'children': ['124', '129', '134']}; {'id': '124', 'type': 'keyword_argument', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'column_name'}; {'id': '126', 'type': 'subscript', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'ret_col'}; {'id': '128', 'type': 'string', 'children': [], 'value': '"name"'}, {'id': '129', 'type': 'keyword_argument', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'data_type_array'}, {'id': '131', 'type': 'subscript', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'ret_col'}, {'id': '133', 'type': 'string', 'children': [], 'value': '"type"'}; {'id': '134', 'type': 'keyword_argument', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'array_brackets'}; {'id': '136', 'type': 'conditional_expression', 'children': ['137', '140', '143'], 'value': 'if'}, {'id': '137', 'type': 'subscript', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'ret_col'}, {'id': '139', 'type': 'string', 'children': [], 'value': "'array_brackets'"}; {'id': '140', 'type': 'comparison_operator', 'children': ['141', '142'], 'value': 'in'}, {'id': '141', 'type': 'string', 'children': [], 'value': '"array_brackets"'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'ret_col'}, {'id': '143', 'type': 'None', 'children': []}; {'id': '144', 'type': 'if_statement', 'children': ['145', '148']}, {'id': '145', 'type': 'comparison_operator', 'children': ['146', '147'], 'value': 'in'}; {'id': '146', 'type': 'string', 'children': [], 'value': '"constraint"'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'ret_col'}; {'id': '148', 'type': 'block', 'children': ['149']}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'assignment', 'children': ['151', '154']}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'col'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'constraint'}; {'id': '154', 'type': 'subscript', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'ret_col'}; {'id': '156', 'type': 'string', 'children': [], 'value': '"constraint"'}, {'id': '157', 'type': 'elif_clause', 'children': ['158', '165']}; {'id': '158', 'type': 'comparison_operator', 'children': ['159', '164'], 'value': '=='}, {'id': '159', 'type': 'call', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'ret_col'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'getName'}, {'id': '163', 'type': 'argument_list', 'children': []}; {'id': '164', 'type': 'string', 'children': [], 'value': '"constraint"'}, {'id': '165', 'type': 'block', 'children': ['166']}; {'id': '166', 'type': 'for_statement', 'children': ['167', '168', '171']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'col_name'}; {'id': '168', 'type': 'subscript', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'ret_col'}; {'id': '170', 'type': 'string', 'children': [], 'value': '"constraint_columns"'}, {'id': '171', 'type': 'block', 'children': ['172', '182']}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'assignment', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'col'}, {'id': '175', 'type': 'subscript', 'children': ['176', '181']}; {'id': '176', 'type': 'attribute', 'children': ['177', '180']}, {'id': '177', 'type': 'attribute', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': '_table'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'columns'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'col_name'}; {'id': '182', 'type': 'if_statement', 'children': ['183', '188', '201', '216']}, {'id': '183', 'type': 'comparison_operator', 'children': ['184', '187'], 'value': '=='}; {'id': '184', 'type': 'subscript', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'ret_col'}; {'id': '186', 'type': 'string', 'children': [], 'value': '"type"'}, {'id': '187', 'type': 'string', 'children': [], 'value': '"PRIMARY KEY"'}; {'id': '188', 'type': 'block', 'children': ['189', '195']}, {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'assignment', 'children': ['191', '194']}, {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'col'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'not_null'}; {'id': '194', 'type': 'True', 'children': []}, {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'assignment', 'children': ['197', '200']}, {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'col'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'primary_key'}; {'id': '200', 'type': 'True', 'children': []}, {'id': '201', 'type': 'elif_clause', 'children': ['202', '209']}; {'id': '202', 'type': 'comparison_operator', 'children': ['203', '206'], 'value': 'in'}, {'id': '203', 'type': 'subscript', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'ret_col'}, {'id': '205', 'type': 'string', 'children': [], 'value': '"type"'}; {'id': '206', 'type': 'list', 'children': ['207', '208'], 'value': '["UNIQUE", "UNIQUE KEY"]'}, {'id': '207', 'type': 'string', 'children': [], 'value': '"UNIQUE"'}; {'id': '208', 'type': 'string', 'children': [], 'value': '"UNIQUE KEY"'}, {'id': '209', 'type': 'block', 'children': ['210']}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}, {'id': '211', 'type': 'assignment', 'children': ['212', '215']}; {'id': '212', 'type': 'attribute', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'unique'}, {'id': '215', 'type': 'True', 'children': []}; {'id': '216', 'type': 'elif_clause', 'children': ['217', '222']}, {'id': '217', 'type': 'comparison_operator', 'children': ['218', '221'], 'value': '=='}; {'id': '218', 'type': 'subscript', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'ret_col'}; {'id': '220', 'type': 'string', 'children': [], 'value': '"type"'}, {'id': '221', 'type': 'string', 'children': [], 'value': '"NOT NULL"'}; {'id': '222', 'type': 'block', 'children': ['223']}, {'id': '223', 'type': 'expression_statement', 'children': ['224']}; {'id': '224', 'type': 'assignment', 'children': ['225', '228']}, {'id': '225', 'type': 'attribute', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'col'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'not_null'}; {'id': '228', 'type': 'True', 'children': []}, {'id': '229', 'type': 'return_statement', 'children': ['230']}; {'id': '230', 'type': 'attribute', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'self'} | def parse(self, ddl=None, source_database=None):
if ddl is not None:
self._ddl = ddl
if source_database is not None:
self.source_database = source_database
if self._ddl is None:
raise ValueError("DDL is not specified")
ret = self._DDL_PARSE_EXPR.parseString(self._ddl)
if "schema" in ret:
self._table.schema = ret["schema"]
self._table.name = ret["table"]
self._table.is_temp = True if "temp" in ret else False
for ret_col in ret["columns"]:
if ret_col.getName() == "column":
col = self._table.columns.append(
column_name=ret_col["name"],
data_type_array=ret_col["type"],
array_brackets=ret_col['array_brackets'] if "array_brackets" in ret_col else None)
if "constraint" in ret_col:
col.constraint = ret_col["constraint"]
elif ret_col.getName() == "constraint":
for col_name in ret_col["constraint_columns"]:
col = self._table.columns[col_name]
if ret_col["type"] == "PRIMARY KEY":
col.not_null = True
col.primary_key = True
elif ret_col["type"] in ["UNIQUE", "UNIQUE KEY"]:
col.unique = True
elif ret_col["type"] == "NOT NULL":
col.not_null = True
return self._table |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_next_valid_time_from_t'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '6', 'type': 'block', 'children': ['7', '17', '26', '33', '58', '76', '85', '94', '103', '116']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '14']}; {'id': '8', 'type': 'call', 'children': ['9', '12']}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'is_time_valid'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '14', 'type': 'block', 'children': ['15']}, {'id': '15', 'type': 'return_statement', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'timestamp'}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 't_day'}; {'id': '20', 'type': 'call', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'get_next_valid_day'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '26', 'type': 'if_statement', 'children': ['27', '30']}, {'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'is'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 't_day'}, {'id': '29', 'type': 'None', 'children': []}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'return_statement', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 't_day'}, {'id': '33', 'type': 'if_statement', 'children': ['34', '37', '47']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': '<'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 't_day'}, {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'sec_from_morning'}, {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'get_next_future_timerange_valid'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 't_day'}, {'id': '47', 'type': 'else_clause', 'children': ['48']}; {'id': '48', 'type': 'block', 'children': ['49']}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'sec_from_morning'}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'get_next_future_timerange_valid'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '58', 'type': 'if_statement', 'children': ['59', '62']}, {'id': '59', 'type': 'comparison_operator', 'children': ['60', '61'], 'value': 'is'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'sec_from_morning'}, {'id': '61', 'type': 'None', 'children': []}; {'id': '62', 'type': 'block', 'children': ['63']}, {'id': '63', 'type': 'if_statement', 'children': ['64', '71']}; {'id': '64', 'type': 'boolean_operator', 'children': ['65', '68'], 'value': 'and'}, {'id': '65', 'type': 'comparison_operator', 'children': ['66', '67'], 'value': 'is'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 't_day'}, {'id': '67', 'type': 'None', 'children': []}; {'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': 'is'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'sec_from_morning'}; {'id': '70', 'type': 'None', 'children': []}, {'id': '71', 'type': 'block', 'children': ['72']}; {'id': '72', 'type': 'return_statement', 'children': ['73']}, {'id': '73', 'type': 'binary_operator', 'children': ['74', '75'], 'value': '+'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 't_day'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'sec_from_morning'}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'timestamp'}, {'id': '79', 'type': 'binary_operator', 'children': ['80', '84'], 'value': '+'}; {'id': '80', 'type': 'call', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'get_day'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '84', 'type': 'integer', 'children': [], 'value': '86400'}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 't_day2'}; {'id': '88', 'type': 'call', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'get_next_valid_day'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'sec_from_morning'}, {'id': '97', 'type': 'call', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'get_next_future_timerange_valid'}, {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 't_day2'}, {'id': '103', 'type': 'if_statement', 'children': ['104', '111']}; {'id': '104', 'type': 'boolean_operator', 'children': ['105', '108'], 'value': 'and'}, {'id': '105', 'type': 'comparison_operator', 'children': ['106', '107'], 'value': 'is'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 't_day2'}, {'id': '107', 'type': 'None', 'children': []}; {'id': '108', 'type': 'comparison_operator', 'children': ['109', '110'], 'value': 'is'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'sec_from_morning'}; {'id': '110', 'type': 'None', 'children': []}, {'id': '111', 'type': 'block', 'children': ['112']}; {'id': '112', 'type': 'return_statement', 'children': ['113']}, {'id': '113', 'type': 'binary_operator', 'children': ['114', '115'], 'value': '+'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 't_day2'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'sec_from_morning'}; {'id': '116', 'type': 'return_statement', 'children': ['117']}, {'id': '117', 'type': 'None', 'children': []} | def get_next_valid_time_from_t(self, timestamp):
if self.is_time_valid(timestamp):
return timestamp
t_day = self.get_next_valid_day(timestamp)
if t_day is None:
return t_day
if timestamp < t_day:
sec_from_morning = self.get_next_future_timerange_valid(t_day)
else:
sec_from_morning = self.get_next_future_timerange_valid(timestamp)
if sec_from_morning is not None:
if t_day is not None and sec_from_morning is not None:
return t_day + sec_from_morning
timestamp = get_day(timestamp) + 86400
t_day2 = self.get_next_valid_day(timestamp)
sec_from_morning = self.get_next_future_timerange_valid(t_day2)
if t_day2 is not None and sec_from_morning is not None:
return t_day2 + sec_from_morning
return None |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_next_invalid_time_from_t'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '6', 'type': 'block', 'children': ['7', '18', '27', '52', '67', '78', '87', '96', '105', '120', '131']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '15']}; {'id': '8', 'type': 'not_operator', 'children': ['9']}, {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'is_time_valid'}, {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'timestamp'}, {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'return_statement', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 't_day'}, {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'get_next_invalid_day'}, {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'timestamp'}, {'id': '27', 'type': 'if_statement', 'children': ['28', '31', '41']}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': '<'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 't_day'}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'sec_from_morning'}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'get_next_future_timerange_invalid'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 't_day'}, {'id': '41', 'type': 'else_clause', 'children': ['42']}; {'id': '42', 'type': 'block', 'children': ['43']}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'sec_from_morning'}; {'id': '46', 'type': 'call', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'get_next_future_timerange_invalid'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '52', 'type': 'if_statement', 'children': ['53', '60']}, {'id': '53', 'type': 'boolean_operator', 'children': ['54', '57'], 'value': 'and'}; {'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': 'is'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 't_day'}; {'id': '56', 'type': 'None', 'children': []}, {'id': '57', 'type': 'comparison_operator', 'children': ['58', '59'], 'value': 'is'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'sec_from_morning'}, {'id': '59', 'type': 'None', 'children': []}; {'id': '60', 'type': 'block', 'children': ['61']}, {'id': '61', 'type': 'return_statement', 'children': ['62']}; {'id': '62', 'type': 'binary_operator', 'children': ['63', '66'], 'value': '+'}, {'id': '63', 'type': 'binary_operator', 'children': ['64', '65'], 'value': '+'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 't_day'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'sec_from_morning'}; {'id': '66', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '67', 'type': 'if_statement', 'children': ['68', '75']}; {'id': '68', 'type': 'boolean_operator', 'children': ['69', '72'], 'value': 'and'}, {'id': '69', 'type': 'comparison_operator', 'children': ['70', '71'], 'value': 'is'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 't_day'}, {'id': '71', 'type': 'None', 'children': []}; {'id': '72', 'type': 'comparison_operator', 'children': ['73', '74'], 'value': 'is'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'sec_from_morning'}; {'id': '74', 'type': 'None', 'children': []}, {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'return_statement', 'children': ['77']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 't_day'}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'timestamp'}, {'id': '81', 'type': 'binary_operator', 'children': ['82', '86'], 'value': '+'}; {'id': '82', 'type': 'call', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'get_day'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '86', 'type': 'integer', 'children': [], 'value': '86400'}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 't_day2'}; {'id': '90', 'type': 'call', 'children': ['91', '94']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'get_next_invalid_day'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'sec_from_morning'}, {'id': '99', 'type': 'call', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'get_next_future_timerange_invalid'}, {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 't_day2'}, {'id': '105', 'type': 'if_statement', 'children': ['106', '113']}; {'id': '106', 'type': 'boolean_operator', 'children': ['107', '110'], 'value': 'and'}, {'id': '107', 'type': 'comparison_operator', 'children': ['108', '109'], 'value': 'is'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 't_day2'}, {'id': '109', 'type': 'None', 'children': []}; {'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': 'is'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'sec_from_morning'}; {'id': '112', 'type': 'None', 'children': []}, {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'return_statement', 'children': ['115']}, {'id': '115', 'type': 'binary_operator', 'children': ['116', '119'], 'value': '+'}; {'id': '116', 'type': 'binary_operator', 'children': ['117', '118'], 'value': '+'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 't_day2'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'sec_from_morning'}, {'id': '119', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '120', 'type': 'if_statement', 'children': ['121', '128']}, {'id': '121', 'type': 'boolean_operator', 'children': ['122', '125'], 'value': 'and'}; {'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': 'is'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 't_day2'}; {'id': '124', 'type': 'None', 'children': []}, {'id': '125', 'type': 'comparison_operator', 'children': ['126', '127'], 'value': 'is'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'sec_from_morning'}, {'id': '127', 'type': 'None', 'children': []}; {'id': '128', 'type': 'block', 'children': ['129']}, {'id': '129', 'type': 'return_statement', 'children': ['130']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 't_day2'}, {'id': '131', 'type': 'return_statement', 'children': ['132']} | def get_next_invalid_time_from_t(self, timestamp):
if not self.is_time_valid(timestamp):
return timestamp
t_day = self.get_next_invalid_day(timestamp)
if timestamp < t_day:
sec_from_morning = self.get_next_future_timerange_invalid(t_day)
else:
sec_from_morning = self.get_next_future_timerange_invalid(timestamp)
if t_day is not None and sec_from_morning is not None:
return t_day + sec_from_morning + 1
if t_day is not None and sec_from_morning is None:
return t_day
timestamp = get_day(timestamp) + 86400
t_day2 = self.get_next_invalid_day(timestamp)
sec_from_morning = self.get_next_future_timerange_invalid(t_day2)
if t_day2 is not None and sec_from_morning is not None:
return t_day2 + sec_from_morning + 1
if t_day2 is not None and sec_from_morning is None:
return t_day2
return None |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_start_and_end_time'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'ref'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '18', '33', '51', '64', '79', '97', '110', '119', '278']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '12', 'type': 'call', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'localtime'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'ref'}; {'id': '18', 'type': 'if_statement', 'children': ['19', '24']}, {'id': '19', 'type': 'comparison_operator', 'children': ['20', '23'], 'value': '=='}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'syear'}, {'id': '23', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '24', 'type': 'block', 'children': ['25']}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'syear'}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'tm_year'}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'day_start'}; {'id': '36', 'type': 'call', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'find_day_by_weekday_offset'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '42', '45', '48']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'syear'}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'smon'}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'swday'}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'swday_offset'}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'start_time'}; {'id': '54', 'type': 'call', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'get_start_of_day'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '60', '63']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'syear'}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'smon'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'day_start'}; {'id': '64', 'type': 'if_statement', 'children': ['65', '70']}, {'id': '65', 'type': 'comparison_operator', 'children': ['66', '69'], 'value': '=='}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'eyear'}, {'id': '69', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '70', 'type': 'block', 'children': ['71']}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'eyear'}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'tm_year'}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'day_end'}; {'id': '82', 'type': 'call', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'find_day_by_weekday_offset'}; {'id': '84', 'type': 'argument_list', 'children': ['85', '88', '91', '94']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'eyear'}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'emon'}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'ewday'}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'ewday_offset'}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'end_time'}; {'id': '100', 'type': 'call', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'get_end_of_day'}; {'id': '102', 'type': 'argument_list', 'children': ['103', '106', '109']}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'eyear'}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'emon'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'day_end'}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'now_epoch'}, {'id': '113', 'type': 'call', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'mktime'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'now'}, {'id': '119', 'type': 'if_statement', 'children': ['120', '123', '201']}; {'id': '120', 'type': 'comparison_operator', 'children': ['121', '122'], 'value': '>'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'start_time'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'end_time'}, {'id': '123', 'type': 'block', 'children': ['124']}; {'id': '124', 'type': 'if_statement', 'children': ['125', '128', '164']}, {'id': '125', 'type': 'comparison_operator', 'children': ['126', '127'], 'value': '>'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'now_epoch'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'end_time'}; {'id': '128', 'type': 'block', 'children': ['129', '149']}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'day_end'}; {'id': '132', 'type': 'call', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'find_day_by_weekday_offset'}; {'id': '134', 'type': 'argument_list', 'children': ['135', '140', '143', '146']}, {'id': '135', 'type': 'binary_operator', 'children': ['136', '139'], 'value': '+'}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'eyear'}, {'id': '139', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'emon'}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'ewday'}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'ewday_offset'}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'assignment', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'end_time'}; {'id': '152', 'type': 'call', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'get_end_of_day'}; {'id': '154', 'type': 'argument_list', 'children': ['155', '160', '163']}, {'id': '155', 'type': 'binary_operator', 'children': ['156', '159'], 'value': '+'}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'eyear'}, {'id': '159', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'emon'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'day_end'}; {'id': '164', 'type': 'else_clause', 'children': ['165']}, {'id': '165', 'type': 'block', 'children': ['166', '186']}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'assignment', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'day_start'}, {'id': '169', 'type': 'call', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'find_day_by_weekday_offset'}, {'id': '171', 'type': 'argument_list', 'children': ['172', '177', '180', '183']}; {'id': '172', 'type': 'binary_operator', 'children': ['173', '176'], 'value': '-'}, {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'syear'}; {'id': '176', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '177', 'type': 'attribute', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'smon'}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'swday'}, {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'swday_offset'}; {'id': '186', 'type': 'expression_statement', 'children': ['187']}, {'id': '187', 'type': 'assignment', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'start_time'}, {'id': '189', 'type': 'call', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'get_start_of_day'}, {'id': '191', 'type': 'argument_list', 'children': ['192', '197', '200']}; {'id': '192', 'type': 'binary_operator', 'children': ['193', '196'], 'value': '-'}, {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'syear'}; {'id': '196', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'smon'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'day_start'}, {'id': '201', 'type': 'else_clause', 'children': ['202']}; {'id': '202', 'type': 'block', 'children': ['203']}, {'id': '203', 'type': 'if_statement', 'children': ['204', '207']}; {'id': '204', 'type': 'comparison_operator', 'children': ['205', '206'], 'value': '>'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'now_epoch'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'end_time'}, {'id': '207', 'type': 'block', 'children': ['208', '228', '243', '263']}; {'id': '208', 'type': 'expression_statement', 'children': ['209']}, {'id': '209', 'type': 'assignment', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'day_start'}, {'id': '211', 'type': 'call', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'find_day_by_weekday_offset'}, {'id': '213', 'type': 'argument_list', 'children': ['214', '219', '222', '225']}; {'id': '214', 'type': 'binary_operator', 'children': ['215', '218'], 'value': '+'}, {'id': '215', 'type': 'attribute', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'syear'}; {'id': '218', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '219', 'type': 'attribute', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'smon'}; {'id': '222', 'type': 'attribute', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'swday'}, {'id': '225', 'type': 'attribute', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'swday_offset'}; {'id': '228', 'type': 'expression_statement', 'children': ['229']}, {'id': '229', 'type': 'assignment', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'start_time'}, {'id': '231', 'type': 'call', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'get_start_of_day'}, {'id': '233', 'type': 'argument_list', 'children': ['234', '239', '242']}; {'id': '234', 'type': 'binary_operator', 'children': ['235', '238'], 'value': '+'}, {'id': '235', 'type': 'attribute', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'syear'}; {'id': '238', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'smon'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'day_start'}, {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'assignment', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'day_end'}; {'id': '246', 'type': 'call', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'find_day_by_weekday_offset'}; {'id': '248', 'type': 'argument_list', 'children': ['249', '254', '257', '260']}, {'id': '249', 'type': 'binary_operator', 'children': ['250', '253'], 'value': '+'}; {'id': '250', 'type': 'attribute', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'eyear'}, {'id': '253', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '254', 'type': 'attribute', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'emon'}, {'id': '257', 'type': 'attribute', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'ewday'}; {'id': '260', 'type': 'attribute', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'ewday_offset'}, {'id': '263', 'type': 'expression_statement', 'children': ['264']}; {'id': '264', 'type': 'assignment', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'end_time'}; {'id': '266', 'type': 'call', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'get_end_of_day'}; {'id': '268', 'type': 'argument_list', 'children': ['269', '274', '277']}, {'id': '269', 'type': 'binary_operator', 'children': ['270', '273'], 'value': '+'}; {'id': '270', 'type': 'attribute', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'eyear'}, {'id': '273', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '274', 'type': 'attribute', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'emon'}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'day_end'}; {'id': '278', 'type': 'return_statement', 'children': ['279']}, {'id': '279', 'type': 'tuple', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'start_time'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'end_time'} | def get_start_and_end_time(self, ref=None):
now = time.localtime(ref)
if self.syear == 0:
self.syear = now.tm_year
day_start = find_day_by_weekday_offset(self.syear, self.smon, self.swday, self.swday_offset)
start_time = get_start_of_day(self.syear, self.smon, day_start)
if self.eyear == 0:
self.eyear = now.tm_year
day_end = find_day_by_weekday_offset(self.eyear, self.emon, self.ewday, self.ewday_offset)
end_time = get_end_of_day(self.eyear, self.emon, day_end)
now_epoch = time.mktime(now)
if start_time > end_time:
if now_epoch > end_time:
day_end = find_day_by_weekday_offset(self.eyear + 1,
self.emon, self.ewday, self.ewday_offset)
end_time = get_end_of_day(self.eyear + 1, self.emon, day_end)
else:
day_start = find_day_by_weekday_offset(self.syear - 1,
self.smon, self.swday, self.swday_offset)
start_time = get_start_of_day(self.syear - 1, self.smon, day_start)
else:
if now_epoch > end_time:
day_start = find_day_by_weekday_offset(self.syear + 1,
self.smon, self.swday, self.swday_offset)
start_time = get_start_of_day(self.syear + 1, self.smon, day_start)
day_end = find_day_by_weekday_offset(self.eyear + 1,
self.emon, self.ewday, self.ewday_offset)
end_time = get_end_of_day(self.eyear + 1, self.emon, day_end)
return (start_time, end_time) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_start_and_end_time'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'ref'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '18', '33', '48', '61', '76', '91', '104', '113', '260']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '12', 'type': 'call', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'localtime'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'ref'}; {'id': '18', 'type': 'if_statement', 'children': ['19', '24']}, {'id': '19', 'type': 'comparison_operator', 'children': ['20', '23'], 'value': '=='}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'syear'}, {'id': '23', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '24', 'type': 'block', 'children': ['25']}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'syear'}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'tm_year'}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'day_start'}; {'id': '36', 'type': 'call', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'find_day_by_offset'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '42', '45']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'syear'}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'smon'}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'smday'}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'start_time'}, {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'get_start_of_day'}, {'id': '53', 'type': 'argument_list', 'children': ['54', '57', '60']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'syear'}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'smon'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'day_start'}, {'id': '61', 'type': 'if_statement', 'children': ['62', '67']}; {'id': '62', 'type': 'comparison_operator', 'children': ['63', '66'], 'value': '=='}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'eyear'}; {'id': '66', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '67', 'type': 'block', 'children': ['68']}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'eyear'}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'now'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'tm_year'}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'day_end'}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'find_day_by_offset'}, {'id': '81', 'type': 'argument_list', 'children': ['82', '85', '88']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'eyear'}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'emon'}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'emday'}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'end_time'}; {'id': '94', 'type': 'call', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'get_end_of_day'}; {'id': '96', 'type': 'argument_list', 'children': ['97', '100', '103']}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'eyear'}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'emon'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'day_end'}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'now_epoch'}, {'id': '107', 'type': 'call', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'mktime'}, {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'now'}, {'id': '113', 'type': 'if_statement', 'children': ['114', '117', '189']}; {'id': '114', 'type': 'comparison_operator', 'children': ['115', '116'], 'value': '>'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'start_time'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'end_time'}, {'id': '117', 'type': 'block', 'children': ['118']}; {'id': '118', 'type': 'if_statement', 'children': ['119', '122', '155']}, {'id': '119', 'type': 'comparison_operator', 'children': ['120', '121'], 'value': '>'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'now_epoch'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'end_time'}; {'id': '122', 'type': 'block', 'children': ['123', '140']}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'day_end'}; {'id': '126', 'type': 'call', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'find_day_by_offset'}; {'id': '128', 'type': 'argument_list', 'children': ['129', '134', '137']}, {'id': '129', 'type': 'binary_operator', 'children': ['130', '133'], 'value': '+'}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'eyear'}, {'id': '133', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'emon'}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'emday'}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'assignment', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'end_time'}, {'id': '143', 'type': 'call', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'get_end_of_day'}, {'id': '145', 'type': 'argument_list', 'children': ['146', '151', '154']}; {'id': '146', 'type': 'binary_operator', 'children': ['147', '150'], 'value': '+'}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'eyear'}; {'id': '150', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'emon'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'day_end'}, {'id': '155', 'type': 'else_clause', 'children': ['156']}; {'id': '156', 'type': 'block', 'children': ['157', '174']}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'day_start'}; {'id': '160', 'type': 'call', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'find_day_by_offset'}; {'id': '162', 'type': 'argument_list', 'children': ['163', '168', '171']}, {'id': '163', 'type': 'binary_operator', 'children': ['164', '167'], 'value': '-'}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'syear'}, {'id': '167', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'smon'}, {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'emday'}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}, {'id': '175', 'type': 'assignment', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'start_time'}, {'id': '177', 'type': 'call', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'get_start_of_day'}, {'id': '179', 'type': 'argument_list', 'children': ['180', '185', '188']}; {'id': '180', 'type': 'binary_operator', 'children': ['181', '184'], 'value': '-'}, {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'syear'}; {'id': '184', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'smon'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'day_start'}, {'id': '189', 'type': 'else_clause', 'children': ['190']}; {'id': '190', 'type': 'block', 'children': ['191']}, {'id': '191', 'type': 'if_statement', 'children': ['192', '195']}; {'id': '192', 'type': 'comparison_operator', 'children': ['193', '194'], 'value': '>'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'now_epoch'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'end_time'}, {'id': '195', 'type': 'block', 'children': ['196', '213', '228', '245']}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'assignment', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'day_start'}, {'id': '199', 'type': 'call', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'find_day_by_offset'}, {'id': '201', 'type': 'argument_list', 'children': ['202', '207', '210']}; {'id': '202', 'type': 'binary_operator', 'children': ['203', '206'], 'value': '+'}, {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'syear'}; {'id': '206', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '207', 'type': 'attribute', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'smon'}; {'id': '210', 'type': 'attribute', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'smday'}, {'id': '213', 'type': 'expression_statement', 'children': ['214']}; {'id': '214', 'type': 'assignment', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'start_time'}; {'id': '216', 'type': 'call', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'get_start_of_day'}; {'id': '218', 'type': 'argument_list', 'children': ['219', '224', '227']}, {'id': '219', 'type': 'binary_operator', 'children': ['220', '223'], 'value': '+'}; {'id': '220', 'type': 'attribute', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'syear'}, {'id': '223', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'smon'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'day_start'}; {'id': '228', 'type': 'expression_statement', 'children': ['229']}, {'id': '229', 'type': 'assignment', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'day_end'}, {'id': '231', 'type': 'call', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'find_day_by_offset'}, {'id': '233', 'type': 'argument_list', 'children': ['234', '239', '242']}; {'id': '234', 'type': 'binary_operator', 'children': ['235', '238'], 'value': '+'}, {'id': '235', 'type': 'attribute', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'eyear'}; {'id': '238', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'emon'}; {'id': '242', 'type': 'attribute', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'emday'}, {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'assignment', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'end_time'}; {'id': '248', 'type': 'call', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'get_end_of_day'}; {'id': '250', 'type': 'argument_list', 'children': ['251', '256', '259']}, {'id': '251', 'type': 'binary_operator', 'children': ['252', '255'], 'value': '+'}; {'id': '252', 'type': 'attribute', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'eyear'}, {'id': '255', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '256', 'type': 'attribute', 'children': ['257', '258']}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'emon'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'day_end'}; {'id': '260', 'type': 'return_statement', 'children': ['261']}, {'id': '261', 'type': 'tuple', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'start_time'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'end_time'} | def get_start_and_end_time(self, ref=None):
now = time.localtime(ref)
if self.syear == 0:
self.syear = now.tm_year
day_start = find_day_by_offset(self.syear, self.smon, self.smday)
start_time = get_start_of_day(self.syear, self.smon, day_start)
if self.eyear == 0:
self.eyear = now.tm_year
day_end = find_day_by_offset(self.eyear, self.emon, self.emday)
end_time = get_end_of_day(self.eyear, self.emon, day_end)
now_epoch = time.mktime(now)
if start_time > end_time:
if now_epoch > end_time:
day_end = find_day_by_offset(self.eyear + 1, self.emon, self.emday)
end_time = get_end_of_day(self.eyear + 1, self.emon, day_end)
else:
day_start = find_day_by_offset(self.syear - 1, self.smon, self.emday)
start_time = get_start_of_day(self.syear - 1, self.smon, day_start)
else:
if now_epoch > end_time:
day_start = find_day_by_offset(self.syear + 1, self.smon, self.smday)
start_time = get_start_of_day(self.syear + 1, self.smon, day_start)
day_end = find_day_by_offset(self.eyear + 1, self.emon, self.emday)
end_time = get_end_of_day(self.eyear + 1, self.emon, day_end)
return (start_time, end_time) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_start_and_end_time'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'ref'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '18', '33', '39', '55', '66', '81', '87', '103', '114', '165', '174', '271']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '12', 'type': 'call', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'localtime'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'ref'}; {'id': '18', 'type': 'if_statement', 'children': ['19', '24']}, {'id': '19', 'type': 'comparison_operator', 'children': ['20', '23'], 'value': '=='}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'syear'}, {'id': '23', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '24', 'type': 'block', 'children': ['25']}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'syear'}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'tm_year'}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'month_start_id'}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'tm_mon'}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'day_start'}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'find_day_by_weekday_offset'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '48', '49', '52']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'syear'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'month_start_id'}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'swday'}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'swday_offset'}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'start_time'}; {'id': '58', 'type': 'call', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'get_start_of_day'}; {'id': '60', 'type': 'argument_list', 'children': ['61', '64', '65']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'syear'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'month_start_id'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'day_start'}; {'id': '66', 'type': 'if_statement', 'children': ['67', '72']}, {'id': '67', 'type': 'comparison_operator', 'children': ['68', '71'], 'value': '=='}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'eyear'}, {'id': '71', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '72', 'type': 'block', 'children': ['73']}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'eyear'}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'tm_year'}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'month_end_id'}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'tm_mon'}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'day_end'}; {'id': '90', 'type': 'call', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'find_day_by_weekday_offset'}; {'id': '92', 'type': 'argument_list', 'children': ['93', '96', '97', '100']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'eyear'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'month_end_id'}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'ewday'}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'ewday_offset'}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'end_time'}; {'id': '106', 'type': 'call', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'get_end_of_day'}; {'id': '108', 'type': 'argument_list', 'children': ['109', '112', '113']}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'eyear'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'month_end_id'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'day_end'}; {'id': '114', 'type': 'if_statement', 'children': ['115', '118']}, {'id': '115', 'type': 'comparison_operator', 'children': ['116', '117'], 'value': '>'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'start_time'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'end_time'}; {'id': '118', 'type': 'block', 'children': ['119', '123', '138', '154']}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'augmented_assignment', 'children': ['121', '122'], 'value': '+='}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'month_end_id'}; {'id': '122', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '123', 'type': 'if_statement', 'children': ['124', '127']}; {'id': '124', 'type': 'comparison_operator', 'children': ['125', '126'], 'value': '>'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'month_end_id'}; {'id': '126', 'type': 'integer', 'children': [], 'value': '12'}, {'id': '127', 'type': 'block', 'children': ['128', '132']}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'month_end_id'}, {'id': '131', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'augmented_assignment', 'children': ['134', '137'], 'value': '+='}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'eyear'}, {'id': '137', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'day_end'}, {'id': '141', 'type': 'call', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'find_day_by_weekday_offset'}, {'id': '143', 'type': 'argument_list', 'children': ['144', '147', '148', '151']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'eyear'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'month_end_id'}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'ewday'}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'ewday_offset'}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'assignment', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'end_time'}, {'id': '157', 'type': 'call', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'get_end_of_day'}, {'id': '159', 'type': 'argument_list', 'children': ['160', '163', '164']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'eyear'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'month_end_id'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'day_end'}, {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'assignment', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'now_epoch'}; {'id': '168', 'type': 'call', 'children': ['169', '172']}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'mktime'}; {'id': '172', 'type': 'argument_list', 'children': ['173']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '174', 'type': 'if_statement', 'children': ['175', '178']}, {'id': '175', 'type': 'comparison_operator', 'children': ['176', '177'], 'value': '<'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'end_time'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'now_epoch'}; {'id': '178', 'type': 'block', 'children': ['179', '183', '187', '202', '217', '233', '244', '260']}, {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'augmented_assignment', 'children': ['181', '182'], 'value': '+='}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'month_end_id'}; {'id': '182', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'augmented_assignment', 'children': ['185', '186'], 'value': '+='}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'month_start_id'}; {'id': '186', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '187', 'type': 'if_statement', 'children': ['188', '191']}; {'id': '188', 'type': 'comparison_operator', 'children': ['189', '190'], 'value': '>'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'month_end_id'}; {'id': '190', 'type': 'integer', 'children': [], 'value': '12'}, {'id': '191', 'type': 'block', 'children': ['192', '196']}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}, {'id': '193', 'type': 'assignment', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'month_end_id'}, {'id': '195', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'augmented_assignment', 'children': ['198', '201'], 'value': '+='}; {'id': '198', 'type': 'attribute', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'eyear'}, {'id': '201', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '202', 'type': 'if_statement', 'children': ['203', '206']}, {'id': '203', 'type': 'comparison_operator', 'children': ['204', '205'], 'value': '>'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'month_start_id'}, {'id': '205', 'type': 'integer', 'children': [], 'value': '12'}; {'id': '206', 'type': 'block', 'children': ['207', '211']}, {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'assignment', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'month_start_id'}; {'id': '210', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'augmented_assignment', 'children': ['213', '216'], 'value': '+='}, {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'syear'}; {'id': '216', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'assignment', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'day_start'}; {'id': '220', 'type': 'call', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'find_day_by_weekday_offset'}; {'id': '222', 'type': 'argument_list', 'children': ['223', '226', '227', '230']}, {'id': '223', 'type': 'attribute', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'syear'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'month_start_id'}, {'id': '227', 'type': 'attribute', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'swday'}; {'id': '230', 'type': 'attribute', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'swday_offset'}, {'id': '233', 'type': 'expression_statement', 'children': ['234']}; {'id': '234', 'type': 'assignment', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'start_time'}; {'id': '236', 'type': 'call', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'get_start_of_day'}; {'id': '238', 'type': 'argument_list', 'children': ['239', '242', '243']}, {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'syear'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'month_start_id'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'day_start'}; {'id': '244', 'type': 'expression_statement', 'children': ['245']}, {'id': '245', 'type': 'assignment', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'day_end'}, {'id': '247', 'type': 'call', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'find_day_by_weekday_offset'}, {'id': '249', 'type': 'argument_list', 'children': ['250', '253', '254', '257']}; {'id': '250', 'type': 'attribute', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'eyear'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'month_end_id'}; {'id': '254', 'type': 'attribute', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'ewday'}, {'id': '257', 'type': 'attribute', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'ewday_offset'}; {'id': '260', 'type': 'expression_statement', 'children': ['261']}, {'id': '261', 'type': 'assignment', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'end_time'}, {'id': '263', 'type': 'call', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'get_end_of_day'}, {'id': '265', 'type': 'argument_list', 'children': ['266', '269', '270']}; {'id': '266', 'type': 'attribute', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'eyear'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'month_end_id'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'day_end'}, {'id': '271', 'type': 'return_statement', 'children': ['272']}; {'id': '272', 'type': 'tuple', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'start_time'} | def get_start_and_end_time(self, ref=None):
now = time.localtime(ref)
if self.syear == 0:
self.syear = now.tm_year
month_start_id = now.tm_mon
day_start = find_day_by_weekday_offset(self.syear,
month_start_id, self.swday, self.swday_offset)
start_time = get_start_of_day(self.syear, month_start_id, day_start)
if self.eyear == 0:
self.eyear = now.tm_year
month_end_id = now.tm_mon
day_end = find_day_by_weekday_offset(self.eyear, month_end_id, self.ewday,
self.ewday_offset)
end_time = get_end_of_day(self.eyear, month_end_id, day_end)
if start_time > end_time:
month_end_id += 1
if month_end_id > 12:
month_end_id = 1
self.eyear += 1
day_end = find_day_by_weekday_offset(self.eyear,
month_end_id, self.ewday, self.ewday_offset)
end_time = get_end_of_day(self.eyear, month_end_id, day_end)
now_epoch = time.mktime(now)
if end_time < now_epoch:
month_end_id += 1
month_start_id += 1
if month_end_id > 12:
month_end_id = 1
self.eyear += 1
if month_start_id > 12:
month_start_id = 1
self.syear += 1
day_start = find_day_by_weekday_offset(self.syear,
month_start_id, self.swday, self.swday_offset)
start_time = get_start_of_day(self.syear, month_start_id, day_start)
day_end = find_day_by_weekday_offset(self.eyear,
month_end_id, self.ewday, self.ewday_offset)
end_time = get_end_of_day(self.eyear, month_end_id, day_end)
return (start_time, end_time) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'flush'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'log'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '24', '35', '98', '264']}, {'id': '9', 'type': 'if_statement', 'children': ['10', '14']}; {'id': '10', 'type': 'not_operator', 'children': ['11']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'my_metrics'}; {'id': '14', 'type': 'block', 'children': ['15', '22']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'string', 'children': [], 'value': '"Flushing - no metrics to send"'}; {'id': '22', 'type': 'return_statement', 'children': ['23']}, {'id': '23', 'type': 'True', 'children': []}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'now'}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '34', 'type': 'argument_list', 'children': []}, {'id': '35', 'type': 'if_statement', 'children': ['36', '49']}; {'id': '36', 'type': 'boolean_operator', 'children': ['37', '40'], 'value': 'and'}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'last_failure'}; {'id': '40', 'type': 'comparison_operator', 'children': ['41', '48'], 'value': '>'}, {'id': '41', 'type': 'binary_operator', 'children': ['42', '45'], 'value': '+'}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'last_failure'}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'metrics_flush_pause'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'now'}, {'id': '49', 'type': 'block', 'children': ['50', '96']}; {'id': '50', 'type': 'if_statement', 'children': ['51', '55']}, {'id': '51', 'type': 'not_operator', 'children': ['52']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'log_metrics_flush_pause'}, {'id': '55', 'type': 'block', 'children': ['56', '76', '90']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'date'}, {'id': '59', 'type': 'call', 'children': ['60', '72']}; {'id': '60', 'type': 'attribute', 'children': ['61', '71']}, {'id': '61', 'type': 'call', 'children': ['62', '67']}; {'id': '62', 'type': 'attribute', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'fromtimestamp'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'last_failure'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'strftime'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'date_fmt'}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '81', 'type': 'argument_list', 'children': ['82', '86', '87']}; {'id': '82', 'type': 'concatenated_string', 'children': ['83', '84', '85']}, {'id': '83', 'type': 'string', 'children': [], 'value': '"Metrics flush paused on connection error "'}; {'id': '84', 'type': 'string', 'children': [], 'value': '"(last failed: %s). "'}, {'id': '85', 'type': 'string', 'children': [], 'value': '"Inner stored metric: %d. Trying to send..."'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'date'}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'metrics_count'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'log_metrics_flush_pause'}, {'id': '95', 'type': 'True', 'children': []}; {'id': '96', 'type': 'return_statement', 'children': ['97']}, {'id': '97', 'type': 'True', 'children': []}; {'id': '98', 'type': 'try_statement', 'children': ['99', '185']}, {'id': '99', 'type': 'block', 'children': ['100', '110', '156', '173', '179']}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'call', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '105', 'type': 'argument_list', 'children': ['106', '107']}; {'id': '106', 'type': 'string', 'children': [], 'value': '"Flushing %d metrics to Graphite/carbon"'}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'metrics_count'}; {'id': '110', 'type': 'if_statement', 'children': ['111', '118', '125']}, {'id': '111', 'type': 'call', 'children': ['112', '117']}; {'id': '112', 'type': 'attribute', 'children': ['113', '116']}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'carbon'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'send_data'}, {'id': '117', 'type': 'argument_list', 'children': []}; {'id': '118', 'type': 'block', 'children': ['119']}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '124']}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'my_metrics'}; {'id': '124', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '125', 'type': 'else_clause', 'children': ['126']}; {'id': '126', 'type': 'block', 'children': ['127', '139', '154']}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'call', 'children': ['129', '132']}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '132', 'type': 'argument_list', 'children': ['133', '136']}, {'id': '133', 'type': 'concatenated_string', 'children': ['134', '135']}; {'id': '134', 'type': 'string', 'children': [], 'value': '"Failed sending metrics to Graphite/carbon. "'}, {'id': '135', 'type': 'string', 'children': [], 'value': '"Inner stored metric: %d"'}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'metrics_count'}, {'id': '139', 'type': 'if_statement', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'log'}, {'id': '141', 'type': 'block', 'children': ['142']}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'call', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '147', 'type': 'argument_list', 'children': ['148', '151']}; {'id': '148', 'type': 'concatenated_string', 'children': ['149', '150']}, {'id': '149', 'type': 'string', 'children': [], 'value': '"Failed sending metrics to Graphite/carbon. "'}; {'id': '150', 'type': 'string', 'children': [], 'value': '"Inner stored metric: %d"'}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'metrics_count'}; {'id': '154', 'type': 'return_statement', 'children': ['155']}, {'id': '155', 'type': 'False', 'children': []}; {'id': '156', 'type': 'if_statement', 'children': ['157', '160']}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'log_metrics_flush_pause'}; {'id': '160', 'type': 'block', 'children': ['161']}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'call', 'children': ['163', '166']}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '166', 'type': 'argument_list', 'children': ['167', '170']}, {'id': '167', 'type': 'concatenated_string', 'children': ['168', '169']}; {'id': '168', 'type': 'string', 'children': [], 'value': '"Metrics flush restored. "'}, {'id': '169', 'type': 'string', 'children': [], 'value': '"Remaining stored metric: %d"'}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'metrics_count'}, {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'assignment', 'children': ['175', '178']}, {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'last_failure'}; {'id': '178', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '184']}, {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'log_metrics_flush_pause'}; {'id': '184', 'type': 'False', 'children': []}, {'id': '185', 'type': 'except_clause', 'children': ['186', '190']}; {'id': '186', 'type': 'as_pattern', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '188', 'type': 'as_pattern_target', 'children': ['189']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'exp'}; {'id': '190', 'type': 'block', 'children': ['191', '245', '256', '262']}, {'id': '191', 'type': 'if_statement', 'children': ['192', '196', '209']}; {'id': '192', 'type': 'not_operator', 'children': ['193']}, {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'log_metrics_flush_pause'}; {'id': '196', 'type': 'block', 'children': ['197']}, {'id': '197', 'type': 'expression_statement', 'children': ['198']}; {'id': '198', 'type': 'call', 'children': ['199', '202']}, {'id': '199', 'type': 'attribute', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '202', 'type': 'argument_list', 'children': ['203', '206']}, {'id': '203', 'type': 'concatenated_string', 'children': ['204', '205']}; {'id': '204', 'type': 'string', 'children': [], 'value': '"Failed sending metrics to Graphite/carbon. "'}, {'id': '205', 'type': 'string', 'children': [], 'value': '"Inner stored metric: %d"'}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'metrics_count'}, {'id': '209', 'type': 'else_clause', 'children': ['210']}; {'id': '210', 'type': 'block', 'children': ['211', '231']}, {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'assignment', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '214', 'type': 'call', 'children': ['215', '227']}, {'id': '215', 'type': 'attribute', 'children': ['216', '226']}; {'id': '216', 'type': 'call', 'children': ['217', '222']}, {'id': '217', 'type': 'attribute', 'children': ['218', '221']}; {'id': '218', 'type': 'attribute', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'fromtimestamp'}; {'id': '222', 'type': 'argument_list', 'children': ['223']}, {'id': '223', 'type': 'attribute', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'last_failure'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'strftime'}, {'id': '227', 'type': 'argument_list', 'children': ['228']}; {'id': '228', 'type': 'attribute', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'date_fmt'}, {'id': '231', 'type': 'expression_statement', 'children': ['232']}; {'id': '232', 'type': 'call', 'children': ['233', '236']}, {'id': '233', 'type': 'attribute', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '236', 'type': 'argument_list', 'children': ['237', '241', '242']}, {'id': '237', 'type': 'concatenated_string', 'children': ['238', '239', '240']}; {'id': '238', 'type': 'string', 'children': [], 'value': '"Metrics flush paused on connection error "'}, {'id': '239', 'type': 'string', 'children': [], 'value': '"(last failed: %s). "'}; {'id': '240', 'type': 'string', 'children': [], 'value': '"Inner stored metric: %d. Trying to send..."'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '242', 'type': 'attribute', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'metrics_count'}, {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'call', 'children': ['247', '250']}, {'id': '247', 'type': 'attribute', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '250', 'type': 'argument_list', 'children': ['251', '252']}, {'id': '251', 'type': 'string', 'children': [], 'value': '"Exception: %s"'}; {'id': '252', 'type': 'call', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '254', 'type': 'argument_list', 'children': ['255']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'exp'}; {'id': '256', 'type': 'expression_statement', 'children': ['257']}, {'id': '257', 'type': 'assignment', 'children': ['258', '261']}; {'id': '258', 'type': 'attribute', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'last_failure'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '262', 'type': 'return_statement', 'children': ['263']}, {'id': '263', 'type': 'False', 'children': []}; {'id': '264', 'type': 'return_statement', 'children': ['265']}, {'id': '265', 'type': 'True', 'children': []} | def flush(self, log=False):
if not self.my_metrics:
logger.debug("Flushing - no metrics to send")
return True
now = int(time.time())
if self.last_failure and self.last_failure + self.metrics_flush_pause > now:
if not self.log_metrics_flush_pause:
date = datetime.datetime.fromtimestamp(
self.last_failure).strftime(self.date_fmt)
logger.warning("Metrics flush paused on connection error "
"(last failed: %s). "
"Inner stored metric: %d. Trying to send...",
date, self.metrics_count)
self.log_metrics_flush_pause = True
return True
try:
logger.debug("Flushing %d metrics to Graphite/carbon", self.metrics_count)
if self.carbon.send_data():
self.my_metrics = []
else:
logger.warning("Failed sending metrics to Graphite/carbon. "
"Inner stored metric: %d", self.metrics_count)
if log:
logger.warning("Failed sending metrics to Graphite/carbon. "
"Inner stored metric: %d", self.metrics_count)
return False
if self.log_metrics_flush_pause:
logger.warning("Metrics flush restored. "
"Remaining stored metric: %d", self.metrics_count)
self.last_failure = 0
self.log_metrics_flush_pause = False
except Exception as exp:
if not self.log_metrics_flush_pause:
logger.warning("Failed sending metrics to Graphite/carbon. "
"Inner stored metric: %d", self.metrics_count)
else:
date = datetime.datetime.fromtimestamp(
self.last_failure).strftime(self.date_fmt)
logger.warning("Metrics flush paused on connection error "
"(last failed: %s). "
"Inner stored metric: %d. Trying to send...",
date, self.metrics_count)
logger.warning("Exception: %s", str(exp))
self.last_failure = now
return False
return True |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'ERROR', 'children': ['2', '252', '317']}; {'id': '2', 'type': 'function_definition', 'children': ['3', '4', '11']}, {'id': '3', 'type': 'function_name', 'children': [], 'value': 'counter'}; {'id': '4', 'type': 'parameters', 'children': ['5', '6', '7', '8']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '32', '36', '40', '53', '66', '78', '134', '154', '239', '241']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '19']}; {'id': '14', 'type': 'pattern_list', 'children': ['15', '16', '17', '18']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': '_min'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': '_max'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': '_sum'}, {'id': '19', 'type': 'call', 'children': ['20', '25']}; {'id': '20', 'type': 'attribute', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'stats'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '25', 'type': 'argument_list', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '27', 'type': 'tuple', 'children': ['28', '29', '30', '31']}; {'id': '28', 'type': 'None', 'children': []}, {'id': '29', 'type': 'None', 'children': []}; {'id': '30', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '31', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'augmented_assignment', 'children': ['34', '35'], 'value': '+='}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '35', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'augmented_assignment', 'children': ['38', '39'], 'value': '+='}; {'id': '38', 'type': 'identifier', 'children': [], 'value': '_sum'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '40', 'type': 'if_statement', 'children': ['41', '48']}, {'id': '41', 'type': 'boolean_operator', 'children': ['42', '45'], 'value': 'or'}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'is'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': '_min'}; {'id': '44', 'type': 'None', 'children': []}, {'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': '<'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': '_min'}; {'id': '48', 'type': 'block', 'children': ['49']}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': '_min'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '53', 'type': 'if_statement', 'children': ['54', '61']}; {'id': '54', 'type': 'boolean_operator', 'children': ['55', '58'], 'value': 'or'}, {'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': 'is'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': '_max'}, {'id': '57', 'type': 'None', 'children': []}; {'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': '>'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': '_max'}, {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': '_max'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '73']}; {'id': '68', 'type': 'subscript', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'stats'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '73', 'type': 'tuple', 'children': ['74', '75', '76', '77']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': '_min'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': '_max'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'count'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': '_sum'}; {'id': '78', 'type': 'if_statement', 'children': ['79', '86']}, {'id': '79', 'type': 'boolean_operator', 'children': ['80', '83'], 'value': 'and'}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'statsd_enabled'}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'statsd_sock'}; {'id': '86', 'type': 'block', 'children': ['87', '101', '110']}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'packet'}; {'id': '90', 'type': 'binary_operator', 'children': ['91', '92'], 'value': '%'}, {'id': '91', 'type': 'string', 'children': [], 'value': "'%s.%s.%s:%d|c'"}; {'id': '92', 'type': 'tuple', 'children': ['93', '96', '99', '100']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'statsd_prefix'}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'packet'}; {'id': '104', 'type': 'call', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'packet'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'encode'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'id': '110', 'type': 'try_statement', 'children': ['111', '124']}, {'id': '111', 'type': 'block', 'children': ['112']}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'call', 'children': ['114', '119']}; {'id': '114', 'type': 'attribute', 'children': ['115', '118']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'statsd_sock'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'sendto'}, {'id': '119', 'type': 'argument_list', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'packet'}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'statsd_addr'}; {'id': '124', 'type': 'except_clause', 'children': ['125', '132']}, {'id': '125', 'type': 'tuple', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'socket'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'socket'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'gaierror'}; {'id': '132', 'type': 'block', 'children': ['133']}, {'id': '133', 'type': 'pass_statement', 'children': []}; {'id': '134', 'type': 'if_statement', 'children': ['135', '142']}, {'id': '135', 'type': 'boolean_operator', 'children': ['136', '139'], 'value': 'and'}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'statsd_enabled'}, {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'carbon'}; {'id': '142', 'type': 'block', 'children': ['143']}, {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'call', 'children': ['145', '148']}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'send_to_graphite'}; {'id': '148', 'type': 'argument_list', 'children': ['149', '150', '151']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '151', 'type': 'keyword_argument', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'timestamp'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '154', 'type': 'if_statement', 'children': ['155', '162', '229']}, {'id': '155', 'type': 'boolean_operator', 'children': ['156', '159'], 'value': 'and'}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'statsd_enabled'}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'file_d'}; {'id': '162', 'type': 'ERROR', 'children': ['163', '179', '185', '217', '218', '221', '223', '224', '227', '228']}, {'id': '163', 'type': 'if_statement', 'children': ['164', '167']}; {'id': '164', 'type': 'comparison_operator', 'children': ['165', '166'], 'value': 'is'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '166', 'type': 'None', 'children': []}, {'id': '167', 'type': 'block', 'children': ['168']}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'assignment', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'timestamp'}, {'id': '171', 'type': 'call', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'call', 'children': ['175', '178']}, {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '178', 'type': 'argument_list', 'children': []}, {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'packet'}; {'id': '182', 'type': 'attribute', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'line_fmt'}, {'id': '185', 'type': 'if_statement', 'children': ['186', '190', '197']}; {'id': '186', 'type': 'not_operator', 'children': ['187']}, {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'date_fmt'}; {'id': '190', 'type': 'block', 'children': ['191']}, {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'assignment', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '194', 'type': 'binary_operator', 'children': ['195', '196'], 'value': '%'}, {'id': '195', 'type': 'string', 'children': [], 'value': '"%s"'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'timestamp'}, {'id': '197', 'type': 'else_clause', 'children': ['198']}; {'id': '198', 'type': 'block', 'children': ['199']}, {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'date'}; {'id': '202', 'type': 'call', 'children': ['203', '213']}, {'id': '203', 'type': 'attribute', 'children': ['204', '212']}; {'id': '204', 'type': 'call', 'children': ['205', '210']}, {'id': '205', 'type': 'attribute', 'children': ['206', '209']}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'fromtimestamp'}; {'id': '210', 'type': 'argument_list', 'children': ['211']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'strftime'}, {'id': '213', 'type': 'argument_list', 'children': ['214']}; {'id': '214', 'type': 'attribute', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'date_fmt'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'packet'}; {'id': '218', 'type': 'attribute', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'packet'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'replace'}, {'id': '221', 'type': 'ERROR', 'children': ['222']}; {'id': '222', 'type': 'string', 'children': [], 'value': '"\n packet = packet.replace("'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'packet'}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'packet'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'replace'}, {'id': '227', 'type': 'string', 'children': [], 'value': '"\n packet = packet.replace("'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'try'}, {'id': '229', 'type': 'block', 'children': ['230']}; {'id': '230', 'type': 'expression_statement', 'children': ['231']}, {'id': '231', 'type': 'call', 'children': ['232', '237']}; {'id': '232', 'type': 'attribute', 'children': ['233', '236']}, {'id': '233', 'type': 'attribute', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'file_d'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'write'}, {'id': '237', 'type': 'argument_list', 'children': ['238']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'packet'}, {'id': '239', 'type': 'ERROR', 'children': ['240']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'except'}, {'id': '241', 'type': 'expression_statement', 'children': ['242']}; {'id': '242', 'type': 'assignment', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'IOError'}; {'id': '244', 'type': 'type', 'children': ['245']}, {'id': '245', 'type': 'call', 'children': ['246', '249']}; {'id': '246', 'type': 'attribute', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '249', 'type': 'argument_list', 'children': ['250', '251']}; {'id': '250', 'type': 'string', 'children': [], 'value': '"Could not write to the file: %s"'}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'packet'}; {'id': '252', 'type': 'if_statement', 'children': ['253', '256']}, {'id': '253', 'type': 'attribute', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'broks_enabled'}; {'id': '256', 'type': 'block', 'children': ['257', '266', '282']}, {'id': '257', 'type': 'expression_statement', 'children': ['258']}; {'id': '258', 'type': 'call', 'children': ['259', '262']}, {'id': '259', 'type': 'attribute', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '262', 'type': 'argument_list', 'children': ['263', '264', '265']}, {'id': '263', 'type': 'string', 'children': [], 'value': '"alignak stat brok: %s = %s"'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '266', 'type': 'if_statement', 'children': ['267', '270']}, {'id': '267', 'type': 'comparison_operator', 'children': ['268', '269'], 'value': 'is'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'timestamp'}, {'id': '269', 'type': 'None', 'children': []}; {'id': '270', 'type': 'block', 'children': ['271']}, {'id': '271', 'type': 'expression_statement', 'children': ['272']}; {'id': '272', 'type': 'assignment', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '274', 'type': 'call', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '276', 'type': 'argument_list', 'children': ['277']}, {'id': '277', 'type': 'call', 'children': ['278', '281']}; {'id': '278', 'type': 'attribute', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '281', 'type': 'argument_list', 'children': []}; {'id': '282', 'type': 'return_statement', 'children': ['283']}, {'id': '283', 'type': 'call', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'Brok'}, {'id': '285', 'type': 'argument_list', 'children': ['286']}; {'id': '286', 'type': 'dictionary', 'children': ['287', '290']}, {'id': '287', 'type': 'pair', 'children': ['288', '289']}; {'id': '288', 'type': 'string', 'children': [], 'value': "'type'"}, {'id': '289', 'type': 'string', 'children': [], 'value': "'alignak_stat'"}; {'id': '290', 'type': 'pair', 'children': ['291', '292']}, {'id': '291', 'type': 'string', 'children': [], 'value': "'data'"}; {'id': '292', 'type': 'dictionary', 'children': ['293', '296', '299', '311', '314']}, {'id': '293', 'type': 'pair', 'children': ['294', '295']}; {'id': '294', 'type': 'string', 'children': [], 'value': "'ts'"}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '296', 'type': 'pair', 'children': ['297', '298']}, {'id': '297', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '298', 'type': 'string', 'children': [], 'value': "'counter'"}, {'id': '299', 'type': 'pair', 'children': ['300', '301']}; {'id': '300', 'type': 'string', 'children': [], 'value': "'metric'"}, {'id': '301', 'type': 'binary_operator', 'children': ['302', '303'], 'value': '%'}; {'id': '302', 'type': 'string', 'children': [], 'value': "'%s.%s.%s'"}, {'id': '303', 'type': 'tuple', 'children': ['304', '307', '310']}; {'id': '304', 'type': 'attribute', 'children': ['305', '306']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'statsd_prefix'}, {'id': '307', 'type': 'attribute', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '311', 'type': 'pair', 'children': ['312', '313']}; {'id': '312', 'type': 'string', 'children': [], 'value': "'value'"}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '314', 'type': 'pair', 'children': ['315', '316']}, {'id': '315', 'type': 'string', 'children': [], 'value': "'uom'"}; {'id': '316', 'type': 'string', 'children': [], 'value': "'c'"}, {'id': '317', 'type': 'return_statement', 'children': ['318']} | def counter(self, key, value, timestamp=None):
_min, _max, count, _sum = self.stats.get(key, (None, None, 0, 0))
count += 1
_sum += value
if _min is None or value < _min:
_min = value
if _max is None or value > _max:
_max = value
self.stats[key] = (_min, _max, count, _sum)
if self.statsd_enabled and self.statsd_sock:
packet = '%s.%s.%s:%d|c' % (self.statsd_prefix, self.name, key, value)
packet = packet.encode('utf-8')
try:
self.statsd_sock.sendto(packet, self.statsd_addr)
except (socket.error, socket.gaierror):
pass
if self.statsd_enabled and self.carbon:
self.send_to_graphite(key, value, timestamp=timestamp)
if self.statsd_enabled and self.file_d:
if timestamp is None:
timestamp = int(time.time())
packet = self.line_fmt
if not self.date_fmt:
date = "%s" % timestamp
else:
date = datetime.datetime.fromtimestamp(timestamp).strftime(self.date_fmt)
packet = packet.replace("
packet = packet.replace("
packet = packet.replace("
packet = packet.replace("
try:
self.file_d.write(packet)
except IOError:
logger.warning("Could not write to the file: %s", packet)
if self.broks_enabled:
logger.debug("alignak stat brok: %s = %s", key, value)
if timestamp is None:
timestamp = int(time.time())
return Brok({'type': 'alignak_stat',
'data': {
'ts': timestamp,
'type': 'counter',
'metric': '%s.%s.%s' % (self.statsd_prefix, self.name, key),
'value': value,
'uom': 'c'
}})
return None |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'create_and_launch_worker'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'module_name'}, {'id': '7', 'type': 'string', 'children': [], 'value': "'fork'"}; {'id': '8', 'type': 'block', 'children': ['9', '17', '21', '25', '99', '105', '132', '144', '158', '164']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '14', 'type': 'argument_list', 'children': ['15', '16']}, {'id': '15', 'type': 'string', 'children': [], 'value': '"Allocating new \'%s\' worker..."'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'module_name'}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '20', 'type': 'None', 'children': []}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': '__warned'}; {'id': '24', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '25', 'type': 'if_statement', 'children': ['26', '29', '34']}; {'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': '=='}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'module_name'}; {'id': '28', 'type': 'string', 'children': [], 'value': "'fork'"}, {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'target'}, {'id': '33', 'type': 'None', 'children': []}; {'id': '34', 'type': 'else_clause', 'children': ['35']}, {'id': '35', 'type': 'block', 'children': ['36', '73']}; {'id': '36', 'type': 'for_statement', 'children': ['37', '38', '43']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '38', 'type': 'attribute', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'modules_manager'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'instances'}, {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'if_statement', 'children': ['45', '52']}, {'id': '45', 'type': 'comparison_operator', 'children': ['46', '51'], 'value': '=='}; {'id': '46', 'type': 'call', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'module'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'get_name'}; {'id': '50', 'type': 'argument_list', 'children': []}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'module_name'}; {'id': '52', 'type': 'block', 'children': ['53', '67']}, {'id': '53', 'type': 'if_statement', 'children': ['54', '64']}; {'id': '54', 'type': 'not_operator', 'children': ['55']}, {'id': '55', 'type': 'call', 'children': ['56', '61']}; {'id': '56', 'type': 'attribute', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'module'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '61', 'type': 'argument_list', 'children': ['62', '63']}; {'id': '62', 'type': 'string', 'children': [], 'value': "'worker_capable'"}, {'id': '63', 'type': 'False', 'children': []}; {'id': '64', 'type': 'block', 'children': ['65']}, {'id': '65', 'type': 'raise_statement', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'NotWorkerMod'}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'work'}, {'id': '73', 'type': 'if_statement', 'children': ['74', '77']}; {'id': '74', 'type': 'comparison_operator', 'children': ['75', '76'], 'value': 'is'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '76', 'type': 'None', 'children': []}, {'id': '77', 'type': 'block', 'children': ['78', '98']}; {'id': '78', 'type': 'if_statement', 'children': ['79', '82']}, {'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': 'not'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'module_name'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': '__warned'}; {'id': '82', 'type': 'block', 'children': ['83', '91']}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'call', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '90']}, {'id': '89', 'type': 'string', 'children': [], 'value': '"No target found for %s, NOT creating a worker for it..."'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'module_name'}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': '__warned'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'module_name'}; {'id': '98', 'type': 'return_statement', 'children': []}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'queue'}; {'id': '102', 'type': 'call', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'Queue'}; {'id': '104', 'type': 'argument_list', 'children': []}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'worker'}; {'id': '108', 'type': 'call', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'Worker'}; {'id': '110', 'type': 'argument_list', 'children': ['111', '112', '113', '116', '119', '124', '127']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'module_name'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'queue'}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'returns_queue'}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'processes_by_worker'}, {'id': '119', 'type': 'keyword_argument', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'max_plugins_output_length'}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'max_plugins_output_length'}; {'id': '124', 'type': 'keyword_argument', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'target'}, {'id': '127', 'type': 'keyword_argument', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'loaded_into'}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'assignment', 'children': ['134', '143']}; {'id': '134', 'type': 'subscript', 'children': ['135', '138']}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'workers'}; {'id': '138', 'type': 'call', 'children': ['139', '142']}, {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'worker'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'get_id'}; {'id': '142', 'type': 'argument_list', 'children': []}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'worker'}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'assignment', 'children': ['146', '157']}; {'id': '146', 'type': 'subscript', 'children': ['147', '152']}, {'id': '147', 'type': 'subscript', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'q_by_mod'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'module_name'}; {'id': '152', 'type': 'call', 'children': ['153', '156']}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'worker'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'get_id'}; {'id': '156', 'type': 'argument_list', 'children': []}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'queue'}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}, {'id': '159', 'type': 'call', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'worker'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '163', 'type': 'argument_list', 'children': []}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}, {'id': '165', 'type': 'call', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '169', 'type': 'argument_list', 'children': ['170', '171', '172', '177']}; {'id': '170', 'type': 'string', 'children': [], 'value': '"Started \'%s\' worker: %s (pid=%d)"'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'module_name'}; {'id': '172', 'type': 'call', 'children': ['173', '176']}, {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'worker'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'get_id'}; {'id': '176', 'type': 'argument_list', 'children': []}, {'id': '177', 'type': 'call', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'worker'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'get_pid'}, {'id': '181', 'type': 'argument_list', 'children': []} | def create_and_launch_worker(self, module_name='fork'):
logger.info("Allocating new '%s' worker...", module_name)
target = None
__warned = []
if module_name == 'fork':
target = None
else:
for module in self.modules_manager.instances:
if module.get_name() == module_name:
if not module.properties.get('worker_capable', False):
raise NotWorkerMod
target = module.work
if target is None:
if module_name not in __warned:
logger.warning("No target found for %s, NOT creating a worker for it...",
module_name)
__warned.append(module_name)
return
queue = Queue()
worker = Worker(module_name, queue, self.returns_queue, self.processes_by_worker,
max_plugins_output_length=self.max_plugins_output_length,
target=target, loaded_into=self.name)
self.workers[worker.get_id()] = worker
self.q_by_mod[module_name][worker.get_id()] = queue
worker.start()
logger.info("Started '%s' worker: %s (pid=%d)",
module_name, worker.get_id(), worker.get_pid()) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'check_and_del_zombie_workers'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '20', '24', '110']}; {'id': '6', 'type': 'for_statement', 'children': ['7', '8', '11']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '8', 'type': 'call', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'active_children'}; {'id': '10', 'type': 'argument_list', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '17', 'type': 'argument_list', 'children': ['18', '19']}; {'id': '18', 'type': 'string', 'children': [], 'value': '"got child: %s"'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'w_to_del'}, {'id': '23', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '24', 'type': 'for_statement', 'children': ['25', '26', '36']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'worker'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'call', 'children': ['30', '35']}; {'id': '30', 'type': 'attribute', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'workers'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '35', 'type': 'argument_list', 'children': []}; {'id': '36', 'type': 'block', 'children': ['37', '54']}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '44', '49']}, {'id': '43', 'type': 'string', 'children': [], 'value': '"checking if worker %s (pid=%d) is alive"'}; {'id': '44', 'type': 'call', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'worker'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'get_id'}; {'id': '48', 'type': 'argument_list', 'children': []}, {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'worker'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'get_pid'}, {'id': '53', 'type': 'argument_list', 'children': []}; {'id': '54', 'type': 'if_statement', 'children': ['55', '66']}, {'id': '55', 'type': 'boolean_operator', 'children': ['56', '60'], 'value': 'and'}; {'id': '56', 'type': 'not_operator', 'children': ['57']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'interrupted'}; {'id': '60', 'type': 'not_operator', 'children': ['61']}, {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'worker'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'is_alive'}, {'id': '65', 'type': 'argument_list', 'children': []}; {'id': '66', 'type': 'block', 'children': ['67', '84', '90', '99']}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '72', 'type': 'argument_list', 'children': ['73', '74', '79']}, {'id': '73', 'type': 'string', 'children': [], 'value': '"The worker %s (pid=%d) went down unexpectedly!"'}; {'id': '74', 'type': 'call', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'worker'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'get_id'}; {'id': '78', 'type': 'argument_list', 'children': []}, {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'worker'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'get_pid'}, {'id': '83', 'type': 'argument_list', 'children': []}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'worker'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'terminate'}, {'id': '89', 'type': 'argument_list', 'children': []}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'worker'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'keyword_argument', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '98', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'call', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'w_to_del'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'call', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'worker'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'get_id'}, {'id': '109', 'type': 'argument_list', 'children': []}; {'id': '110', 'type': 'for_statement', 'children': ['111', '112', '113']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'worker_id'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'w_to_del'}, {'id': '113', 'type': 'block', 'children': ['114', '122', '136', '183']}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'worker'}, {'id': '117', 'type': 'subscript', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'workers'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'worker_id'}; {'id': '122', 'type': 'delete_statement', 'children': ['123']}, {'id': '123', 'type': 'subscript', 'children': ['124', '131']}; {'id': '124', 'type': 'subscript', 'children': ['125', '128']}, {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'q_by_mod'}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'worker'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'module_name'}, {'id': '131', 'type': 'call', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'worker'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'get_id'}, {'id': '135', 'type': 'argument_list', 'children': []}; {'id': '136', 'type': 'for_statement', 'children': ['137', '138', '141']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'scheduler_uuid'}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'schedulers'}, {'id': '141', 'type': 'block', 'children': ['142', '150']}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'assignment', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'sched'}, {'id': '145', 'type': 'subscript', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'schedulers'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'scheduler_uuid'}; {'id': '150', 'type': 'for_statement', 'children': ['151', '152', '162']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'act'}; {'id': '152', 'type': 'call', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '154', 'type': 'argument_list', 'children': ['155']}, {'id': '155', 'type': 'call', 'children': ['156', '161']}; {'id': '156', 'type': 'attribute', 'children': ['157', '160']}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'sched'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'actions'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '161', 'type': 'argument_list', 'children': []}; {'id': '162', 'type': 'block', 'children': ['163']}, {'id': '163', 'type': 'if_statement', 'children': ['164', '175']}; {'id': '164', 'type': 'boolean_operator', 'children': ['165', '170'], 'value': 'and'}, {'id': '165', 'type': 'comparison_operator', 'children': ['166', '169'], 'value': '=='}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'act'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'status'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'ACT_STATUS_QUEUED'}; {'id': '170', 'type': 'comparison_operator', 'children': ['171', '174'], 'value': '=='}, {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'act'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'my_worker'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'worker_id'}, {'id': '175', 'type': 'block', 'children': ['176']}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'call', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'assign_to_a_queue'}, {'id': '181', 'type': 'argument_list', 'children': ['182']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'act'}, {'id': '183', 'type': 'delete_statement', 'children': ['184']}; {'id': '184', 'type': 'subscript', 'children': ['185', '188']}, {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'workers'} | def check_and_del_zombie_workers(self):
for p in active_children():
logger.debug("got child: %s", p)
w_to_del = []
for worker in list(self.workers.values()):
logger.debug("checking if worker %s (pid=%d) is alive",
worker.get_id(), worker.get_pid())
if not self.interrupted and not worker.is_alive():
logger.warning("The worker %s (pid=%d) went down unexpectedly!",
worker.get_id(), worker.get_pid())
worker.terminate()
worker.join(timeout=1)
w_to_del.append(worker.get_id())
for worker_id in w_to_del:
worker = self.workers[worker_id]
del self.q_by_mod[worker.module_name][worker.get_id()]
for scheduler_uuid in self.schedulers:
sched = self.schedulers[scheduler_uuid]
for act in list(sched.actions.values()):
if act.status == ACT_STATUS_QUEUED and act.my_worker == worker_id:
self.assign_to_a_queue(act)
del self.workers[worker_id] |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_actions'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'actions_list'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'scheduler_instance_id'}, {'id': '7', 'type': 'block', 'children': ['8', '12', '61', '77', '85']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'scheduler_link'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'for_statement', 'children': ['13', '14', '17', '50']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'scheduler_id'}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'schedulers'}, {'id': '17', 'type': 'block', 'children': ['18', '30']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '23', 'type': 'argument_list', 'children': ['24', '25']}; {'id': '24', 'type': 'string', 'children': [], 'value': '"Trying to add an action, scheduler: %s"'}, {'id': '25', 'type': 'subscript', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'schedulers'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'scheduler_id'}; {'id': '30', 'type': 'if_statement', 'children': ['31', '40']}, {'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': '=='}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'scheduler_instance_id'}, {'id': '33', 'type': 'attribute', 'children': ['34', '39']}; {'id': '34', 'type': 'subscript', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'schedulers'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'scheduler_id'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'instance_id'}; {'id': '40', 'type': 'block', 'children': ['41', '49']}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'scheduler_link'}; {'id': '44', 'type': 'subscript', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'schedulers'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'scheduler_id'}, {'id': '49', 'type': 'break_statement', 'children': []}; {'id': '50', 'type': 'else_clause', 'children': ['51']}, {'id': '51', 'type': 'block', 'children': ['52', '60']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '57', 'type': 'argument_list', 'children': ['58', '59']}; {'id': '58', 'type': 'string', 'children': [], 'value': '"Trying to add actions from an unknwown scheduler: %s"'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'scheduler_instance_id'}; {'id': '60', 'type': 'return_statement', 'children': []}, {'id': '61', 'type': 'if_statement', 'children': ['62', '64']}; {'id': '62', 'type': 'not_operator', 'children': ['63']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'scheduler_link'}; {'id': '64', 'type': 'block', 'children': ['65', '76']}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '70', 'type': 'argument_list', 'children': ['71', '74', '75']}, {'id': '71', 'type': 'concatenated_string', 'children': ['72', '73']}; {'id': '72', 'type': 'string', 'children': [], 'value': '"Trying to add actions, but scheduler link is not found for: %s, "'}, {'id': '73', 'type': 'string', 'children': [], 'value': '"actions: %s"'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'scheduler_instance_id'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'actions_list'}; {'id': '76', 'type': 'return_statement', 'children': []}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '82', 'type': 'argument_list', 'children': ['83', '84']}, {'id': '83', 'type': 'string', 'children': [], 'value': '"Found scheduler link: %s"'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'scheduler_link'}, {'id': '85', 'type': 'for_statement', 'children': ['86', '87', '88']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'action'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'actions_list'}; {'id': '88', 'type': 'block', 'children': ['89', '98', '133', '141', '149', '159']}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '92', 'type': 'call', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '94', 'type': 'argument_list', 'children': ['95', '96', '97']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '96', 'type': 'string', 'children': [], 'value': "'uuid'"}, {'id': '97', 'type': 'None', 'children': []}; {'id': '98', 'type': 'if_statement', 'children': ['99', '102']}, {'id': '99', 'type': 'comparison_operator', 'children': ['100', '101'], 'value': 'is'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'uuid'}, {'id': '101', 'type': 'None', 'children': []}; {'id': '102', 'type': 'block', 'children': ['103']}, {'id': '103', 'type': 'try_statement', 'children': ['104', '121']}; {'id': '104', 'type': 'block', 'children': ['105', '115']}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '108', 'type': 'call', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'unserialize'}; {'id': '110', 'type': 'argument_list', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '112', 'type': 'keyword_argument', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'no_load'}; {'id': '114', 'type': 'True', 'children': []}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'uuid'}, {'id': '121', 'type': 'except_clause', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'AlignakClassLookupException'}, {'id': '123', 'type': 'block', 'children': ['124', '132']}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'call', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '129', 'type': 'argument_list', 'children': ['130', '131']}; {'id': '130', 'type': 'string', 'children': [], 'value': "'Cannot un-serialize action: %s'"}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'action'}; {'id': '132', 'type': 'continue_statement', 'children': []}, {'id': '133', 'type': 'if_statement', 'children': ['134', '139']}; {'id': '134', 'type': 'comparison_operator', 'children': ['135', '136'], 'value': 'in'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'scheduler_link'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'actions'}, {'id': '139', 'type': 'block', 'children': ['140']}; {'id': '140', 'type': 'continue_statement', 'children': []}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '146']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'action'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'my_scheduler'}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'scheduler_link'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'uuid'}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'assignment', 'children': ['151', '158']}, {'id': '151', 'type': 'subscript', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'scheduler_link'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'actions'}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'action'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'action'}, {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'call', 'children': ['161', '164']}, {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'assign_to_a_queue'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'action'} | def add_actions(self, actions_list, scheduler_instance_id):
scheduler_link = None
for scheduler_id in self.schedulers:
logger.debug("Trying to add an action, scheduler: %s", self.schedulers[scheduler_id])
if scheduler_instance_id == self.schedulers[scheduler_id].instance_id:
scheduler_link = self.schedulers[scheduler_id]
break
else:
logger.error("Trying to add actions from an unknwown scheduler: %s",
scheduler_instance_id)
return
if not scheduler_link:
logger.error("Trying to add actions, but scheduler link is not found for: %s, "
"actions: %s", scheduler_instance_id, actions_list)
return
logger.debug("Found scheduler link: %s", scheduler_link)
for action in actions_list:
uuid = getattr(action, 'uuid', None)
if uuid is None:
try:
action = unserialize(action, no_load=True)
uuid = action.uuid
except AlignakClassLookupException:
logger.error('Cannot un-serialize action: %s', action)
continue
if uuid in scheduler_link.actions:
continue
action.my_scheduler = scheduler_link.uuid
scheduler_link.actions[action.uuid] = action
self.assign_to_a_queue(action) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'split_semicolon'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'maxsplit'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '11', '20', '27', '40', '44', '127']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'split_line'}; {'id': '14', 'type': 'call', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'string', 'children': [], 'value': "';'"}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'split_line_size'}, {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'split_line'}, {'id': '27', 'type': 'if_statement', 'children': ['28', '35']}; {'id': '28', 'type': 'boolean_operator', 'children': ['29', '32'], 'value': 'or'}, {'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': 'is'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'maxsplit'}, {'id': '31', 'type': 'None', 'children': []}; {'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': '<'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'maxsplit'}; {'id': '34', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'maxsplit'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'split_line_size'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '43', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '44', 'type': 'while_statement', 'children': ['45', '50']}, {'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': '<'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '47', 'type': 'binary_operator', 'children': ['48', '49'], 'value': '-'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'split_line_size'}, {'id': '49', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '50', 'type': 'block', 'children': ['51', '62', '78']}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'ends'}; {'id': '54', 'type': 'call', 'children': ['55', '60']}, {'id': '55', 'type': 'attribute', 'children': ['56', '59']}; {'id': '56', 'type': 'subscript', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'split_line'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'endswith'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'string', 'children': [], 'value': "'\\\\'"}; {'id': '62', 'type': 'if_statement', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'ends'}; {'id': '64', 'type': 'block', 'children': ['65']}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '70']}, {'id': '67', 'type': 'subscript', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'split_line'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '70', 'type': 'subscript', 'children': ['71', '74']}, {'id': '71', 'type': 'subscript', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'split_line'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '74', 'type': 'slice', 'children': ['75', '76']}, {'id': '75', 'type': 'colon', 'children': []}; {'id': '76', 'type': 'unary_operator', 'children': ['77'], 'value': '-'}, {'id': '77', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '78', 'type': 'if_statement', 'children': ['79', '91', '121']}, {'id': '79', 'type': 'boolean_operator', 'children': ['80', '86'], 'value': 'and'}; {'id': '80', 'type': 'parenthesized_expression', 'children': ['81']}, {'id': '81', 'type': 'boolean_operator', 'children': ['82', '83'], 'value': 'or'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'ends'}, {'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': '>='}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'maxsplit'}; {'id': '86', 'type': 'comparison_operator', 'children': ['87', '88'], 'value': '<'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '88', 'type': 'binary_operator', 'children': ['89', '90'], 'value': '-'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'split_line_size'}; {'id': '90', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '91', 'type': 'block', 'children': ['92', '111', '117']}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'assignment', 'children': ['94', '97']}; {'id': '94', 'type': 'subscript', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'split_line'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '97', 'type': 'call', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'string', 'children': [], 'value': '";"'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'list', 'children': ['103', '106'], 'value': '[split_line[i], split_line[i + 1]]'}, {'id': '103', 'type': 'subscript', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'split_line'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '106', 'type': 'subscript', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'split_line'}; {'id': '108', 'type': 'binary_operator', 'children': ['109', '110'], 'value': '+'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '110', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '111', 'type': 'delete_statement', 'children': ['112']}; {'id': '112', 'type': 'subscript', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'split_line'}; {'id': '114', 'type': 'binary_operator', 'children': ['115', '116'], 'value': '+'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '116', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'augmented_assignment', 'children': ['119', '120'], 'value': '-='}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'split_line_size'}; {'id': '120', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '121', 'type': 'else_clause', 'children': ['122']}; {'id': '122', 'type': 'block', 'children': ['123']}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'augmented_assignment', 'children': ['125', '126'], 'value': '+='}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '126', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '127', 'type': 'return_statement', 'children': ['128']} | def split_semicolon(line, maxsplit=None):
r
split_line = line.split(';')
split_line_size = len(split_line)
if maxsplit is None or maxsplit < 0:
maxsplit = split_line_size
i = 0
while i < split_line_size - 1:
ends = split_line[i].endswith('\\')
if ends:
split_line[i] = split_line[i][:-1]
if (ends or i >= maxsplit) and i < split_line_size - 1:
split_line[i] = ";".join([split_line[i], split_line[i + 1]])
del split_line[i + 1]
split_line_size -= 1
else:
i += 1
return split_line |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_by_number_values'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'x00'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'y00'}; {'id': '6', 'type': 'block', 'children': ['7', '20', '34']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '17']}; {'id': '8', 'type': 'comparison_operator', 'children': ['9', '13'], 'value': '<'}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'x00'}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'y00'}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'return_statement', 'children': ['19']}, {'id': '19', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '20', 'type': 'if_statement', 'children': ['21', '30']}, {'id': '21', 'type': 'comparison_operator', 'children': ['22', '26'], 'value': '>'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'x00'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'y00'}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'return_statement', 'children': ['32']}; {'id': '32', 'type': 'unary_operator', 'children': ['33'], 'value': '-'}, {'id': '33', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '34', 'type': 'return_statement', 'children': ['35']}, {'id': '35', 'type': 'integer', 'children': [], 'value': '0'} | def sort_by_number_values(x00, y00):
if len(x00) < len(y00):
return 1
if len(x00) > len(y00):
return -1
return 0 |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_item'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '8', 'type': 'True', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '21', '25', '296', '371']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'name_property'}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '15', 'type': 'argument_list', 'children': ['16', '19', '20']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': '__class__'}, {'id': '19', 'type': 'string', 'children': [], 'value': '"name_property"'}; {'id': '20', 'type': 'None', 'children': []}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'generated_hosts'}; {'id': '24', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '25', 'type': 'if_statement', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'name_property'}, {'id': '27', 'type': 'block', 'children': ['28', '37']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '33', 'type': 'argument_list', 'children': ['34', '35', '36']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'name_property'}; {'id': '36', 'type': 'None', 'children': []}, {'id': '37', 'type': 'if_statement', 'children': ['38', '47']}; {'id': '38', 'type': 'boolean_operator', 'children': ['39', '44'], 'value': 'and'}, {'id': '39', 'type': 'boolean_operator', 'children': ['40', '41'], 'value': 'and'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': 'in'}; {'id': '42', 'type': 'string', 'children': [], 'value': "'['"}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': 'in'}, {'id': '45', 'type': 'string', 'children': [], 'value': "']'"}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '47', 'type': 'block', 'children': ['48', '69']}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'id': '51', 'type': 'subscript', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '53', 'type': 'slice', 'children': ['54', '62', '63']}; {'id': '54', 'type': 'binary_operator', 'children': ['55', '61'], 'value': '+'}, {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'find'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'string', 'children': [], 'value': '"["'}, {'id': '61', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '62', 'type': 'colon', 'children': []}, {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'find'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'string', 'children': [], 'value': '"]"'}, {'id': '69', 'type': 'if_statement', 'children': ['70', '73']}; {'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': 'in'}, {'id': '71', 'type': 'string', 'children': [], 'value': "'-'"}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'id': '73', 'type': 'block', 'children': ['74', '82', '91', '95', '99', '103', '156', '171', '186']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '79', 'type': 'argument_list', 'children': ['80', '81']}; {'id': '80', 'type': 'string', 'children': [], 'value': '"Found an host with a patterned name: %s"'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'limits'}, {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'string', 'children': [], 'value': "'-'"}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'fmt'}; {'id': '94', 'type': 'string', 'children': [], 'value': '"%d"'}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'min_v'}; {'id': '98', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'max_v'}; {'id': '102', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '103', 'type': 'if_statement', 'children': ['104', '110', '136']}; {'id': '104', 'type': 'comparison_operator', 'children': ['105', '109'], 'value': '=='}, {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'limits'}, {'id': '109', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '110', 'type': 'block', 'children': ['111', '117']}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'fmt'}; {'id': '114', 'type': 'subscript', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'limits'}; {'id': '116', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'assignment', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'new_name'}; {'id': '120', 'type': 'call', 'children': ['121', '124']}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '124', 'type': 'argument_list', 'children': ['125', '135']}, {'id': '125', 'type': 'binary_operator', 'children': ['126', '127'], 'value': '%'}; {'id': '126', 'type': 'string', 'children': [], 'value': "'[%s-%s-%s]'"}, {'id': '127', 'type': 'tuple', 'children': ['128', '131', '134']}; {'id': '128', 'type': 'subscript', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'limits'}; {'id': '130', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '131', 'type': 'subscript', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'limits'}, {'id': '133', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'fmt'}, {'id': '135', 'type': 'string', 'children': [], 'value': "'***'"}; {'id': '136', 'type': 'else_clause', 'children': ['137']}, {'id': '137', 'type': 'block', 'children': ['138']}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'new_name'}, {'id': '141', 'type': 'call', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'replace'}, {'id': '145', 'type': 'argument_list', 'children': ['146', '155']}; {'id': '146', 'type': 'binary_operator', 'children': ['147', '148'], 'value': '%'}, {'id': '147', 'type': 'string', 'children': [], 'value': "'[%s-%s]'"}; {'id': '148', 'type': 'tuple', 'children': ['149', '152']}, {'id': '149', 'type': 'subscript', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'limits'}, {'id': '151', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '152', 'type': 'subscript', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'limits'}; {'id': '154', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '155', 'type': 'string', 'children': [], 'value': "'***'"}; {'id': '156', 'type': 'try_statement', 'children': ['157', '167']}, {'id': '157', 'type': 'block', 'children': ['158']}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}, {'id': '159', 'type': 'assignment', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'min_v'}, {'id': '161', 'type': 'call', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '163', 'type': 'argument_list', 'children': ['164']}; {'id': '164', 'type': 'subscript', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'limits'}; {'id': '166', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '167', 'type': 'except_clause', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '169', 'type': 'block', 'children': ['170']}; {'id': '170', 'type': 'pass_statement', 'children': []}, {'id': '171', 'type': 'try_statement', 'children': ['172', '182']}; {'id': '172', 'type': 'block', 'children': ['173']}, {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'assignment', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'max_v'}; {'id': '176', 'type': 'call', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}, {'id': '179', 'type': 'subscript', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'limits'}, {'id': '181', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '182', 'type': 'except_clause', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '184', 'type': 'block', 'children': ['185']}, {'id': '185', 'type': 'pass_statement', 'children': []}; {'id': '186', 'type': 'for_statement', 'children': ['187', '188', '195']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '188', 'type': 'call', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '190', 'type': 'argument_list', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'min_v'}; {'id': '192', 'type': 'binary_operator', 'children': ['193', '194'], 'value': '+'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'max_v'}; {'id': '194', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '195', 'type': 'block', 'children': ['196', '212', '219', '227', '241', '289']}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'call', 'children': ['198', '201']}; {'id': '198', 'type': 'attribute', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '201', 'type': 'argument_list', 'children': ['202', '203']}; {'id': '202', 'type': 'string', 'children': [], 'value': '"- cloning host: %s"'}, {'id': '203', 'type': 'call', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'new_name'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'replace'}, {'id': '207', 'type': 'argument_list', 'children': ['208', '209']}; {'id': '208', 'type': 'string', 'children': [], 'value': "'***'"}, {'id': '209', 'type': 'binary_operator', 'children': ['210', '211'], 'value': '%'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'fmt'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '212', 'type': 'expression_statement', 'children': ['213']}, {'id': '213', 'type': 'assignment', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'new_host'}, {'id': '215', 'type': 'call', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'deepcopy'}, {'id': '217', 'type': 'argument_list', 'children': ['218']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '219', 'type': 'expression_statement', 'children': ['220']}; {'id': '220', 'type': 'assignment', 'children': ['221', '224']}, {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'new_host'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '224', 'type': 'call', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'get_a_new_object_id'}; {'id': '226', 'type': 'argument_list', 'children': []}, {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'assignment', 'children': ['229', '232']}, {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'new_host'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'host_name'}; {'id': '232', 'type': 'call', 'children': ['233', '236']}, {'id': '233', 'type': 'attribute', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'new_name'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '236', 'type': 'argument_list', 'children': ['237', '238']}, {'id': '237', 'type': 'string', 'children': [], 'value': "'***'"}; {'id': '238', 'type': 'binary_operator', 'children': ['239', '240'], 'value': '%'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'fmt'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'idx'}, {'id': '241', 'type': 'for_statement', 'children': ['242', '243', '249']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '243', 'type': 'list', 'children': ['244', '245', '246', '247', '248'], 'value': "['display_name', 'alias', 'notes', 'notes_url', 'action_url']"}; {'id': '244', 'type': 'string', 'children': [], 'value': "'display_name'"}, {'id': '245', 'type': 'string', 'children': [], 'value': "'alias'"}; {'id': '246', 'type': 'string', 'children': [], 'value': "'notes'"}, {'id': '247', 'type': 'string', 'children': [], 'value': "'notes_url'"}; {'id': '248', 'type': 'string', 'children': [], 'value': "'action_url'"}, {'id': '249', 'type': 'block', 'children': ['250', '261', '269']}; {'id': '250', 'type': 'if_statement', 'children': ['251', '259']}, {'id': '251', 'type': 'comparison_operator', 'children': ['252', '258'], 'value': 'is'}; {'id': '252', 'type': 'call', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '254', 'type': 'argument_list', 'children': ['255', '256', '257']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'new_host'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '257', 'type': 'None', 'children': []}; {'id': '258', 'type': 'None', 'children': []}, {'id': '259', 'type': 'block', 'children': ['260']}; {'id': '260', 'type': 'continue_statement', 'children': []}, {'id': '261', 'type': 'expression_statement', 'children': ['262']}; {'id': '262', 'type': 'assignment', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '264', 'type': 'call', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '266', 'type': 'argument_list', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'new_host'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '269', 'type': 'if_statement', 'children': ['270', '273']}; {'id': '270', 'type': 'comparison_operator', 'children': ['271', '272'], 'value': 'in'}, {'id': '271', 'type': 'string', 'children': [], 'value': "'$HOSTNAME$'"}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '273', 'type': 'block', 'children': ['274']}; {'id': '274', 'type': 'expression_statement', 'children': ['275']}, {'id': '275', 'type': 'call', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'setattr'}, {'id': '277', 'type': 'argument_list', 'children': ['278', '279', '280']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'new_host'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '280', 'type': 'call', 'children': ['281', '284']}, {'id': '281', 'type': 'attribute', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '284', 'type': 'argument_list', 'children': ['285', '286']}, {'id': '285', 'type': 'string', 'children': [], 'value': "'$HOSTNAME$'"}; {'id': '286', 'type': 'attribute', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'new_host'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'host_name'}, {'id': '289', 'type': 'expression_statement', 'children': ['290']}; {'id': '290', 'type': 'call', 'children': ['291', '294']}, {'id': '291', 'type': 'attribute', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'generated_hosts'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '294', 'type': 'argument_list', 'children': ['295']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'new_host'}; {'id': '296', 'type': 'if_statement', 'children': ['297', '298', '343']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'generated_hosts'}; {'id': '298', 'type': 'block', 'children': ['299', '327']}, {'id': '299', 'type': 'for_statement', 'children': ['300', '301', '302']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'new_host'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'generated_hosts'}; {'id': '302', 'type': 'block', 'children': ['303', '317']}, {'id': '303', 'type': 'if_statement', 'children': ['304', '307']}; {'id': '304', 'type': 'comparison_operator', 'children': ['305', '306'], 'value': 'is'}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '306', 'type': 'True', 'children': []}, {'id': '307', 'type': 'block', 'children': ['308']}; {'id': '308', 'type': 'expression_statement', 'children': ['309']}, {'id': '309', 'type': 'assignment', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'new_host'}, {'id': '311', 'type': 'call', 'children': ['312', '315']}; {'id': '312', 'type': 'attribute', 'children': ['313', '314']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'index_item'}, {'id': '315', 'type': 'argument_list', 'children': ['316']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'new_host'}, {'id': '317', 'type': 'expression_statement', 'children': ['318']}; {'id': '318', 'type': 'assignment', 'children': ['319', '326']}, {'id': '319', 'type': 'subscript', 'children': ['320', '323']}; {'id': '320', 'type': 'attribute', 'children': ['321', '322']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '323', 'type': 'attribute', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'new_host'}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'new_host'}, {'id': '327', 'type': 'expression_statement', 'children': ['328']}; {'id': '328', 'type': 'call', 'children': ['329', '332']}, {'id': '329', 'type': 'attribute', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '332', 'type': 'argument_list', 'children': ['333', '334', '338']}, {'id': '333', 'type': 'string', 'children': [], 'value': '" cloned %d hosts from %s"'}; {'id': '334', 'type': 'call', 'children': ['335', '336']}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '336', 'type': 'argument_list', 'children': ['337']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'generated_hosts'}; {'id': '338', 'type': 'call', 'children': ['339', '342']}, {'id': '339', 'type': 'attribute', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'get_name'}; {'id': '342', 'type': 'argument_list', 'children': []}, {'id': '343', 'type': 'else_clause', 'children': ['344']}; {'id': '344', 'type': 'block', 'children': ['345', '361']}, {'id': '345', 'type': 'if_statement', 'children': ['346', '351']}; {'id': '346', 'type': 'boolean_operator', 'children': ['347', '350'], 'value': 'and'}, {'id': '347', 'type': 'comparison_operator', 'children': ['348', '349'], 'value': 'is'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'index'}, {'id': '349', 'type': 'True', 'children': []}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'name_property'}, {'id': '351', 'type': 'block', 'children': ['352']}; {'id': '352', 'type': 'expression_statement', 'children': ['353']}, {'id': '353', 'type': 'assignment', 'children': ['354', '355']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '355', 'type': 'call', 'children': ['356', '359']}; {'id': '356', 'type': 'attribute', 'children': ['357', '358']}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'index_item'}, {'id': '359', 'type': 'argument_list', 'children': ['360']}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '361', 'type': 'expression_statement', 'children': ['362']}; {'id': '362', 'type': 'assignment', 'children': ['363', '370']}, {'id': '363', 'type': 'subscript', 'children': ['364', '367']}; {'id': '364', 'type': 'attribute', 'children': ['365', '366']}, {'id': '365', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '367', 'type': 'attribute', 'children': ['368', '369']}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '371', 'type': 'return_statement', 'children': ['372']} | def add_item(self, item, index=True):
name_property = getattr(self.__class__, "name_property", None)
generated_hosts = []
if name_property:
name = getattr(item, name_property, None)
if name and '[' in name and ']' in name:
pattern = name[name.find("[")+1:name.find("]")]
if '-' in pattern:
logger.debug("Found an host with a patterned name: %s", pattern)
limits = pattern.split('-')
fmt = "%d"
min_v = 1
max_v = 1
if len(limits) == 3:
fmt = limits[2]
new_name = name.replace('[%s-%s-%s]' % (limits[0], limits[1], fmt), '***')
else:
new_name = name.replace('[%s-%s]' % (limits[0], limits[1]), '***')
try:
min_v = int(limits[0])
except ValueError:
pass
try:
max_v = int(limits[1])
except ValueError:
pass
for idx in range(min_v, max_v + 1):
logger.debug("- cloning host: %s", new_name.replace('***', fmt % idx))
new_host = deepcopy(item)
new_host.uuid = get_a_new_object_id()
new_host.host_name = new_name.replace('***', fmt % idx)
for prop in ['display_name', 'alias', 'notes', 'notes_url', 'action_url']:
if getattr(new_host, prop, None) is None:
continue
value = getattr(new_host, prop)
if '$HOSTNAME$' in value:
setattr(new_host, prop, value.replace('$HOSTNAME$',
new_host.host_name))
generated_hosts.append(new_host)
if generated_hosts:
for new_host in generated_hosts:
if index is True:
new_host = self.index_item(new_host)
self.items[new_host.uuid] = new_host
logger.info(" cloned %d hosts from %s", len(generated_hosts), item.get_name())
else:
if index is True and name_property:
item = self.index_item(item)
self.items[item.uuid] = item
return generated_hosts |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'explode_contact_groups_into_contacts'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'contactgroups'}; {'id': '6', 'type': 'block', 'children': ['7', '16', '20', '53', '60']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '14']}; {'id': '8', 'type': 'not_operator', 'children': ['9']}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '11', 'type': 'argument_list', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '13', 'type': 'string', 'children': [], 'value': "'contact_groups'"}; {'id': '14', 'type': 'block', 'children': ['15']}, {'id': '15', 'type': 'return_statement', 'children': []}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'cgnames'}, {'id': '19', 'type': 'string', 'children': [], 'value': "''"}; {'id': '20', 'type': 'if_statement', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'contact_groups'}; {'id': '24', 'type': 'block', 'children': ['25']}, {'id': '25', 'type': 'if_statement', 'children': ['26', '33', '40']}; {'id': '26', 'type': 'call', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'contact_groups'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'cgnames'}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'contact_groups'}; {'id': '40', 'type': 'else_clause', 'children': ['41']}, {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'cgnames'}, {'id': '45', 'type': 'call', 'children': ['46', '51']}; {'id': '46', 'type': 'attribute', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'contact_groups'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'string', 'children': [], 'value': "','"}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'cgnames'}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'strip_and_uniq'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'cgnames'}; {'id': '60', 'type': 'for_statement', 'children': ['61', '62', '63']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'cgname'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'cgnames'}, {'id': '63', 'type': 'block', 'children': ['64', '73', '98', '107']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'contactgroup'}, {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'contactgroups'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'find_by_name'}, {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'cgname'}, {'id': '73', 'type': 'if_statement', 'children': ['74', '76']}; {'id': '74', 'type': 'not_operator', 'children': ['75']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'contactgroup'}; {'id': '76', 'type': 'block', 'children': ['77', '97']}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'add_error'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'binary_operator', 'children': ['84', '85'], 'value': '%'}; {'id': '84', 'type': 'string', 'children': [], 'value': '"The contact group \'%s\' defined on the %s \'%s\' do not exist"'}, {'id': '85', 'type': 'tuple', 'children': ['86', '87', '92']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'cgname'}, {'id': '87', 'type': 'attribute', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': '__class__'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'my_type'}; {'id': '92', 'type': 'call', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'get_name'}; {'id': '96', 'type': 'argument_list', 'children': []}, {'id': '97', 'type': 'continue_statement', 'children': []}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'cnames'}, {'id': '101', 'type': 'call', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'contactgroups'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'get_members_of_group'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'cgname'}, {'id': '107', 'type': 'if_statement', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'cnames'}, {'id': '109', 'type': 'block', 'children': ['110']}; {'id': '110', 'type': 'if_statement', 'children': ['111', '116', '127']}, {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '113', 'type': 'argument_list', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '115', 'type': 'string', 'children': [], 'value': "'contacts'"}; {'id': '116', 'type': 'block', 'children': ['117']}, {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'assignment', 'children': ['119', '122']}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'contacts'}; {'id': '122', 'type': 'binary_operator', 'children': ['123', '126'], 'value': '+'}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'contacts'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'cnames'}, {'id': '127', 'type': 'else_clause', 'children': ['128']}; {'id': '128', 'type': 'block', 'children': ['129']}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '134']}, {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'contacts'} | def explode_contact_groups_into_contacts(item, contactgroups):
if not hasattr(item, 'contact_groups'):
return
cgnames = ''
if item.contact_groups:
if isinstance(item.contact_groups, list):
cgnames = item.contact_groups
else:
cgnames = item.contact_groups.split(',')
cgnames = strip_and_uniq(cgnames)
for cgname in cgnames:
contactgroup = contactgroups.find_by_name(cgname)
if not contactgroup:
item.add_error("The contact group '%s' defined on the %s '%s' do not exist"
% (cgname, item.__class__.my_type, item.get_name()))
continue
cnames = contactgroups.get_members_of_group(cgname)
if cnames:
if hasattr(item, 'contacts'):
item.contacts = item.contacts + cnames
else:
item.contacts = cnames |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'dfs_loop_search'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '6', 'type': 'block', 'children': ['7', '17', '122']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '16']}, {'id': '9', 'type': 'subscript', 'children': ['10', '15']}; {'id': '10', 'type': 'subscript', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'root'}, {'id': '15', 'type': 'string', 'children': [], 'value': "'dfs_loop_status'"}; {'id': '16', 'type': 'string', 'children': [], 'value': "'DFS_TEMPORARY_CHECKED'"}, {'id': '17', 'type': 'for_statement', 'children': ['18', '19', '26']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '19', 'type': 'subscript', 'children': ['20', '25']}; {'id': '20', 'type': 'subscript', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'root'}, {'id': '25', 'type': 'string', 'children': [], 'value': '"sons"'}; {'id': '26', 'type': 'block', 'children': ['27', '37', '59', '84']}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'child_status'}; {'id': '30', 'type': 'subscript', 'children': ['31', '36']}, {'id': '31', 'type': 'subscript', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'nodes'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '36', 'type': 'string', 'children': [], 'value': "'dfs_loop_status'"}, {'id': '37', 'type': 'if_statement', 'children': ['38', '41']}; {'id': '38', 'type': 'comparison_operator', 'children': ['39', '40'], 'value': '=='}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'child_status'}; {'id': '40', 'type': 'string', 'children': [], 'value': "'DFS_UNCHECKED'"}, {'id': '41', 'type': 'block', 'children': ['42', '49']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'dfs_loop_search'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'child'}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'child_status'}; {'id': '52', 'type': 'subscript', 'children': ['53', '58']}, {'id': '53', 'type': 'subscript', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'nodes'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '58', 'type': 'string', 'children': [], 'value': "'dfs_loop_status'"}, {'id': '59', 'type': 'if_statement', 'children': ['60', '63']}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': '=='}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'child_status'}; {'id': '62', 'type': 'string', 'children': [], 'value': "'DFS_TEMPORARY_CHECKED'"}, {'id': '63', 'type': 'block', 'children': ['64', '74']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '73']}; {'id': '66', 'type': 'subscript', 'children': ['67', '72']}, {'id': '67', 'type': 'subscript', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'nodes'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '72', 'type': 'string', 'children': [], 'value': "'dfs_loop_status'"}, {'id': '73', 'type': 'string', 'children': [], 'value': "'DFS_LOOP_INSIDE'"}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '83']}; {'id': '76', 'type': 'subscript', 'children': ['77', '82']}, {'id': '77', 'type': 'subscript', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'nodes'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '82', 'type': 'string', 'children': [], 'value': "'dfs_loop_status'"}, {'id': '83', 'type': 'string', 'children': [], 'value': "'DFS_LOOP_INSIDE'"}; {'id': '84', 'type': 'if_statement', 'children': ['85', '90']}, {'id': '85', 'type': 'comparison_operator', 'children': ['86', '87'], 'value': 'in'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'child_status'}, {'id': '87', 'type': 'tuple', 'children': ['88', '89']}; {'id': '88', 'type': 'string', 'children': [], 'value': "'DFS_NEAR_LOOP'"}, {'id': '89', 'type': 'string', 'children': [], 'value': "'DFS_LOOP_INSIDE'"}; {'id': '90', 'type': 'block', 'children': ['91', '112']}, {'id': '91', 'type': 'if_statement', 'children': ['92', '101']}; {'id': '92', 'type': 'comparison_operator', 'children': ['93', '100'], 'value': '!='}, {'id': '93', 'type': 'subscript', 'children': ['94', '99']}; {'id': '94', 'type': 'subscript', 'children': ['95', '98']}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'root'}, {'id': '99', 'type': 'string', 'children': [], 'value': "'dfs_loop_status'"}; {'id': '100', 'type': 'string', 'children': [], 'value': "'DFS_LOOP_INSIDE'"}, {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '111']}; {'id': '104', 'type': 'subscript', 'children': ['105', '110']}, {'id': '105', 'type': 'subscript', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'nodes'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '110', 'type': 'string', 'children': [], 'value': "'dfs_loop_status'"}, {'id': '111', 'type': 'string', 'children': [], 'value': "'DFS_NEAR_LOOP'"}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'assignment', 'children': ['114', '121']}; {'id': '114', 'type': 'subscript', 'children': ['115', '120']}, {'id': '115', 'type': 'subscript', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'nodes'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '120', 'type': 'string', 'children': [], 'value': "'dfs_loop_status'"}, {'id': '121', 'type': 'string', 'children': [], 'value': "'DFS_LOOP_INSIDE'"}; {'id': '122', 'type': 'if_statement', 'children': ['123', '132']}, {'id': '123', 'type': 'comparison_operator', 'children': ['124', '131'], 'value': '=='}; {'id': '124', 'type': 'subscript', 'children': ['125', '130']}, {'id': '125', 'type': 'subscript', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'nodes'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '130', 'type': 'string', 'children': [], 'value': "'dfs_loop_status'"}, {'id': '131', 'type': 'string', 'children': [], 'value': "'DFS_TEMPORARY_CHECKED'"}; {'id': '132', 'type': 'block', 'children': ['133']}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '142']}, {'id': '135', 'type': 'subscript', 'children': ['136', '141']}; {'id': '136', 'type': 'subscript', 'children': ['137', '140']}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'root'}, {'id': '141', 'type': 'string', 'children': [], 'value': "'dfs_loop_status'"} | def dfs_loop_search(self, root):
self.nodes[root]['dfs_loop_status'] = 'DFS_TEMPORARY_CHECKED'
for child in self.nodes[root]["sons"]:
child_status = self.nodes[child]['dfs_loop_status']
if child_status == 'DFS_UNCHECKED':
self.dfs_loop_search(child)
child_status = self.nodes[child]['dfs_loop_status']
if child_status == 'DFS_TEMPORARY_CHECKED':
self.nodes[child]['dfs_loop_status'] = 'DFS_LOOP_INSIDE'
self.nodes[root]['dfs_loop_status'] = 'DFS_LOOP_INSIDE'
if child_status in ('DFS_NEAR_LOOP', 'DFS_LOOP_INSIDE'):
if self.nodes[root]['dfs_loop_status'] != 'DFS_LOOP_INSIDE':
self.nodes[root]['dfs_loop_status'] = 'DFS_NEAR_LOOP'
self.nodes[child]['dfs_loop_status'] = 'DFS_LOOP_INSIDE'
if self.nodes[root]['dfs_loop_status'] == 'DFS_TEMPORARY_CHECKED':
self.nodes[root]['dfs_loop_status'] = 'DFS_OK' |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'eval_complex_cor_pattern'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'hosts'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'hostgroups'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'servicegroups'}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'running'}; {'id': '12', 'type': 'False', 'children': []}, {'id': '13', 'type': 'block', 'children': ['14', '20', '30', '34', '38', '42', '46', '321', '329', '370', '376']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'DependencyNode'}, {'id': '19', 'type': 'argument_list', 'children': []}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'eval_xof_pattern'}, {'id': '27', 'type': 'argument_list', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'in_par'}, {'id': '33', 'type': 'False', 'children': []}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '37', 'type': 'string', 'children': [], 'value': "''"}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'son_is_not'}, {'id': '41', 'type': 'False', 'children': []}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'stacked_parenthesis'}, {'id': '45', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '46', 'type': 'for_statement', 'children': ['47', '48', '49']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'if_statement', 'children': ['51', '54', '96', '180', '187', '221', '315']}, {'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': '=='}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'char'}, {'id': '53', 'type': 'string', 'children': [], 'value': "'('"}; {'id': '54', 'type': 'block', 'children': ['55', '59', '63', '71', '87']}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'augmented_assignment', 'children': ['57', '58'], 'value': '+='}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'stacked_parenthesis'}; {'id': '58', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'in_par'}; {'id': '62', 'type': 'True', 'children': []}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '66', 'type': 'call', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '70', 'type': 'argument_list', 'children': []}, {'id': '71', 'type': 'if_statement', 'children': ['72', '79']}; {'id': '72', 'type': 'boolean_operator', 'children': ['73', '76'], 'value': 'and'}, {'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': '=='}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'stacked_parenthesis'}, {'id': '75', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': '!='}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '78', 'type': 'string', 'children': [], 'value': "''"}, {'id': '79', 'type': 'block', 'children': ['80', '86']}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '83', 'type': 'argument_list', 'children': ['84', '85']}; {'id': '84', 'type': 'string', 'children': [], 'value': '"ERROR : bad expression near"'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '86', 'type': 'continue_statement', 'children': []}, {'id': '87', 'type': 'if_statement', 'children': ['88', '91']}; {'id': '88', 'type': 'comparison_operator', 'children': ['89', '90'], 'value': '>'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'stacked_parenthesis'}; {'id': '90', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '91', 'type': 'block', 'children': ['92']}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'augmented_assignment', 'children': ['94', '95'], 'value': '+='}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '96', 'type': 'elif_clause', 'children': ['97', '100']}, {'id': '97', 'type': 'comparison_operator', 'children': ['98', '99'], 'value': '=='}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'char'}, {'id': '99', 'type': 'string', 'children': [], 'value': "')'"}; {'id': '100', 'type': 'block', 'children': ['101', '105', '118', '176']}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'augmented_assignment', 'children': ['103', '104'], 'value': '-='}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'stacked_parenthesis'}; {'id': '104', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '105', 'type': 'if_statement', 'children': ['106', '109']}; {'id': '106', 'type': 'comparison_operator', 'children': ['107', '108'], 'value': '<'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'stacked_parenthesis'}; {'id': '108', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '109', 'type': 'block', 'children': ['110', '117']}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '113', 'type': 'argument_list', 'children': ['114', '115', '116']}; {'id': '114', 'type': 'string', 'children': [], 'value': '"Error : bad expression near"'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '116', 'type': 'string', 'children': [], 'value': '"too much \')\'"'}, {'id': '117', 'type': 'continue_statement', 'children': []}; {'id': '118', 'type': 'if_statement', 'children': ['119', '122']}, {'id': '119', 'type': 'comparison_operator', 'children': ['120', '121'], 'value': '=='}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'stacked_parenthesis'}, {'id': '121', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '122', 'type': 'block', 'children': ['123', '131', '145', '158', '167', '171', '175']}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '126', 'type': 'call', 'children': ['127', '130']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '130', 'type': 'argument_list', 'children': []}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'son'}; {'id': '134', 'type': 'call', 'children': ['135', '138']}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'eval_cor_pattern'}; {'id': '138', 'type': 'argument_list', 'children': ['139', '140', '141', '142', '143', '144']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'hosts'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'hostgroups'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'servicegroups'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'running'}, {'id': '145', 'type': 'if_statement', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'son_is_not'}, {'id': '147', 'type': 'block', 'children': ['148', '154']}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'assignment', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'son'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'not_value'}, {'id': '153', 'type': 'True', 'children': []}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'assignment', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'son_is_not'}, {'id': '157', 'type': 'False', 'children': []}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}, {'id': '159', 'type': 'call', 'children': ['160', '165']}; {'id': '160', 'type': 'attribute', 'children': ['161', '164']}, {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'sons'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '165', 'type': 'argument_list', 'children': ['166']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'son'}, {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'assignment', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'in_par'}; {'id': '170', 'type': 'False', 'children': []}, {'id': '171', 'type': 'expression_statement', 'children': ['172']}; {'id': '172', 'type': 'assignment', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '174', 'type': 'string', 'children': [], 'value': "''"}, {'id': '175', 'type': 'continue_statement', 'children': []}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'augmented_assignment', 'children': ['178', '179'], 'value': '+='}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '180', 'type': 'elif_clause', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'in_par'}; {'id': '182', 'type': 'block', 'children': ['183']}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'augmented_assignment', 'children': ['185', '186'], 'value': '+='}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'char'}, {'id': '187', 'type': 'elif_clause', 'children': ['188', '191']}; {'id': '188', 'type': 'comparison_operator', 'children': ['189', '190'], 'value': '=='}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '190', 'type': 'string', 'children': [], 'value': "'!'"}, {'id': '191', 'type': 'block', 'children': ['192', '200', '217']}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}, {'id': '193', 'type': 'assignment', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '195', 'type': 'call', 'children': ['196', '199']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '199', 'type': 'argument_list', 'children': []}; {'id': '200', 'type': 'if_statement', 'children': ['201', '208']}, {'id': '201', 'type': 'boolean_operator', 'children': ['202', '203'], 'value': 'and'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '203', 'type': 'comparison_operator', 'children': ['204', '207'], 'value': '!='}; {'id': '204', 'type': 'subscript', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '206', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '207', 'type': 'string', 'children': [], 'value': "'!'"}; {'id': '208', 'type': 'block', 'children': ['209', '216']}, {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'call', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '212', 'type': 'argument_list', 'children': ['213', '214', '215']}, {'id': '213', 'type': 'string', 'children': [], 'value': '"Error : bad expression near"'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '215', 'type': 'string', 'children': [], 'value': '"wrong position for \'!\'"'}; {'id': '216', 'type': 'continue_statement', 'children': []}, {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'assignment', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'son_is_not'}; {'id': '220', 'type': 'True', 'children': []}, {'id': '221', 'type': 'elif_clause', 'children': ['222', '227']}; {'id': '222', 'type': 'comparison_operator', 'children': ['223', '224'], 'value': 'in'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '224', 'type': 'list', 'children': ['225', '226'], 'value': "['&', '|']"}, {'id': '225', 'type': 'string', 'children': [], 'value': "'&'"}; {'id': '226', 'type': 'string', 'children': [], 'value': "'|'"}, {'id': '227', 'type': 'block', 'children': ['228', '236', '257', '270', '311']}; {'id': '228', 'type': 'expression_statement', 'children': ['229']}, {'id': '229', 'type': 'assignment', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '231', 'type': 'call', 'children': ['232', '235']}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '235', 'type': 'argument_list', 'children': []}; {'id': '236', 'type': 'if_statement', 'children': ['237', '254']}, {'id': '237', 'type': 'boolean_operator', 'children': ['238', '249'], 'value': 'and'}; {'id': '238', 'type': 'boolean_operator', 'children': ['239', '244'], 'value': 'and'}, {'id': '239', 'type': 'comparison_operator', 'children': ['240', '243'], 'value': 'is'}; {'id': '240', 'type': 'attribute', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'operand'}, {'id': '243', 'type': 'None', 'children': []}; {'id': '244', 'type': 'comparison_operator', 'children': ['245', '248'], 'value': '!='}, {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'operand'}; {'id': '248', 'type': 'string', 'children': [], 'value': "'of:'"}, {'id': '249', 'type': 'comparison_operator', 'children': ['250', '251'], 'value': '!='}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'char'}, {'id': '251', 'type': 'attribute', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'operand'}; {'id': '254', 'type': 'block', 'children': ['255']}, {'id': '255', 'type': 'return_statement', 'children': ['256']}; {'id': '256', 'type': 'None', 'children': []}, {'id': '257', 'type': 'if_statement', 'children': ['258', '263']}; {'id': '258', 'type': 'comparison_operator', 'children': ['259', '262'], 'value': '!='}, {'id': '259', 'type': 'attribute', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'operand'}; {'id': '262', 'type': 'string', 'children': [], 'value': "'of:'"}, {'id': '263', 'type': 'block', 'children': ['264']}; {'id': '264', 'type': 'expression_statement', 'children': ['265']}, {'id': '265', 'type': 'assignment', 'children': ['266', '269']}; {'id': '266', 'type': 'attribute', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'operand'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '270', 'type': 'if_statement', 'children': ['271', '274']}, {'id': '271', 'type': 'comparison_operator', 'children': ['272', '273'], 'value': '!='}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '273', 'type': 'string', 'children': [], 'value': "''"}; {'id': '274', 'type': 'block', 'children': ['275', '289', '302']}, {'id': '275', 'type': 'expression_statement', 'children': ['276']}; {'id': '276', 'type': 'assignment', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'son'}; {'id': '278', 'type': 'call', 'children': ['279', '282']}, {'id': '279', 'type': 'attribute', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'eval_cor_pattern'}; {'id': '282', 'type': 'argument_list', 'children': ['283', '284', '285', '286', '287', '288']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'hosts'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'hostgroups'}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'servicegroups'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'running'}, {'id': '289', 'type': 'if_statement', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'son_is_not'}, {'id': '291', 'type': 'block', 'children': ['292', '298']}; {'id': '292', 'type': 'expression_statement', 'children': ['293']}, {'id': '293', 'type': 'assignment', 'children': ['294', '297']}; {'id': '294', 'type': 'attribute', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'son'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'not_value'}, {'id': '297', 'type': 'True', 'children': []}; {'id': '298', 'type': 'expression_statement', 'children': ['299']}, {'id': '299', 'type': 'assignment', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'son_is_not'}, {'id': '301', 'type': 'False', 'children': []}; {'id': '302', 'type': 'expression_statement', 'children': ['303']}, {'id': '303', 'type': 'call', 'children': ['304', '309']}; {'id': '304', 'type': 'attribute', 'children': ['305', '308']}, {'id': '305', 'type': 'attribute', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'sons'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '309', 'type': 'argument_list', 'children': ['310']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'son'}, {'id': '311', 'type': 'expression_statement', 'children': ['312']}; {'id': '312', 'type': 'assignment', 'children': ['313', '314']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '314', 'type': 'string', 'children': [], 'value': "''"}, {'id': '315', 'type': 'else_clause', 'children': ['316']}; {'id': '316', 'type': 'block', 'children': ['317']}, {'id': '317', 'type': 'expression_statement', 'children': ['318']}; {'id': '318', 'type': 'augmented_assignment', 'children': ['319', '320'], 'value': '+='}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'char'}, {'id': '321', 'type': 'expression_statement', 'children': ['322']}; {'id': '322', 'type': 'assignment', 'children': ['323', '324']}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '324', 'type': 'call', 'children': ['325', '328']}, {'id': '325', 'type': 'attribute', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '328', 'type': 'argument_list', 'children': []}, {'id': '329', 'type': 'if_statement', 'children': ['330', '333']}; {'id': '330', 'type': 'comparison_operator', 'children': ['331', '332'], 'value': '!='}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '332', 'type': 'string', 'children': [], 'value': "''"}, {'id': '333', 'type': 'block', 'children': ['334', '348', '361']}; {'id': '334', 'type': 'expression_statement', 'children': ['335']}, {'id': '335', 'type': 'assignment', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'son'}, {'id': '337', 'type': 'call', 'children': ['338', '341']}; {'id': '338', 'type': 'attribute', 'children': ['339', '340']}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'eval_cor_pattern'}, {'id': '341', 'type': 'argument_list', 'children': ['342', '343', '344', '345', '346', '347']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'hosts'}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'hostgroups'}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'servicegroups'}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'running'}; {'id': '348', 'type': 'if_statement', 'children': ['349', '350']}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'son_is_not'}; {'id': '350', 'type': 'block', 'children': ['351', '357']}, {'id': '351', 'type': 'expression_statement', 'children': ['352']}; {'id': '352', 'type': 'assignment', 'children': ['353', '356']}, {'id': '353', 'type': 'attribute', 'children': ['354', '355']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'son'}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'not_value'}; {'id': '356', 'type': 'True', 'children': []}, {'id': '357', 'type': 'expression_statement', 'children': ['358']}; {'id': '358', 'type': 'assignment', 'children': ['359', '360']}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'son_is_not'}; {'id': '360', 'type': 'False', 'children': []}, {'id': '361', 'type': 'expression_statement', 'children': ['362']}; {'id': '362', 'type': 'call', 'children': ['363', '368']}, {'id': '363', 'type': 'attribute', 'children': ['364', '367']}; {'id': '364', 'type': 'attribute', 'children': ['365', '366']}, {'id': '365', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'sons'}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '368', 'type': 'argument_list', 'children': ['369']}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'son'}; {'id': '370', 'type': 'expression_statement', 'children': ['371']}, {'id': '371', 'type': 'call', 'children': ['372', '375']}; {'id': '372', 'type': 'attribute', 'children': ['373', '374']}, {'id': '373', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'switch_zeros_of_values'}, {'id': '375', 'type': 'argument_list', 'children': []}; {'id': '376', 'type': 'return_statement', 'children': ['377']}, {'id': '377', 'type': 'identifier', 'children': [], 'value': 'node'} | def eval_complex_cor_pattern(self, pattern, hosts, services,
hostgroups, servicegroups, running=False):
node = DependencyNode()
pattern = self.eval_xof_pattern(node, pattern)
in_par = False
tmp = ''
son_is_not = False
stacked_parenthesis = 0
for char in pattern:
if char == '(':
stacked_parenthesis += 1
in_par = True
tmp = tmp.strip()
if stacked_parenthesis == 1 and tmp != '':
print("ERROR : bad expression near", tmp)
continue
if stacked_parenthesis > 1:
tmp += char
elif char == ')':
stacked_parenthesis -= 1
if stacked_parenthesis < 0:
print("Error : bad expression near", tmp, "too much ')'")
continue
if stacked_parenthesis == 0:
tmp = tmp.strip()
son = self.eval_cor_pattern(tmp, hosts, services,
hostgroups, servicegroups, running)
if son_is_not:
son.not_value = True
son_is_not = False
node.sons.append(son)
in_par = False
tmp = ''
continue
tmp += char
elif in_par:
tmp += char
elif char == '!':
tmp = tmp.strip()
if tmp and tmp[0] != '!':
print("Error : bad expression near", tmp, "wrong position for '!'")
continue
son_is_not = True
elif char in ['&', '|']:
tmp = tmp.strip()
if node.operand is not None and node.operand != 'of:' and char != node.operand:
return None
if node.operand != 'of:':
node.operand = char
if tmp != '':
son = self.eval_cor_pattern(tmp, hosts, services,
hostgroups, servicegroups, running)
if son_is_not:
son.not_value = True
son_is_not = False
node.sons.append(son)
tmp = ''
else:
tmp += char
tmp = tmp.strip()
if tmp != '':
son = self.eval_cor_pattern(tmp, hosts, services,
hostgroups, servicegroups, running)
if son_is_not:
son.not_value = True
son_is_not = False
node.sons.append(son)
node.switch_zeros_of_values()
return node |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_next_valid_time_from_t'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '6', 'type': 'block', 'children': ['7', '14', '18', '27', '34', '38', '225', '233']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'original_t'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'res_from_cache'}, {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'find_next_valid_time_from_cache'}, {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'timestamp'}, {'id': '27', 'type': 'if_statement', 'children': ['28', '31']}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '30'], 'value': 'is'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'res_from_cache'}; {'id': '30', 'type': 'None', 'children': []}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'return_statement', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'res_from_cache'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'still_loop'}, {'id': '37', 'type': 'True', 'children': []}; {'id': '38', 'type': 'while_statement', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'still_loop'}; {'id': '40', 'type': 'block', 'children': ['41', '45', '49', '67', '82', '129', '189']}, {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'local_min'}; {'id': '44', 'type': 'None', 'children': []}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'dr_mins'}; {'id': '48', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '49', 'type': 'for_statement', 'children': ['50', '51', '54']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'daterange'}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'dateranges'}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'dr_mins'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'daterange'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'get_next_valid_time_from_t'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'timestamp'}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 's_dr_mins'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'list_comprehension', 'children': ['74', '75', '78']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '75', 'type': 'for_in_clause', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'dr_mins'}; {'id': '78', 'type': 'if_clause', 'children': ['79']}, {'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': 'is'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '81', 'type': 'None', 'children': []}; {'id': '82', 'type': 'for_statement', 'children': ['83', '84', '85']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 't01'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 's_dr_mins'}, {'id': '85', 'type': 'block', 'children': ['86']}; {'id': '86', 'type': 'if_statement', 'children': ['87', '93', '102']}, {'id': '87', 'type': 'boolean_operator', 'children': ['88', '92'], 'value': 'and'}; {'id': '88', 'type': 'not_operator', 'children': ['89']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'exclude'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'still_loop'}, {'id': '93', 'type': 'block', 'children': ['94', '98']}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'local_min'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 't01'}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'still_loop'}, {'id': '101', 'type': 'False', 'children': []}; {'id': '102', 'type': 'else_clause', 'children': ['103']}, {'id': '103', 'type': 'block', 'children': ['104']}; {'id': '104', 'type': 'for_statement', 'children': ['105', '106', '109']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'timeperiod'}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'exclude'}, {'id': '109', 'type': 'block', 'children': ['110']}; {'id': '110', 'type': 'if_statement', 'children': ['111', '120']}, {'id': '111', 'type': 'boolean_operator', 'children': ['112', '119'], 'value': 'and'}; {'id': '112', 'type': 'not_operator', 'children': ['113']}, {'id': '113', 'type': 'call', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'timeperiod'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'is_time_valid'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 't01'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'still_loop'}; {'id': '120', 'type': 'block', 'children': ['121', '125']}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'local_min'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 't01'}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'assignment', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'still_loop'}; {'id': '128', 'type': 'False', 'children': []}, {'id': '129', 'type': 'if_statement', 'children': ['130', '133']}; {'id': '130', 'type': 'comparison_operator', 'children': ['131', '132'], 'value': 'is'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'local_min'}; {'id': '132', 'type': 'None', 'children': []}, {'id': '133', 'type': 'block', 'children': ['134', '138', '163', '178']}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'exc_mins'}, {'id': '137', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '138', 'type': 'if_statement', 'children': ['139', '142']}, {'id': '139', 'type': 'comparison_operator', 'children': ['140', '141'], 'value': '!='}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 's_dr_mins'}, {'id': '141', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '142', 'type': 'block', 'children': ['143']}, {'id': '143', 'type': 'for_statement', 'children': ['144', '145', '148']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'timeperiod'}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'exclude'}; {'id': '148', 'type': 'block', 'children': ['149']}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'call', 'children': ['151', '154']}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'exc_mins'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '154', 'type': 'argument_list', 'children': ['155']}, {'id': '155', 'type': 'call', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'timeperiod'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'get_next_invalid_time_from_t'}, {'id': '159', 'type': 'argument_list', 'children': ['160']}; {'id': '160', 'type': 'subscript', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 's_dr_mins'}; {'id': '162', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'assignment', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 's_exc_mins'}; {'id': '166', 'type': 'call', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '168', 'type': 'argument_list', 'children': ['169']}, {'id': '169', 'type': 'list_comprehension', 'children': ['170', '171', '174']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '171', 'type': 'for_in_clause', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'exc_mins'}; {'id': '174', 'type': 'if_clause', 'children': ['175']}, {'id': '175', 'type': 'comparison_operator', 'children': ['176', '177'], 'value': 'is'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '177', 'type': 'None', 'children': []}; {'id': '178', 'type': 'if_statement', 'children': ['179', '182']}, {'id': '179', 'type': 'comparison_operator', 'children': ['180', '181'], 'value': '!='}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 's_exc_mins'}, {'id': '181', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '182', 'type': 'block', 'children': ['183']}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'local_min'}; {'id': '186', 'type': 'subscript', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 's_exc_mins'}; {'id': '188', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '189', 'type': 'if_statement', 'children': ['190', '193', '198']}; {'id': '190', 'type': 'comparison_operator', 'children': ['191', '192'], 'value': 'is'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'local_min'}; {'id': '192', 'type': 'None', 'children': []}, {'id': '193', 'type': 'block', 'children': ['194']}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}, {'id': '195', 'type': 'assignment', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'still_loop'}, {'id': '197', 'type': 'False', 'children': []}; {'id': '198', 'type': 'else_clause', 'children': ['199']}, {'id': '199', 'type': 'block', 'children': ['200', '204']}; {'id': '200', 'type': 'expression_statement', 'children': ['201']}, {'id': '201', 'type': 'assignment', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'timestamp'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'local_min'}; {'id': '204', 'type': 'if_statement', 'children': ['205', '216']}, {'id': '205', 'type': 'comparison_operator', 'children': ['206', '207'], 'value': '>'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'timestamp'}, {'id': '207', 'type': 'binary_operator', 'children': ['208', '215'], 'value': '+'}; {'id': '208', 'type': 'binary_operator', 'children': ['209', '210'], 'value': '+'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'original_t'}; {'id': '210', 'type': 'binary_operator', 'children': ['211', '214'], 'value': '*'}, {'id': '211', 'type': 'binary_operator', 'children': ['212', '213'], 'value': '*'}; {'id': '212', 'type': 'integer', 'children': [], 'value': '3600'}, {'id': '213', 'type': 'integer', 'children': [], 'value': '24'}; {'id': '214', 'type': 'integer', 'children': [], 'value': '366'}, {'id': '215', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '216', 'type': 'block', 'children': ['217', '221']}, {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'assignment', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'still_loop'}; {'id': '220', 'type': 'False', 'children': []}, {'id': '221', 'type': 'expression_statement', 'children': ['222']}; {'id': '222', 'type': 'assignment', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'local_min'}; {'id': '224', 'type': 'None', 'children': []}, {'id': '225', 'type': 'expression_statement', 'children': ['226']}; {'id': '226', 'type': 'assignment', 'children': ['227', '232']}, {'id': '227', 'type': 'subscript', 'children': ['228', '231']}; {'id': '228', 'type': 'attribute', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'cache'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'original_t'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'local_min'}, {'id': '233', 'type': 'return_statement', 'children': ['234']} | def get_next_valid_time_from_t(self, timestamp):
timestamp = int(timestamp)
original_t = timestamp
res_from_cache = self.find_next_valid_time_from_cache(timestamp)
if res_from_cache is not None:
return res_from_cache
still_loop = True
while still_loop:
local_min = None
dr_mins = []
for daterange in self.dateranges:
dr_mins.append(daterange.get_next_valid_time_from_t(timestamp))
s_dr_mins = sorted([d for d in dr_mins if d is not None])
for t01 in s_dr_mins:
if not self.exclude and still_loop:
local_min = t01
still_loop = False
else:
for timeperiod in self.exclude:
if not timeperiod.is_time_valid(t01) and still_loop:
local_min = t01
still_loop = False
if local_min is None:
exc_mins = []
if s_dr_mins != []:
for timeperiod in self.exclude:
exc_mins.append(timeperiod.get_next_invalid_time_from_t(s_dr_mins[0]))
s_exc_mins = sorted([d for d in exc_mins if d is not None])
if s_exc_mins != []:
local_min = s_exc_mins[0]
if local_min is None:
still_loop = False
else:
timestamp = local_min
if timestamp > original_t + 3600 * 24 * 366 + 1:
still_loop = False
local_min = None
self.cache[original_t] = local_min
return local_min |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_next_invalid_time_from_t'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '6', 'type': 'block', 'children': ['7', '14', '18', '22', '97', '104', '108', '189', '206', '258']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'original_t'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'dr_mins'}, {'id': '21', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '22', 'type': 'for_statement', 'children': ['23', '24', '27']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'daterange'}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'dateranges'}, {'id': '27', 'type': 'block', 'children': ['28', '32', '36']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'timestamp'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'original_t'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'cont'}, {'id': '35', 'type': 'True', 'children': []}; {'id': '36', 'type': 'while_statement', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'cont'}; {'id': '38', 'type': 'block', 'children': ['39', '48', '81']}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'daterange'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'get_next_valid_time_from_t'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '48', 'type': 'if_statement', 'children': ['49', '52', '75']}, {'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': 'is'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '51', 'type': 'None', 'children': []}; {'id': '52', 'type': 'block', 'children': ['53', '62', '71']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '56', 'type': 'call', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'daterange'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'get_next_invalid_time_from_t'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'dr_mins'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'tuple', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '75', 'type': 'else_clause', 'children': ['76']}; {'id': '76', 'type': 'block', 'children': ['77']}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'cont'}; {'id': '80', 'type': 'False', 'children': []}, {'id': '81', 'type': 'if_statement', 'children': ['82', '92']}; {'id': '82', 'type': 'comparison_operator', 'children': ['83', '84'], 'value': '>'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '84', 'type': 'binary_operator', 'children': ['85', '86'], 'value': '+'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'original_t'}; {'id': '86', 'type': 'parenthesized_expression', 'children': ['87']}, {'id': '87', 'type': 'binary_operator', 'children': ['88', '91'], 'value': '*'}; {'id': '88', 'type': 'binary_operator', 'children': ['89', '90'], 'value': '*'}, {'id': '89', 'type': 'integer', 'children': [], 'value': '3600'}; {'id': '90', 'type': 'integer', 'children': [], 'value': '24'}, {'id': '91', 'type': 'integer', 'children': [], 'value': '365'}; {'id': '92', 'type': 'block', 'children': ['93']}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'cont'}; {'id': '96', 'type': 'False', 'children': []}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'periods'}; {'id': '100', 'type': 'call', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'merge_periods'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'dr_mins'}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'dr_mins'}, {'id': '107', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '108', 'type': 'for_statement', 'children': ['109', '110', '113']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'exclude'}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'exclude'}, {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'for_statement', 'children': ['115', '116', '119']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'daterange'}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'exclude'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'dateranges'}, {'id': '119', 'type': 'block', 'children': ['120', '124', '128']}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'assignment', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'timestamp'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'original_t'}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'cont'}, {'id': '127', 'type': 'True', 'children': []}; {'id': '128', 'type': 'while_statement', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'cont'}; {'id': '130', 'type': 'block', 'children': ['131', '140', '173']}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '134', 'type': 'call', 'children': ['135', '138']}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'daterange'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'get_next_valid_time_from_t'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '140', 'type': 'if_statement', 'children': ['141', '144', '167']}, {'id': '141', 'type': 'comparison_operator', 'children': ['142', '143'], 'value': 'is'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '143', 'type': 'None', 'children': []}; {'id': '144', 'type': 'block', 'children': ['145', '154', '163']}, {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'assignment', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'end'}; {'id': '148', 'type': 'call', 'children': ['149', '152']}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'daterange'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'get_next_invalid_time_from_t'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'call', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'dr_mins'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '159', 'type': 'argument_list', 'children': ['160']}; {'id': '160', 'type': 'tuple', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'assignment', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'end'}, {'id': '167', 'type': 'else_clause', 'children': ['168']}; {'id': '168', 'type': 'block', 'children': ['169']}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'cont'}; {'id': '172', 'type': 'False', 'children': []}, {'id': '173', 'type': 'if_statement', 'children': ['174', '184']}; {'id': '174', 'type': 'comparison_operator', 'children': ['175', '176'], 'value': '>'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '176', 'type': 'binary_operator', 'children': ['177', '178'], 'value': '+'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'original_t'}; {'id': '178', 'type': 'parenthesized_expression', 'children': ['179']}, {'id': '179', 'type': 'binary_operator', 'children': ['180', '183'], 'value': '*'}; {'id': '180', 'type': 'binary_operator', 'children': ['181', '182'], 'value': '*'}, {'id': '181', 'type': 'integer', 'children': [], 'value': '3600'}; {'id': '182', 'type': 'integer', 'children': [], 'value': '24'}, {'id': '183', 'type': 'integer', 'children': [], 'value': '365'}; {'id': '184', 'type': 'block', 'children': ['185']}, {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'assignment', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'cont'}; {'id': '188', 'type': 'False', 'children': []}, {'id': '189', 'type': 'if_statement', 'children': ['190', '192', '197']}; {'id': '190', 'type': 'not_operator', 'children': ['191']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'dr_mins'}; {'id': '192', 'type': 'block', 'children': ['193']}, {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'assignment', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'periods_exclude'}; {'id': '196', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '197', 'type': 'else_clause', 'children': ['198']}; {'id': '198', 'type': 'block', 'children': ['199']}, {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'periods_exclude'}; {'id': '202', 'type': 'call', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'merge_periods'}; {'id': '204', 'type': 'argument_list', 'children': ['205']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'dr_mins'}; {'id': '206', 'type': 'if_statement', 'children': ['207', '213']}, {'id': '207', 'type': 'comparison_operator', 'children': ['208', '212'], 'value': '>='}; {'id': '208', 'type': 'call', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '210', 'type': 'argument_list', 'children': ['211']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'periods'}; {'id': '212', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '213', 'type': 'block', 'children': ['214', '225', '252']}; {'id': '214', 'type': 'if_statement', 'children': ['215', '222']}, {'id': '215', 'type': 'comparison_operator', 'children': ['216', '221'], 'value': '>'}; {'id': '216', 'type': 'subscript', 'children': ['217', '220']}, {'id': '217', 'type': 'subscript', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'periods'}, {'id': '219', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '220', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'original_t'}; {'id': '222', 'type': 'block', 'children': ['223']}, {'id': '223', 'type': 'return_statement', 'children': ['224']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'original_t'}, {'id': '225', 'type': 'if_statement', 'children': ['226', '232']}; {'id': '226', 'type': 'comparison_operator', 'children': ['227', '231'], 'value': '>='}, {'id': '227', 'type': 'call', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '229', 'type': 'argument_list', 'children': ['230']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'periods_exclude'}, {'id': '231', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '232', 'type': 'block', 'children': ['233']}, {'id': '233', 'type': 'if_statement', 'children': ['234', '245']}; {'id': '234', 'type': 'comparison_operator', 'children': ['235', '240'], 'value': '<'}, {'id': '235', 'type': 'subscript', 'children': ['236', '239']}; {'id': '236', 'type': 'subscript', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'periods_exclude'}; {'id': '238', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '239', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '240', 'type': 'subscript', 'children': ['241', '244']}, {'id': '241', 'type': 'subscript', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'periods'}, {'id': '243', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '244', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '245', 'type': 'block', 'children': ['246']}; {'id': '246', 'type': 'return_statement', 'children': ['247']}, {'id': '247', 'type': 'subscript', 'children': ['248', '251']}; {'id': '248', 'type': 'subscript', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'periods_exclude'}; {'id': '250', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '251', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '252', 'type': 'return_statement', 'children': ['253']}, {'id': '253', 'type': 'subscript', 'children': ['254', '257']}; {'id': '254', 'type': 'subscript', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'periods'}; {'id': '256', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '257', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '258', 'type': 'return_statement', 'children': ['259']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'original_t'} | def get_next_invalid_time_from_t(self, timestamp):
timestamp = int(timestamp)
original_t = timestamp
dr_mins = []
for daterange in self.dateranges:
timestamp = original_t
cont = True
while cont:
start = daterange.get_next_valid_time_from_t(timestamp)
if start is not None:
end = daterange.get_next_invalid_time_from_t(start)
dr_mins.append((start, end))
timestamp = end
else:
cont = False
if timestamp > original_t + (3600 * 24 * 365):
cont = False
periods = merge_periods(dr_mins)
dr_mins = []
for exclude in self.exclude:
for daterange in exclude.dateranges:
timestamp = original_t
cont = True
while cont:
start = daterange.get_next_valid_time_from_t(timestamp)
if start is not None:
end = daterange.get_next_invalid_time_from_t(start)
dr_mins.append((start, end))
timestamp = end
else:
cont = False
if timestamp > original_t + (3600 * 24 * 365):
cont = False
if not dr_mins:
periods_exclude = []
else:
periods_exclude = merge_periods(dr_mins)
if len(periods) >= 1:
if periods[0][0] > original_t:
return original_t
if len(periods_exclude) >= 1:
if periods_exclude[0][0] < periods[0][1]:
return periods_exclude[0][0]
return periods[0][1]
return original_t |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'is_correct'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '29', '71', '147', '161']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'valid'}, {'id': '9', 'type': 'True', 'children': []}; {'id': '10', 'type': 'for_statement', 'children': ['11', '12', '22']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'timeperiod'}; {'id': '12', 'type': 'call', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}, {'id': '15', 'type': 'call', 'children': ['16', '21']}; {'id': '16', 'type': 'attribute', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '21', 'type': 'argument_list', 'children': []}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'timeperiod'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'rec_tag'}; {'id': '28', 'type': 'False', 'children': []}, {'id': '29', 'type': 'for_statement', 'children': ['30', '31', '41']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'timeperiod'}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '40']}, {'id': '35', 'type': 'attribute', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '40', 'type': 'argument_list', 'children': []}, {'id': '41', 'type': 'block', 'children': ['42', '61']}; {'id': '42', 'type': 'for_statement', 'children': ['43', '44', '54']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'tmp_tp'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'call', 'children': ['48', '53']}; {'id': '48', 'type': 'attribute', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '53', 'type': 'argument_list', 'children': []}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'tmp_tp'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'rec_tag'}; {'id': '60', 'type': 'False', 'children': []}, {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'valid'}; {'id': '64', 'type': 'boolean_operator', 'children': ['65', '70'], 'value': 'and'}, {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'timeperiod'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'check_exclude_rec'}, {'id': '69', 'type': 'argument_list', 'children': []}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'valid'}, {'id': '71', 'type': 'for_statement', 'children': ['72', '73', '83']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'timeperiod'}, {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '82']}, {'id': '77', 'type': 'attribute', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '82', 'type': 'argument_list', 'children': []}, {'id': '83', 'type': 'block', 'children': ['84', '88', '131', '139']}; {'id': '84', 'type': 'delete_statement', 'children': ['85']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'timeperiod'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'rec_tag'}; {'id': '88', 'type': 'if_statement', 'children': ['89', '95']}, {'id': '89', 'type': 'not_operator', 'children': ['90']}; {'id': '90', 'type': 'call', 'children': ['91', '94']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'timeperiod'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'is_correct'}; {'id': '94', 'type': 'argument_list', 'children': []}, {'id': '95', 'type': 'block', 'children': ['96', '100', '109', '124']}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'valid'}, {'id': '99', 'type': 'False', 'children': []}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'source'}, {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '105', 'type': 'argument_list', 'children': ['106', '107', '108']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'timeperiod'}, {'id': '107', 'type': 'string', 'children': [], 'value': "'imported_from'"}; {'id': '108', 'type': 'string', 'children': [], 'value': '"unknown source"'}, {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '112', 'type': 'binary_operator', 'children': ['113', '114'], 'value': '%'}, {'id': '113', 'type': 'string', 'children': [], 'value': '"Configuration in %s::%s is incorrect; from: %s"'}; {'id': '114', 'type': 'tuple', 'children': ['115', '118', '123']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'timeperiod'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'my_type'}; {'id': '118', 'type': 'call', 'children': ['119', '122']}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'timeperiod'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'get_name'}; {'id': '122', 'type': 'argument_list', 'children': []}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'call', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'add_error'}, {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'augmented_assignment', 'children': ['133', '136'], 'value': '+='}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'configuration_errors'}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'timeperiod'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'configuration_errors'}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'augmented_assignment', 'children': ['141', '144'], 'value': '+='}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'configuration_warnings'}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'timeperiod'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'configuration_warnings'}, {'id': '147', 'type': 'for_statement', 'children': ['148', '149', '150']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'timeperiod'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '150', 'type': 'block', 'children': ['151']}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'assignment', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'valid'}; {'id': '154', 'type': 'boolean_operator', 'children': ['155', '160'], 'value': 'and'}, {'id': '155', 'type': 'call', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'timeperiod'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'is_correct'}, {'id': '159', 'type': 'argument_list', 'children': []}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'valid'}, {'id': '161', 'type': 'return_statement', 'children': ['162']} | def is_correct(self):
valid = True
for timeperiod in list(self.items.values()):
timeperiod.rec_tag = False
for timeperiod in list(self.items.values()):
for tmp_tp in list(self.items.values()):
tmp_tp.rec_tag = False
valid = timeperiod.check_exclude_rec() and valid
for timeperiod in list(self.items.values()):
del timeperiod.rec_tag
if not timeperiod.is_correct():
valid = False
source = getattr(timeperiod, 'imported_from', "unknown source")
msg = "Configuration in %s::%s is incorrect; from: %s" % (
timeperiod.my_type, timeperiod.get_name(), source
)
self.add_error(msg)
self.configuration_errors += timeperiod.configuration_errors
self.configuration_warnings += timeperiod.configuration_warnings
for timeperiod in self:
valid = timeperiod.is_correct() and valid
return valid |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_scheduler_ordered_list'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'realm'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '28', '32', '36', '40', '86', '90', '97', '104', '111', '117']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'scheduler_links'}; {'id': '10', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '11', 'type': 'for_statement', 'children': ['12', '13', '16']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'scheduler_link_uuid'}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'realm'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'schedulers'}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'scheduler_links'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'subscript', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'schedulers'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'scheduler_link_uuid'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'alive'}, {'id': '31', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'spare'}, {'id': '35', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'deads'}, {'id': '39', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '40', 'type': 'for_statement', 'children': ['41', '42', '43']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'sdata'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'scheduler_links'}, {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'if_statement', 'children': ['45', '53', '61', '77']}, {'id': '45', 'type': 'boolean_operator', 'children': ['46', '49'], 'value': 'and'}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'sdata'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'alive'}, {'id': '49', 'type': 'not_operator', 'children': ['50']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'sdata'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'spare'}, {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'alive'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'sdata'}, {'id': '61', 'type': 'elif_clause', 'children': ['62', '69']}; {'id': '62', 'type': 'boolean_operator', 'children': ['63', '66'], 'value': 'and'}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'sdata'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'alive'}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'sdata'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'spare'}, {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'spare'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'sdata'}, {'id': '77', 'type': 'else_clause', 'children': ['78']}; {'id': '78', 'type': 'block', 'children': ['79']}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'deads'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'sdata'}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'scheduler_links'}, {'id': '89', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'scheduler_links'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'alive'}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'scheduler_links'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'spare'}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'call', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'scheduler_links'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'deads'}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'call', 'children': ['113', '116']}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'scheduler_links'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '116', 'type': 'argument_list', 'children': []}, {'id': '117', 'type': 'return_statement', 'children': ['118']} | def get_scheduler_ordered_list(self, realm):
scheduler_links = []
for scheduler_link_uuid in realm.schedulers:
scheduler_links.append(self.schedulers[scheduler_link_uuid])
alive = []
spare = []
deads = []
for sdata in scheduler_links:
if sdata.alive and not sdata.spare:
alive.append(sdata)
elif sdata.alive and sdata.spare:
spare.append(sdata)
else:
deads.append(sdata)
scheduler_links = []
scheduler_links.extend(alive)
scheduler_links.extend(spare)
scheduler_links.extend(deads)
scheduler_links.reverse()
return scheduler_links |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'dispatch'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'test'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '22', '34', '47', '54', '60', '172', '263', '363']}, {'id': '9', 'type': 'if_statement', 'children': ['10', '14']}; {'id': '10', 'type': 'not_operator', 'children': ['11']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'new_to_dispatch'}; {'id': '14', 'type': 'block', 'children': ['15']}, {'id': '15', 'type': 'raise_statement', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'DispatcherError'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'concatenated_string', 'children': ['20', '21']}; {'id': '20', 'type': 'string', 'children': [], 'value': '"Dispatcher cannot dispatch, "'}, {'id': '21', 'type': 'string', 'children': [], 'value': '"because no configuration is prepared!"'}; {'id': '22', 'type': 'if_statement', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'first_dispatch_done'}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'raise_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'DispatcherError'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'concatenated_string', 'children': ['32', '33']}; {'id': '32', 'type': 'string', 'children': [], 'value': '"Dispatcher cannot dispatch, "'}, {'id': '33', 'type': 'string', 'children': [], 'value': '"because the configuration is still dispatched!"'}; {'id': '34', 'type': 'if_statement', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'dispatch_ok'}; {'id': '38', 'type': 'block', 'children': ['39', '46']}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'string', 'children': [], 'value': '"Dispatching is already done and ok..."'}; {'id': '46', 'type': 'return_statement', 'children': []}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'string', 'children': [], 'value': '"Trying to send configuration to the satellites..."'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'dispatch_ok'}, {'id': '59', 'type': 'True', 'children': []}; {'id': '60', 'type': 'for_statement', 'children': ['61', '62', '65']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'arbiters'}, {'id': '65', 'type': 'block', 'children': ['66', '74', '81', '88', '104', '121', '131', '141', '153', '159', '166']}; {'id': '66', 'type': 'if_statement', 'children': ['67', '72']}, {'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': '=='}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'link'}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'arbiter_link'}; {'id': '72', 'type': 'block', 'children': ['73']}, {'id': '73', 'type': 'continue_statement', 'children': []}; {'id': '74', 'type': 'if_statement', 'children': ['75', '79']}, {'id': '75', 'type': 'not_operator', 'children': ['76']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'active'}, {'id': '79', 'type': 'block', 'children': ['80']}; {'id': '80', 'type': 'continue_statement', 'children': []}, {'id': '81', 'type': 'if_statement', 'children': ['82', '86']}; {'id': '82', 'type': 'not_operator', 'children': ['83']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'link'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'spare'}; {'id': '86', 'type': 'block', 'children': ['87']}, {'id': '87', 'type': 'continue_statement', 'children': []}; {'id': '88', 'type': 'if_statement', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'link'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'configuration_sent'}; {'id': '92', 'type': 'block', 'children': ['93', '103']}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'call', 'children': ['95', '98']}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '98', 'type': 'argument_list', 'children': ['99', '100']}, {'id': '99', 'type': 'string', 'children': [], 'value': '"Arbiter %s already sent!"'}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '103', 'type': 'continue_statement', 'children': []}; {'id': '104', 'type': 'if_statement', 'children': ['105', '109']}, {'id': '105', 'type': 'not_operator', 'children': ['106']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'reachable'}, {'id': '109', 'type': 'block', 'children': ['110', '120']}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'call', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '115', 'type': 'argument_list', 'children': ['116', '117']}; {'id': '116', 'type': 'string', 'children': [], 'value': '"Arbiter %s is not reachable to receive its configuration"'}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'link'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '120', 'type': 'continue_statement', 'children': []}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'call', 'children': ['123', '126']}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '126', 'type': 'argument_list', 'children': ['127', '128']}, {'id': '127', 'type': 'string', 'children': [], 'value': '"Sending configuration to the arbiter %s"'}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'call', 'children': ['133', '136']}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '136', 'type': 'argument_list', 'children': ['137', '138']}, {'id': '137', 'type': 'string', 'children': [], 'value': '"- %s"'}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'cfg'}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'call', 'children': ['143', '146']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'link'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'put_conf'}; {'id': '146', 'type': 'argument_list', 'children': ['147', '150']}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'link'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '150', 'type': 'keyword_argument', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'test'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'test'}, {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'assignment', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'link'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'configuration_sent'}; {'id': '158', 'type': 'True', 'children': []}, {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'call', 'children': ['161', '164']}, {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}, {'id': '165', 'type': 'string', 'children': [], 'value': '"- sent"'}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}, {'id': '167', 'type': 'call', 'children': ['168', '171']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'do_not_run'}, {'id': '171', 'type': 'argument_list', 'children': []}; {'id': '172', 'type': 'for_statement', 'children': ['173', '174', '177']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '174', 'type': 'attribute', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'schedulers'}, {'id': '177', 'type': 'block', 'children': ['178', '194', '201', '218', '228', '238', '250', '256']}; {'id': '178', 'type': 'if_statement', 'children': ['179', '182']}, {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'link'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'configuration_sent'}; {'id': '182', 'type': 'block', 'children': ['183', '193']}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'call', 'children': ['185', '188']}, {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '188', 'type': 'argument_list', 'children': ['189', '190']}, {'id': '189', 'type': 'string', 'children': [], 'value': '"Scheduler %s already sent!"'}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '193', 'type': 'continue_statement', 'children': []}; {'id': '194', 'type': 'if_statement', 'children': ['195', '199']}, {'id': '195', 'type': 'not_operator', 'children': ['196']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'active'}, {'id': '199', 'type': 'block', 'children': ['200']}; {'id': '200', 'type': 'continue_statement', 'children': []}, {'id': '201', 'type': 'if_statement', 'children': ['202', '206']}; {'id': '202', 'type': 'not_operator', 'children': ['203']}, {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'link'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'reachable'}; {'id': '206', 'type': 'block', 'children': ['207', '217']}, {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'call', 'children': ['209', '212']}, {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '212', 'type': 'argument_list', 'children': ['213', '214']}, {'id': '213', 'type': 'string', 'children': [], 'value': '"Scheduler %s is not reachable to receive its configuration"'}; {'id': '214', 'type': 'attribute', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '217', 'type': 'continue_statement', 'children': []}; {'id': '218', 'type': 'expression_statement', 'children': ['219']}, {'id': '219', 'type': 'call', 'children': ['220', '223']}; {'id': '220', 'type': 'attribute', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '223', 'type': 'argument_list', 'children': ['224', '225']}; {'id': '224', 'type': 'string', 'children': [], 'value': '"Sending configuration to the scheduler %s"'}, {'id': '225', 'type': 'attribute', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'link'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '228', 'type': 'expression_statement', 'children': ['229']}, {'id': '229', 'type': 'call', 'children': ['230', '233']}; {'id': '230', 'type': 'attribute', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '233', 'type': 'argument_list', 'children': ['234', '235']}; {'id': '234', 'type': 'string', 'children': [], 'value': '"- %s"'}, {'id': '235', 'type': 'attribute', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'link'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '238', 'type': 'expression_statement', 'children': ['239']}, {'id': '239', 'type': 'call', 'children': ['240', '243']}; {'id': '240', 'type': 'attribute', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'put_conf'}, {'id': '243', 'type': 'argument_list', 'children': ['244', '247']}; {'id': '244', 'type': 'attribute', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'cfg'}, {'id': '247', 'type': 'keyword_argument', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'test'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'test'}; {'id': '250', 'type': 'expression_statement', 'children': ['251']}, {'id': '251', 'type': 'assignment', 'children': ['252', '255']}; {'id': '252', 'type': 'attribute', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'configuration_sent'}, {'id': '255', 'type': 'True', 'children': []}; {'id': '256', 'type': 'expression_statement', 'children': ['257']}, {'id': '257', 'type': 'call', 'children': ['258', '261']}; {'id': '258', 'type': 'attribute', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '261', 'type': 'argument_list', 'children': ['262']}; {'id': '262', 'type': 'string', 'children': [], 'value': '"- sent"'}, {'id': '263', 'type': 'for_statement', 'children': ['264', '265', '268']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'link'}, {'id': '265', 'type': 'attribute', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'satellites'}; {'id': '268', 'type': 'block', 'children': ['269', '288', '295', '315', '328', '338', '350', '356']}, {'id': '269', 'type': 'if_statement', 'children': ['270', '273']}; {'id': '270', 'type': 'attribute', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'configuration_sent'}, {'id': '273', 'type': 'block', 'children': ['274', '287']}; {'id': '274', 'type': 'expression_statement', 'children': ['275']}, {'id': '275', 'type': 'call', 'children': ['276', '279']}; {'id': '276', 'type': 'attribute', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '279', 'type': 'argument_list', 'children': ['280', '281', '284']}; {'id': '280', 'type': 'string', 'children': [], 'value': '"%s %s already sent!"'}, {'id': '281', 'type': 'attribute', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'link'}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '284', 'type': 'attribute', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '287', 'type': 'continue_statement', 'children': []}; {'id': '288', 'type': 'if_statement', 'children': ['289', '293']}, {'id': '289', 'type': 'not_operator', 'children': ['290']}; {'id': '290', 'type': 'attribute', 'children': ['291', '292']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'active'}, {'id': '293', 'type': 'block', 'children': ['294']}; {'id': '294', 'type': 'continue_statement', 'children': []}, {'id': '295', 'type': 'if_statement', 'children': ['296', '300']}; {'id': '296', 'type': 'not_operator', 'children': ['297']}, {'id': '297', 'type': 'attribute', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'link'}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'reachable'}; {'id': '300', 'type': 'block', 'children': ['301', '314']}, {'id': '301', 'type': 'expression_statement', 'children': ['302']}; {'id': '302', 'type': 'call', 'children': ['303', '306']}, {'id': '303', 'type': 'attribute', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '306', 'type': 'argument_list', 'children': ['307', '308', '311']}, {'id': '307', 'type': 'string', 'children': [], 'value': '"%s %s is not reachable to receive its configuration"'}; {'id': '308', 'type': 'attribute', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '311', 'type': 'attribute', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'link'}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '314', 'type': 'continue_statement', 'children': []}, {'id': '315', 'type': 'expression_statement', 'children': ['316']}; {'id': '316', 'type': 'call', 'children': ['317', '320']}, {'id': '317', 'type': 'attribute', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '320', 'type': 'argument_list', 'children': ['321', '322', '325']}, {'id': '321', 'type': 'string', 'children': [], 'value': '"Sending configuration to the %s %s"'}; {'id': '322', 'type': 'attribute', 'children': ['323', '324']}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '325', 'type': 'attribute', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'link'}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '328', 'type': 'expression_statement', 'children': ['329']}, {'id': '329', 'type': 'call', 'children': ['330', '333']}; {'id': '330', 'type': 'attribute', 'children': ['331', '332']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '333', 'type': 'argument_list', 'children': ['334', '335']}; {'id': '334', 'type': 'string', 'children': [], 'value': '"- %s"'}, {'id': '335', 'type': 'attribute', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'link'}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '338', 'type': 'expression_statement', 'children': ['339']}, {'id': '339', 'type': 'call', 'children': ['340', '343']}; {'id': '340', 'type': 'attribute', 'children': ['341', '342']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'put_conf'}, {'id': '343', 'type': 'argument_list', 'children': ['344', '347']}; {'id': '344', 'type': 'attribute', 'children': ['345', '346']}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'cfg'}, {'id': '347', 'type': 'keyword_argument', 'children': ['348', '349']}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'test'}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'test'}; {'id': '350', 'type': 'expression_statement', 'children': ['351']}, {'id': '351', 'type': 'assignment', 'children': ['352', '355']}; {'id': '352', 'type': 'attribute', 'children': ['353', '354']}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'configuration_sent'}, {'id': '355', 'type': 'True', 'children': []}; {'id': '356', 'type': 'expression_statement', 'children': ['357']}, {'id': '357', 'type': 'call', 'children': ['358', '361']}; {'id': '358', 'type': 'attribute', 'children': ['359', '360']}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '361', 'type': 'argument_list', 'children': ['362']}; {'id': '362', 'type': 'string', 'children': [], 'value': '"- sent"'}, {'id': '363', 'type': 'if_statement', 'children': ['364', '367']}; {'id': '364', 'type': 'attribute', 'children': ['365', '366']}, {'id': '365', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'dispatch_ok'}, {'id': '367', 'type': 'block', 'children': ['368', '374']}; {'id': '368', 'type': 'expression_statement', 'children': ['369']}, {'id': '369', 'type': 'assignment', 'children': ['370', '373']}; {'id': '370', 'type': 'attribute', 'children': ['371', '372']}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'new_to_dispatch'}, {'id': '373', 'type': 'False', 'children': []}; {'id': '374', 'type': 'expression_statement', 'children': ['375']}, {'id': '375', 'type': 'assignment', 'children': ['376', '379']}; {'id': '376', 'type': 'attribute', 'children': ['377', '378']}, {'id': '377', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'first_dispatch_done'}, {'id': '379', 'type': 'True', 'children': []} | def dispatch(self, test=False):
if not self.new_to_dispatch:
raise DispatcherError("Dispatcher cannot dispatch, "
"because no configuration is prepared!")
if self.first_dispatch_done:
raise DispatcherError("Dispatcher cannot dispatch, "
"because the configuration is still dispatched!")
if self.dispatch_ok:
logger.info("Dispatching is already done and ok...")
return
logger.info("Trying to send configuration to the satellites...")
self.dispatch_ok = True
for link in self.arbiters:
if link == self.arbiter_link:
continue
if not link.active:
continue
if not link.spare:
continue
if link.configuration_sent:
logger.debug("Arbiter %s already sent!", link.name)
continue
if not link.reachable:
logger.debug("Arbiter %s is not reachable to receive its configuration",
link.name)
continue
logger.info("Sending configuration to the arbiter %s", link.name)
logger.debug("- %s", link.cfg)
link.put_conf(link.cfg, test=test)
link.configuration_sent = True
logger.info("- sent")
link.do_not_run()
for link in self.schedulers:
if link.configuration_sent:
logger.debug("Scheduler %s already sent!", link.name)
continue
if not link.active:
continue
if not link.reachable:
logger.debug("Scheduler %s is not reachable to receive its configuration",
link.name)
continue
logger.info("Sending configuration to the scheduler %s", link.name)
logger.debug("- %s", link.cfg)
link.put_conf(link.cfg, test=test)
link.configuration_sent = True
logger.info("- sent")
for link in self.satellites:
if link.configuration_sent:
logger.debug("%s %s already sent!", link.type, link.name)
continue
if not link.active:
continue
if not link.reachable:
logger.warning("%s %s is not reachable to receive its configuration",
link.type, link.name)
continue
logger.info("Sending configuration to the %s %s", link.type, link.name)
logger.debug("- %s", link.cfg)
link.put_conf(link.cfg, test=test)
link.configuration_sent = True
logger.info("- sent")
if self.dispatch_ok:
self.new_to_dispatch = False
self.first_dispatch_done = True |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_value_from_element'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'elt'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '7', 'type': 'block', 'children': ['8', '12', '25', '34', '41']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'if_statement', 'children': ['13', '18']}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '15', 'type': 'argument_list', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '18', 'type': 'block', 'children': ['19']}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '24']}, {'id': '21', 'type': 'pattern_list', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '28', 'type': 'call', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32', '33']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'elt'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '33', 'type': 'None', 'children': []}; {'id': '34', 'type': 'if_statement', 'children': ['35', '38']}, {'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': 'is'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '37', 'type': 'None', 'children': []}; {'id': '38', 'type': 'block', 'children': ['39']}, {'id': '39', 'type': 'return_statement', 'children': ['40']}; {'id': '40', 'type': 'string', 'children': [], 'value': "'n/a'"}, {'id': '41', 'type': 'try_statement', 'children': ['42', '105', '110']}; {'id': '42', 'type': 'block', 'children': ['43', '59', '71', '79', '83', '99']}, {'id': '43', 'type': 'if_statement', 'children': ['44', '49']}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'return_statement', 'children': ['51']}, {'id': '51', 'type': 'binary_operator', 'children': ['52', '53'], 'value': '%'}; {'id': '52', 'type': 'string', 'children': [], 'value': '"[%s]"'}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'string', 'children': [], 'value': "','"}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '59', 'type': 'if_statement', 'children': ['60', '68']}; {'id': '60', 'type': 'not_operator', 'children': ['61']}, {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '63', 'type': 'argument_list', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'collections'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'Callable'}; {'id': '68', 'type': 'block', 'children': ['69']}, {'id': '69', 'type': 'return_statement', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '71', 'type': 'if_statement', 'children': ['72', '74']}; {'id': '72', 'type': 'not_operator', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '74', 'type': 'block', 'children': ['75']}, {'id': '75', 'type': 'return_statement', 'children': ['76']}; {'id': '76', 'type': 'call', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '78', 'type': 'argument_list', 'children': []}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'real_args'}; {'id': '82', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '83', 'type': 'for_statement', 'children': ['84', '85', '86']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'arg'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '86', 'type': 'block', 'children': ['87']}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'call', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'real_args'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '95', 'type': 'argument_list', 'children': ['96', '97', '98']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'arg'}; {'id': '98', 'type': 'None', 'children': []}, {'id': '99', 'type': 'return_statement', 'children': ['100']}; {'id': '100', 'type': 'call', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'list_splat', 'children': ['104']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'real_args'}, {'id': '105', 'type': 'except_clause', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}, {'id': '107', 'type': 'block', 'children': ['108']}; {'id': '108', 'type': 'return_statement', 'children': ['109']}, {'id': '109', 'type': 'string', 'children': [], 'value': "'n/a'"}; {'id': '110', 'type': 'except_clause', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'UnicodeError'}; {'id': '112', 'type': 'block', 'children': ['113', '129']}, {'id': '113', 'type': 'if_statement', 'children': ['114', '119']}; {'id': '114', 'type': 'call', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '116', 'type': 'argument_list', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'string_types'}, {'id': '119', 'type': 'block', 'children': ['120']}; {'id': '120', 'type': 'return_statement', 'children': ['121']}, {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '123', 'type': 'argument_list', 'children': ['124', '125', '126']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '125', 'type': 'string', 'children': [], 'value': "'utf8'"}; {'id': '126', 'type': 'keyword_argument', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '128', 'type': 'string', 'children': [], 'value': "'ignore'"}, {'id': '129', 'type': 'return_statement', 'children': ['130']} | def _get_value_from_element(self, elt, prop):
args = None
if isinstance(prop, tuple):
prop, args = prop
value = getattr(elt, prop, None)
if value is None:
return 'n/a'
try:
if isinstance(value, list):
return "[%s]" % ','.join(value)
if not isinstance(value, collections.Callable):
return value
if not args:
return value()
real_args = []
for arg in args:
real_args.append(getattr(self, arg, None))
return value(*real_args)
except AttributeError:
return 'n/a'
except UnicodeError:
if isinstance(value, string_types):
return str(value, 'utf8', errors='ignore')
return 'n/a' |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_type_of_macro'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'macros'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'objs'}; {'id': '6', 'type': 'block', 'children': ['7', '9']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '9', 'type': 'for_statement', 'children': ['10', '11', '12']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'macro'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'macros'}; {'id': '12', 'type': 'block', 'children': ['13', '131']}, {'id': '13', 'type': 'if_statement', 'children': ['14', '21', '31', '57', '83', '109']}; {'id': '14', 'type': 'call', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 're'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '20']}, {'id': '19', 'type': 'string', 'children': [], 'value': "r'ARG\\d'"}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'macro'}, {'id': '21', 'type': 'block', 'children': ['22', '30']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '29']}; {'id': '24', 'type': 'subscript', 'children': ['25', '28']}, {'id': '25', 'type': 'subscript', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'macros'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'macro'}; {'id': '28', 'type': 'string', 'children': [], 'value': "'type'"}, {'id': '29', 'type': 'string', 'children': [], 'value': "'ARGN'"}; {'id': '30', 'type': 'continue_statement', 'children': []}, {'id': '31', 'type': 'elif_clause', 'children': ['32', '39']}; {'id': '32', 'type': 'call', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 're'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '38']}, {'id': '37', 'type': 'string', 'children': [], 'value': "r'_HOST\\w'"}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'macro'}, {'id': '39', 'type': 'block', 'children': ['40', '48', '56']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '47']}; {'id': '42', 'type': 'subscript', 'children': ['43', '46']}, {'id': '43', 'type': 'subscript', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'macros'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'macro'}; {'id': '46', 'type': 'string', 'children': [], 'value': "'type'"}, {'id': '47', 'type': 'string', 'children': [], 'value': "'CUSTOM'"}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '55']}; {'id': '50', 'type': 'subscript', 'children': ['51', '54']}, {'id': '51', 'type': 'subscript', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'macros'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'macro'}; {'id': '54', 'type': 'string', 'children': [], 'value': "'class'"}, {'id': '55', 'type': 'string', 'children': [], 'value': "'HOST'"}; {'id': '56', 'type': 'continue_statement', 'children': []}, {'id': '57', 'type': 'elif_clause', 'children': ['58', '65']}; {'id': '58', 'type': 'call', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 're'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '62', 'type': 'argument_list', 'children': ['63', '64']}, {'id': '63', 'type': 'string', 'children': [], 'value': "r'_SERVICE\\w'"}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'macro'}, {'id': '65', 'type': 'block', 'children': ['66', '74', '82']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '73']}; {'id': '68', 'type': 'subscript', 'children': ['69', '72']}, {'id': '69', 'type': 'subscript', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'macros'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'macro'}; {'id': '72', 'type': 'string', 'children': [], 'value': "'type'"}, {'id': '73', 'type': 'string', 'children': [], 'value': "'CUSTOM'"}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '81']}; {'id': '76', 'type': 'subscript', 'children': ['77', '80']}, {'id': '77', 'type': 'subscript', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'macros'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'macro'}; {'id': '80', 'type': 'string', 'children': [], 'value': "'class'"}, {'id': '81', 'type': 'string', 'children': [], 'value': "'SERVICE'"}; {'id': '82', 'type': 'continue_statement', 'children': []}, {'id': '83', 'type': 'elif_clause', 'children': ['84', '91']}; {'id': '84', 'type': 'call', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 're'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '90']}, {'id': '89', 'type': 'string', 'children': [], 'value': "r'_CONTACT\\w'"}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'macro'}, {'id': '91', 'type': 'block', 'children': ['92', '100', '108']}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'assignment', 'children': ['94', '99']}; {'id': '94', 'type': 'subscript', 'children': ['95', '98']}, {'id': '95', 'type': 'subscript', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'macros'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'macro'}; {'id': '98', 'type': 'string', 'children': [], 'value': "'type'"}, {'id': '99', 'type': 'string', 'children': [], 'value': "'CUSTOM'"}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '107']}; {'id': '102', 'type': 'subscript', 'children': ['103', '106']}, {'id': '103', 'type': 'subscript', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'macros'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'macro'}; {'id': '106', 'type': 'string', 'children': [], 'value': "'class'"}, {'id': '107', 'type': 'string', 'children': [], 'value': "'CONTACT'"}; {'id': '108', 'type': 'continue_statement', 'children': []}, {'id': '109', 'type': 'elif_clause', 'children': ['110', '121']}; {'id': '110', 'type': 'comparison_operator', 'children': ['111', '120'], 'value': '>'}, {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'call', 'children': ['115', '118']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'macro'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}, {'id': '119', 'type': 'string', 'children': [], 'value': "':'"}; {'id': '120', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '121', 'type': 'block', 'children': ['122', '130']}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'assignment', 'children': ['124', '129']}; {'id': '124', 'type': 'subscript', 'children': ['125', '128']}, {'id': '125', 'type': 'subscript', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'macros'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'macro'}; {'id': '128', 'type': 'string', 'children': [], 'value': "'type'"}, {'id': '129', 'type': 'string', 'children': [], 'value': "'ONDEMAND'"}; {'id': '130', 'type': 'continue_statement', 'children': []}, {'id': '131', 'type': 'for_statement', 'children': ['132', '133', '134']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'objs'}; {'id': '134', 'type': 'block', 'children': ['135']}, {'id': '135', 'type': 'if_statement', 'children': ['136', '141']}; {'id': '136', 'type': 'comparison_operator', 'children': ['137', '138'], 'value': 'in'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'macro'}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'macros'}, {'id': '141', 'type': 'block', 'children': ['142', '150', '158']}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'assignment', 'children': ['144', '149']}; {'id': '144', 'type': 'subscript', 'children': ['145', '148']}, {'id': '145', 'type': 'subscript', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'macros'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'macro'}; {'id': '148', 'type': 'string', 'children': [], 'value': "'type'"}, {'id': '149', 'type': 'string', 'children': [], 'value': "'object'"}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}, {'id': '151', 'type': 'assignment', 'children': ['152', '157']}; {'id': '152', 'type': 'subscript', 'children': ['153', '156']}, {'id': '153', 'type': 'subscript', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'macros'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'macro'}; {'id': '156', 'type': 'string', 'children': [], 'value': "'object'"}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'obj'} | def _get_type_of_macro(macros, objs):
r
for macro in macros:
if re.match(r'ARG\d', macro):
macros[macro]['type'] = 'ARGN'
continue
elif re.match(r'_HOST\w', macro):
macros[macro]['type'] = 'CUSTOM'
macros[macro]['class'] = 'HOST'
continue
elif re.match(r'_SERVICE\w', macro):
macros[macro]['type'] = 'CUSTOM'
macros[macro]['class'] = 'SERVICE'
continue
elif re.match(r'_CONTACT\w', macro):
macros[macro]['type'] = 'CUSTOM'
macros[macro]['class'] = 'CONTACT'
continue
elif len(macro.split(':')) > 1:
macros[macro]['type'] = 'ONDEMAND'
continue
for obj in objs:
if macro in obj.macros:
macros[macro]['type'] = 'object'
macros[macro]['object'] = obj
continue |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_resolve_ondemand'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'macro'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '7', 'type': 'block', 'children': ['8', '17', '24', '30', '216']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'elts'}, {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'macro'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'string', 'children': [], 'value': "':'"}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'nb_parts'}; {'id': '20', 'type': 'call', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'elts'}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'macro_name'}, {'id': '27', 'type': 'subscript', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'elts'}, {'id': '29', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '30', 'type': 'if_statement', 'children': ['31', '34', '122']}, {'id': '31', 'type': 'comparison_operator', 'children': ['32', '33'], 'value': '=='}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'nb_parts'}, {'id': '33', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '34', 'type': 'block', 'children': ['35', '39', '51', '79', '91']}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '38', 'type': 'string', 'children': [], 'value': "''"}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '44']}, {'id': '41', 'type': 'tuple_pattern', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'host_name'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'service_description'}; {'id': '44', 'type': 'tuple', 'children': ['45', '48']}, {'id': '45', 'type': 'subscript', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'elts'}, {'id': '47', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '48', 'type': 'subscript', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'elts'}; {'id': '50', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '51', 'type': 'if_statement', 'children': ['52', '55']}; {'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': '=='}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'host_name'}; {'id': '54', 'type': 'string', 'children': [], 'value': "''"}, {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'for_statement', 'children': ['57', '58', '59']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'elt'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'if_statement', 'children': ['61', '72']}, {'id': '61', 'type': 'boolean_operator', 'children': ['62', '65'], 'value': 'and'}; {'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': 'is'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'elt'}; {'id': '64', 'type': 'None', 'children': []}, {'id': '65', 'type': 'comparison_operator', 'children': ['66', '69'], 'value': '=='}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'elt'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': '__class__'}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'host_class'}; {'id': '72', 'type': 'block', 'children': ['73']}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'host_name'}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'elt'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'host_name'}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'serv'}; {'id': '82', 'type': 'call', 'children': ['83', '88']}, {'id': '83', 'type': 'attribute', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'find_srv_by_name_and_hostname'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'host_name'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'service_description'}, {'id': '91', 'type': 'if_statement', 'children': ['92', '95']}; {'id': '92', 'type': 'comparison_operator', 'children': ['93', '94'], 'value': 'is'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'serv'}; {'id': '94', 'type': 'None', 'children': []}, {'id': '95', 'type': 'block', 'children': ['96', '102', '110', '120']}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'serv'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '105', 'type': 'subscript', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'macros'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'macro_name'}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '113', 'type': 'call', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': '_get_value_from_element'}, {'id': '117', 'type': 'argument_list', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'serv'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '120', 'type': 'return_statement', 'children': ['121']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '122', 'type': 'else_clause', 'children': ['123']}, {'id': '123', 'type': 'block', 'children': ['124', '128', '134', '162', '214']}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '127', 'type': 'string', 'children': [], 'value': "''"}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'elt_name'}, {'id': '131', 'type': 'subscript', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'elts'}, {'id': '133', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '134', 'type': 'if_statement', 'children': ['135', '138']}, {'id': '135', 'type': 'comparison_operator', 'children': ['136', '137'], 'value': '=='}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'elt_name'}, {'id': '137', 'type': 'string', 'children': [], 'value': "''"}; {'id': '138', 'type': 'block', 'children': ['139']}, {'id': '139', 'type': 'for_statement', 'children': ['140', '141', '142']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'elt'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '142', 'type': 'block', 'children': ['143']}, {'id': '143', 'type': 'if_statement', 'children': ['144', '155']}; {'id': '144', 'type': 'boolean_operator', 'children': ['145', '148'], 'value': 'and'}, {'id': '145', 'type': 'comparison_operator', 'children': ['146', '147'], 'value': 'is'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'elt'}, {'id': '147', 'type': 'None', 'children': []}; {'id': '148', 'type': 'comparison_operator', 'children': ['149', '152'], 'value': '=='}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'elt'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'host_class'}, {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'assignment', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'elt_name'}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'elt'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'host_name'}; {'id': '162', 'type': 'for_statement', 'children': ['163', '164', '167']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'od_list'}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'lists_on_demand'}, {'id': '167', 'type': 'block', 'children': ['168', '174']}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'assignment', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'od_list'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'inner_class'}; {'id': '174', 'type': 'if_statement', 'children': ['175', '180']}, {'id': '175', 'type': 'comparison_operator', 'children': ['176', '177'], 'value': 'in'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'macro_name'}, {'id': '177', 'type': 'attribute', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'macros'}; {'id': '180', 'type': 'block', 'children': ['181', '189', '198']}, {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'assignment', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '184', 'type': 'subscript', 'children': ['185', '188']}, {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'macros'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'macro_name'}, {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'assignment', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '192', 'type': 'call', 'children': ['193', '196']}, {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'od_list'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'find_by_name'}; {'id': '196', 'type': 'argument_list', 'children': ['197']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'elt_name'}; {'id': '198', 'type': 'if_statement', 'children': ['199', '202']}, {'id': '199', 'type': 'comparison_operator', 'children': ['200', '201'], 'value': 'is'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '201', 'type': 'None', 'children': []}; {'id': '202', 'type': 'block', 'children': ['203', '213']}, {'id': '203', 'type': 'expression_statement', 'children': ['204']}; {'id': '204', 'type': 'assignment', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '206', 'type': 'call', 'children': ['207', '210']}, {'id': '207', 'type': 'attribute', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': '_get_value_from_element'}; {'id': '210', 'type': 'argument_list', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '213', 'type': 'break_statement', 'children': []}; {'id': '214', 'type': 'return_statement', 'children': ['215']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '216', 'type': 'return_statement', 'children': ['217']}, {'id': '217', 'type': 'string', 'children': [], 'value': "'n/a'"} | def _resolve_ondemand(self, macro, data):
elts = macro.split(':')
nb_parts = len(elts)
macro_name = elts[0]
if nb_parts == 3:
val = ''
(host_name, service_description) = (elts[1], elts[2])
if host_name == '':
for elt in data:
if elt is not None and elt.__class__ == self.host_class:
host_name = elt.host_name
serv = self.services.find_srv_by_name_and_hostname(host_name, service_description)
if serv is not None:
cls = serv.__class__
prop = cls.macros[macro_name]
val = self._get_value_from_element(serv, prop)
return val
else:
val = ''
elt_name = elts[1]
if elt_name == '':
for elt in data:
if elt is not None and elt.__class__ == self.host_class:
elt_name = elt.host_name
for od_list in self.lists_on_demand:
cls = od_list.inner_class
if macro_name in cls.macros:
prop = cls.macros[macro_name]
i = od_list.find_by_name(elt_name)
if i is not None:
val = self._get_value_from_element(i, prop)
break
return val
return 'n/a' |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'parse'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '23', '35', '44', '101', '110', '120', '340', '350']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'sub_directory'}, {'id': '9', 'type': 'string', 'children': [], 'value': "'alignak.d'"}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'dir_name'}, {'id': '13', 'type': 'call', 'children': ['14', '19']}; {'id': '14', 'type': 'attribute', 'children': ['15', '18']}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'dirname'}, {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'configuration_file'}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'dir_name'}; {'id': '26', 'type': 'call', 'children': ['27', '32']}, {'id': '27', 'type': 'attribute', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'dir_name'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'sub_directory'}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '40']}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'cfg_files'}; {'id': '40', 'type': 'list', 'children': ['41'], 'value': '[self.configuration_file]'}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'configuration_file'}; {'id': '44', 'type': 'if_statement', 'children': ['45', '53']}, {'id': '45', 'type': 'call', 'children': ['46', '51']}; {'id': '46', 'type': 'attribute', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'os'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'exists'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'dir_name'}, {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'for_statement', 'children': ['55', '59', '68']}, {'id': '55', 'type': 'pattern_list', 'children': ['56', '57', '58']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'root'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'walk_files'}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'walk'}, {'id': '63', 'type': 'argument_list', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'dir_name'}, {'id': '65', 'type': 'keyword_argument', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'followlinks'}, {'id': '67', 'type': 'True', 'children': []}; {'id': '68', 'type': 'block', 'children': ['69']}, {'id': '69', 'type': 'for_statement', 'children': ['70', '71', '72']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'found_file'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'walk_files'}; {'id': '72', 'type': 'block', 'children': ['73', '84']}, {'id': '73', 'type': 'if_statement', 'children': ['74', '82']}; {'id': '74', 'type': 'not_operator', 'children': ['75']}, {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'search'}, {'id': '79', 'type': 'argument_list', 'children': ['80', '81']}; {'id': '80', 'type': 'string', 'children': [], 'value': 'r"\\.ini$"'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'found_file'}; {'id': '82', 'type': 'block', 'children': ['83']}, {'id': '83', 'type': 'continue_statement', 'children': []}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'call', 'children': ['86', '91']}; {'id': '86', 'type': 'attribute', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'cfg_files'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '98']}, {'id': '93', 'type': 'attribute', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '98', 'type': 'argument_list', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'root'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'found_file'}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'call', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'binary_operator', 'children': ['106', '107'], 'value': '%'}; {'id': '106', 'type': 'string', 'children': [], 'value': '"Loading configuration files: %s "'}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'cfg_files'}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '115', 'type': 'call', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'configparser'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'ConfigParser'}, {'id': '119', 'type': 'argument_list', 'children': []}; {'id': '120', 'type': 'try_statement', 'children': ['121', '273', '308']}, {'id': '121', 'type': 'block', 'children': ['122', '133', '165']}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'call', 'children': ['124', '129']}; {'id': '124', 'type': 'attribute', 'children': ['125', '128']}, {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'read'}, {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'cfg_files'}, {'id': '133', 'type': 'if_statement', 'children': ['134', '141']}; {'id': '134', 'type': 'comparison_operator', 'children': ['135', '140'], 'value': '=='}, {'id': '135', 'type': 'attribute', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': '_sections'}; {'id': '140', 'type': 'dictionary', 'children': []}, {'id': '141', 'type': 'block', 'children': ['142', '151', '158']}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'call', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'binary_operator', 'children': ['147', '148'], 'value': '%'}, {'id': '147', 'type': 'string', 'children': [], 'value': '"* bad formatted configuration file: %s "'}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'configuration_file'}, {'id': '151', 'type': 'if_statement', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'embedded'}, {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'raise_statement', 'children': ['157']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}, {'id': '159', 'type': 'call', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'exit'}, {'id': '163', 'type': 'argument_list', 'children': ['164']}; {'id': '164', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '165', 'type': 'for_statement', 'children': ['166', '167', '174']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'section'}, {'id': '167', 'type': 'call', 'children': ['168', '173']}; {'id': '168', 'type': 'attribute', 'children': ['169', '172']}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'sections'}, {'id': '173', 'type': 'argument_list', 'children': []}; {'id': '174', 'type': 'block', 'children': ['175', '187']}, {'id': '175', 'type': 'if_statement', 'children': ['176', '179']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '179', 'type': 'block', 'children': ['180']}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}, {'id': '181', 'type': 'call', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '183', 'type': 'argument_list', 'children': ['184']}; {'id': '184', 'type': 'binary_operator', 'children': ['185', '186'], 'value': '%'}, {'id': '185', 'type': 'string', 'children': [], 'value': '"- section: %s"'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'section'}, {'id': '187', 'type': 'for_statement', 'children': ['188', '191', '199']}; {'id': '188', 'type': 'tuple_pattern', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '191', 'type': 'call', 'children': ['192', '197']}; {'id': '192', 'type': 'attribute', 'children': ['193', '196']}, {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '197', 'type': 'argument_list', 'children': ['198']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'section'}, {'id': '199', 'type': 'block', 'children': ['200', '208', '215', '223', '237']}; {'id': '200', 'type': 'expression_statement', 'children': ['201']}, {'id': '201', 'type': 'assignment', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'inner_property'}, {'id': '203', 'type': 'binary_operator', 'children': ['204', '205'], 'value': '%'}; {'id': '204', 'type': 'string', 'children': [], 'value': '"%s.%s"'}, {'id': '205', 'type': 'tuple', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'section'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '208', 'type': 'expression_statement', 'children': ['209']}, {'id': '209', 'type': 'call', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'setattr'}, {'id': '211', 'type': 'argument_list', 'children': ['212', '213', '214']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'inner_property'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '215', 'type': 'expression_statement', 'children': ['216']}; {'id': '216', 'type': 'assignment', 'children': ['217', '222']}, {'id': '217', 'type': 'subscript', 'children': ['218', '221']}; {'id': '218', 'type': 'attribute', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'environ'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'inner_property'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '223', 'type': 'if_statement', 'children': ['224', '227']}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'verbose'}, {'id': '227', 'type': 'block', 'children': ['228']}; {'id': '228', 'type': 'expression_statement', 'children': ['229']}, {'id': '229', 'type': 'call', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '231', 'type': 'argument_list', 'children': ['232']}; {'id': '232', 'type': 'binary_operator', 'children': ['233', '234'], 'value': '%'}, {'id': '233', 'type': 'string', 'children': [], 'value': '" %s = %s"'}; {'id': '234', 'type': 'tuple', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'inner_property'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '237', 'type': 'if_statement', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'export'}, {'id': '241', 'type': 'block', 'children': ['242', '253', '261']}; {'id': '242', 'type': 'expression_statement', 'children': ['243']}, {'id': '243', 'type': 'assignment', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'inner_property'}, {'id': '245', 'type': 'call', 'children': ['246', '249']}; {'id': '246', 'type': 'attribute', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'sub'}, {'id': '249', 'type': 'argument_list', 'children': ['250', '251', '252']}; {'id': '250', 'type': 'string', 'children': [], 'value': "'[^0-9a-zA-Z]+'"}, {'id': '251', 'type': 'string', 'children': [], 'value': "'_'"}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'inner_property'}, {'id': '253', 'type': 'expression_statement', 'children': ['254']}; {'id': '254', 'type': 'assignment', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'inner_property'}; {'id': '256', 'type': 'call', 'children': ['257', '260']}, {'id': '257', 'type': 'attribute', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'inner_property'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'upper'}; {'id': '260', 'type': 'argument_list', 'children': []}, {'id': '261', 'type': 'expression_statement', 'children': ['262']}; {'id': '262', 'type': 'call', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '264', 'type': 'argument_list', 'children': ['265']}, {'id': '265', 'type': 'binary_operator', 'children': ['266', '267'], 'value': '%'}; {'id': '266', 'type': 'string', 'children': [], 'value': '"export %s=%s"'}, {'id': '267', 'type': 'tuple', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'inner_property'}, {'id': '269', 'type': 'call', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'cmd_quote'}, {'id': '271', 'type': 'argument_list', 'children': ['272']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '273', 'type': 'except_clause', 'children': ['274', '280']}; {'id': '274', 'type': 'as_pattern', 'children': ['275', '278']}, {'id': '275', 'type': 'attribute', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'configparser'}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'ParsingError'}; {'id': '278', 'type': 'as_pattern_target', 'children': ['279']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'exp'}; {'id': '280', 'type': 'block', 'children': ['281', '294', '301']}, {'id': '281', 'type': 'expression_statement', 'children': ['282']}; {'id': '282', 'type': 'call', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '284', 'type': 'argument_list', 'children': ['285']}, {'id': '285', 'type': 'binary_operator', 'children': ['286', '287'], 'value': '%'}; {'id': '286', 'type': 'string', 'children': [], 'value': '"* parsing error in config file : %s\\n%s"'}, {'id': '287', 'type': 'tuple', 'children': ['288', '291']}; {'id': '288', 'type': 'attribute', 'children': ['289', '290']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'configuration_file'}, {'id': '291', 'type': 'attribute', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'exp'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'message'}; {'id': '294', 'type': 'if_statement', 'children': ['295', '298']}, {'id': '295', 'type': 'attribute', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'embedded'}; {'id': '298', 'type': 'block', 'children': ['299']}, {'id': '299', 'type': 'return_statement', 'children': ['300']}; {'id': '300', 'type': 'False', 'children': []}, {'id': '301', 'type': 'expression_statement', 'children': ['302']}; {'id': '302', 'type': 'call', 'children': ['303', '306']}, {'id': '303', 'type': 'attribute', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '306', 'type': 'argument_list', 'children': ['307']}, {'id': '307', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '308', 'type': 'except_clause', 'children': ['309', '315']}, {'id': '309', 'type': 'as_pattern', 'children': ['310', '313']}; {'id': '310', 'type': 'attribute', 'children': ['311', '312']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'configparser'}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'InterpolationMissingOptionError'}, {'id': '313', 'type': 'as_pattern_target', 'children': ['314']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'exp'}, {'id': '315', 'type': 'block', 'children': ['316', '326', '333']}; {'id': '316', 'type': 'expression_statement', 'children': ['317']}, {'id': '317', 'type': 'call', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '319', 'type': 'argument_list', 'children': ['320']}; {'id': '320', 'type': 'binary_operator', 'children': ['321', '322'], 'value': '%'}, {'id': '321', 'type': 'string', 'children': [], 'value': '"* incorrect or missing variable: %s"'}; {'id': '322', 'type': 'call', 'children': ['323', '324']}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '324', 'type': 'argument_list', 'children': ['325']}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'exp'}; {'id': '326', 'type': 'if_statement', 'children': ['327', '330']}, {'id': '327', 'type': 'attribute', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'embedded'}; {'id': '330', 'type': 'block', 'children': ['331']}, {'id': '331', 'type': 'return_statement', 'children': ['332']}; {'id': '332', 'type': 'False', 'children': []}, {'id': '333', 'type': 'expression_statement', 'children': ['334']}; {'id': '334', 'type': 'call', 'children': ['335', '338']}, {'id': '335', 'type': 'attribute', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'exit'}; {'id': '338', 'type': 'argument_list', 'children': ['339']}, {'id': '339', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '340', 'type': 'if_statement', 'children': ['341', '344']}, {'id': '341', 'type': 'attribute', 'children': ['342', '343']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'verbose'}; {'id': '344', 'type': 'block', 'children': ['345']}, {'id': '345', 'type': 'expression_statement', 'children': ['346']}; {'id': '346', 'type': 'call', 'children': ['347', '348']}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '348', 'type': 'argument_list', 'children': ['349']}, {'id': '349', 'type': 'string', 'children': [], 'value': '"Configuration file parsed correctly"'}; {'id': '350', 'type': 'return_statement', 'children': ['351']}, {'id': '351', 'type': 'True', 'children': []} | def parse(self):
sub_directory = 'alignak.d'
dir_name = os.path.dirname(self.configuration_file)
dir_name = os.path.join(dir_name, sub_directory)
self.cfg_files = [self.configuration_file]
if os.path.exists(dir_name):
for root, _, walk_files in os.walk(dir_name, followlinks=True):
for found_file in walk_files:
if not re.search(r"\.ini$", found_file):
continue
self.cfg_files.append(os.path.join(root, found_file))
print("Loading configuration files: %s " % self.cfg_files)
self.config = configparser.ConfigParser()
try:
self.config.read(self.cfg_files)
if self.config._sections == {}:
print("* bad formatted configuration file: %s " % self.configuration_file)
if self.embedded:
raise ValueError
sys.exit(2)
for section in self.config.sections():
if self.verbose:
print("- section: %s" % section)
for (key, value) in self.config.items(section):
inner_property = "%s.%s" % (section, key)
setattr(self, inner_property, value)
os.environ[inner_property] = value
if self.verbose:
print(" %s = %s" % (inner_property, value))
if self.export:
inner_property = re.sub('[^0-9a-zA-Z]+', '_', inner_property)
inner_property = inner_property.upper()
print("export %s=%s" % (inner_property, cmd_quote(value)))
except configparser.ParsingError as exp:
print("* parsing error in config file : %s\n%s"
% (self.configuration_file, exp.message))
if self.embedded:
return False
sys.exit(3)
except configparser.InterpolationMissingOptionError as exp:
print("* incorrect or missing variable: %s" % str(exp))
if self.embedded:
return False
sys.exit(3)
if self.verbose:
print("Configuration file parsed correctly")
return True |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_modules'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'daemon_name'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'names_only'}, {'id': '13', 'type': 'True', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '46', '114']}, {'id': '15', 'type': 'if_statement', 'children': ['16', '19']}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'is'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '18', 'type': 'None', 'children': []}, {'id': '19', 'type': 'block', 'children': ['20', '31', '44']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'sections'}, {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': '_search_sections'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'binary_operator', 'children': ['29', '30'], 'value': '+'}, {'id': '29', 'type': 'string', 'children': [], 'value': "'module.'"}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '31', 'type': 'if_statement', 'children': ['32', '37']}; {'id': '32', 'type': 'comparison_operator', 'children': ['33', '36'], 'value': 'in'}, {'id': '33', 'type': 'binary_operator', 'children': ['34', '35'], 'value': '+'}; {'id': '34', 'type': 'string', 'children': [], 'value': "'module.'"}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'sections'}, {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'return_statement', 'children': ['39']}, {'id': '39', 'type': 'subscript', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'sections'}, {'id': '41', 'type': 'binary_operator', 'children': ['42', '43'], 'value': '+'}; {'id': '42', 'type': 'string', 'children': [], 'value': "'module.'"}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '44', 'type': 'return_statement', 'children': ['45']}, {'id': '45', 'type': 'dictionary', 'children': []}; {'id': '46', 'type': 'if_statement', 'children': ['47', '50']}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'is'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'daemon_name'}, {'id': '49', 'type': 'None', 'children': []}; {'id': '50', 'type': 'block', 'children': ['51', '60', '112']}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'section'}; {'id': '54', 'type': 'call', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'get_daemons'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'daemon_name'}; {'id': '60', 'type': 'if_statement', 'children': ['61', '68']}, {'id': '61', 'type': 'boolean_operator', 'children': ['62', '65'], 'value': 'and'}; {'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': 'in'}, {'id': '63', 'type': 'string', 'children': [], 'value': "'modules'"}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'section'}, {'id': '65', 'type': 'subscript', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'section'}, {'id': '67', 'type': 'string', 'children': [], 'value': "'modules'"}; {'id': '68', 'type': 'block', 'children': ['69', '73', '110']}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'modules'}; {'id': '72', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '73', 'type': 'for_statement', 'children': ['74', '75', '83']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'module_name'}, {'id': '75', 'type': 'call', 'children': ['76', '81']}; {'id': '76', 'type': 'attribute', 'children': ['77', '80']}, {'id': '77', 'type': 'subscript', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'section'}, {'id': '79', 'type': 'string', 'children': [], 'value': "'modules'"}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'string', 'children': [], 'value': "','"}, {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'if_statement', 'children': ['85', '86', '94']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'names_only'}; {'id': '86', 'type': 'block', 'children': ['87']}, {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'call', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'modules'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'module_name'}; {'id': '94', 'type': 'else_clause', 'children': ['95']}, {'id': '95', 'type': 'block', 'children': ['96']}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'call', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'modules'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'call', 'children': ['103', '106']}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'get_modules'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'keyword_argument', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'module_name'}; {'id': '110', 'type': 'return_statement', 'children': ['111']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'modules'}; {'id': '112', 'type': 'return_statement', 'children': ['113']}, {'id': '113', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '114', 'type': 'return_statement', 'children': ['115']}, {'id': '115', 'type': 'call', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': '_search_sections'}, {'id': '119', 'type': 'argument_list', 'children': ['120']} | def get_modules(self, name=None, daemon_name=None, names_only=True):
if name is not None:
sections = self._search_sections('module.' + name)
if 'module.' + name in sections:
return sections['module.' + name]
return {}
if daemon_name is not None:
section = self.get_daemons(daemon_name)
if 'modules' in section and section['modules']:
modules = []
for module_name in section['modules'].split(','):
if names_only:
modules.append(module_name)
else:
modules.append(self.get_modules(name=module_name))
return modules
return []
return self._search_sections('module.') |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'daemon_connection_init'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 's_link'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'set_wait_new_conf'}; {'id': '8', 'type': 'False', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '23', '44', '50', '63', '69', '75', '79', '127']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '15', 'type': 'argument_list', 'children': ['16', '17', '20']}; {'id': '16', 'type': 'string', 'children': [], 'value': '"Daemon connection initialization: %s %s"'}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 's_link'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 's_link'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '23', 'type': 'if_statement', 'children': ['24', '28']}; {'id': '24', 'type': 'not_operator', 'children': ['25']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 's_link'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'active'}; {'id': '28', 'type': 'block', 'children': ['29', '42']}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '36', '39']}, {'id': '35', 'type': 'string', 'children': [], 'value': '"%s \'%s\' is not active, do not initialize its connection!"'}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 's_link'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 's_link'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '42', 'type': 'return_statement', 'children': ['43']}, {'id': '43', 'type': 'False', 'children': []}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 's_link'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'create_connection'}, {'id': '49', 'type': 'argument_list', 'children': []}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '55', 'type': 'argument_list', 'children': ['56', '57', '60']}; {'id': '56', 'type': 'string', 'children': [], 'value': '"[%s] Getting running identifier for \'%s\'"'}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 's_link'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 's_link'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'alive'}; {'id': '68', 'type': 'True', 'children': []}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 's_link'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'reachable'}; {'id': '74', 'type': 'True', 'children': []}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'got_a_running_id'}; {'id': '78', 'type': 'None', 'children': []}, {'id': '79', 'type': 'for_statement', 'children': ['80', '81', '88']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '83', 'type': 'argument_list', 'children': ['84', '85']}; {'id': '84', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 's_link'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'max_check_attempts'}; {'id': '88', 'type': 'block', 'children': ['89', '97', '120']}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'got_a_running_id'}; {'id': '92', 'type': 'call', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 's_link'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'get_running_id'}; {'id': '96', 'type': 'argument_list', 'children': []}, {'id': '97', 'type': 'if_statement', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'got_a_running_id'}, {'id': '99', 'type': 'block', 'children': ['100', '110', '119']}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 's_link'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'last_connection'}, {'id': '105', 'type': 'call', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '109', 'type': 'argument_list', 'children': []}; {'id': '110', 'type': 'if_statement', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'set_wait_new_conf'}; {'id': '112', 'type': 'block', 'children': ['113']}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'call', 'children': ['115', '118']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 's_link'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'wait_new_conf'}; {'id': '118', 'type': 'argument_list', 'children': []}, {'id': '119', 'type': 'break_statement', 'children': []}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'call', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'sleep'}, {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'float', 'children': [], 'value': '0.3'}, {'id': '127', 'type': 'return_statement', 'children': ['128']} | def daemon_connection_init(self, s_link, set_wait_new_conf=False):
logger.debug("Daemon connection initialization: %s %s", s_link.type, s_link.name)
if not s_link.active:
logger.warning("%s '%s' is not active, do not initialize its connection!",
s_link.type, s_link.name)
return False
s_link.create_connection()
logger.debug("[%s] Getting running identifier for '%s'", self.name, s_link.name)
s_link.alive = True
s_link.reachable = True
got_a_running_id = None
for _ in range(0, s_link.max_check_attempts):
got_a_running_id = s_link.get_running_id()
if got_a_running_id:
s_link.last_connection = time.time()
if set_wait_new_conf:
s_link.wait_new_conf()
break
time.sleep(0.3)
return got_a_running_id |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'do_daemon_init_and_start'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'set_proc_title'}, {'id': '7', 'type': 'True', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '21', '27', '33', '39', '74', '80', '97', '107', '114', '136', '144', '152', '159']}, {'id': '9', 'type': 'if_statement', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'set_proc_title'}, {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'set_proctitle'}, {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'change_to_user_group'}; {'id': '26', 'type': 'argument_list', 'children': []}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'change_to_workdir'}; {'id': '32', 'type': 'argument_list', 'children': []}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'check_parallel_run'}; {'id': '38', 'type': 'argument_list', 'children': []}, {'id': '39', 'type': 'if_statement', 'children': ['40', '43', '61']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'is_daemon'}, {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'if_statement', 'children': ['45', '51']}, {'id': '45', 'type': 'not_operator', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'daemonize'}; {'id': '50', 'type': 'argument_list', 'children': []}, {'id': '51', 'type': 'block', 'children': ['52', '59']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'string', 'children': [], 'value': '"I could not daemonize myself :("'}, {'id': '59', 'type': 'return_statement', 'children': ['60']}; {'id': '60', 'type': 'False', 'children': []}, {'id': '61', 'type': 'else_clause', 'children': ['62']}; {'id': '62', 'type': 'block', 'children': ['63']}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'write_pid'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'getpid'}, {'id': '73', 'type': 'argument_list', 'children': []}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'setup_alignak_logger'}, {'id': '79', 'type': 'argument_list', 'children': []}; {'id': '80', 'type': 'if_statement', 'children': ['81', '87']}, {'id': '81', 'type': 'not_operator', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'setup_communication_daemon'}; {'id': '86', 'type': 'argument_list', 'children': []}, {'id': '87', 'type': 'block', 'children': ['88', '95']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'string', 'children': [], 'value': '"I could not setup my communication daemon :("'}, {'id': '95', 'type': 'return_statement', 'children': ['96']}; {'id': '96', 'type': 'False', 'children': []}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'sync_manager'}; {'id': '102', 'type': 'call', 'children': ['103', '106']}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': '_create_manager'}; {'id': '106', 'type': 'argument_list', 'children': []}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'call', 'children': ['109', '112']}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'string', 'children': [], 'value': '"Starting http_daemon thread"'}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'assignment', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'http_thread'}, {'id': '119', 'type': 'call', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'threading'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'Thread'}, {'id': '123', 'type': 'argument_list', 'children': ['124', '129']}; {'id': '124', 'type': 'keyword_argument', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'http_daemon_thread'}, {'id': '129', 'type': 'keyword_argument', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '131', 'type': 'binary_operator', 'children': ['132', '133'], 'value': '%'}; {'id': '132', 'type': 'string', 'children': [], 'value': "'%s-http_thread'"}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'id': '137', 'type': 'assignment', 'children': ['138', '143']}; {'id': '138', 'type': 'attribute', 'children': ['139', '142']}, {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'http_thread'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'daemon'}, {'id': '143', 'type': 'True', 'children': []}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'call', 'children': ['146', '151']}; {'id': '146', 'type': 'attribute', 'children': ['147', '150']}, {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'http_thread'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '151', 'type': 'argument_list', 'children': []}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'call', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'string', 'children': [], 'value': '"HTTP daemon thread started"'}, {'id': '159', 'type': 'return_statement', 'children': ['160']} | def do_daemon_init_and_start(self, set_proc_title=True):
if set_proc_title:
self.set_proctitle(self.name)
self.change_to_user_group()
self.change_to_workdir()
self.check_parallel_run()
if self.is_daemon:
if not self.daemonize():
logger.error("I could not daemonize myself :(")
return False
else:
self.write_pid(os.getpid())
self.setup_alignak_logger()
if not self.setup_communication_daemon():
logger.error("I could not setup my communication daemon :(")
return False
self.sync_manager = self._create_manager()
logger.info("Starting http_daemon thread")
self.http_thread = threading.Thread(target=self.http_daemon_thread,
name='%s-http_thread' % self.name)
self.http_thread.daemon = True
self.http_thread.start()
logger.info("HTTP daemon thread started")
return True |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'make_a_pause'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'timeout'}, {'id': '7', 'type': 'float', 'children': [], 'value': '0.0001'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'check_time_change'}; {'id': '10', 'type': 'True', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '21', '42', '50', '58', '66', '72', '81', '90', '94', '106']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '16']}, {'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': '=='}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'timeout'}, {'id': '15', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '20', 'type': 'float', 'children': [], 'value': '0.0001'}, {'id': '21', 'type': 'if_statement', 'children': ['22', '24']}; {'id': '22', 'type': 'not_operator', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'check_time_change'}; {'id': '24', 'type': 'block', 'children': ['25', '32', '38']}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'sleep'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'augmented_assignment', 'children': ['34', '37'], 'value': '+='}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'sleep_time'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '38', 'type': 'return_statement', 'children': ['39']}, {'id': '39', 'type': 'expression_list', 'children': ['40', '41']}; {'id': '40', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '41', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'before'}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '49', 'type': 'argument_list', 'children': []}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'time_changed'}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'check_for_system_time_change'}, {'id': '57', 'type': 'argument_list', 'children': []}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'after'}, {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '65', 'type': 'argument_list', 'children': []}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'elapsed'}, {'id': '69', 'type': 'binary_operator', 'children': ['70', '71'], 'value': '-'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'after'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'before'}; {'id': '72', 'type': 'if_statement', 'children': ['73', '76']}, {'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': '>'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'elapsed'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '76', 'type': 'block', 'children': ['77']}, {'id': '77', 'type': 'return_statement', 'children': ['78']}; {'id': '78', 'type': 'expression_list', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'elapsed'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'time_changed'}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'sleep'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'binary_operator', 'children': ['88', '89'], 'value': '-'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'timeout'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'elapsed'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'augmented_assignment', 'children': ['92', '93'], 'value': '+='}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'before'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'time_changed'}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'augmented_assignment', 'children': ['96', '99'], 'value': '+='}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'sleep_time'}, {'id': '99', 'type': 'binary_operator', 'children': ['100', '105'], 'value': '-'}; {'id': '100', 'type': 'call', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '104', 'type': 'argument_list', 'children': []}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'before'}; {'id': '106', 'type': 'return_statement', 'children': ['107']}, {'id': '107', 'type': 'expression_list', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'elapsed'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'time_changed'} | def make_a_pause(self, timeout=0.0001, check_time_change=True):
if timeout == 0:
timeout = 0.0001
if not check_time_change:
time.sleep(timeout)
self.sleep_time += timeout
return 0, 0
before = time.time()
time_changed = self.check_for_system_time_change()
after = time.time()
elapsed = after - before
if elapsed > timeout:
return elapsed, time_changed
time.sleep(timeout - elapsed)
before += time_changed
self.sleep_time += time.time() - before
return elapsed, time_changed |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'explode_hostgroup'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'svc_dep'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'hostgroups'}, {'id': '7', 'type': 'block', 'children': ['8', '27', '46', '65']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'snames'}, {'id': '11', 'type': 'list_comprehension', 'children': ['12', '17']}; {'id': '12', 'type': 'call', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '16', 'type': 'argument_list', 'children': []}, {'id': '17', 'type': 'for_in_clause', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'd'}, {'id': '19', 'type': 'call', 'children': ['20', '25']}; {'id': '20', 'type': 'attribute', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'svc_dep'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'service_description'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'string', 'children': [], 'value': "','"}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'dep_snames'}; {'id': '30', 'type': 'list_comprehension', 'children': ['31', '36']}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '35', 'type': 'argument_list', 'children': []}; {'id': '36', 'type': 'for_in_clause', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '38', 'type': 'call', 'children': ['39', '44']}, {'id': '39', 'type': 'attribute', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'svc_dep'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'dependent_service_description'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'string', 'children': [], 'value': "','"}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'hg_names'}, {'id': '49', 'type': 'list_comprehension', 'children': ['50', '55']}; {'id': '50', 'type': 'call', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '54', 'type': 'argument_list', 'children': []}, {'id': '55', 'type': 'for_in_clause', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '57', 'type': 'call', 'children': ['58', '63']}; {'id': '58', 'type': 'attribute', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'svc_dep'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'hostgroup_name'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'string', 'children': [], 'value': "','"}, {'id': '65', 'type': 'for_statement', 'children': ['66', '67', '68']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'hg_name'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'hg_names'}; {'id': '68', 'type': 'block', 'children': ['69', '78', '97', '101', '120']}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'hostgroup'}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'hostgroups'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'find_by_name'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'hg_name'}; {'id': '78', 'type': 'if_statement', 'children': ['79', '82']}, {'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': 'is'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'hostgroup'}, {'id': '81', 'type': 'None', 'children': []}; {'id': '82', 'type': 'block', 'children': ['83', '89', '96']}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '86', 'type': 'binary_operator', 'children': ['87', '88'], 'value': '%'}, {'id': '87', 'type': 'string', 'children': [], 'value': '"ERROR: the servicedependecy got an unknown hostgroup_name \'%s\'"'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'hg_name'}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'call', 'children': ['91', '94']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'add_error'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '96', 'type': 'continue_statement', 'children': []}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'hnames'}; {'id': '100', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'call', 'children': ['103', '106']}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'hnames'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}, {'id': '107', 'type': 'list_comprehension', 'children': ['108', '113']}; {'id': '108', 'type': 'call', 'children': ['109', '112']}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '112', 'type': 'argument_list', 'children': []}, {'id': '113', 'type': 'for_in_clause', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'm'}, {'id': '115', 'type': 'call', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'hostgroup'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'get_hosts'}, {'id': '119', 'type': 'argument_list', 'children': []}; {'id': '120', 'type': 'for_statement', 'children': ['121', '122', '123']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'hname'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'hnames'}, {'id': '123', 'type': 'block', 'children': ['124']}; {'id': '124', 'type': 'for_statement', 'children': ['125', '126', '127']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'dep_sname'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'dep_snames'}, {'id': '127', 'type': 'block', 'children': ['128']}; {'id': '128', 'type': 'for_statement', 'children': ['129', '130', '131']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'sname'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'snames'}, {'id': '131', 'type': 'block', 'children': ['132', '140', '146', '152', '158', '164']}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'new_sd'}, {'id': '135', 'type': 'call', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'svc_dep'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'copy'}, {'id': '139', 'type': 'argument_list', 'children': []}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'assignment', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'new_sd'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'host_name'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'hname'}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'assignment', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'new_sd'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'service_description'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'sname'}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'assignment', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'new_sd'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'dependent_host_name'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'hname'}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}, {'id': '159', 'type': 'assignment', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'new_sd'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'dependent_service_description'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'dep_sname'}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}, {'id': '165', 'type': 'call', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'add_item'}, {'id': '169', 'type': 'argument_list', 'children': ['170']} | def explode_hostgroup(self, svc_dep, hostgroups):
snames = [d.strip() for d in svc_dep.service_description.split(',')]
dep_snames = [d.strip() for d in svc_dep.dependent_service_description.split(',')]
hg_names = [n.strip() for n in svc_dep.hostgroup_name.split(',')]
for hg_name in hg_names:
hostgroup = hostgroups.find_by_name(hg_name)
if hostgroup is None:
err = "ERROR: the servicedependecy got an unknown hostgroup_name '%s'" % hg_name
self.add_error(err)
continue
hnames = []
hnames.extend([m.strip() for m in hostgroup.get_hosts()])
for hname in hnames:
for dep_sname in dep_snames:
for sname in snames:
new_sd = svc_dep.copy()
new_sd.host_name = hname
new_sd.service_description = sname
new_sd.dependent_host_name = hname
new_sd.dependent_service_description = dep_sname
self.add_item(new_sd) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'linkify_sd_by_s'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'hosts'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '7', 'type': 'block', 'children': ['8', '12', '18', '24', '234']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'to_del'}, {'id': '11', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'errors'}, {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'configuration_errors'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'warns'}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'configuration_warnings'}; {'id': '24', 'type': 'for_statement', 'children': ['25', '26', '27']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'servicedep'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'try_statement', 'children': ['29', '212']}, {'id': '29', 'type': 'block', 'children': ['30', '36', '42', '52', '113', '121', '127', '133', '143', '204']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 's_name'}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'servicedep'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'dependent_service_description'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'hst_name'}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'servicedep'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'dependent_host_name'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'serv'}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'find_srv_by_name_and_hostname'}, {'id': '49', 'type': 'argument_list', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'hst_name'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 's_name'}; {'id': '52', 'type': 'if_statement', 'children': ['53', '56']}, {'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': 'is'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'serv'}, {'id': '55', 'type': 'None', 'children': []}; {'id': '56', 'type': 'block', 'children': ['57', '66', '105', '112']}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '60', 'type': 'call', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'hosts'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'find_by_name'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'hst_name'}; {'id': '66', 'type': 'if_statement', 'children': ['67', '77', '89']}, {'id': '67', 'type': 'not_operator', 'children': ['68']}; {'id': '68', 'type': 'parenthesized_expression', 'children': ['69']}, {'id': '69', 'type': 'boolean_operator', 'children': ['70', '71'], 'value': 'and'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'host'}, {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'is_excluded_for_sdesc'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 's_name'}, {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'binary_operator', 'children': ['85', '86'], 'value': '%'}, {'id': '85', 'type': 'string', 'children': [], 'value': '"Service %s not found for host %s"'}; {'id': '86', 'type': 'tuple', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 's_name'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'hst_name'}, {'id': '89', 'type': 'elif_clause', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'host'}, {'id': '91', 'type': 'block', 'children': ['92']}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'warns'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'binary_operator', 'children': ['99', '102'], 'value': '%'}, {'id': '99', 'type': 'concatenated_string', 'children': ['100', '101']}; {'id': '100', 'type': 'string', 'children': [], 'value': '"Service %s is excluded from host %s ; "'}, {'id': '101', 'type': 'string', 'children': [], 'value': '"removing this servicedependency as it\'s unusuable."'}; {'id': '102', 'type': 'tuple', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 's_name'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'hst_name'}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'call', 'children': ['107', '110']}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'to_del'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'servicedep'}; {'id': '112', 'type': 'continue_statement', 'children': []}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '118']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'servicedep'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'dependent_service_description'}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'serv'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'uuid'}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 's_name'}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'servicedep'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'service_description'}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'assignment', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'hst_name'}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'servicedep'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'host_name'}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'serv'}; {'id': '136', 'type': 'call', 'children': ['137', '140']}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'find_srv_by_name_and_hostname'}; {'id': '140', 'type': 'argument_list', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'hst_name'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 's_name'}, {'id': '143', 'type': 'if_statement', 'children': ['144', '147']}; {'id': '144', 'type': 'comparison_operator', 'children': ['145', '146'], 'value': 'is'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'serv'}; {'id': '146', 'type': 'None', 'children': []}, {'id': '147', 'type': 'block', 'children': ['148', '157', '196', '203']}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'assignment', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'host'}, {'id': '151', 'type': 'call', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'hosts'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'find_by_name'}, {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'hst_name'}, {'id': '157', 'type': 'if_statement', 'children': ['158', '168', '180']}; {'id': '158', 'type': 'not_operator', 'children': ['159']}, {'id': '159', 'type': 'parenthesized_expression', 'children': ['160']}; {'id': '160', 'type': 'boolean_operator', 'children': ['161', '162'], 'value': 'and'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '162', 'type': 'call', 'children': ['163', '166']}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'host'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'is_excluded_for_sdesc'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 's_name'}; {'id': '168', 'type': 'block', 'children': ['169']}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'call', 'children': ['171', '174']}, {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'errors'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '174', 'type': 'argument_list', 'children': ['175']}, {'id': '175', 'type': 'binary_operator', 'children': ['176', '177'], 'value': '%'}; {'id': '176', 'type': 'string', 'children': [], 'value': '"Service %s not found for host %s"'}, {'id': '177', 'type': 'tuple', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 's_name'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'hst_name'}; {'id': '180', 'type': 'elif_clause', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '182', 'type': 'block', 'children': ['183']}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'call', 'children': ['185', '188']}, {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'warns'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '188', 'type': 'argument_list', 'children': ['189']}, {'id': '189', 'type': 'binary_operator', 'children': ['190', '193'], 'value': '%'}; {'id': '190', 'type': 'concatenated_string', 'children': ['191', '192']}, {'id': '191', 'type': 'string', 'children': [], 'value': '"Service %s is excluded from host %s ; "'}; {'id': '192', 'type': 'string', 'children': [], 'value': '"removing this servicedependency as it\'s unusuable."'}, {'id': '193', 'type': 'tuple', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 's_name'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'hst_name'}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'call', 'children': ['198', '201']}; {'id': '198', 'type': 'attribute', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'to_del'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '201', 'type': 'argument_list', 'children': ['202']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'servicedep'}, {'id': '203', 'type': 'continue_statement', 'children': []}; {'id': '204', 'type': 'expression_statement', 'children': ['205']}, {'id': '205', 'type': 'assignment', 'children': ['206', '209']}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'servicedep'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'service_description'}, {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'serv'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '212', 'type': 'except_clause', 'children': ['213', '217']}, {'id': '213', 'type': 'as_pattern', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}, {'id': '215', 'type': 'as_pattern_target', 'children': ['216']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'err'}, {'id': '217', 'type': 'block', 'children': ['218', '227']}; {'id': '218', 'type': 'expression_statement', 'children': ['219']}, {'id': '219', 'type': 'call', 'children': ['220', '223']}; {'id': '220', 'type': 'attribute', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '223', 'type': 'argument_list', 'children': ['224', '225', '226']}; {'id': '224', 'type': 'string', 'children': [], 'value': '"[servicedependency] fail to linkify by service %s: %s"'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'servicedep'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'err'}, {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'call', 'children': ['229', '232']}, {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'to_del'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '232', 'type': 'argument_list', 'children': ['233']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'servicedep'}; {'id': '234', 'type': 'for_statement', 'children': ['235', '236', '237']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'servicedep'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'to_del'}, {'id': '237', 'type': 'block', 'children': ['238']}; {'id': '238', 'type': 'expression_statement', 'children': ['239']}, {'id': '239', 'type': 'call', 'children': ['240', '243']}; {'id': '240', 'type': 'attribute', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'remove_item'}, {'id': '243', 'type': 'argument_list', 'children': ['244']} | def linkify_sd_by_s(self, hosts, services):
to_del = []
errors = self.configuration_errors
warns = self.configuration_warnings
for servicedep in self:
try:
s_name = servicedep.dependent_service_description
hst_name = servicedep.dependent_host_name
serv = services.find_srv_by_name_and_hostname(hst_name, s_name)
if serv is None:
host = hosts.find_by_name(hst_name)
if not (host and host.is_excluded_for_sdesc(s_name)):
errors.append("Service %s not found for host %s" % (s_name, hst_name))
elif host:
warns.append("Service %s is excluded from host %s ; "
"removing this servicedependency as it's unusuable."
% (s_name, hst_name))
to_del.append(servicedep)
continue
servicedep.dependent_service_description = serv.uuid
s_name = servicedep.service_description
hst_name = servicedep.host_name
serv = services.find_srv_by_name_and_hostname(hst_name, s_name)
if serv is None:
host = hosts.find_by_name(hst_name)
if not (host and host.is_excluded_for_sdesc(s_name)):
errors.append("Service %s not found for host %s" % (s_name, hst_name))
elif host:
warns.append("Service %s is excluded from host %s ; "
"removing this servicedependency as it's unusuable."
% (s_name, hst_name))
to_del.append(servicedep)
continue
servicedep.service_description = serv.uuid
except AttributeError as err:
logger.error("[servicedependency] fail to linkify by service %s: %s",
servicedep, err)
to_del.append(servicedep)
for servicedep in to_del:
self.remove_item(servicedep) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'init'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '21', '48', '291']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '11']}, {'id': '7', 'type': 'not_operator', 'children': ['8']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'enabled'}, {'id': '11', 'type': 'block', 'children': ['12', '19']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'string', 'children': [], 'value': '" the module is disabled."'}, {'id': '19', 'type': 'return_statement', 'children': ['20']}; {'id': '20', 'type': 'True', 'children': []}, {'id': '21', 'type': 'try_statement', 'children': ['22', '31']}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'connections'}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'test_connection'}; {'id': '30', 'type': 'argument_list', 'children': []}, {'id': '31', 'type': 'except_clause', 'children': ['32', '36']}; {'id': '32', 'type': 'as_pattern', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '34', 'type': 'as_pattern_target', 'children': ['35']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'exp'}; {'id': '36', 'type': 'block', 'children': ['37']}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '44']}, {'id': '43', 'type': 'string', 'children': [], 'value': '"initialization, test connection failed. Error: %s"'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'exp'}; {'id': '48', 'type': 'if_statement', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'influxdb_enabled'}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'try_statement', 'children': ['54', '274']}; {'id': '54', 'type': 'block', 'children': ['55', '65', '115', '197', '268']}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'dbs'}; {'id': '58', 'type': 'call', 'children': ['59', '64']}, {'id': '59', 'type': 'attribute', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'influx'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'get_list_database'}; {'id': '64', 'type': 'argument_list', 'children': []}, {'id': '65', 'type': 'for_statement', 'children': ['66', '67', '68', '92']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'db'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'dbs'}; {'id': '68', 'type': 'block', 'children': ['69']}, {'id': '69', 'type': 'if_statement', 'children': ['70', '80']}; {'id': '70', 'type': 'comparison_operator', 'children': ['71', '77'], 'value': '=='}, {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'string', 'children': [], 'value': "'name'"}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'influxdb_database'}; {'id': '80', 'type': 'block', 'children': ['81', '91']}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '86', 'type': 'argument_list', 'children': ['87', '88']}, {'id': '87', 'type': 'string', 'children': [], 'value': '"the database %s is existing."'}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'influxdb_database'}, {'id': '91', 'type': 'break_statement', 'children': []}; {'id': '92', 'type': 'else_clause', 'children': ['93']}, {'id': '93', 'type': 'block', 'children': ['94', '104']}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '99', 'type': 'argument_list', 'children': ['100', '101']}; {'id': '100', 'type': 'string', 'children': [], 'value': '"creating database %s..."'}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'influxdb_database'}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'call', 'children': ['106', '111']}; {'id': '106', 'type': 'attribute', 'children': ['107', '110']}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'influx'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'create_database'}, {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'influxdb_database'}, {'id': '115', 'type': 'if_statement', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'influxdb_retention_name'}, {'id': '119', 'type': 'block', 'children': ['120', '130']}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'assignment', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'rps'}, {'id': '123', 'type': 'call', 'children': ['124', '129']}; {'id': '124', 'type': 'attribute', 'children': ['125', '128']}, {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'influx'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'get_list_retention_policies'}, {'id': '129', 'type': 'argument_list', 'children': []}; {'id': '130', 'type': 'for_statement', 'children': ['131', '132', '133', '157']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'rp'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'rps'}, {'id': '133', 'type': 'block', 'children': ['134']}; {'id': '134', 'type': 'if_statement', 'children': ['135', '145']}, {'id': '135', 'type': 'comparison_operator', 'children': ['136', '142'], 'value': '=='}; {'id': '136', 'type': 'call', 'children': ['137', '140']}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'rp'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}, {'id': '141', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'influxdb_retention_name'}, {'id': '145', 'type': 'block', 'children': ['146', '156']}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'call', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '151', 'type': 'argument_list', 'children': ['152', '153']}; {'id': '152', 'type': 'string', 'children': [], 'value': '"the retention policy %s is existing."'}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'influxdb_retention_name'}; {'id': '156', 'type': 'break_statement', 'children': []}, {'id': '157', 'type': 'else_clause', 'children': ['158']}; {'id': '158', 'type': 'block', 'children': ['159', '175']}, {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'call', 'children': ['161', '164']}, {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '164', 'type': 'argument_list', 'children': ['165', '166', '169', '172']}, {'id': '165', 'type': 'string', 'children': [], 'value': '"creating database retention policy: %s - %s - %s..."'}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'influxdb_retention_name'}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'influxdb_retention_duration'}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'influxdb_retention_replication'}, {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'call', 'children': ['177', '182']}, {'id': '177', 'type': 'attribute', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'influx'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'create_retention_policy'}; {'id': '182', 'type': 'argument_list', 'children': ['183', '186', '189', '192']}, {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'influxdb_retention_name'}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'influxdb_retention_duration'}, {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'influxdb_retention_replication'}; {'id': '192', 'type': 'keyword_argument', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'database'}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'influxdb_database'}, {'id': '197', 'type': 'if_statement', 'children': ['198', '201']}; {'id': '198', 'type': 'attribute', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'influxdb_username'}, {'id': '201', 'type': 'block', 'children': ['202', '212']}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'assignment', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'users'}, {'id': '205', 'type': 'call', 'children': ['206', '211']}; {'id': '206', 'type': 'attribute', 'children': ['207', '210']}, {'id': '207', 'type': 'attribute', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'influx'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'get_list_users'}, {'id': '211', 'type': 'argument_list', 'children': []}; {'id': '212', 'type': 'for_statement', 'children': ['213', '214', '215', '239']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'users'}, {'id': '215', 'type': 'block', 'children': ['216']}; {'id': '216', 'type': 'if_statement', 'children': ['217', '227']}, {'id': '217', 'type': 'comparison_operator', 'children': ['218', '224'], 'value': '=='}; {'id': '218', 'type': 'call', 'children': ['219', '222']}, {'id': '219', 'type': 'attribute', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'user'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '222', 'type': 'argument_list', 'children': ['223']}, {'id': '223', 'type': 'string', 'children': [], 'value': "'user'"}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'influxdb_username'}, {'id': '227', 'type': 'block', 'children': ['228', '238']}; {'id': '228', 'type': 'expression_statement', 'children': ['229']}, {'id': '229', 'type': 'call', 'children': ['230', '233']}; {'id': '230', 'type': 'attribute', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '233', 'type': 'argument_list', 'children': ['234', '235']}; {'id': '234', 'type': 'string', 'children': [], 'value': '"the user %s is existing."'}, {'id': '235', 'type': 'attribute', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'influxdb_username'}; {'id': '238', 'type': 'break_statement', 'children': []}, {'id': '239', 'type': 'else_clause', 'children': ['240']}; {'id': '240', 'type': 'block', 'children': ['241', '251']}, {'id': '241', 'type': 'expression_statement', 'children': ['242']}; {'id': '242', 'type': 'call', 'children': ['243', '246']}, {'id': '243', 'type': 'attribute', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '246', 'type': 'argument_list', 'children': ['247', '248']}, {'id': '247', 'type': 'string', 'children': [], 'value': '"creating user: %s..."'}; {'id': '248', 'type': 'attribute', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'influxdb_username'}, {'id': '251', 'type': 'expression_statement', 'children': ['252']}; {'id': '252', 'type': 'call', 'children': ['253', '258']}, {'id': '253', 'type': 'attribute', 'children': ['254', '257']}; {'id': '254', 'type': 'attribute', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'influx'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'create_user'}; {'id': '258', 'type': 'argument_list', 'children': ['259', '262', '265']}, {'id': '259', 'type': 'attribute', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'influxdb_username'}; {'id': '262', 'type': 'attribute', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'influxdb_password'}, {'id': '265', 'type': 'keyword_argument', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'admin'}, {'id': '267', 'type': 'False', 'children': []}; {'id': '268', 'type': 'expression_statement', 'children': ['269']}, {'id': '269', 'type': 'assignment', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'connections'}, {'id': '271', 'type': 'boolean_operator', 'children': ['272', '273'], 'value': 'or'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'connections'}, {'id': '273', 'type': 'True', 'children': []}; {'id': '274', 'type': 'except_clause', 'children': ['275', '279']}, {'id': '275', 'type': 'as_pattern', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '277', 'type': 'as_pattern_target', 'children': ['278']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'exp'}, {'id': '279', 'type': 'block', 'children': ['280']}; {'id': '280', 'type': 'expression_statement', 'children': ['281']}, {'id': '281', 'type': 'call', 'children': ['282', '285']}; {'id': '282', 'type': 'attribute', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '285', 'type': 'argument_list', 'children': ['286', '287']}; {'id': '286', 'type': 'string', 'children': [], 'value': '"InfluxDB, DB initialization failed. Error: %s"'}, {'id': '287', 'type': 'call', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '289', 'type': 'argument_list', 'children': ['290']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'exp'}, {'id': '291', 'type': 'return_statement', 'children': ['292']} | def init(self):
if not self.enabled:
logger.info(" the module is disabled.")
return True
try:
connections = self.test_connection()
except Exception as exp:
logger.error("initialization, test connection failed. Error: %s", str(exp))
if self.influxdb_enabled:
try:
dbs = self.influx.get_list_database()
for db in dbs:
if db.get('name') == self.influxdb_database:
logger.info("the database %s is existing.", self.influxdb_database)
break
else:
logger.info("creating database %s...", self.influxdb_database)
self.influx.create_database(self.influxdb_database)
if self.influxdb_retention_name:
rps = self.influx.get_list_retention_policies()
for rp in rps:
if rp.get('name') == self.influxdb_retention_name:
logger.info("the retention policy %s is existing.",
self.influxdb_retention_name)
break
else:
logger.info("creating database retention policy: %s - %s - %s...",
self.influxdb_retention_name, self.influxdb_retention_duration,
self.influxdb_retention_replication)
self.influx.create_retention_policy(
self.influxdb_retention_name, self.influxdb_retention_duration,
self.influxdb_retention_replication, database=self.influxdb_database)
if self.influxdb_username:
users = self.influx.get_list_users()
for user in users:
if user.get('user') == self.influxdb_username:
logger.info("the user %s is existing.",
self.influxdb_username)
break
else:
logger.info("creating user: %s...", self.influxdb_username)
self.influx.create_user(self.influxdb_username, self.influxdb_password,
admin=False)
connections = connections or True
except Exception as exp:
logger.error("InfluxDB, DB initialization failed. Error: %s", str(exp))
return connections |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_metrics_from_perfdata'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'perf_data'}, {'id': '7', 'type': 'block', 'children': ['8', '12', '19', '189', '198']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '11', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'metrics'}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'PerfDatas'}, {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'perf_data'}, {'id': '19', 'type': 'for_statement', 'children': ['20', '21', '22']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'metric'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'metrics'}; {'id': '22', 'type': 'block', 'children': ['23', '35', '49', '58', '70', '75', '91', '110', '129', '148', '167']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30', '31', '32']}, {'id': '29', 'type': 'string', 'children': [], 'value': '"service: %s, metric: %s (%s)"'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'metric'}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'metric'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': '__dict__'}, {'id': '35', 'type': 'if_statement', 'children': ['36', '42']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '40'], 'value': 'in'}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'metric'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '40', 'type': 'list', 'children': ['41'], 'value': "['time']"}, {'id': '41', 'type': 'string', 'children': [], 'value': "'time'"}; {'id': '42', 'type': 'block', 'children': ['43']}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'metric'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '48', 'type': 'string', 'children': [], 'value': '"duration"'}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'sanitize_name'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'metric'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '61', 'type': 'call', 'children': ['62', '67']}; {'id': '62', 'type': 'attribute', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'multiple_values'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'sub'}, {'id': '67', 'type': 'argument_list', 'children': ['68', '69']}; {'id': '68', 'type': 'string', 'children': [], 'value': "r'.\\1'"}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '70', 'type': 'if_statement', 'children': ['71', '73']}, {'id': '71', 'type': 'not_operator', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'continue_statement', 'children': []}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'name_value'}; {'id': '78', 'type': 'dictionary', 'children': ['79', '84']}, {'id': '79', 'type': 'pair', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'metric'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '84', 'type': 'pair', 'children': ['85', '88']}, {'id': '85', 'type': 'binary_operator', 'children': ['86', '87'], 'value': '+'}; {'id': '86', 'type': 'string', 'children': [], 'value': "'uom_'"}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'metric'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'uom'}, {'id': '91', 'type': 'if_statement', 'children': ['92', '99']}; {'id': '92', 'type': 'boolean_operator', 'children': ['93', '96'], 'value': 'and'}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'metric'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'send_warning'}, {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '107']}; {'id': '102', 'type': 'subscript', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'name_value'}; {'id': '104', 'type': 'binary_operator', 'children': ['105', '106'], 'value': '+'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '106', 'type': 'string', 'children': [], 'value': "'_warn'"}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'metric'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '110', 'type': 'if_statement', 'children': ['111', '118']}, {'id': '111', 'type': 'boolean_operator', 'children': ['112', '115'], 'value': 'and'}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'metric'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'critical'}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'send_critical'}; {'id': '118', 'type': 'block', 'children': ['119']}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '126']}, {'id': '121', 'type': 'subscript', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'name_value'}, {'id': '123', 'type': 'binary_operator', 'children': ['124', '125'], 'value': '+'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '125', 'type': 'string', 'children': [], 'value': "'_crit'"}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'metric'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'critical'}, {'id': '129', 'type': 'if_statement', 'children': ['130', '137']}; {'id': '130', 'type': 'boolean_operator', 'children': ['131', '134'], 'value': 'and'}, {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'metric'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'send_min'}, {'id': '137', 'type': 'block', 'children': ['138']}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'assignment', 'children': ['140', '145']}; {'id': '140', 'type': 'subscript', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'name_value'}; {'id': '142', 'type': 'binary_operator', 'children': ['143', '144'], 'value': '+'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '144', 'type': 'string', 'children': [], 'value': "'_min'"}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'metric'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '148', 'type': 'if_statement', 'children': ['149', '156']}, {'id': '149', 'type': 'boolean_operator', 'children': ['150', '153'], 'value': 'and'}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'metric'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'send_max'}; {'id': '156', 'type': 'block', 'children': ['157']}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '164']}, {'id': '159', 'type': 'subscript', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'name_value'}, {'id': '161', 'type': 'binary_operator', 'children': ['162', '163'], 'value': '+'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '163', 'type': 'string', 'children': [], 'value': "'_max'"}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'metric'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '167', 'type': 'for_statement', 'children': ['168', '171', '176']}; {'id': '168', 'type': 'pattern_list', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '171', 'type': 'call', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'name_value'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '175', 'type': 'argument_list', 'children': []}; {'id': '176', 'type': 'block', 'children': ['177']}, {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'call', 'children': ['179', '182']}, {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '182', 'type': 'argument_list', 'children': ['183']}, {'id': '183', 'type': 'tuple', 'children': ['184', '185', '186']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'metric'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'uom'}, {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'call', 'children': ['191', '194']}, {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '194', 'type': 'argument_list', 'children': ['195', '196', '197']}, {'id': '195', 'type': 'string', 'children': [], 'value': '"Metrics: %s - %s"'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '198', 'type': 'return_statement', 'children': ['199']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'result'} | def get_metrics_from_perfdata(self, service, perf_data):
result = []
metrics = PerfDatas(perf_data)
for metric in metrics:
logger.debug("service: %s, metric: %s (%s)", service, metric, metric.__dict__)
if metric.name in ['time']:
metric.name = "duration"
name = sanitize_name(metric.name)
name = self.multiple_values.sub(r'.\1', name)
if not name:
continue
name_value = {
name: metric.value,
'uom_' + name: metric.uom
}
if metric.warning and self.send_warning:
name_value[name + '_warn'] = metric.warning
if metric.critical and self.send_critical:
name_value[name + '_crit'] = metric.critical
if metric.min and self.send_min:
name_value[name + '_min'] = metric.min
if metric.max and self.send_max:
name_value[name + '_max'] = metric.max
for key, value in name_value.items():
result.append((key, value, metric.uom))
logger.debug("Metrics: %s - %s", service, result)
return result |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'manage_service_check_result_brok'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '6', 'type': 'block', 'children': ['7', '19', '31', '39', '47', '55', '76', '97', '111', '123', '168', '175', '248', '255', '296', '328', '365', '369', '390']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'host_name'}; {'id': '10', 'type': 'call', 'children': ['11', '16']}, {'id': '11', 'type': 'attribute', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18']}, {'id': '17', 'type': 'string', 'children': [], 'value': "'host_name'"}; {'id': '18', 'type': 'None', 'children': []}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'service_description'}; {'id': '22', 'type': 'call', 'children': ['23', '28']}, {'id': '23', 'type': 'attribute', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30']}, {'id': '29', 'type': 'string', 'children': [], 'value': "'service_description'"}; {'id': '30', 'type': 'None', 'children': []}, {'id': '31', 'type': 'if_statement', 'children': ['32', '37']}; {'id': '32', 'type': 'boolean_operator', 'children': ['33', '35'], 'value': 'or'}, {'id': '33', 'type': 'not_operator', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'host_name'}, {'id': '35', 'type': 'not_operator', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'service_description'}, {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'return_statement', 'children': []}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'service_id'}; {'id': '42', 'type': 'binary_operator', 'children': ['43', '46'], 'value': '+'}, {'id': '43', 'type': 'binary_operator', 'children': ['44', '45'], 'value': '+'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'host_name'}, {'id': '45', 'type': 'string', 'children': [], 'value': '"/"'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'service_description'}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '54']}, {'id': '53', 'type': 'string', 'children': [], 'value': '"service check result: %s"'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'service_id'}, {'id': '55', 'type': 'if_statement', 'children': ['56', '66']}; {'id': '56', 'type': 'boolean_operator', 'children': ['57', '61'], 'value': 'and'}, {'id': '57', 'type': 'not_operator', 'children': ['58']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'ignore_unknown'}, {'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': 'not'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'host_name'}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'hosts_cache'}; {'id': '66', 'type': 'block', 'children': ['67', '75']}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '72']}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '72', 'type': 'argument_list', 'children': ['73', '74']}, {'id': '73', 'type': 'string', 'children': [], 'value': '"received service check result for an unknown host: %s"'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'service_id'}, {'id': '75', 'type': 'return_statement', 'children': []}; {'id': '76', 'type': 'if_statement', 'children': ['77', '87']}, {'id': '77', 'type': 'boolean_operator', 'children': ['78', '83'], 'value': 'and'}; {'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': 'not'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'service_id'}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'services_cache'}, {'id': '83', 'type': 'not_operator', 'children': ['84']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'ignore_unknown'}, {'id': '87', 'type': 'block', 'children': ['88', '96']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '93', 'type': 'argument_list', 'children': ['94', '95']}; {'id': '94', 'type': 'string', 'children': [], 'value': '"received service check result for an unknown service: %s"'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'service_id'}; {'id': '96', 'type': 'return_statement', 'children': []}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'metrics'}; {'id': '100', 'type': 'call', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'get_metrics_from_perfdata'}; {'id': '104', 'type': 'argument_list', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'service_description'}; {'id': '106', 'type': 'subscript', 'children': ['107', '110']}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '110', 'type': 'string', 'children': [], 'value': "'perf_data'"}, {'id': '111', 'type': 'if_statement', 'children': ['112', '114']}; {'id': '112', 'type': 'not_operator', 'children': ['113']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'metrics'}; {'id': '114', 'type': 'block', 'children': ['115', '122']}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'call', 'children': ['117', '120']}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}, {'id': '121', 'type': 'string', 'children': [], 'value': '"no metrics to send ..."'}; {'id': '122', 'type': 'return_statement', 'children': []}, {'id': '123', 'type': 'if_statement', 'children': ['124', '134', '155']}; {'id': '124', 'type': 'comparison_operator', 'children': ['125', '128', '133'], 'value': '>='}, {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'ignore_latency_limit'}; {'id': '128', 'type': 'subscript', 'children': ['129', '132']}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '132', 'type': 'string', 'children': [], 'value': "'latency'"}, {'id': '133', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '134', 'type': 'block', 'children': ['135']}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'check_time'}; {'id': '138', 'type': 'binary_operator', 'children': ['139', '147'], 'value': '-'}, {'id': '139', 'type': 'call', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'subscript', 'children': ['143', '146']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '146', 'type': 'string', 'children': [], 'value': "'last_chk'"}, {'id': '147', 'type': 'call', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'subscript', 'children': ['151', '154']}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '154', 'type': 'string', 'children': [], 'value': "'latency'"}, {'id': '155', 'type': 'else_clause', 'children': ['156']}; {'id': '156', 'type': 'block', 'children': ['157']}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'check_time'}; {'id': '160', 'type': 'call', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}, {'id': '163', 'type': 'subscript', 'children': ['164', '167']}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '167', 'type': 'string', 'children': [], 'value': "'last_chk'"}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'assignment', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'hname'}, {'id': '171', 'type': 'call', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'sanitize_name'}, {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'host_name'}, {'id': '175', 'type': 'if_statement', 'children': ['176', '181']}; {'id': '176', 'type': 'comparison_operator', 'children': ['177', '178'], 'value': 'in'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'host_name'}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'hosts_cache'}, {'id': '181', 'type': 'block', 'children': ['182', '215']}; {'id': '182', 'type': 'if_statement', 'children': ['183', '194']}, {'id': '183', 'type': 'call', 'children': ['184', '191']}; {'id': '184', 'type': 'attribute', 'children': ['185', '190']}, {'id': '185', 'type': 'subscript', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'hosts_cache'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'host_name'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '191', 'type': 'argument_list', 'children': ['192', '193']}; {'id': '192', 'type': 'string', 'children': [], 'value': "'_GRAPHITE_GROUP'"}, {'id': '193', 'type': 'None', 'children': []}; {'id': '194', 'type': 'block', 'children': ['195']}, {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'assignment', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'hname'}; {'id': '198', 'type': 'call', 'children': ['199', '202']}, {'id': '199', 'type': 'attribute', 'children': ['200', '201']}; {'id': '200', 'type': 'string', 'children': [], 'value': '"."'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '202', 'type': 'argument_list', 'children': ['203']}, {'id': '203', 'type': 'tuple', 'children': ['204', '214']}; {'id': '204', 'type': 'call', 'children': ['205', '212']}, {'id': '205', 'type': 'attribute', 'children': ['206', '211']}; {'id': '206', 'type': 'subscript', 'children': ['207', '210']}, {'id': '207', 'type': 'attribute', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'hosts_cache'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'host_name'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '212', 'type': 'argument_list', 'children': ['213']}, {'id': '213', 'type': 'string', 'children': [], 'value': "'_GRAPHITE_GROUP'"}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'hname'}, {'id': '215', 'type': 'if_statement', 'children': ['216', '227']}; {'id': '216', 'type': 'call', 'children': ['217', '224']}, {'id': '217', 'type': 'attribute', 'children': ['218', '223']}; {'id': '218', 'type': 'subscript', 'children': ['219', '222']}, {'id': '219', 'type': 'attribute', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'hosts_cache'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'host_name'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '224', 'type': 'argument_list', 'children': ['225', '226']}, {'id': '225', 'type': 'string', 'children': [], 'value': "'_GRAPHITE_PRE'"}; {'id': '226', 'type': 'None', 'children': []}, {'id': '227', 'type': 'block', 'children': ['228']}; {'id': '228', 'type': 'expression_statement', 'children': ['229']}, {'id': '229', 'type': 'assignment', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'hname'}, {'id': '231', 'type': 'call', 'children': ['232', '235']}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}, {'id': '233', 'type': 'string', 'children': [], 'value': '"."'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '235', 'type': 'argument_list', 'children': ['236']}; {'id': '236', 'type': 'tuple', 'children': ['237', '247']}, {'id': '237', 'type': 'call', 'children': ['238', '245']}; {'id': '238', 'type': 'attribute', 'children': ['239', '244']}, {'id': '239', 'type': 'subscript', 'children': ['240', '243']}; {'id': '240', 'type': 'attribute', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'hosts_cache'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'host_name'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '245', 'type': 'argument_list', 'children': ['246']}; {'id': '246', 'type': 'string', 'children': [], 'value': "'_GRAPHITE_PRE'"}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'hname'}; {'id': '248', 'type': 'expression_statement', 'children': ['249']}, {'id': '249', 'type': 'assignment', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'desc'}, {'id': '251', 'type': 'call', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'sanitize_name'}, {'id': '253', 'type': 'argument_list', 'children': ['254']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'service_description'}, {'id': '255', 'type': 'if_statement', 'children': ['256', '261']}; {'id': '256', 'type': 'comparison_operator', 'children': ['257', '258'], 'value': 'in'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'service_id'}; {'id': '258', 'type': 'attribute', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'services_cache'}, {'id': '261', 'type': 'block', 'children': ['262']}; {'id': '262', 'type': 'if_statement', 'children': ['263', '274']}, {'id': '263', 'type': 'call', 'children': ['264', '271']}; {'id': '264', 'type': 'attribute', 'children': ['265', '270']}, {'id': '265', 'type': 'subscript', 'children': ['266', '269']}; {'id': '266', 'type': 'attribute', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'services_cache'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'service_id'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '271', 'type': 'argument_list', 'children': ['272', '273']}; {'id': '272', 'type': 'string', 'children': [], 'value': "'_GRAPHITE_POST'"}, {'id': '273', 'type': 'None', 'children': []}; {'id': '274', 'type': 'block', 'children': ['275']}, {'id': '275', 'type': 'expression_statement', 'children': ['276']}; {'id': '276', 'type': 'assignment', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'desc'}; {'id': '278', 'type': 'call', 'children': ['279', '282']}, {'id': '279', 'type': 'attribute', 'children': ['280', '281']}; {'id': '280', 'type': 'string', 'children': [], 'value': '"."'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '282', 'type': 'argument_list', 'children': ['283']}, {'id': '283', 'type': 'tuple', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'desc'}, {'id': '285', 'type': 'call', 'children': ['286', '293']}; {'id': '286', 'type': 'attribute', 'children': ['287', '292']}, {'id': '287', 'type': 'subscript', 'children': ['288', '291']}; {'id': '288', 'type': 'attribute', 'children': ['289', '290']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'services_cache'}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'service_id'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '293', 'type': 'argument_list', 'children': ['294', '295']}; {'id': '294', 'type': 'string', 'children': [], 'value': "'_GRAPHITE_POST'"}, {'id': '295', 'type': 'None', 'children': []}; {'id': '296', 'type': 'if_statement', 'children': ['297', '300', '315']}, {'id': '297', 'type': 'attribute', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'graphite_data_source'}; {'id': '300', 'type': 'block', 'children': ['301']}, {'id': '301', 'type': 'expression_statement', 'children': ['302']}; {'id': '302', 'type': 'assignment', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '304', 'type': 'call', 'children': ['305', '308']}, {'id': '305', 'type': 'attribute', 'children': ['306', '307']}; {'id': '306', 'type': 'string', 'children': [], 'value': "'.'"}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '308', 'type': 'argument_list', 'children': ['309']}, {'id': '309', 'type': 'tuple', 'children': ['310', '311', '314']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'hname'}, {'id': '311', 'type': 'attribute', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'graphite_data_source'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'desc'}, {'id': '315', 'type': 'else_clause', 'children': ['316']}; {'id': '316', 'type': 'block', 'children': ['317']}, {'id': '317', 'type': 'expression_statement', 'children': ['318']}; {'id': '318', 'type': 'assignment', 'children': ['319', '320']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '320', 'type': 'call', 'children': ['321', '324']}, {'id': '321', 'type': 'attribute', 'children': ['322', '323']}; {'id': '322', 'type': 'string', 'children': [], 'value': "'.'"}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '324', 'type': 'argument_list', 'children': ['325']}, {'id': '325', 'type': 'tuple', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'hname'}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'desc'}; {'id': '328', 'type': 'if_statement', 'children': ['329', '344']}, {'id': '329', 'type': 'boolean_operator', 'children': ['330', '333'], 'value': 'and'}; {'id': '330', 'type': 'attribute', 'children': ['331', '332']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'realms_prefix'}, {'id': '333', 'type': 'call', 'children': ['334', '341']}; {'id': '334', 'type': 'attribute', 'children': ['335', '340']}, {'id': '335', 'type': 'subscript', 'children': ['336', '339']}; {'id': '336', 'type': 'attribute', 'children': ['337', '338']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'hosts_cache'}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'host_name'}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '341', 'type': 'argument_list', 'children': ['342', '343']}; {'id': '342', 'type': 'string', 'children': [], 'value': "'realm_name'"}, {'id': '343', 'type': 'None', 'children': []}; {'id': '344', 'type': 'block', 'children': ['345']}, {'id': '345', 'type': 'expression_statement', 'children': ['346']}; {'id': '346', 'type': 'assignment', 'children': ['347', '348']}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '348', 'type': 'call', 'children': ['349', '352']}, {'id': '349', 'type': 'attribute', 'children': ['350', '351']}; {'id': '350', 'type': 'string', 'children': [], 'value': "'.'"}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '352', 'type': 'argument_list', 'children': ['353']}, {'id': '353', 'type': 'tuple', 'children': ['354', '364']}; {'id': '354', 'type': 'call', 'children': ['355', '362']}, {'id': '355', 'type': 'attribute', 'children': ['356', '361']}; {'id': '356', 'type': 'subscript', 'children': ['357', '360']}, {'id': '357', 'type': 'attribute', 'children': ['358', '359']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'hosts_cache'}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'host_name'}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '362', 'type': 'argument_list', 'children': ['363']}, {'id': '363', 'type': 'string', 'children': [], 'value': "'realm_name'"}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '365', 'type': 'expression_statement', 'children': ['366']}; {'id': '366', 'type': 'assignment', 'children': ['367', '368']}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'realm_name'}; {'id': '368', 'type': 'None', 'children': []}, {'id': '369', 'type': 'if_statement', 'children': ['370', '375']}; {'id': '370', 'type': 'comparison_operator', 'children': ['371', '372'], 'value': 'in'}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'host_name'}; {'id': '372', 'type': 'attribute', 'children': ['373', '374']}, {'id': '373', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'hosts_cache'}, {'id': '375', 'type': 'block', 'children': ['376']}; {'id': '376', 'type': 'expression_statement', 'children': ['377']}, {'id': '377', 'type': 'assignment', 'children': ['378', '379']}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'realm_name'}, {'id': '379', 'type': 'call', 'children': ['380', '387']}; {'id': '380', 'type': 'attribute', 'children': ['381', '386']}, {'id': '381', 'type': 'subscript', 'children': ['382', '385']}; {'id': '382', 'type': 'attribute', 'children': ['383', '384']}, {'id': '383', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'hosts_cache'}, {'id': '385', 'type': 'identifier', 'children': [], 'value': 'host_name'}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '387', 'type': 'argument_list', 'children': ['388', '389']}; {'id': '388', 'type': 'string', 'children': [], 'value': "'realm_name'"}, {'id': '389', 'type': 'None', 'children': []}; {'id': '390', 'type': 'expression_statement', 'children': ['391']}, {'id': '391', 'type': 'call', 'children': ['392', '395']}; {'id': '392', 'type': 'attribute', 'children': ['393', '394']}, {'id': '393', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '394', 'type': 'identifier', 'children': [], 'value': 'send_to_tsdb'}, {'id': '395', 'type': 'argument_list', 'children': ['396', '397', '398', '399', '400', '401']}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'realm_name'}, {'id': '397', 'type': 'identifier', 'children': [], 'value': 'host_name'}; {'id': '398', 'type': 'identifier', 'children': [], 'value': 'service_description'}, {'id': '399', 'type': 'identifier', 'children': [], 'value': 'metrics'}; {'id': '400', 'type': 'identifier', 'children': [], 'value': 'check_time'}, {'id': '401', 'type': 'identifier', 'children': [], 'value': 'path'} | def manage_service_check_result_brok(self, b):
host_name = b.data.get('host_name', None)
service_description = b.data.get('service_description', None)
if not host_name or not service_description:
return
service_id = host_name+"/"+service_description
logger.debug("service check result: %s", service_id)
if not self.ignore_unknown and host_name not in self.hosts_cache:
logger.warning("received service check result for an unknown host: %s", service_id)
return
if service_id not in self.services_cache and not self.ignore_unknown:
logger.warning("received service check result for an unknown service: %s", service_id)
return
metrics = self.get_metrics_from_perfdata(service_description, b.data['perf_data'])
if not metrics:
logger.debug("no metrics to send ...")
return
if self.ignore_latency_limit >= b.data['latency'] > 0:
check_time = int(b.data['last_chk']) - int(b.data['latency'])
else:
check_time = int(b.data['last_chk'])
hname = sanitize_name(host_name)
if host_name in self.hosts_cache:
if self.hosts_cache[host_name].get('_GRAPHITE_GROUP', None):
hname = ".".join((self.hosts_cache[host_name].get('_GRAPHITE_GROUP'), hname))
if self.hosts_cache[host_name].get('_GRAPHITE_PRE', None):
hname = ".".join((self.hosts_cache[host_name].get('_GRAPHITE_PRE'), hname))
desc = sanitize_name(service_description)
if service_id in self.services_cache:
if self.services_cache[service_id].get('_GRAPHITE_POST', None):
desc = ".".join((desc, self.services_cache[service_id].get('_GRAPHITE_POST', None)))
if self.graphite_data_source:
path = '.'.join((hname, self.graphite_data_source, desc))
else:
path = '.'.join((hname, desc))
if self.realms_prefix and self.hosts_cache[host_name].get('realm_name', None):
path = '.'.join((self.hosts_cache[host_name].get('realm_name'), path))
realm_name = None
if host_name in self.hosts_cache:
realm_name = self.hosts_cache[host_name].get('realm_name', None)
self.send_to_tsdb(realm_name, host_name, service_description, metrics, check_time, path) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'manage_host_check_result_brok'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '6', 'type': 'block', 'children': ['7', '19', '24', '32', '53', '67', '79', '124', '131', '204', '258', '295', '299', '320']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'host_name'}; {'id': '10', 'type': 'call', 'children': ['11', '16']}, {'id': '11', 'type': 'attribute', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18']}, {'id': '17', 'type': 'string', 'children': [], 'value': "'host_name'"}; {'id': '18', 'type': 'None', 'children': []}, {'id': '19', 'type': 'if_statement', 'children': ['20', '22']}; {'id': '20', 'type': 'not_operator', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'host_name'}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'return_statement', 'children': []}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '29', 'type': 'argument_list', 'children': ['30', '31']}; {'id': '30', 'type': 'string', 'children': [], 'value': '"host check result: %s"'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'host_name'}; {'id': '32', 'type': 'if_statement', 'children': ['33', '43']}, {'id': '33', 'type': 'boolean_operator', 'children': ['34', '39'], 'value': 'and'}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'not'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'host_name'}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'hosts_cache'}, {'id': '39', 'type': 'not_operator', 'children': ['40']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'ignore_unknown'}, {'id': '43', 'type': 'block', 'children': ['44', '52']}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '49', 'type': 'argument_list', 'children': ['50', '51']}; {'id': '50', 'type': 'string', 'children': [], 'value': '"received host check result for an unknown host: %s"'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'host_name'}; {'id': '52', 'type': 'return_statement', 'children': []}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'metrics'}; {'id': '56', 'type': 'call', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'get_metrics_from_perfdata'}; {'id': '60', 'type': 'argument_list', 'children': ['61', '62']}, {'id': '61', 'type': 'string', 'children': [], 'value': "'host_check'"}; {'id': '62', 'type': 'subscript', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '66', 'type': 'string', 'children': [], 'value': "'perf_data'"}, {'id': '67', 'type': 'if_statement', 'children': ['68', '70']}; {'id': '68', 'type': 'not_operator', 'children': ['69']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'metrics'}; {'id': '70', 'type': 'block', 'children': ['71', '78']}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'string', 'children': [], 'value': '"no metrics to send ..."'}; {'id': '78', 'type': 'return_statement', 'children': []}, {'id': '79', 'type': 'if_statement', 'children': ['80', '90', '111']}; {'id': '80', 'type': 'comparison_operator', 'children': ['81', '84', '89'], 'value': '>='}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'ignore_latency_limit'}; {'id': '84', 'type': 'subscript', 'children': ['85', '88']}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '88', 'type': 'string', 'children': [], 'value': "'latency'"}, {'id': '89', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '90', 'type': 'block', 'children': ['91']}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'check_time'}; {'id': '94', 'type': 'binary_operator', 'children': ['95', '103'], 'value': '-'}, {'id': '95', 'type': 'call', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'subscript', 'children': ['99', '102']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '102', 'type': 'string', 'children': [], 'value': "'last_chk'"}, {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'subscript', 'children': ['107', '110']}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '110', 'type': 'string', 'children': [], 'value': "'latency'"}, {'id': '111', 'type': 'else_clause', 'children': ['112']}; {'id': '112', 'type': 'block', 'children': ['113']}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'check_time'}; {'id': '116', 'type': 'call', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}, {'id': '119', 'type': 'subscript', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '123', 'type': 'string', 'children': [], 'value': "'last_chk'"}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'hname'}, {'id': '127', 'type': 'call', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'sanitize_name'}, {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'host_name'}, {'id': '131', 'type': 'if_statement', 'children': ['132', '137']}; {'id': '132', 'type': 'comparison_operator', 'children': ['133', '134'], 'value': 'in'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'host_name'}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'hosts_cache'}, {'id': '137', 'type': 'block', 'children': ['138', '171']}; {'id': '138', 'type': 'if_statement', 'children': ['139', '150']}, {'id': '139', 'type': 'call', 'children': ['140', '147']}; {'id': '140', 'type': 'attribute', 'children': ['141', '146']}, {'id': '141', 'type': 'subscript', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'hosts_cache'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'host_name'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '147', 'type': 'argument_list', 'children': ['148', '149']}; {'id': '148', 'type': 'string', 'children': [], 'value': "'_GRAPHITE_GROUP'"}, {'id': '149', 'type': 'None', 'children': []}; {'id': '150', 'type': 'block', 'children': ['151']}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'assignment', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'hname'}; {'id': '154', 'type': 'call', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'string', 'children': [], 'value': '"."'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '158', 'type': 'argument_list', 'children': ['159']}, {'id': '159', 'type': 'tuple', 'children': ['160', '170']}; {'id': '160', 'type': 'call', 'children': ['161', '168']}, {'id': '161', 'type': 'attribute', 'children': ['162', '167']}; {'id': '162', 'type': 'subscript', 'children': ['163', '166']}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'hosts_cache'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'host_name'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '168', 'type': 'argument_list', 'children': ['169']}, {'id': '169', 'type': 'string', 'children': [], 'value': "'_GRAPHITE_GROUP'"}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'hname'}, {'id': '171', 'type': 'if_statement', 'children': ['172', '183']}; {'id': '172', 'type': 'call', 'children': ['173', '180']}, {'id': '173', 'type': 'attribute', 'children': ['174', '179']}; {'id': '174', 'type': 'subscript', 'children': ['175', '178']}, {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'hosts_cache'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'host_name'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '180', 'type': 'argument_list', 'children': ['181', '182']}, {'id': '181', 'type': 'string', 'children': [], 'value': "'_GRAPHITE_PRE'"}; {'id': '182', 'type': 'None', 'children': []}, {'id': '183', 'type': 'block', 'children': ['184']}; {'id': '184', 'type': 'expression_statement', 'children': ['185']}, {'id': '185', 'type': 'assignment', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'hname'}, {'id': '187', 'type': 'call', 'children': ['188', '191']}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}, {'id': '189', 'type': 'string', 'children': [], 'value': '"."'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '191', 'type': 'argument_list', 'children': ['192']}; {'id': '192', 'type': 'tuple', 'children': ['193', '203']}, {'id': '193', 'type': 'call', 'children': ['194', '201']}; {'id': '194', 'type': 'attribute', 'children': ['195', '200']}, {'id': '195', 'type': 'subscript', 'children': ['196', '199']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'hosts_cache'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'host_name'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '201', 'type': 'argument_list', 'children': ['202']}; {'id': '202', 'type': 'string', 'children': [], 'value': "'_GRAPHITE_PRE'"}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'hname'}; {'id': '204', 'type': 'if_statement', 'children': ['205', '208', '243']}, {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'graphite_data_source'}; {'id': '208', 'type': 'block', 'children': ['209', '222']}, {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'assignment', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '212', 'type': 'call', 'children': ['213', '216']}, {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'string', 'children': [], 'value': "'.'"}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '216', 'type': 'argument_list', 'children': ['217']}, {'id': '217', 'type': 'tuple', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'hname'}, {'id': '219', 'type': 'attribute', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'graphite_data_source'}; {'id': '222', 'type': 'if_statement', 'children': ['223', '226']}, {'id': '223', 'type': 'attribute', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'hostcheck'}; {'id': '226', 'type': 'block', 'children': ['227']}, {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'assignment', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '230', 'type': 'call', 'children': ['231', '234']}, {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'string', 'children': [], 'value': "'.'"}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '234', 'type': 'argument_list', 'children': ['235']}, {'id': '235', 'type': 'tuple', 'children': ['236', '237', '240']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'hname'}, {'id': '237', 'type': 'attribute', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'graphite_data_source'}; {'id': '240', 'type': 'attribute', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'hostcheck'}, {'id': '243', 'type': 'else_clause', 'children': ['244']}; {'id': '244', 'type': 'block', 'children': ['245']}, {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'assignment', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '248', 'type': 'call', 'children': ['249', '252']}, {'id': '249', 'type': 'attribute', 'children': ['250', '251']}; {'id': '250', 'type': 'string', 'children': [], 'value': "'.'"}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '252', 'type': 'argument_list', 'children': ['253']}, {'id': '253', 'type': 'tuple', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'hname'}, {'id': '255', 'type': 'attribute', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'hostcheck'}; {'id': '258', 'type': 'if_statement', 'children': ['259', '274']}, {'id': '259', 'type': 'boolean_operator', 'children': ['260', '263'], 'value': 'and'}; {'id': '260', 'type': 'attribute', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'realms_prefix'}, {'id': '263', 'type': 'call', 'children': ['264', '271']}; {'id': '264', 'type': 'attribute', 'children': ['265', '270']}, {'id': '265', 'type': 'subscript', 'children': ['266', '269']}; {'id': '266', 'type': 'attribute', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'hosts_cache'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'host_name'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '271', 'type': 'argument_list', 'children': ['272', '273']}; {'id': '272', 'type': 'string', 'children': [], 'value': "'realm_name'"}, {'id': '273', 'type': 'None', 'children': []}; {'id': '274', 'type': 'block', 'children': ['275']}, {'id': '275', 'type': 'expression_statement', 'children': ['276']}; {'id': '276', 'type': 'assignment', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '278', 'type': 'call', 'children': ['279', '282']}, {'id': '279', 'type': 'attribute', 'children': ['280', '281']}; {'id': '280', 'type': 'string', 'children': [], 'value': "'.'"}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '282', 'type': 'argument_list', 'children': ['283']}, {'id': '283', 'type': 'tuple', 'children': ['284', '294']}; {'id': '284', 'type': 'call', 'children': ['285', '292']}, {'id': '285', 'type': 'attribute', 'children': ['286', '291']}; {'id': '286', 'type': 'subscript', 'children': ['287', '290']}, {'id': '287', 'type': 'attribute', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'hosts_cache'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'host_name'}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '292', 'type': 'argument_list', 'children': ['293']}, {'id': '293', 'type': 'string', 'children': [], 'value': "'realm_name'"}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '295', 'type': 'expression_statement', 'children': ['296']}; {'id': '296', 'type': 'assignment', 'children': ['297', '298']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'realm_name'}; {'id': '298', 'type': 'None', 'children': []}, {'id': '299', 'type': 'if_statement', 'children': ['300', '305']}; {'id': '300', 'type': 'comparison_operator', 'children': ['301', '302'], 'value': 'in'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'host_name'}; {'id': '302', 'type': 'attribute', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'hosts_cache'}, {'id': '305', 'type': 'block', 'children': ['306']}; {'id': '306', 'type': 'expression_statement', 'children': ['307']}, {'id': '307', 'type': 'assignment', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'realm_name'}, {'id': '309', 'type': 'call', 'children': ['310', '317']}; {'id': '310', 'type': 'attribute', 'children': ['311', '316']}, {'id': '311', 'type': 'subscript', 'children': ['312', '315']}; {'id': '312', 'type': 'attribute', 'children': ['313', '314']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'hosts_cache'}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'host_name'}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '317', 'type': 'argument_list', 'children': ['318', '319']}; {'id': '318', 'type': 'string', 'children': [], 'value': "'realm_name'"}, {'id': '319', 'type': 'None', 'children': []}; {'id': '320', 'type': 'expression_statement', 'children': ['321']}, {'id': '321', 'type': 'call', 'children': ['322', '325']}; {'id': '322', 'type': 'attribute', 'children': ['323', '324']}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'send_to_tsdb'}, {'id': '325', 'type': 'argument_list', 'children': ['326', '327', '328', '331', '332', '333']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'realm_name'}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'host_name'}; {'id': '328', 'type': 'attribute', 'children': ['329', '330']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'hostcheck'}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'metrics'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'check_time'}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'path'} | def manage_host_check_result_brok(self, b):
host_name = b.data.get('host_name', None)
if not host_name:
return
logger.debug("host check result: %s", host_name)
if host_name not in self.hosts_cache and not self.ignore_unknown:
logger.warning("received host check result for an unknown host: %s", host_name)
return
metrics = self.get_metrics_from_perfdata('host_check', b.data['perf_data'])
if not metrics:
logger.debug("no metrics to send ...")
return
if self.ignore_latency_limit >= b.data['latency'] > 0:
check_time = int(b.data['last_chk']) - int(b.data['latency'])
else:
check_time = int(b.data['last_chk'])
hname = sanitize_name(host_name)
if host_name in self.hosts_cache:
if self.hosts_cache[host_name].get('_GRAPHITE_GROUP', None):
hname = ".".join((self.hosts_cache[host_name].get('_GRAPHITE_GROUP'), hname))
if self.hosts_cache[host_name].get('_GRAPHITE_PRE', None):
hname = ".".join((self.hosts_cache[host_name].get('_GRAPHITE_PRE'), hname))
if self.graphite_data_source:
path = '.'.join((hname, self.graphite_data_source))
if self.hostcheck:
path = '.'.join((hname, self.graphite_data_source, self.hostcheck))
else:
path = '.'.join((hname, self.hostcheck))
if self.realms_prefix and self.hosts_cache[host_name].get('realm_name', None):
path = '.'.join((self.hosts_cache[host_name].get('realm_name'), path))
realm_name = None
if host_name in self.hosts_cache:
realm_name = self.hosts_cache[host_name].get('realm_name', None)
self.send_to_tsdb(realm_name, host_name, self.hostcheck, metrics, check_time, path) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'resolve_elements'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '28', '42', '57', '69', '75', '79', '138', '159']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '10']}, {'id': '7', 'type': 'attribute', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'leaf'}; {'id': '10', 'type': 'block', 'children': ['11', '21']}, {'id': '11', 'type': 'if_statement', 'children': ['12', '16']}; {'id': '12', 'type': 'not_operator', 'children': ['13']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'return_statement', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '20', 'type': 'argument_list', 'children': []}, {'id': '21', 'type': 'return_statement', 'children': ['22']}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'not_nodes'}, {'id': '31', 'type': 'list_comprehension', 'children': ['32', '33', '38']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '33', 'type': 'for_in_clause', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'sons'}; {'id': '38', 'type': 'if_clause', 'children': ['39']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'not_value'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'positiv_nodes'}, {'id': '45', 'type': 'list_comprehension', 'children': ['46', '47', '52']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '47', 'type': 'for_in_clause', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'sons'}; {'id': '52', 'type': 'if_clause', 'children': ['53']}, {'id': '53', 'type': 'not_operator', 'children': ['54']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'not_value'}, {'id': '57', 'type': 'if_statement', 'children': ['58', '62']}; {'id': '58', 'type': 'not_operator', 'children': ['59']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'operand'}; {'id': '62', 'type': 'block', 'children': ['63']}, {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'operand'}; {'id': '68', 'type': 'string', 'children': [], 'value': "'|'"}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '72', 'type': 'call', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '74', 'type': 'argument_list', 'children': []}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '78', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '79', 'type': 'for_statement', 'children': ['80', '81', '82']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'positiv_nodes'}; {'id': '82', 'type': 'block', 'children': ['83', '91', '134']}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'node_members'}; {'id': '86', 'type': 'call', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'resolve_elements'}; {'id': '90', 'type': 'argument_list', 'children': []}, {'id': '91', 'type': 'if_statement', 'children': ['92', '97', '107']}; {'id': '92', 'type': 'comparison_operator', 'children': ['93', '96'], 'value': '=='}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'operand'}; {'id': '96', 'type': 'string', 'children': [], 'value': "'|'"}, {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '101', 'type': 'call', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'union'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'node_members'}, {'id': '107', 'type': 'elif_clause', 'children': ['108', '113']}; {'id': '108', 'type': 'comparison_operator', 'children': ['109', '112'], 'value': '=='}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'operand'}; {'id': '112', 'type': 'string', 'children': [], 'value': "'&'"}, {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'if_statement', 'children': ['115', '118', '123']}, {'id': '115', 'type': 'comparison_operator', 'children': ['116', '117'], 'value': '=='}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '117', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '118', 'type': 'block', 'children': ['119']}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'node_members'}, {'id': '123', 'type': 'else_clause', 'children': ['124']}; {'id': '124', 'type': 'block', 'children': ['125']}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'assignment', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '128', 'type': 'call', 'children': ['129', '132']}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'intersection'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'node_members'}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'augmented_assignment', 'children': ['136', '137'], 'value': '+='}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '137', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '138', 'type': 'for_statement', 'children': ['139', '140', '141']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'not_nodes'}, {'id': '141', 'type': 'block', 'children': ['142', '150']}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'assignment', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'node_members'}, {'id': '145', 'type': 'call', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'resolve_elements'}, {'id': '149', 'type': 'argument_list', 'children': []}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}, {'id': '151', 'type': 'assignment', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '153', 'type': 'call', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'difference'}, {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'node_members'}, {'id': '159', 'type': 'return_statement', 'children': ['160']} | def resolve_elements(self):
if self.leaf:
if not self.content:
return set()
return set(self.content)
not_nodes = [s for s in self.sons if s.not_value]
positiv_nodes = [s for s in self.sons if not s.not_value]
if not self.operand:
self.operand = '|'
res = set()
i = 0
for node in positiv_nodes:
node_members = node.resolve_elements()
if self.operand == '|':
res = res.union(node_members)
elif self.operand == '&':
if i == 0:
res = node_members
else:
res = res.intersection(node_members)
i += 1
for node in not_nodes:
node_members = node.resolve_elements()
res = res.difference(node_members)
return res |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'eval_cor_pattern'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '6', 'type': 'block', 'children': ['7', '15', '19', '32', '38', '113', '117', '121', '125', '361', '369', '392']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '14', 'type': 'argument_list', 'children': []}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'complex_node'}; {'id': '18', 'type': 'False', 'children': []}, {'id': '19', 'type': 'for_statement', 'children': ['20', '21', '22']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'char'}, {'id': '21', 'type': 'string', 'children': [], 'value': "'()+&|,'"}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'if_statement', 'children': ['24', '27']}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': 'in'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'complex_node'}, {'id': '31', 'type': 'True', 'children': []}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'ComplexExpressionNode'}, {'id': '37', 'type': 'argument_list', 'children': []}; {'id': '38', 'type': 'if_statement', 'children': ['39', '41']}, {'id': '39', 'type': 'not_operator', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'complex_node'}, {'id': '41', 'type': 'block', 'children': ['42', '64', '72', '78', '89', '111']}; {'id': '42', 'type': 'if_statement', 'children': ['43', '49']}, {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'startswith'}, {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'string', 'children': [], 'value': "'!'"}, {'id': '49', 'type': 'block', 'children': ['50', '56']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'not_value'}, {'id': '55', 'type': 'True', 'children': []}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'id': '59', 'type': 'subscript', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'id': '61', 'type': 'slice', 'children': ['62', '63']}; {'id': '62', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '63', 'type': 'colon', 'children': []}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'operand'}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'ctx'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'leaf'}, {'id': '77', 'type': 'True', 'children': []}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'assignment', 'children': ['80', '83']}; {'id': '80', 'type': 'pattern_list', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'find_object'}, {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'id': '89', 'type': 'if_statement', 'children': ['90', '93', '100']}; {'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': 'is'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '92', 'type': 'None', 'children': []}, {'id': '93', 'type': 'block', 'children': ['94']}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'content'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '100', 'type': 'else_clause', 'children': ['101']}, {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'call', 'children': ['104', '109']}; {'id': '104', 'type': 'attribute', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'configuration_errors'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '111', 'type': 'return_statement', 'children': ['112']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'in_par'}; {'id': '116', 'type': 'False', 'children': []}, {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'assignment', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '120', 'type': 'string', 'children': [], 'value': "''"}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'stacked_par'}; {'id': '124', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '125', 'type': 'for_statement', 'children': ['126', '127', '128']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'char'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '128', 'type': 'block', 'children': ['129']}, {'id': '129', 'type': 'if_statement', 'children': ['130', '135', '186', '243', '289', '355']}; {'id': '130', 'type': 'comparison_operator', 'children': ['131', '132'], 'value': 'in'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '132', 'type': 'tuple', 'children': ['133', '134']}, {'id': '133', 'type': 'string', 'children': [], 'value': "','"}; {'id': '134', 'type': 'string', 'children': [], 'value': "'|'"}, {'id': '135', 'type': 'block', 'children': ['136']}; {'id': '136', 'type': 'if_statement', 'children': ['137', '138', '143']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'in_par'}; {'id': '138', 'type': 'block', 'children': ['139']}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'augmented_assignment', 'children': ['141', '142'], 'value': '+='}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'char'}, {'id': '143', 'type': 'else_clause', 'children': ['144']}; {'id': '144', 'type': 'block', 'children': ['145', '153', '159', '182']}, {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'assignment', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '148', 'type': 'call', 'children': ['149', '152']}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '152', 'type': 'argument_list', 'children': []}, {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'assignment', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'operand'}; {'id': '158', 'type': 'string', 'children': [], 'value': "'|'"}, {'id': '159', 'type': 'if_statement', 'children': ['160', '163']}; {'id': '160', 'type': 'comparison_operator', 'children': ['161', '162'], 'value': '!='}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '162', 'type': 'string', 'children': [], 'value': "''"}, {'id': '163', 'type': 'block', 'children': ['164', '173']}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}, {'id': '165', 'type': 'assignment', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'son'}, {'id': '167', 'type': 'call', 'children': ['168', '171']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'eval_cor_pattern'}, {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'call', 'children': ['175', '180']}, {'id': '175', 'type': 'attribute', 'children': ['176', '179']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'sons'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '180', 'type': 'argument_list', 'children': ['181']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'son'}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}, {'id': '183', 'type': 'assignment', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '185', 'type': 'string', 'children': [], 'value': "''"}; {'id': '186', 'type': 'elif_clause', 'children': ['187', '192']}, {'id': '187', 'type': 'comparison_operator', 'children': ['188', '189'], 'value': 'in'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'char'}, {'id': '189', 'type': 'tuple', 'children': ['190', '191']}; {'id': '190', 'type': 'string', 'children': [], 'value': "'&'"}, {'id': '191', 'type': 'string', 'children': [], 'value': "'+'"}; {'id': '192', 'type': 'block', 'children': ['193']}, {'id': '193', 'type': 'if_statement', 'children': ['194', '195', '200']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'in_par'}, {'id': '195', 'type': 'block', 'children': ['196']}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'augmented_assignment', 'children': ['198', '199'], 'value': '+='}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '200', 'type': 'else_clause', 'children': ['201']}, {'id': '201', 'type': 'block', 'children': ['202', '210', '216', '239']}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'assignment', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '205', 'type': 'call', 'children': ['206', '209']}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '209', 'type': 'argument_list', 'children': []}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}, {'id': '211', 'type': 'assignment', 'children': ['212', '215']}; {'id': '212', 'type': 'attribute', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'operand'}, {'id': '215', 'type': 'string', 'children': [], 'value': "'&'"}; {'id': '216', 'type': 'if_statement', 'children': ['217', '220']}, {'id': '217', 'type': 'comparison_operator', 'children': ['218', '219'], 'value': '!='}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '219', 'type': 'string', 'children': [], 'value': "''"}; {'id': '220', 'type': 'block', 'children': ['221', '230']}, {'id': '221', 'type': 'expression_statement', 'children': ['222']}; {'id': '222', 'type': 'assignment', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'son'}; {'id': '224', 'type': 'call', 'children': ['225', '228']}, {'id': '225', 'type': 'attribute', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'eval_cor_pattern'}; {'id': '228', 'type': 'argument_list', 'children': ['229']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '230', 'type': 'expression_statement', 'children': ['231']}, {'id': '231', 'type': 'call', 'children': ['232', '237']}; {'id': '232', 'type': 'attribute', 'children': ['233', '236']}, {'id': '233', 'type': 'attribute', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'node'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'sons'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '237', 'type': 'argument_list', 'children': ['238']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'son'}, {'id': '239', 'type': 'expression_statement', 'children': ['240']}; {'id': '240', 'type': 'assignment', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '242', 'type': 'string', 'children': [], 'value': "''"}, {'id': '243', 'type': 'elif_clause', 'children': ['244', '247']}; {'id': '244', 'type': 'comparison_operator', 'children': ['245', '246'], 'value': '=='}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '246', 'type': 'string', 'children': [], 'value': "'('"}, {'id': '247', 'type': 'block', 'children': ['248', '252', '256', '264', '280']}; {'id': '248', 'type': 'expression_statement', 'children': ['249']}, {'id': '249', 'type': 'augmented_assignment', 'children': ['250', '251'], 'value': '+='}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'stacked_par'}, {'id': '251', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '252', 'type': 'expression_statement', 'children': ['253']}, {'id': '253', 'type': 'assignment', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'in_par'}, {'id': '255', 'type': 'True', 'children': []}; {'id': '256', 'type': 'expression_statement', 'children': ['257']}, {'id': '257', 'type': 'assignment', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '259', 'type': 'call', 'children': ['260', '263']}; {'id': '260', 'type': 'attribute', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '263', 'type': 'argument_list', 'children': []}; {'id': '264', 'type': 'if_statement', 'children': ['265', '272']}, {'id': '265', 'type': 'boolean_operator', 'children': ['266', '269'], 'value': 'and'}; {'id': '266', 'type': 'comparison_operator', 'children': ['267', '268'], 'value': '=='}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'stacked_par'}; {'id': '268', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '269', 'type': 'comparison_operator', 'children': ['270', '271'], 'value': '!='}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '271', 'type': 'string', 'children': [], 'value': "''"}; {'id': '272', 'type': 'block', 'children': ['273', '279']}, {'id': '273', 'type': 'expression_statement', 'children': ['274']}; {'id': '274', 'type': 'call', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '276', 'type': 'argument_list', 'children': ['277', '278']}, {'id': '277', 'type': 'string', 'children': [], 'value': '"ERROR : bad expression near"'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '279', 'type': 'continue_statement', 'children': []}; {'id': '280', 'type': 'if_statement', 'children': ['281', '284']}, {'id': '281', 'type': 'comparison_operator', 'children': ['282', '283'], 'value': '>'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'stacked_par'}, {'id': '283', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '284', 'type': 'block', 'children': ['285']}, {'id': '285', 'type': 'expression_statement', 'children': ['286']}; {'id': '286', 'type': 'augmented_assignment', 'children': ['287', '288'], 'value': '+='}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'char'}, {'id': '289', 'type': 'elif_clause', 'children': ['290', '293']}; {'id': '290', 'type': 'comparison_operator', 'children': ['291', '292'], 'value': '=='}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'char'}; {'id': '292', 'type': 'string', 'children': [], 'value': "')'"}, {'id': '293', 'type': 'block', 'children': ['294', '298', '311', '351']}; {'id': '294', 'type': 'expression_statement', 'children': ['295']}, {'id': '295', 'type': 'augmented_assignment', 'children': ['296', '297'], 'value': '-='}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'stacked_par'}, {'id': '297', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '298', 'type': 'if_statement', 'children': ['299', '302']}, {'id': '299', 'type': 'comparison_operator', 'children': ['300', '301'], 'value': '<'}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'stacked_par'}, {'id': '301', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '302', 'type': 'block', 'children': ['303', '310']}, {'id': '303', 'type': 'expression_statement', 'children': ['304']}; {'id': '304', 'type': 'call', 'children': ['305', '306']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '306', 'type': 'argument_list', 'children': ['307', '308', '309']}, {'id': '307', 'type': 'string', 'children': [], 'value': '"Error : bad expression near"'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '309', 'type': 'string', 'children': [], 'value': '"too much \')\'"'}; {'id': '310', 'type': 'continue_statement', 'children': []}, {'id': '311', 'type': 'if_statement', 'children': ['312', '315']}; {'id': '312', 'type': 'comparison_operator', 'children': ['313', '314'], 'value': '=='}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'stacked_par'}; {'id': '314', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '315', 'type': 'block', 'children': ['316', '324', '333', '342', '346', '350']}; {'id': '316', 'type': 'expression_statement', 'children': ['317']}, {'id': '317', 'type': 'assignment', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '319', 'type': 'call', 'children': ['320', '323']}; {'id': '320', 'type': 'attribute', 'children': ['321', '322']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '323', 'type': 'argument_list', 'children': []}; {'id': '324', 'type': 'expression_statement', 'children': ['325']}, {'id': '325', 'type': 'assignment', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'son'}, {'id': '327', 'type': 'call', 'children': ['328', '331']}; {'id': '328', 'type': 'attribute', 'children': ['329', '330']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'eval_cor_pattern'}, {'id': '331', 'type': 'argument_list', 'children': ['332']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '333', 'type': 'expression_statement', 'children': ['334']}; {'id': '334', 'type': 'call', 'children': ['335', '340']}, {'id': '335', 'type': 'attribute', 'children': ['336', '339']}; {'id': '336', 'type': 'attribute', 'children': ['337', '338']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'sons'}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '340', 'type': 'argument_list', 'children': ['341']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'son'}; {'id': '342', 'type': 'expression_statement', 'children': ['343']}, {'id': '343', 'type': 'assignment', 'children': ['344', '345']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'in_par'}, {'id': '345', 'type': 'False', 'children': []}; {'id': '346', 'type': 'expression_statement', 'children': ['347']}, {'id': '347', 'type': 'assignment', 'children': ['348', '349']}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '349', 'type': 'string', 'children': [], 'value': "''"}; {'id': '350', 'type': 'continue_statement', 'children': []}, {'id': '351', 'type': 'expression_statement', 'children': ['352']}; {'id': '352', 'type': 'augmented_assignment', 'children': ['353', '354'], 'value': '+='}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'char'}, {'id': '355', 'type': 'else_clause', 'children': ['356']}; {'id': '356', 'type': 'block', 'children': ['357']}, {'id': '357', 'type': 'expression_statement', 'children': ['358']}; {'id': '358', 'type': 'augmented_assignment', 'children': ['359', '360'], 'value': '+='}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'char'}, {'id': '361', 'type': 'expression_statement', 'children': ['362']}; {'id': '362', 'type': 'assignment', 'children': ['363', '364']}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '364', 'type': 'call', 'children': ['365', '368']}, {'id': '365', 'type': 'attribute', 'children': ['366', '367']}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '368', 'type': 'argument_list', 'children': []}, {'id': '369', 'type': 'if_statement', 'children': ['370', '373']}; {'id': '370', 'type': 'comparison_operator', 'children': ['371', '372'], 'value': '!='}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '372', 'type': 'string', 'children': [], 'value': "''"}, {'id': '373', 'type': 'block', 'children': ['374', '383']}; {'id': '374', 'type': 'expression_statement', 'children': ['375']}, {'id': '375', 'type': 'assignment', 'children': ['376', '377']}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'son'}, {'id': '377', 'type': 'call', 'children': ['378', '381']}; {'id': '378', 'type': 'attribute', 'children': ['379', '380']}, {'id': '379', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'eval_cor_pattern'}, {'id': '381', 'type': 'argument_list', 'children': ['382']}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '383', 'type': 'expression_statement', 'children': ['384']}; {'id': '384', 'type': 'call', 'children': ['385', '390']}, {'id': '385', 'type': 'attribute', 'children': ['386', '389']}; {'id': '386', 'type': 'attribute', 'children': ['387', '388']}, {'id': '387', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'sons'}, {'id': '389', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '390', 'type': 'argument_list', 'children': ['391']}, {'id': '391', 'type': 'identifier', 'children': [], 'value': 'son'}; {'id': '392', 'type': 'return_statement', 'children': ['393']}, {'id': '393', 'type': 'identifier', 'children': [], 'value': 'node'} | def eval_cor_pattern(self, pattern):
pattern = pattern.strip()
complex_node = False
for char in '()+&|,':
if char in pattern:
complex_node = True
node = ComplexExpressionNode()
if not complex_node:
if pattern.startswith('!'):
node.not_value = True
pattern = pattern[1:]
node.operand = self.ctx
node.leaf = True
obj, error = self.find_object(pattern)
if obj is not None:
node.content = obj
else:
node.configuration_errors.append(error)
return node
in_par = False
tmp = ''
stacked_par = 0
for char in pattern:
if char in (',', '|'):
if in_par:
tmp += char
else:
tmp = tmp.strip()
node.operand = '|'
if tmp != '':
son = self.eval_cor_pattern(tmp)
node.sons.append(son)
tmp = ''
elif char in ('&', '+'):
if in_par:
tmp += char
else:
tmp = tmp.strip()
node.operand = '&'
if tmp != '':
son = self.eval_cor_pattern(tmp)
node.sons.append(son)
tmp = ''
elif char == '(':
stacked_par += 1
in_par = True
tmp = tmp.strip()
if stacked_par == 1 and tmp != '':
print("ERROR : bad expression near", tmp)
continue
if stacked_par > 1:
tmp += char
elif char == ')':
stacked_par -= 1
if stacked_par < 0:
print("Error : bad expression near", tmp, "too much ')'")
continue
if stacked_par == 0:
tmp = tmp.strip()
son = self.eval_cor_pattern(tmp)
node.sons.append(son)
in_par = False
tmp = ''
continue
tmp += char
else:
tmp += char
tmp = tmp.strip()
if tmp != '':
son = self.eval_cor_pattern(tmp)
node.sons.append(son)
return node |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_object'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '15', '23', '69', '176', '187']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '14', 'type': 'None', 'children': []}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '18', 'type': 'call', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '22', 'type': 'argument_list', 'children': []}, {'id': '23', 'type': 'if_statement', 'children': ['24', '27']}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '26'], 'value': '=='}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'pattern'}; {'id': '26', 'type': 'string', 'children': [], 'value': "'*'"}, {'id': '27', 'type': 'block', 'children': ['28', '65']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '31', 'type': 'list_comprehension', 'children': ['32', '35', '49']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'host_name'}, {'id': '35', 'type': 'for_in_clause', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'h'}, {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '48']}, {'id': '41', 'type': 'attribute', 'children': ['42', '47']}; {'id': '42', 'type': 'attribute', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'all_elements'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '48', 'type': 'argument_list', 'children': []}, {'id': '49', 'type': 'if_clause', 'children': ['50']}; {'id': '50', 'type': 'boolean_operator', 'children': ['51', '59'], 'value': 'and'}, {'id': '51', 'type': 'comparison_operator', 'children': ['52', '58'], 'value': '!='}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '56', '57']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '56', 'type': 'string', 'children': [], 'value': "'host_name'"}, {'id': '57', 'type': 'string', 'children': [], 'value': "''"}; {'id': '58', 'type': 'string', 'children': [], 'value': "''"}, {'id': '59', 'type': 'not_operator', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'h'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'is_tpl'}; {'id': '64', 'type': 'argument_list', 'children': []}, {'id': '65', 'type': 'return_statement', 'children': ['66']}; {'id': '66', 'type': 'expression_list', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '69', 'type': 'if_statement', 'children': ['70', '75']}; {'id': '70', 'type': 'comparison_operator', 'children': ['71', '74'], 'value': '=='}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'ctx'}; {'id': '74', 'type': 'string', 'children': [], 'value': "'hostgroups'"}, {'id': '75', 'type': 'block', 'children': ['76', '87', '105', '113', '120', '172']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'hgr'}, {'id': '79', 'type': 'call', 'children': ['80', '85']}; {'id': '80', 'type': 'attribute', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'grps'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'find_by_name'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'id': '87', 'type': 'if_statement', 'children': ['88', '90']}; {'id': '88', 'type': 'not_operator', 'children': ['89']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'hgr'}; {'id': '90', 'type': 'block', 'children': ['91', '101']}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '94', 'type': 'binary_operator', 'children': ['95', '96'], 'value': '%'}, {'id': '95', 'type': 'string', 'children': [], 'value': '"Error : cannot find the %s of the expression \'%s\'"'}; {'id': '96', 'type': 'tuple', 'children': ['97', '100']}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'ctx'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'id': '101', 'type': 'return_statement', 'children': ['102']}; {'id': '102', 'type': 'expression_list', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'hgr'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'elts'}; {'id': '108', 'type': 'call', 'children': ['109', '112']}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'hgr'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'get_hosts'}; {'id': '112', 'type': 'argument_list', 'children': []}, {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'elts'}; {'id': '116', 'type': 'call', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'strip_and_uniq'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'elts'}; {'id': '120', 'type': 'if_statement', 'children': ['121', '124']}, {'id': '121', 'type': 'comparison_operator', 'children': ['122', '123'], 'value': 'in'}; {'id': '122', 'type': 'string', 'children': [], 'value': "'*'"}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'elts'}; {'id': '124', 'type': 'block', 'children': ['125', '165']}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'call', 'children': ['127', '130']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'elts'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}, {'id': '131', 'type': 'list_comprehension', 'children': ['132', '135', '149']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'host_name'}, {'id': '135', 'type': 'for_in_clause', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'h'}, {'id': '137', 'type': 'call', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'call', 'children': ['141', '148']}, {'id': '141', 'type': 'attribute', 'children': ['142', '147']}; {'id': '142', 'type': 'attribute', 'children': ['143', '146']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'all_elements'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '148', 'type': 'argument_list', 'children': []}, {'id': '149', 'type': 'if_clause', 'children': ['150']}; {'id': '150', 'type': 'boolean_operator', 'children': ['151', '159'], 'value': 'and'}, {'id': '151', 'type': 'comparison_operator', 'children': ['152', '158'], 'value': '!='}; {'id': '152', 'type': 'call', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '154', 'type': 'argument_list', 'children': ['155', '156', '157']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '156', 'type': 'string', 'children': [], 'value': "'host_name'"}, {'id': '157', 'type': 'string', 'children': [], 'value': "''"}; {'id': '158', 'type': 'string', 'children': [], 'value': "''"}, {'id': '159', 'type': 'not_operator', 'children': ['160']}; {'id': '160', 'type': 'call', 'children': ['161', '164']}, {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'h'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'is_tpl'}; {'id': '164', 'type': 'argument_list', 'children': []}, {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'call', 'children': ['167', '170']}, {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'elts'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '170', 'type': 'argument_list', 'children': ['171']}, {'id': '171', 'type': 'string', 'children': [], 'value': "'*'"}; {'id': '172', 'type': 'return_statement', 'children': ['173']}, {'id': '173', 'type': 'expression_list', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'elts'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'assignment', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '179', 'type': 'call', 'children': ['180', '185']}; {'id': '180', 'type': 'attribute', 'children': ['181', '184']}, {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'grps'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'find_hosts_that_use_template'}, {'id': '185', 'type': 'argument_list', 'children': ['186']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'id': '187', 'type': 'return_statement', 'children': ['188']}; {'id': '188', 'type': 'expression_list', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'obj'} | def find_object(self, pattern):
obj = None
error = None
pattern = pattern.strip()
if pattern == '*':
obj = [h.host_name for h in list(self.all_elements.items.values())
if getattr(h, 'host_name', '') != '' and not h.is_tpl()]
return obj, error
if self.ctx == 'hostgroups':
hgr = self.grps.find_by_name(pattern)
if not hgr:
error = "Error : cannot find the %s of the expression '%s'" % (self.ctx, pattern)
return hgr, error
elts = hgr.get_hosts()
elts = strip_and_uniq(elts)
if '*' in elts:
elts.extend([h.host_name for h in list(self.all_elements.items.values())
if getattr(h, 'host_name', '') != '' and not h.is_tpl()])
elts.remove('*')
return elts, error
obj = self.grps.find_hosts_that_use_template(pattern)
return obj, error |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'clean_queues'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '26', '45', '64', '90', '96', '245', '251', '323', '329']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '17']}, {'id': '7', 'type': 'comparison_operator', 'children': ['8', '16'], 'value': '=='}; {'id': '8', 'type': 'call', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '10', 'type': 'argument_list', 'children': ['11', '14', '15']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'pushed_conf'}; {'id': '14', 'type': 'string', 'children': [], 'value': "'tick_clean_queues'"}, {'id': '15', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '16', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '17', 'type': 'block', 'children': ['18', '25']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'string', 'children': [], 'value': '"No queues cleaning..."'}, {'id': '25', 'type': 'return_statement', 'children': []}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'max_checks'}, {'id': '29', 'type': 'binary_operator', 'children': ['30', '31'], 'value': '*'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'MULTIPLIER_MAX_CHECKS'}, {'id': '31', 'type': 'parenthesized_expression', 'children': ['32']}; {'id': '32', 'type': 'binary_operator', 'children': ['33', '39'], 'value': '+'}, {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'hosts'}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'max_broks'}; {'id': '48', 'type': 'binary_operator', 'children': ['49', '50'], 'value': '*'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'MULTIPLIER_MAX_BROKS'}; {'id': '50', 'type': 'parenthesized_expression', 'children': ['51']}, {'id': '51', 'type': 'binary_operator', 'children': ['52', '58'], 'value': '+'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'hosts'}; {'id': '58', 'type': 'call', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'max_actions'}, {'id': '67', 'type': 'binary_operator', 'children': ['68', '76'], 'value': '*'}; {'id': '68', 'type': 'binary_operator', 'children': ['69', '70'], 'value': '*'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'MULTIPLIER_MAX_ACTIONS'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'contacts'}; {'id': '76', 'type': 'parenthesized_expression', 'children': ['77']}, {'id': '77', 'type': 'binary_operator', 'children': ['78', '84'], 'value': '+'}; {'id': '78', 'type': 'call', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'hosts'}; {'id': '84', 'type': 'call', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'nb_checks_dropped'}, {'id': '95', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '96', 'type': 'if_statement', 'children': ['97', '107']}, {'id': '97', 'type': 'boolean_operator', 'children': ['98', '99'], 'value': 'and'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'max_checks'}, {'id': '99', 'type': 'comparison_operator', 'children': ['100', '106'], 'value': '>'}; {'id': '100', 'type': 'call', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'checks'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'max_checks'}, {'id': '107', 'type': 'block', 'children': ['108', '125', '139', '148', '157', '170']}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'to_del_checks'}, {'id': '111', 'type': 'list_comprehension', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '113', 'type': 'for_in_clause', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'c'}, {'id': '115', 'type': 'call', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'call', 'children': ['119', '124']}, {'id': '119', 'type': 'attribute', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'checks'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '124', 'type': 'argument_list', 'children': []}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'call', 'children': ['127', '130']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'to_del_checks'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}, {'id': '131', 'type': 'keyword_argument', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '133', 'type': 'lambda', 'children': ['134', '136']}; {'id': '134', 'type': 'lambda_parameters', 'children': ['135']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'creation_time'}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'to_del_checks'}; {'id': '142', 'type': 'subscript', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'to_del_checks'}; {'id': '144', 'type': 'slice', 'children': ['145', '146']}, {'id': '145', 'type': 'colon', 'children': []}; {'id': '146', 'type': 'unary_operator', 'children': ['147'], 'value': '-'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'max_checks'}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'assignment', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'nb_checks_dropped'}, {'id': '153', 'type': 'call', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'to_del_checks'}, {'id': '157', 'type': 'if_statement', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'to_del_checks'}, {'id': '159', 'type': 'block', 'children': ['160']}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}, {'id': '161', 'type': 'call', 'children': ['162', '165']}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '165', 'type': 'argument_list', 'children': ['166', '167']}; {'id': '166', 'type': 'string', 'children': [], 'value': '"I have to drop some checks (%d)..., sorry :("'}, {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'nb_checks_dropped'}; {'id': '170', 'type': 'for_statement', 'children': ['171', '172', '173']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'chk'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'to_del_checks'}, {'id': '173', 'type': 'block', 'children': ['174', '180', '192', '200', '207', '224', '239']}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}, {'id': '175', 'type': 'assignment', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'c_id'}, {'id': '177', 'type': 'attribute', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'chk'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}, {'id': '181', 'type': 'assignment', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '183', 'type': 'call', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '185', 'type': 'argument_list', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '187', 'type': 'binary_operator', 'children': ['188', '191'], 'value': '+'}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'chk'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'ref_type'}, {'id': '191', 'type': 'string', 'children': [], 'value': "'s'"}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}, {'id': '193', 'type': 'assignment', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'elt'}, {'id': '195', 'type': 'subscript', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'chk'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'ref'}; {'id': '200', 'type': 'expression_statement', 'children': ['201']}, {'id': '201', 'type': 'call', 'children': ['202', '205']}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'elt'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'remove_in_progress_check'}, {'id': '205', 'type': 'argument_list', 'children': ['206']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'chk'}, {'id': '207', 'type': 'for_statement', 'children': ['208', '209', '212']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'dependent_checks'}, {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'chk'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'depend_on_me'}; {'id': '212', 'type': 'block', 'children': ['213']}, {'id': '213', 'type': 'expression_statement', 'children': ['214']}; {'id': '214', 'type': 'call', 'children': ['215', '220']}, {'id': '215', 'type': 'attribute', 'children': ['216', '219']}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'dependent_checks'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'depend_on'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '220', 'type': 'argument_list', 'children': ['221']}, {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'chk'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '224', 'type': 'for_statement', 'children': ['225', '226', '229']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'c_temp'}; {'id': '226', 'type': 'attribute', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'chk'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'depend_on'}, {'id': '229', 'type': 'block', 'children': ['230']}; {'id': '230', 'type': 'expression_statement', 'children': ['231']}, {'id': '231', 'type': 'call', 'children': ['232', '237']}; {'id': '232', 'type': 'attribute', 'children': ['233', '236']}, {'id': '233', 'type': 'attribute', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'c_temp'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'depend_on_me'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'remove'}, {'id': '237', 'type': 'argument_list', 'children': ['238']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'chk'}, {'id': '239', 'type': 'delete_statement', 'children': ['240']}; {'id': '240', 'type': 'subscript', 'children': ['241', '244']}, {'id': '241', 'type': 'attribute', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'checks'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'c_id'}, {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'assignment', 'children': ['247', '250']}, {'id': '247', 'type': 'attribute', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'nb_broks_dropped'}; {'id': '250', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '251', 'type': 'for_statement', 'children': ['252', '253', '265']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'broker_link'}, {'id': '253', 'type': 'call', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '255', 'type': 'argument_list', 'children': ['256']}; {'id': '256', 'type': 'call', 'children': ['257', '264']}, {'id': '257', 'type': 'attribute', 'children': ['258', '263']}; {'id': '258', 'type': 'attribute', 'children': ['259', '262']}, {'id': '259', 'type': 'attribute', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'my_daemon'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'brokers'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '264', 'type': 'argument_list', 'children': []}, {'id': '265', 'type': 'block', 'children': ['266']}; {'id': '266', 'type': 'if_statement', 'children': ['267', '277']}, {'id': '267', 'type': 'boolean_operator', 'children': ['268', '269'], 'value': 'and'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'max_broks'}, {'id': '269', 'type': 'comparison_operator', 'children': ['270', '276'], 'value': '>'}; {'id': '270', 'type': 'call', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '272', 'type': 'argument_list', 'children': ['273']}, {'id': '273', 'type': 'attribute', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'broker_link'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'broks'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'max_broks'}, {'id': '277', 'type': 'block', 'children': ['278', '295', '312']}; {'id': '278', 'type': 'expression_statement', 'children': ['279']}, {'id': '279', 'type': 'call', 'children': ['280', '283']}; {'id': '280', 'type': 'attribute', 'children': ['281', '282']}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '283', 'type': 'argument_list', 'children': ['284', '287', '293', '294']}; {'id': '284', 'type': 'concatenated_string', 'children': ['285', '286']}, {'id': '285', 'type': 'string', 'children': [], 'value': '"I have to drop some broks (%d > %d) for the broker %s "'}; {'id': '286', 'type': 'string', 'children': [], 'value': '"..., sorry :("'}, {'id': '287', 'type': 'call', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '289', 'type': 'argument_list', 'children': ['290']}; {'id': '290', 'type': 'attribute', 'children': ['291', '292']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'broker_link'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'broks'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'max_broks'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'broker_link'}, {'id': '295', 'type': 'expression_statement', 'children': ['296']}; {'id': '296', 'type': 'assignment', 'children': ['297', '298']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'kept_broks'}; {'id': '298', 'type': 'call', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '300', 'type': 'argument_list', 'children': ['301', '304']}, {'id': '301', 'type': 'attribute', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'broker_link'}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'broks'}; {'id': '304', 'type': 'keyword_argument', 'children': ['305', '306']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '306', 'type': 'lambda', 'children': ['307', '309']}, {'id': '307', 'type': 'lambda_parameters', 'children': ['308']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '309', 'type': 'attribute', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'creation_time'}; {'id': '312', 'type': 'expression_statement', 'children': ['313']}, {'id': '313', 'type': 'assignment', 'children': ['314', '317']}; {'id': '314', 'type': 'attribute', 'children': ['315', '316']}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'broker_link'}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'broks'}, {'id': '317', 'type': 'subscript', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'kept_broks'}, {'id': '319', 'type': 'slice', 'children': ['320', '321', '322']}; {'id': '320', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '321', 'type': 'colon', 'children': []}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'max_broks'}, {'id': '323', 'type': 'expression_statement', 'children': ['324']}; {'id': '324', 'type': 'assignment', 'children': ['325', '328']}, {'id': '325', 'type': 'attribute', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'nb_actions_dropped'}; {'id': '328', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '329', 'type': 'if_statement', 'children': ['330', '340']}; {'id': '330', 'type': 'boolean_operator', 'children': ['331', '332'], 'value': 'and'}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'max_actions'}; {'id': '332', 'type': 'comparison_operator', 'children': ['333', '339'], 'value': '>'}, {'id': '333', 'type': 'call', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '335', 'type': 'argument_list', 'children': ['336']}; {'id': '336', 'type': 'attribute', 'children': ['337', '338']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'actions'}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'max_actions'}; {'id': '340', 'type': 'block', 'children': ['341', '355', '372', '386', '395', '404']}, {'id': '341', 'type': 'expression_statement', 'children': ['342']}; {'id': '342', 'type': 'call', 'children': ['343', '346']}, {'id': '343', 'type': 'attribute', 'children': ['344', '345']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '346', 'type': 'argument_list', 'children': ['347', '348', '354']}, {'id': '347', 'type': 'string', 'children': [], 'value': '"I have to del some actions (currently: %d, max: %d)..., sorry :("'}; {'id': '348', 'type': 'call', 'children': ['349', '350']}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '350', 'type': 'argument_list', 'children': ['351']}, {'id': '351', 'type': 'attribute', 'children': ['352', '353']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'actions'}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'max_actions'}, {'id': '355', 'type': 'expression_statement', 'children': ['356']}; {'id': '356', 'type': 'assignment', 'children': ['357', '358']}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'to_del_actions'}; {'id': '358', 'type': 'list_comprehension', 'children': ['359', '360']}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '360', 'type': 'for_in_clause', 'children': ['361', '362']}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '362', 'type': 'call', 'children': ['363', '364']}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '364', 'type': 'argument_list', 'children': ['365']}, {'id': '365', 'type': 'call', 'children': ['366', '371']}; {'id': '366', 'type': 'attribute', 'children': ['367', '370']}, {'id': '367', 'type': 'attribute', 'children': ['368', '369']}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'actions'}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '371', 'type': 'argument_list', 'children': []}; {'id': '372', 'type': 'expression_statement', 'children': ['373']}, {'id': '373', 'type': 'call', 'children': ['374', '377']}; {'id': '374', 'type': 'attribute', 'children': ['375', '376']}, {'id': '375', 'type': 'identifier', 'children': [], 'value': 'to_del_actions'}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'sort'}, {'id': '377', 'type': 'argument_list', 'children': ['378']}; {'id': '378', 'type': 'keyword_argument', 'children': ['379', '380']}, {'id': '379', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '380', 'type': 'lambda', 'children': ['381', '383']}, {'id': '381', 'type': 'lambda_parameters', 'children': ['382']}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '383', 'type': 'attribute', 'children': ['384', '385']}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'x'}, {'id': '385', 'type': 'identifier', 'children': [], 'value': 'creation_time'}; {'id': '386', 'type': 'expression_statement', 'children': ['387']}, {'id': '387', 'type': 'assignment', 'children': ['388', '389']}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'to_del_actions'}, {'id': '389', 'type': 'subscript', 'children': ['390', '391']}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'to_del_actions'}, {'id': '391', 'type': 'slice', 'children': ['392', '393']}; {'id': '392', 'type': 'colon', 'children': []}, {'id': '393', 'type': 'unary_operator', 'children': ['394'], 'value': '-'}; {'id': '394', 'type': 'identifier', 'children': [], 'value': 'max_actions'}, {'id': '395', 'type': 'expression_statement', 'children': ['396']}; {'id': '396', 'type': 'assignment', 'children': ['397', '400']}, {'id': '397', 'type': 'attribute', 'children': ['398', '399']}; {'id': '398', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '399', 'type': 'identifier', 'children': [], 'value': 'nb_actions_dropped'}; {'id': '400', 'type': 'call', 'children': ['401', '402']}, {'id': '401', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '402', 'type': 'argument_list', 'children': ['403']}, {'id': '403', 'type': 'identifier', 'children': [], 'value': 'to_del_actions'}; {'id': '404', 'type': 'for_statement', 'children': ['405', '406', '407']}, {'id': '405', 'type': 'identifier', 'children': [], 'value': 'act'}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'to_del_actions'}, {'id': '407', 'type': 'block', 'children': ['408', '429']}; {'id': '408', 'type': 'if_statement', 'children': ['409', '414']}, {'id': '409', 'type': 'comparison_operator', 'children': ['410', '413'], 'value': '=='}; {'id': '410', 'type': 'attribute', 'children': ['411', '412']}, {'id': '411', 'type': 'identifier', 'children': [], 'value': 'act'}; {'id': '412', 'type': 'identifier', 'children': [], 'value': 'is_a'}, {'id': '413', 'type': 'string', 'children': [], 'value': "'notification'"}; {'id': '414', 'type': 'block', 'children': ['415']}, {'id': '415', 'type': 'expression_statement', 'children': ['416']}; {'id': '416', 'type': 'call', 'children': ['417', '427']}, {'id': '417', 'type': 'attribute', 'children': ['418', '426']}; {'id': '418', 'type': 'call', 'children': ['419', '422']}, {'id': '419', 'type': 'attribute', 'children': ['420', '421']}; {'id': '420', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '421', 'type': 'identifier', 'children': [], 'value': 'find_item_by_id'}; {'id': '422', 'type': 'argument_list', 'children': ['423']}, {'id': '423', 'type': 'attribute', 'children': ['424', '425']}; {'id': '424', 'type': 'identifier', 'children': [], 'value': 'act'}, {'id': '425', 'type': 'identifier', 'children': [], 'value': 'ref'}; {'id': '426', 'type': 'identifier', 'children': [], 'value': 'remove_in_progress_notification'}, {'id': '427', 'type': 'argument_list', 'children': ['428']}; {'id': '428', 'type': 'identifier', 'children': [], 'value': 'act'}, {'id': '429', 'type': 'delete_statement', 'children': ['430']}; {'id': '430', 'type': 'subscript', 'children': ['431', '434']}, {'id': '431', 'type': 'attribute', 'children': ['432', '433']}; {'id': '432', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '433', 'type': 'identifier', 'children': [], 'value': 'actions'}; {'id': '434', 'type': 'attribute', 'children': ['435', '436']}, {'id': '435', 'type': 'identifier', 'children': [], 'value': 'act'} | def clean_queues(self):
if getattr(self.pushed_conf, 'tick_clean_queues', 0) == 0:
logger.debug("No queues cleaning...")
return
max_checks = MULTIPLIER_MAX_CHECKS * (len(self.hosts) + len(self.services))
max_broks = MULTIPLIER_MAX_BROKS * (len(self.hosts) + len(self.services))
max_actions = MULTIPLIER_MAX_ACTIONS * len(self.contacts) * (len(self.hosts) +
len(self.services))
self.nb_checks_dropped = 0
if max_checks and len(self.checks) > max_checks:
to_del_checks = [c for c in list(self.checks.values())]
to_del_checks.sort(key=lambda x: x.creation_time)
to_del_checks = to_del_checks[:-max_checks]
self.nb_checks_dropped = len(to_del_checks)
if to_del_checks:
logger.warning("I have to drop some checks (%d)..., sorry :(",
self.nb_checks_dropped)
for chk in to_del_checks:
c_id = chk.uuid
items = getattr(self, chk.ref_type + 's')
elt = items[chk.ref]
elt.remove_in_progress_check(chk)
for dependent_checks in chk.depend_on_me:
dependent_checks.depend_on.remove(chk.uuid)
for c_temp in chk.depend_on:
c_temp.depend_on_me.remove(chk)
del self.checks[c_id]
self.nb_broks_dropped = 0
for broker_link in list(self.my_daemon.brokers.values()):
if max_broks and len(broker_link.broks) > max_broks:
logger.warning("I have to drop some broks (%d > %d) for the broker %s "
"..., sorry :(", len(broker_link.broks), max_broks, broker_link)
kept_broks = sorted(broker_link.broks, key=lambda x: x.creation_time)
broker_link.broks = kept_broks[0:max_broks]
self.nb_actions_dropped = 0
if max_actions and len(self.actions) > max_actions:
logger.warning("I have to del some actions (currently: %d, max: %d)..., sorry :(",
len(self.actions), max_actions)
to_del_actions = [c for c in list(self.actions.values())]
to_del_actions.sort(key=lambda x: x.creation_time)
to_del_actions = to_del_actions[:-max_actions]
self.nb_actions_dropped = len(to_del_actions)
for act in to_del_actions:
if act.is_a == 'notification':
self.find_item_by_id(act.ref).remove_in_progress_notification(act)
del self.actions[act.uuid] |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'scatter_master_notifications'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '14', '52', '66']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'now'}, {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '13', 'type': 'argument_list', 'children': []}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'notifications'}, {'id': '17', 'type': 'list_comprehension', 'children': ['18', '19', '28']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '19', 'type': 'for_in_clause', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '21', 'type': 'call', 'children': ['22', '27']}; {'id': '22', 'type': 'attribute', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'actions'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '27', 'type': 'argument_list', 'children': []}; {'id': '28', 'type': 'if_clause', 'children': ['29']}, {'id': '29', 'type': 'boolean_operator', 'children': ['30', '46'], 'value': 'and'}; {'id': '30', 'type': 'boolean_operator', 'children': ['31', '42'], 'value': 'and'}, {'id': '31', 'type': 'boolean_operator', 'children': ['32', '37'], 'value': 'and'}; {'id': '32', 'type': 'comparison_operator', 'children': ['33', '36'], 'value': '=='}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'is_a'}; {'id': '36', 'type': 'string', 'children': [], 'value': "u'notification'"}, {'id': '37', 'type': 'comparison_operator', 'children': ['38', '41'], 'value': '=='}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'status'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'ACT_STATUS_SCHEDULED'}; {'id': '42', 'type': 'not_operator', 'children': ['43']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'contact'}; {'id': '46', 'type': 'call', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'a'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'is_launchable'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '52', 'type': 'if_statement', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'notifications'}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '60', 'type': 'argument_list', 'children': ['61', '62']}, {'id': '61', 'type': 'string', 'children': [], 'value': '"Scatter master notification: %d notifications"'}; {'id': '62', 'type': 'call', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'notifications'}; {'id': '66', 'type': 'for_statement', 'children': ['67', '68', '69']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'notification'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'notifications'}, {'id': '69', 'type': 'block', 'children': ['70', '78', '89', '93', '97', '117', '196']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '75', 'type': 'argument_list', 'children': ['76', '77']}; {'id': '76', 'type': 'string', 'children': [], 'value': '"Scheduler got a master notification: %s"'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'notification'}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'find_item_by_id'}, {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'notification'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'ref'}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '92', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'notification_period'}; {'id': '96', 'type': 'None', 'children': []}, {'id': '97', 'type': 'if_statement', 'children': ['98', '106']}; {'id': '98', 'type': 'comparison_operator', 'children': ['99', '105'], 'value': 'is'}, {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '101', 'type': 'argument_list', 'children': ['102', '103', '104']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '103', 'type': 'string', 'children': [], 'value': "'notification_period'"}; {'id': '104', 'type': 'None', 'children': []}, {'id': '105', 'type': 'None', 'children': []}; {'id': '106', 'type': 'block', 'children': ['107']}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'notification_period'}; {'id': '110', 'type': 'subscript', 'children': ['111', '114']}, {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'timeperiods'}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'notification_period'}, {'id': '117', 'type': 'if_statement', 'children': ['118', '135']}; {'id': '118', 'type': 'not_operator', 'children': ['119']}, {'id': '119', 'type': 'call', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'is_blocking_notifications'}, {'id': '123', 'type': 'argument_list', 'children': ['124', '125', '128', '131', '134']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'notification_period'}, {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'hosts'}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'notification'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'now'}, {'id': '135', 'type': 'block', 'children': ['136', '171']}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'id': '137', 'type': 'assignment', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'children'}, {'id': '139', 'type': 'call', 'children': ['140', '143']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'scatter_notification'}, {'id': '143', 'type': 'argument_list', 'children': ['144', '145', '148', '151', '154', '157', '160']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'notification'}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'contacts'}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'notificationways'}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'timeperiods'}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'macromodulations'}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'escalations'}; {'id': '160', 'type': 'call', 'children': ['161', '164']}, {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'find_item_by_id'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}, {'id': '165', 'type': 'call', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '167', 'type': 'argument_list', 'children': ['168', '169', '170']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '169', 'type': 'string', 'children': [], 'value': '"host"'}; {'id': '170', 'type': 'None', 'children': []}, {'id': '171', 'type': 'for_statement', 'children': ['172', '173', '174']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'notif'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '174', 'type': 'block', 'children': ['175', '183', '189']}, {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'call', 'children': ['177', '180']}, {'id': '177', 'type': 'attribute', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '180', 'type': 'argument_list', 'children': ['181', '182']}, {'id': '181', 'type': 'string', 'children': [], 'value': '" - child notification: %s"'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'notif'}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '188']}, {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'notif'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'ACT_STATUS_SCHEDULED'}, {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'call', 'children': ['191', '194']}, {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '194', 'type': 'argument_list', 'children': ['195']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'notif'}; {'id': '196', 'type': 'if_statement', 'children': ['197', '202', '277']}, {'id': '197', 'type': 'comparison_operator', 'children': ['198', '201'], 'value': '=='}; {'id': '198', 'type': 'attribute', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'notification'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'type'}, {'id': '201', 'type': 'string', 'children': [], 'value': "u'PROBLEM'"}; {'id': '202', 'type': 'block', 'children': ['203', '214']}, {'id': '203', 'type': 'if_statement', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'children'}, {'id': '205', 'type': 'block', 'children': ['206']}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}, {'id': '207', 'type': 'assignment', 'children': ['208', '211']}; {'id': '208', 'type': 'attribute', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'current_notification_number'}, {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'notification'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'notif_nb'}; {'id': '214', 'type': 'if_statement', 'children': ['215', '224', '260']}, {'id': '215', 'type': 'boolean_operator', 'children': ['216', '219'], 'value': 'and'}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'notification_interval'}, {'id': '219', 'type': 'comparison_operator', 'children': ['220', '223'], 'value': 'is'}; {'id': '220', 'type': 'attribute', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'notification'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 't_to_go'}, {'id': '223', 'type': 'None', 'children': []}; {'id': '224', 'type': 'block', 'children': ['225', '242', '252']}, {'id': '225', 'type': 'expression_statement', 'children': ['226']}; {'id': '226', 'type': 'assignment', 'children': ['227', '230']}, {'id': '227', 'type': 'attribute', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'notification'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 't_to_go'}; {'id': '230', 'type': 'call', 'children': ['231', '234']}, {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'get_next_notification_time'}; {'id': '234', 'type': 'argument_list', 'children': ['235', '236', '239']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'notification'}; {'id': '236', 'type': 'attribute', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'escalations'}, {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'timeperiods'}; {'id': '242', 'type': 'expression_statement', 'children': ['243']}, {'id': '243', 'type': 'assignment', 'children': ['244', '247']}; {'id': '244', 'type': 'attribute', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'notification'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'notif_nb'}, {'id': '247', 'type': 'binary_operator', 'children': ['248', '251'], 'value': '+'}; {'id': '248', 'type': 'attribute', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'current_notification_number'}, {'id': '251', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '252', 'type': 'expression_statement', 'children': ['253']}, {'id': '253', 'type': 'call', 'children': ['254', '257']}; {'id': '254', 'type': 'attribute', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '257', 'type': 'argument_list', 'children': ['258', '259']}; {'id': '258', 'type': 'string', 'children': [], 'value': '"Repeat master notification: %s"'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'notification'}; {'id': '260', 'type': 'else_clause', 'children': ['261']}, {'id': '261', 'type': 'block', 'children': ['262', '269']}; {'id': '262', 'type': 'expression_statement', 'children': ['263']}, {'id': '263', 'type': 'call', 'children': ['264', '267']}; {'id': '264', 'type': 'attribute', 'children': ['265', '266']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'remove_in_progress_notification'}, {'id': '267', 'type': 'argument_list', 'children': ['268']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'notification'}, {'id': '269', 'type': 'expression_statement', 'children': ['270']}; {'id': '270', 'type': 'call', 'children': ['271', '274']}, {'id': '271', 'type': 'attribute', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '274', 'type': 'argument_list', 'children': ['275', '276']}, {'id': '275', 'type': 'string', 'children': [], 'value': '"Remove master notification (no repeat): %s"'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'notification'}, {'id': '277', 'type': 'else_clause', 'children': ['278']}; {'id': '278', 'type': 'block', 'children': ['279', '287']}, {'id': '279', 'type': 'expression_statement', 'children': ['280']}; {'id': '280', 'type': 'call', 'children': ['281', '284']}, {'id': '281', 'type': 'attribute', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '284', 'type': 'argument_list', 'children': ['285', '286']}, {'id': '285', 'type': 'string', 'children': [], 'value': '"Remove master notification (no more a problem): %s"'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'notification'}, {'id': '287', 'type': 'expression_statement', 'children': ['288']}; {'id': '288', 'type': 'call', 'children': ['289', '292']}, {'id': '289', 'type': 'attribute', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'remove_in_progress_notification'}; {'id': '292', 'type': 'argument_list', 'children': ['293']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'notification'} | def scatter_master_notifications(self):
now = time.time()
notifications = [a for a in self.actions.values()
if a.is_a == u'notification' and a.status == ACT_STATUS_SCHEDULED
and not a.contact and a.is_launchable(now)]
if notifications:
logger.debug("Scatter master notification: %d notifications",
len(notifications))
for notification in notifications:
logger.debug("Scheduler got a master notification: %s", notification)
item = self.find_item_by_id(notification.ref)
children = []
notification_period = None
if getattr(item, 'notification_period', None) is not None:
notification_period = self.timeperiods[item.notification_period]
if not item.is_blocking_notifications(notification_period,
self.hosts, self.services,
notification.type, now):
children = item.scatter_notification(
notification, self.contacts, self.notificationways, self.timeperiods,
self.macromodulations, self.escalations,
self.find_item_by_id(getattr(item, "host", None))
)
for notif in children:
logger.debug(" - child notification: %s", notif)
notif.status = ACT_STATUS_SCHEDULED
self.add(notif)
if notification.type == u'PROBLEM':
if children:
item.current_notification_number = notification.notif_nb
if item.notification_interval and notification.t_to_go is not None:
notification.t_to_go = item.get_next_notification_time(notification,
self.escalations,
self.timeperiods)
notification.notif_nb = item.current_notification_number + 1
logger.debug("Repeat master notification: %s", notification)
else:
item.remove_in_progress_notification(notification)
logger.debug("Remove master notification (no repeat): %s", notification)
else:
logger.debug("Remove master notification (no more a problem): %s", notification)
item.remove_in_progress_notification(notification) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'log_initial_states'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '18']}; {'id': '6', 'type': 'for_statement', 'children': ['7', '8', '11']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'elt'}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'hosts'}, {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'elt'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'raise_initial_state'}, {'id': '17', 'type': 'argument_list', 'children': []}; {'id': '18', 'type': 'for_statement', 'children': ['19', '20', '23']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'elt'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'elt'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'raise_initial_state'}, {'id': '29', 'type': 'argument_list', 'children': []} | def log_initial_states(self):
for elt in self.hosts:
elt.raise_initial_state()
for elt in self.services:
elt.raise_initial_state() |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_retention_data'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '16', '106', '119', '213', '226']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'retention_data'}, {'id': '9', 'type': 'dictionary', 'children': ['10', '13']}; {'id': '10', 'type': 'pair', 'children': ['11', '12']}, {'id': '11', 'type': 'string', 'children': [], 'value': "'hosts'"}; {'id': '12', 'type': 'dictionary', 'children': []}, {'id': '13', 'type': 'pair', 'children': ['14', '15']}; {'id': '14', 'type': 'string', 'children': [], 'value': "'services'"}, {'id': '15', 'type': 'dictionary', 'children': []}; {'id': '16', 'type': 'for_statement', 'children': ['17', '18', '21']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'hosts'}, {'id': '21', 'type': 'block', 'children': ['22', '26', '34', '45', '96']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'h_dict'}, {'id': '25', 'type': 'dictionary', 'children': []}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'properties'}, {'id': '29', 'type': 'attribute', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': '__class__'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'attribute', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'host'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'running_properties'}, {'id': '45', 'type': 'for_statement', 'children': ['46', '49', '57']}; {'id': '46', 'type': 'pattern_list', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'entry'}, {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'properties'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '56', 'type': 'argument_list', 'children': []}, {'id': '57', 'type': 'block', 'children': ['58', '65', '73', '79', '90']}; {'id': '58', 'type': 'if_statement', 'children': ['59', '63']}, {'id': '59', 'type': 'not_operator', 'children': ['60']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'retention'}, {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'continue_statement', 'children': []}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '70', 'type': 'argument_list', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'prepare_retention'}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'retention_preparation'}, {'id': '79', 'type': 'if_statement', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'prepare_retention'}, {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '85', 'type': 'call', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'prepare_retention'}, {'id': '87', 'type': 'argument_list', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'host'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '95']}; {'id': '92', 'type': 'subscript', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'h_dict'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'assignment', 'children': ['98', '105']}; {'id': '98', 'type': 'subscript', 'children': ['99', '102']}, {'id': '99', 'type': 'subscript', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'retention_data'}, {'id': '101', 'type': 'string', 'children': [], 'value': "'hosts'"}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'host_name'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'h_dict'}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'call', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '111', 'type': 'argument_list', 'children': ['112', '113']}; {'id': '112', 'type': 'string', 'children': [], 'value': "'%d hosts sent to retention'"}, {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'subscript', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'retention_data'}; {'id': '118', 'type': 'string', 'children': [], 'value': "'hosts'"}, {'id': '119', 'type': 'for_statement', 'children': ['120', '121', '124']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '124', 'type': 'block', 'children': ['125', '129', '137', '148', '199']}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'assignment', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 's_dict'}; {'id': '128', 'type': 'dictionary', 'children': []}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '132', 'type': 'attribute', 'children': ['133', '136']}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'properties'}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'call', 'children': ['139', '142']}, {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'properties'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}, {'id': '143', 'type': 'attribute', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': '__class__'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'running_properties'}; {'id': '148', 'type': 'for_statement', 'children': ['149', '152', '160']}, {'id': '149', 'type': 'pattern_list', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '152', 'type': 'call', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '154', 'type': 'argument_list', 'children': ['155']}, {'id': '155', 'type': 'call', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '159', 'type': 'argument_list', 'children': []}; {'id': '160', 'type': 'block', 'children': ['161', '168', '176', '182', '193']}, {'id': '161', 'type': 'if_statement', 'children': ['162', '166']}; {'id': '162', 'type': 'not_operator', 'children': ['163']}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'entry'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'retention'}; {'id': '166', 'type': 'block', 'children': ['167']}, {'id': '167', 'type': 'continue_statement', 'children': []}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'assignment', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '171', 'type': 'call', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '173', 'type': 'argument_list', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'assignment', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'prepare_retention'}, {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'entry'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'retention_preparation'}; {'id': '182', 'type': 'if_statement', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'prepare_retention'}; {'id': '184', 'type': 'block', 'children': ['185']}, {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'assignment', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '188', 'type': 'call', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'prepare_retention'}; {'id': '190', 'type': 'argument_list', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'assignment', 'children': ['195', '198']}, {'id': '195', 'type': 'subscript', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 's_dict'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'val'}, {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '212']}, {'id': '201', 'type': 'subscript', 'children': ['202', '205']}; {'id': '202', 'type': 'subscript', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'retention_data'}; {'id': '204', 'type': 'string', 'children': [], 'value': "'services'"}, {'id': '205', 'type': 'tuple', 'children': ['206', '209']}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'host_name'}, {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'service_description'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 's_dict'}, {'id': '213', 'type': 'expression_statement', 'children': ['214']}; {'id': '214', 'type': 'call', 'children': ['215', '218']}, {'id': '215', 'type': 'attribute', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '218', 'type': 'argument_list', 'children': ['219', '220']}, {'id': '219', 'type': 'string', 'children': [], 'value': "'%d services sent to retention'"}; {'id': '220', 'type': 'call', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '222', 'type': 'argument_list', 'children': ['223']}, {'id': '223', 'type': 'subscript', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'retention_data'}, {'id': '225', 'type': 'string', 'children': [], 'value': "'services'"}; {'id': '226', 'type': 'return_statement', 'children': ['227']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'retention_data'} | def get_retention_data(self):
retention_data = {
'hosts': {}, 'services': {}
}
for host in self.hosts:
h_dict = {}
properties = host.__class__.properties
properties.update(host.__class__.running_properties)
for prop, entry in list(properties.items()):
if not entry.retention:
continue
val = getattr(host, prop)
prepare_retention = entry.retention_preparation
if prepare_retention:
val = prepare_retention(host, val)
h_dict[prop] = val
retention_data['hosts'][host.host_name] = h_dict
logger.info('%d hosts sent to retention', len(retention_data['hosts']))
for service in self.services:
s_dict = {}
properties = service.__class__.properties
properties.update(service.__class__.running_properties)
for prop, entry in list(properties.items()):
if not entry.retention:
continue
val = getattr(service, prop)
prepare_retention = entry.retention_preparation
if prepare_retention:
val = prepare_retention(service, val)
s_dict[prop] = val
retention_data['services'][(service.host_name, service.service_description)] = s_dict
logger.info('%d services sent to retention', len(retention_data['services']))
return retention_data |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'restore_retention_data_item'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '7', 'type': 'block', 'children': ['8', '16', '27', '86', '132', '138', '224', '256', '284', '290', '296', '334', '340']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'properties'}, {'id': '11', 'type': 'attribute', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '__class__'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'update'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'attribute', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'running_properties'}, {'id': '27', 'type': 'for_statement', 'children': ['28', '31', '39']}; {'id': '28', 'type': 'pattern_list', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'entry'}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'properties'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '38', 'type': 'argument_list', 'children': []}, {'id': '39', 'type': 'block', 'children': ['40', '47', '53', '59']}; {'id': '40', 'type': 'if_statement', 'children': ['41', '45']}, {'id': '41', 'type': 'not_operator', 'children': ['42']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'retention'}, {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'continue_statement', 'children': []}, {'id': '47', 'type': 'if_statement', 'children': ['48', '51']}; {'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': 'not'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '51', 'type': 'block', 'children': ['52']}; {'id': '52', 'type': 'continue_statement', 'children': []}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'restore_retention'}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'retention_restoration'}, {'id': '59', 'type': 'if_statement', 'children': ['60', '61', '75']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'restore_retention'}, {'id': '61', 'type': 'block', 'children': ['62']}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'setattr'}, {'id': '65', 'type': 'argument_list', 'children': ['66', '67', '68']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'restore_retention'}; {'id': '70', 'type': 'argument_list', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '72', 'type': 'subscript', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '75', 'type': 'else_clause', 'children': ['76']}; {'id': '76', 'type': 'block', 'children': ['77']}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'setattr'}; {'id': '80', 'type': 'argument_list', 'children': ['81', '82', '83']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '83', 'type': 'subscript', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '86', 'type': 'for_statement', 'children': ['87', '88', '91']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'notification_uuid'}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'notifications_in_progress'}, {'id': '91', 'type': 'block', 'children': ['92', '100', '108', '117', '125']}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'notification'}, {'id': '95', 'type': 'subscript', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'notifications_in_progress'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'notification_uuid'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '105']}; {'id': '102', 'type': 'subscript', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'notification'}; {'id': '104', 'type': 'string', 'children': [], 'value': "'ref'"}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'my_notification'}, {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'Notification'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'keyword_argument', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'notification'}, {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'assignment', 'children': ['119', '124']}, {'id': '119', 'type': 'subscript', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'notifications_in_progress'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'notification_uuid'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'my_notification'}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'call', 'children': ['127', '130']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'my_notification'}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'call', 'children': ['134', '137']}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'update_in_checking'}, {'id': '137', 'type': 'argument_list', 'children': []}; {'id': '138', 'type': 'for_statement', 'children': ['139', '140', '143']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'downtime_uuid'}; {'id': '140', 'type': 'subscript', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '142', 'type': 'string', 'children': [], 'value': "'downtimes'"}, {'id': '143', 'type': 'block', 'children': ['144', '152', '160', '169', '189', '217']}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'assignment', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'downtime'}, {'id': '147', 'type': 'subscript', 'children': ['148', '151']}; {'id': '148', 'type': 'subscript', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '150', 'type': 'string', 'children': [], 'value': "'downtimes'"}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'downtime_uuid'}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'assignment', 'children': ['154', '157']}; {'id': '154', 'type': 'subscript', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'downtime'}; {'id': '156', 'type': 'string', 'children': [], 'value': "'ref'"}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}, {'id': '161', 'type': 'assignment', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'my_downtime'}, {'id': '163', 'type': 'call', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'Downtime'}, {'id': '165', 'type': 'argument_list', 'children': ['166']}; {'id': '166', 'type': 'keyword_argument', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'downtime'}, {'id': '169', 'type': 'if_statement', 'children': ['170', '173']}; {'id': '170', 'type': 'subscript', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'downtime'}; {'id': '172', 'type': 'string', 'children': [], 'value': "'comment_id'"}, {'id': '173', 'type': 'block', 'children': ['174']}; {'id': '174', 'type': 'if_statement', 'children': ['175', '182']}, {'id': '175', 'type': 'comparison_operator', 'children': ['176', '179'], 'value': 'not'}; {'id': '176', 'type': 'subscript', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'downtime'}; {'id': '178', 'type': 'string', 'children': [], 'value': "'comment_id'"}, {'id': '179', 'type': 'subscript', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '181', 'type': 'string', 'children': [], 'value': "'comments'"}; {'id': '182', 'type': 'block', 'children': ['183']}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '188']}, {'id': '185', 'type': 'subscript', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'downtime'}, {'id': '187', 'type': 'string', 'children': [], 'value': "'comment_id'"}; {'id': '188', 'type': 'string', 'children': [], 'value': "''"}, {'id': '189', 'type': 'if_statement', 'children': ['190', '195']}; {'id': '190', 'type': 'comparison_operator', 'children': ['191', '192'], 'value': 'in'}, {'id': '191', 'type': 'string', 'children': [], 'value': "'uuid'"}; {'id': '192', 'type': 'subscript', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'downtime'}; {'id': '194', 'type': 'string', 'children': [], 'value': "'comment_id'"}, {'id': '195', 'type': 'block', 'children': ['196', '207']}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'call', 'children': ['198', '203']}; {'id': '198', 'type': 'attribute', 'children': ['199', '202']}, {'id': '199', 'type': 'subscript', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '201', 'type': 'string', 'children': [], 'value': "'comments'"}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '203', 'type': 'argument_list', 'children': ['204']}; {'id': '204', 'type': 'subscript', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'downtime'}; {'id': '206', 'type': 'string', 'children': [], 'value': "'comment_id'"}, {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'assignment', 'children': ['209', '212']}, {'id': '209', 'type': 'subscript', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'downtime'}, {'id': '211', 'type': 'string', 'children': [], 'value': "'comment_id'"}; {'id': '212', 'type': 'subscript', 'children': ['213', '216']}, {'id': '213', 'type': 'subscript', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'downtime'}, {'id': '215', 'type': 'string', 'children': [], 'value': "'comment_id'"}; {'id': '216', 'type': 'string', 'children': [], 'value': "'uuid'"}, {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'call', 'children': ['219', '222']}, {'id': '219', 'type': 'attribute', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'add_downtime'}; {'id': '222', 'type': 'argument_list', 'children': ['223']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'my_downtime'}; {'id': '224', 'type': 'for_statement', 'children': ['225', '226', '229']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'comment_uuid'}; {'id': '226', 'type': 'subscript', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '228', 'type': 'string', 'children': [], 'value': "'comments'"}, {'id': '229', 'type': 'block', 'children': ['230', '238', '246']}; {'id': '230', 'type': 'expression_statement', 'children': ['231']}, {'id': '231', 'type': 'assignment', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'comment'}, {'id': '233', 'type': 'subscript', 'children': ['234', '237']}; {'id': '234', 'type': 'subscript', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '236', 'type': 'string', 'children': [], 'value': "'comments'"}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'comment_uuid'}; {'id': '238', 'type': 'expression_statement', 'children': ['239']}, {'id': '239', 'type': 'assignment', 'children': ['240', '243']}; {'id': '240', 'type': 'subscript', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'comment'}; {'id': '242', 'type': 'string', 'children': [], 'value': "'ref'"}, {'id': '243', 'type': 'attribute', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '246', 'type': 'expression_statement', 'children': ['247']}, {'id': '247', 'type': 'call', 'children': ['248', '251']}; {'id': '248', 'type': 'attribute', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'add_comment'}, {'id': '251', 'type': 'argument_list', 'children': ['252']}; {'id': '252', 'type': 'call', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'Comment'}; {'id': '254', 'type': 'argument_list', 'children': ['255']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'comment'}; {'id': '256', 'type': 'if_statement', 'children': ['257', '262']}, {'id': '257', 'type': 'comparison_operator', 'children': ['258', '261'], 'value': 'is'}; {'id': '258', 'type': 'attribute', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'acknowledgement'}, {'id': '261', 'type': 'None', 'children': []}; {'id': '262', 'type': 'block', 'children': ['263', '273']}, {'id': '263', 'type': 'expression_statement', 'children': ['264']}; {'id': '264', 'type': 'assignment', 'children': ['265', '270']}, {'id': '265', 'type': 'subscript', 'children': ['266', '269']}; {'id': '266', 'type': 'attribute', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'acknowledgement'}, {'id': '269', 'type': 'string', 'children': [], 'value': "'ref'"}; {'id': '270', 'type': 'attribute', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'uuid'}, {'id': '273', 'type': 'expression_statement', 'children': ['274']}; {'id': '274', 'type': 'assignment', 'children': ['275', '278']}, {'id': '275', 'type': 'attribute', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'acknowledgement'}; {'id': '278', 'type': 'call', 'children': ['279', '280']}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'Acknowledge'}; {'id': '280', 'type': 'argument_list', 'children': ['281']}, {'id': '281', 'type': 'attribute', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'acknowledgement'}; {'id': '284', 'type': 'expression_statement', 'children': ['285']}, {'id': '285', 'type': 'assignment', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'new_notified_contacts'}, {'id': '287', 'type': 'call', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '289', 'type': 'argument_list', 'children': []}; {'id': '290', 'type': 'expression_statement', 'children': ['291']}, {'id': '291', 'type': 'assignment', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'new_notified_contacts_ids'}, {'id': '293', 'type': 'call', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '295', 'type': 'argument_list', 'children': []}; {'id': '296', 'type': 'for_statement', 'children': ['297', '298', '301']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'contact_name'}; {'id': '298', 'type': 'attribute', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'notified_contacts'}, {'id': '301', 'type': 'block', 'children': ['302', '313']}; {'id': '302', 'type': 'expression_statement', 'children': ['303']}, {'id': '303', 'type': 'assignment', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'contact'}, {'id': '305', 'type': 'call', 'children': ['306', '311']}; {'id': '306', 'type': 'attribute', 'children': ['307', '310']}, {'id': '307', 'type': 'attribute', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'contacts'}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'find_by_name'}, {'id': '311', 'type': 'argument_list', 'children': ['312']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'contact_name'}, {'id': '313', 'type': 'if_statement', 'children': ['314', '317']}; {'id': '314', 'type': 'comparison_operator', 'children': ['315', '316'], 'value': 'is'}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'contact'}; {'id': '316', 'type': 'None', 'children': []}, {'id': '317', 'type': 'block', 'children': ['318', '325']}; {'id': '318', 'type': 'expression_statement', 'children': ['319']}, {'id': '319', 'type': 'call', 'children': ['320', '323']}; {'id': '320', 'type': 'attribute', 'children': ['321', '322']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'new_notified_contacts'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'add'}, {'id': '323', 'type': 'argument_list', 'children': ['324']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'contact_name'}, {'id': '325', 'type': 'expression_statement', 'children': ['326']}; {'id': '326', 'type': 'call', 'children': ['327', '330']}, {'id': '327', 'type': 'attribute', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'new_notified_contacts_ids'}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '330', 'type': 'argument_list', 'children': ['331']}, {'id': '331', 'type': 'attribute', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'contact'}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '334', 'type': 'expression_statement', 'children': ['335']}, {'id': '335', 'type': 'assignment', 'children': ['336', '339']}; {'id': '336', 'type': 'attribute', 'children': ['337', '338']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'notified_contacts'}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'new_notified_contacts'}; {'id': '340', 'type': 'expression_statement', 'children': ['341']}, {'id': '341', 'type': 'assignment', 'children': ['342', '345']}; {'id': '342', 'type': 'attribute', 'children': ['343', '344']}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'notified_contacts_ids'}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'new_notified_contacts_ids'} | def restore_retention_data_item(self, data, item):
properties = item.__class__.properties
properties.update(item.__class__.running_properties)
for prop, entry in list(properties.items()):
if not entry.retention:
continue
if prop not in data:
continue
restore_retention = entry.retention_restoration
if restore_retention:
setattr(item, prop, restore_retention(item, data[prop]))
else:
setattr(item, prop, data[prop])
for notification_uuid in item.notifications_in_progress:
notification = item.notifications_in_progress[notification_uuid]
notification['ref'] = item.uuid
my_notification = Notification(params=notification)
item.notifications_in_progress[notification_uuid] = my_notification
self.add(my_notification)
item.update_in_checking()
for downtime_uuid in data['downtimes']:
downtime = data['downtimes'][downtime_uuid]
downtime['ref'] = item.uuid
my_downtime = Downtime(params=downtime)
if downtime['comment_id']:
if downtime['comment_id'] not in data['comments']:
downtime['comment_id'] = ''
if 'uuid' in downtime['comment_id']:
data['comments'].append(downtime['comment_id'])
downtime['comment_id'] = downtime['comment_id']['uuid']
item.add_downtime(my_downtime)
for comment_uuid in data['comments']:
comment = data['comments'][comment_uuid]
comment['ref'] = item.uuid
item.add_comment(Comment(comment))
if item.acknowledgement is not None:
item.acknowledgement['ref'] = item.uuid
item.acknowledgement = Acknowledge(item.acknowledgement)
new_notified_contacts = set()
new_notified_contacts_ids = set()
for contact_name in item.notified_contacts:
contact = self.contacts.find_by_name(contact_name)
if contact is not None:
new_notified_contacts.add(contact_name)
new_notified_contacts_ids.add(contact.uuid)
item.notified_contacts = new_notified_contacts
item.notified_contacts_ids = new_notified_contacts_ids |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'fill_initial_broks'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'broker_name'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '23', '96', '117', '132', '140', '148', '176', '191', '206', '309', '327', '335', '350', '362', '368', '374', '385']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'broker_uuid'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18']}, {'id': '17', 'type': 'string', 'children': [], 'value': '"My brokers: %s"'}; {'id': '18', 'type': 'attribute', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'my_daemon'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'brokers'}, {'id': '23', 'type': 'for_statement', 'children': ['24', '25', '37', '69']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'broker_link'}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '36']}, {'id': '29', 'type': 'attribute', 'children': ['30', '35']}; {'id': '30', 'type': 'attribute', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'my_daemon'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'brokers'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '36', 'type': 'argument_list', 'children': []}, {'id': '37', 'type': 'block', 'children': ['38', '46']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '43', 'type': 'argument_list', 'children': ['44', '45']}; {'id': '44', 'type': 'string', 'children': [], 'value': '"Searching broker: %s"'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'broker_link'}; {'id': '46', 'type': 'if_statement', 'children': ['47', '52']}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': '=='}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'broker_name'}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'broker_link'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '52', 'type': 'block', 'children': ['53', '59', '68']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'broker_uuid'}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'broker_link'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'uuid'}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '64', 'type': 'argument_list', 'children': ['65', '66', '67']}, {'id': '65', 'type': 'string', 'children': [], 'value': '"Filling initial broks for: %s (%s)"'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'broker_name'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'broker_uuid'}; {'id': '68', 'type': 'break_statement', 'children': []}, {'id': '69', 'type': 'else_clause', 'children': ['70']}; {'id': '70', 'type': 'block', 'children': ['71', '94']}, {'id': '71', 'type': 'if_statement', 'children': ['72', '75', '84']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'pushed_conf'}, {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '81', 'type': 'argument_list', 'children': ['82', '83']}; {'id': '82', 'type': 'string', 'children': [], 'value': '"Requested initial broks for an unknown broker: %s"'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'broker_name'}; {'id': '84', 'type': 'else_clause', 'children': ['85']}, {'id': '85', 'type': 'block', 'children': ['86']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '91', 'type': 'argument_list', 'children': ['92', '93']}; {'id': '92', 'type': 'string', 'children': [], 'value': '"Requested initial broks for an unknown broker: %s"'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'broker_name'}; {'id': '94', 'type': 'return_statement', 'children': ['95']}, {'id': '95', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '96', 'type': 'if_statement', 'children': ['97', '106']}, {'id': '97', 'type': 'attribute', 'children': ['98', '105']}; {'id': '98', 'type': 'subscript', 'children': ['99', '104']}, {'id': '99', 'type': 'attribute', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'my_daemon'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'brokers'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'broker_uuid'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'initialized'}; {'id': '106', 'type': 'block', 'children': ['107', '115']}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'call', 'children': ['109', '112']}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '112', 'type': 'argument_list', 'children': ['113', '114']}, {'id': '113', 'type': 'string', 'children': [], 'value': '"The broker %s still got its initial broks..."'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'broker_name'}, {'id': '115', 'type': 'return_statement', 'children': ['116']}; {'id': '116', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'assignment', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'initial_broks_count'}; {'id': '120', 'type': 'call', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}, {'id': '123', 'type': 'attribute', 'children': ['124', '131']}; {'id': '124', 'type': 'subscript', 'children': ['125', '130']}, {'id': '125', 'type': 'attribute', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'my_daemon'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'brokers'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'broker_uuid'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'broks'}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'brok'}, {'id': '135', 'type': 'call', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'get_program_status_brok'}, {'id': '139', 'type': 'argument_list', 'children': []}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'call', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'add_brok'}, {'id': '145', 'type': 'argument_list', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'brok'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'broker_uuid'}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'assignment', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'initial_status_types'}, {'id': '151', 'type': 'tuple', 'children': ['152', '155', '158', '161', '164', '167', '170', '173']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'timeperiods'}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'commands'}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'contacts'}, {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'contactgroups'}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'hosts'}, {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'hostgroups'}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'servicegroups'}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'assignment', 'children': ['178', '183']}; {'id': '178', 'type': 'attribute', 'children': ['179', '182']}, {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'pushed_conf'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'skip_initial_broks'}, {'id': '183', 'type': 'call', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '185', 'type': 'argument_list', 'children': ['186', '189', '190']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'pushed_conf'}, {'id': '189', 'type': 'string', 'children': [], 'value': "'skip_initial_broks'"}; {'id': '190', 'type': 'False', 'children': []}, {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'call', 'children': ['193', '196']}, {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '196', 'type': 'argument_list', 'children': ['197', '198']}, {'id': '197', 'type': 'string', 'children': [], 'value': '"Skipping initial broks? %s"'}; {'id': '198', 'type': 'call', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '200', 'type': 'argument_list', 'children': ['201']}, {'id': '201', 'type': 'attribute', 'children': ['202', '205']}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'pushed_conf'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'skip_initial_broks'}; {'id': '206', 'type': 'if_statement', 'children': ['207', '213']}, {'id': '207', 'type': 'not_operator', 'children': ['208']}; {'id': '208', 'type': 'attribute', 'children': ['209', '212']}, {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'pushed_conf'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'skip_initial_broks'}, {'id': '213', 'type': 'block', 'children': ['214', '257']}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}, {'id': '215', 'type': 'assignment', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'initial_status_types'}, {'id': '217', 'type': 'tuple', 'children': ['218', '221', '224', '227', '230', '233', '236', '239', '242', '245', '248', '251', '254']}; {'id': '218', 'type': 'attribute', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'realms'}, {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'timeperiods'}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'commands'}, {'id': '227', 'type': 'attribute', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'notificationways'}; {'id': '230', 'type': 'attribute', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'contacts'}, {'id': '233', 'type': 'attribute', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'contactgroups'}; {'id': '236', 'type': 'attribute', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'hosts'}, {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'hostgroups'}; {'id': '242', 'type': 'attribute', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'hostdependencies'}, {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '248', 'type': 'attribute', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'servicegroups'}, {'id': '251', 'type': 'attribute', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'servicedependencies'}; {'id': '254', 'type': 'attribute', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'escalations'}, {'id': '257', 'type': 'for_statement', 'children': ['258', '259', '260']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'tab'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'initial_status_types'}; {'id': '260', 'type': 'block', 'children': ['261']}, {'id': '261', 'type': 'for_statement', 'children': ['262', '263', '264']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'tab'}; {'id': '264', 'type': 'block', 'children': ['265', '269', '292', '301']}, {'id': '265', 'type': 'expression_statement', 'children': ['266']}; {'id': '266', 'type': 'assignment', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'member_items'}; {'id': '268', 'type': 'None', 'children': []}, {'id': '269', 'type': 'if_statement', 'children': ['270', '275']}; {'id': '270', 'type': 'call', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '272', 'type': 'argument_list', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '274', 'type': 'string', 'children': [], 'value': "'members'"}, {'id': '275', 'type': 'block', 'children': ['276']}; {'id': '276', 'type': 'expression_statement', 'children': ['277']}, {'id': '277', 'type': 'assignment', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'member_items'}, {'id': '279', 'type': 'call', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '281', 'type': 'argument_list', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '283', 'type': 'call', 'children': ['284', '289']}; {'id': '284', 'type': 'attribute', 'children': ['285', '288']}, {'id': '285', 'type': 'attribute', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'my_type'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'replace'}, {'id': '289', 'type': 'argument_list', 'children': ['290', '291']}; {'id': '290', 'type': 'string', 'children': [], 'value': '"group"'}, {'id': '291', 'type': 'string', 'children': [], 'value': '"s"'}; {'id': '292', 'type': 'expression_statement', 'children': ['293']}, {'id': '293', 'type': 'assignment', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'brok'}, {'id': '295', 'type': 'call', 'children': ['296', '299']}; {'id': '296', 'type': 'attribute', 'children': ['297', '298']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'get_initial_status_brok'}, {'id': '299', 'type': 'argument_list', 'children': ['300']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'member_items'}, {'id': '301', 'type': 'expression_statement', 'children': ['302']}; {'id': '302', 'type': 'call', 'children': ['303', '306']}, {'id': '303', 'type': 'attribute', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'add_brok'}; {'id': '306', 'type': 'argument_list', 'children': ['307', '308']}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'brok'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'broker_uuid'}, {'id': '309', 'type': 'expression_statement', 'children': ['310']}; {'id': '310', 'type': 'assignment', 'children': ['311', '312']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'brok'}; {'id': '312', 'type': 'call', 'children': ['313', '314']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'Brok'}; {'id': '314', 'type': 'argument_list', 'children': ['315']}, {'id': '315', 'type': 'dictionary', 'children': ['316', '319']}; {'id': '316', 'type': 'pair', 'children': ['317', '318']}, {'id': '317', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '318', 'type': 'string', 'children': [], 'value': "'initial_broks_done'"}, {'id': '319', 'type': 'pair', 'children': ['320', '321']}; {'id': '320', 'type': 'string', 'children': [], 'value': "'data'"}, {'id': '321', 'type': 'dictionary', 'children': ['322']}; {'id': '322', 'type': 'pair', 'children': ['323', '324']}, {'id': '323', 'type': 'string', 'children': [], 'value': "'instance_id'"}; {'id': '324', 'type': 'attribute', 'children': ['325', '326']}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'instance_id'}, {'id': '327', 'type': 'expression_statement', 'children': ['328']}; {'id': '328', 'type': 'call', 'children': ['329', '332']}, {'id': '329', 'type': 'attribute', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'add_brok'}; {'id': '332', 'type': 'argument_list', 'children': ['333', '334']}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'brok'}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'broker_uuid'}, {'id': '335', 'type': 'expression_statement', 'children': ['336']}; {'id': '336', 'type': 'assignment', 'children': ['337', '338']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'final_broks_count'}; {'id': '338', 'type': 'call', 'children': ['339', '340']}, {'id': '339', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '340', 'type': 'argument_list', 'children': ['341']}, {'id': '341', 'type': 'attribute', 'children': ['342', '349']}; {'id': '342', 'type': 'subscript', 'children': ['343', '348']}, {'id': '343', 'type': 'attribute', 'children': ['344', '347']}; {'id': '344', 'type': 'attribute', 'children': ['345', '346']}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'my_daemon'}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'brokers'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'broker_uuid'}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'broks'}; {'id': '350', 'type': 'expression_statement', 'children': ['351']}, {'id': '351', 'type': 'assignment', 'children': ['352', '361']}; {'id': '352', 'type': 'attribute', 'children': ['353', '360']}, {'id': '353', 'type': 'subscript', 'children': ['354', '359']}; {'id': '354', 'type': 'attribute', 'children': ['355', '358']}, {'id': '355', 'type': 'attribute', 'children': ['356', '357']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'my_daemon'}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'brokers'}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'broker_uuid'}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'initialized'}, {'id': '361', 'type': 'True', 'children': []}; {'id': '362', 'type': 'expression_statement', 'children': ['363']}, {'id': '363', 'type': 'call', 'children': ['364', '367']}; {'id': '364', 'type': 'attribute', 'children': ['365', '366']}, {'id': '365', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'send_broks_to_modules'}, {'id': '367', 'type': 'argument_list', 'children': []}; {'id': '368', 'type': 'expression_statement', 'children': ['369']}, {'id': '369', 'type': 'assignment', 'children': ['370', '373']}; {'id': '370', 'type': 'attribute', 'children': ['371', '372']}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'raised_initial_broks'}, {'id': '373', 'type': 'True', 'children': []}; {'id': '374', 'type': 'expression_statement', 'children': ['375']}, {'id': '375', 'type': 'call', 'children': ['376', '379']}; {'id': '376', 'type': 'attribute', 'children': ['377', '378']}, {'id': '377', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '379', 'type': 'argument_list', 'children': ['380', '381', '384']}; {'id': '380', 'type': 'string', 'children': [], 'value': '"Created %d initial broks for %s"'}, {'id': '381', 'type': 'binary_operator', 'children': ['382', '383'], 'value': '-'}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'final_broks_count'}, {'id': '383', 'type': 'identifier', 'children': [], 'value': 'initial_broks_count'}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'broker_name'}, {'id': '385', 'type': 'return_statement', 'children': ['386']}; {'id': '386', 'type': 'binary_operator', 'children': ['387', '388'], 'value': '-'}, {'id': '387', 'type': 'identifier', 'children': [], 'value': 'final_broks_count'} | def fill_initial_broks(self, broker_name):
broker_uuid = None
logger.debug("My brokers: %s", self.my_daemon.brokers)
for broker_link in list(self.my_daemon.brokers.values()):
logger.debug("Searching broker: %s", broker_link)
if broker_name == broker_link.name:
broker_uuid = broker_link.uuid
logger.info("Filling initial broks for: %s (%s)", broker_name, broker_uuid)
break
else:
if self.pushed_conf:
logger.error("Requested initial broks for an unknown broker: %s", broker_name)
else:
logger.info("Requested initial broks for an unknown broker: %s", broker_name)
return 0
if self.my_daemon.brokers[broker_uuid].initialized:
logger.warning("The broker %s still got its initial broks...", broker_name)
return 0
initial_broks_count = len(self.my_daemon.brokers[broker_uuid].broks)
brok = self.get_program_status_brok()
self.add_brok(brok, broker_uuid)
initial_status_types = (self.timeperiods, self.commands,
self.contacts, self.contactgroups,
self.hosts, self.hostgroups,
self.services, self.servicegroups)
self.pushed_conf.skip_initial_broks = getattr(self.pushed_conf, 'skip_initial_broks', False)
logger.debug("Skipping initial broks? %s", str(self.pushed_conf.skip_initial_broks))
if not self.pushed_conf.skip_initial_broks:
initial_status_types = (self.realms, self.timeperiods, self.commands,
self.notificationways, self.contacts, self.contactgroups,
self.hosts, self.hostgroups, self.hostdependencies,
self.services, self.servicegroups, self.servicedependencies,
self.escalations)
for tab in initial_status_types:
for item in tab:
member_items = None
if hasattr(item, 'members'):
member_items = getattr(self, item.my_type.replace("group", "s"))
brok = item.get_initial_status_brok(member_items)
self.add_brok(brok, broker_uuid)
brok = Brok({'type': 'initial_broks_done', 'data': {'instance_id': self.instance_id}})
self.add_brok(brok, broker_uuid)
final_broks_count = len(self.my_daemon.brokers[broker_uuid].broks)
self.my_daemon.brokers[broker_uuid].initialized = True
self.send_broks_to_modules()
self.raised_initial_broks = True
logger.info("Created %d initial broks for %s",
final_broks_count - initial_broks_count, broker_name)
return final_broks_count - initial_broks_count |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'consume_results'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '16', '36', '162', '166']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'queue_size'}, {'id': '9', 'type': 'call', 'children': ['10', '15']}; {'id': '10', 'type': 'attribute', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'waiting_results'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'qsize'}, {'id': '15', 'type': 'argument_list', 'children': []}; {'id': '16', 'type': 'for_statement', 'children': ['17', '18', '22']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'queue_size'}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'manage_results'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'call', 'children': ['30', '35']}; {'id': '30', 'type': 'attribute', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'waiting_results'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '35', 'type': 'argument_list', 'children': []}; {'id': '36', 'type': 'for_statement', 'children': ['37', '38', '48']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'chk'}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'call', 'children': ['42', '47']}; {'id': '42', 'type': 'attribute', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'checks'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '47', 'type': 'argument_list', 'children': []}; {'id': '48', 'type': 'block', 'children': ['49']}, {'id': '49', 'type': 'if_statement', 'children': ['50', '55']}; {'id': '50', 'type': 'comparison_operator', 'children': ['51', '54'], 'value': '=='}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'chk'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'ACT_STATUS_WAIT_CONSUME'}, {'id': '55', 'type': 'block', 'children': ['56', '64', '75', '79', '99', '143']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '61', 'type': 'argument_list', 'children': ['62', '63']}; {'id': '62', 'type': 'string', 'children': [], 'value': '"Consuming: %s"'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'chk'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'find_item_by_id'}, {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'chk'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'ref'}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'notification_period'}; {'id': '78', 'type': 'None', 'children': []}, {'id': '79', 'type': 'if_statement', 'children': ['80', '88']}; {'id': '80', 'type': 'comparison_operator', 'children': ['81', '87'], 'value': 'is'}, {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '83', 'type': 'argument_list', 'children': ['84', '85', '86']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '85', 'type': 'string', 'children': [], 'value': "'notification_period'"}; {'id': '86', 'type': 'None', 'children': []}, {'id': '87', 'type': 'None', 'children': []}; {'id': '88', 'type': 'block', 'children': ['89']}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'notification_period'}; {'id': '92', 'type': 'subscript', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'timeperiods'}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'notification_period'}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'dep_checks'}; {'id': '102', 'type': 'call', 'children': ['103', '106']}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'consume_result'}; {'id': '106', 'type': 'argument_list', 'children': ['107', '108', '109', '112', '115', '118', '121', '124', '127', '130', '133']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'chk'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'notification_period'}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'hosts'}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'timeperiods'}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'macromodulations'}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'checkmodulations'}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'businessimpactmodulations'}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'resultmodulations'}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'checks'}, {'id': '133', 'type': 'boolean_operator', 'children': ['134', '139'], 'value': 'and'}; {'id': '134', 'type': 'attribute', 'children': ['135', '138']}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'pushed_conf'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'log_active_checks'}, {'id': '139', 'type': 'not_operator', 'children': ['140']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'chk'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'passive_check'}, {'id': '143', 'type': 'for_statement', 'children': ['144', '145', '146']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'check'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'dep_checks'}; {'id': '146', 'type': 'block', 'children': ['147', '155']}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'call', 'children': ['149', '152']}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '152', 'type': 'argument_list', 'children': ['153', '154']}, {'id': '153', 'type': 'string', 'children': [], 'value': '"-> raised a dependency check: %s"'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'chk'}, {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'call', 'children': ['157', '160']}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '160', 'type': 'argument_list', 'children': ['161']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'check'}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}, {'id': '163', 'type': 'assignment', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'have_resolved_checks'}, {'id': '165', 'type': 'True', 'children': []}; {'id': '166', 'type': 'while_statement', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'have_resolved_checks'}; {'id': '168', 'type': 'block', 'children': ['169', '173', '220']}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'have_resolved_checks'}; {'id': '172', 'type': 'False', 'children': []}, {'id': '173', 'type': 'for_statement', 'children': ['174', '175', '185']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'chk'}, {'id': '175', 'type': 'call', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '177', 'type': 'argument_list', 'children': ['178']}; {'id': '178', 'type': 'call', 'children': ['179', '184']}, {'id': '179', 'type': 'attribute', 'children': ['180', '183']}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'checks'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '184', 'type': 'argument_list', 'children': []}, {'id': '185', 'type': 'block', 'children': ['186']}; {'id': '186', 'type': 'if_statement', 'children': ['187', '192']}, {'id': '187', 'type': 'comparison_operator', 'children': ['188', '191'], 'value': '=='}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'chk'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'status'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'ACT_STATUS_WAITING_ME'}; {'id': '192', 'type': 'block', 'children': ['193', '214']}, {'id': '193', 'type': 'for_statement', 'children': ['194', '195', '198']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'dependent_checks'}, {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'chk'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'depend_on_me'}; {'id': '198', 'type': 'block', 'children': ['199', '210']}, {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'call', 'children': ['201', '206']}, {'id': '201', 'type': 'attribute', 'children': ['202', '205']}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'dependent_checks'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'depend_on'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '206', 'type': 'argument_list', 'children': ['207']}, {'id': '207', 'type': 'attribute', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'chk'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}, {'id': '211', 'type': 'assignment', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'have_resolved_checks'}, {'id': '213', 'type': 'True', 'children': []}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}, {'id': '215', 'type': 'assignment', 'children': ['216', '219']}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'chk'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'status'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'ACT_STATUS_ZOMBIE'}; {'id': '220', 'type': 'for_statement', 'children': ['221', '222', '232']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'chk'}; {'id': '222', 'type': 'call', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '224', 'type': 'argument_list', 'children': ['225']}, {'id': '225', 'type': 'call', 'children': ['226', '231']}; {'id': '226', 'type': 'attribute', 'children': ['227', '230']}, {'id': '227', 'type': 'attribute', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'checks'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '231', 'type': 'argument_list', 'children': []}; {'id': '232', 'type': 'block', 'children': ['233']}, {'id': '233', 'type': 'if_statement', 'children': ['234', '244']}; {'id': '234', 'type': 'boolean_operator', 'children': ['235', '240'], 'value': 'and'}, {'id': '235', 'type': 'comparison_operator', 'children': ['236', '239'], 'value': '=='}; {'id': '236', 'type': 'attribute', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'chk'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'status'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'ACT_STATUS_WAIT_DEPEND'}; {'id': '240', 'type': 'not_operator', 'children': ['241']}, {'id': '241', 'type': 'attribute', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'chk'}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'depend_on'}; {'id': '244', 'type': 'block', 'children': ['245', '256', '260', '280', '324']}, {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'assignment', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '248', 'type': 'call', 'children': ['249', '252']}, {'id': '249', 'type': 'attribute', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'find_item_by_id'}; {'id': '252', 'type': 'argument_list', 'children': ['253']}, {'id': '253', 'type': 'attribute', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'chk'}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'ref'}; {'id': '256', 'type': 'expression_statement', 'children': ['257']}, {'id': '257', 'type': 'assignment', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'notification_period'}, {'id': '259', 'type': 'None', 'children': []}; {'id': '260', 'type': 'if_statement', 'children': ['261', '269']}, {'id': '261', 'type': 'comparison_operator', 'children': ['262', '268'], 'value': 'is'}; {'id': '262', 'type': 'call', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '264', 'type': 'argument_list', 'children': ['265', '266', '267']}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '266', 'type': 'string', 'children': [], 'value': "'notification_period'"}, {'id': '267', 'type': 'None', 'children': []}; {'id': '268', 'type': 'None', 'children': []}, {'id': '269', 'type': 'block', 'children': ['270']}; {'id': '270', 'type': 'expression_statement', 'children': ['271']}, {'id': '271', 'type': 'assignment', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'notification_period'}, {'id': '273', 'type': 'subscript', 'children': ['274', '277']}; {'id': '274', 'type': 'attribute', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'timeperiods'}, {'id': '277', 'type': 'attribute', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'notification_period'}; {'id': '280', 'type': 'expression_statement', 'children': ['281']}, {'id': '281', 'type': 'assignment', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'dep_checks'}, {'id': '283', 'type': 'call', 'children': ['284', '287']}; {'id': '284', 'type': 'attribute', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'consume_result'}, {'id': '287', 'type': 'argument_list', 'children': ['288', '289', '290', '293', '296', '299', '302', '305', '308', '311', '314']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'chk'}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'notification_period'}; {'id': '290', 'type': 'attribute', 'children': ['291', '292']}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'hosts'}, {'id': '293', 'type': 'attribute', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '296', 'type': 'attribute', 'children': ['297', '298']}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'timeperiods'}, {'id': '299', 'type': 'attribute', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'macromodulations'}; {'id': '302', 'type': 'attribute', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'checkmodulations'}, {'id': '305', 'type': 'attribute', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'businessimpactmodulations'}; {'id': '308', 'type': 'attribute', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'resultmodulations'}, {'id': '311', 'type': 'attribute', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'checks'}; {'id': '314', 'type': 'boolean_operator', 'children': ['315', '320'], 'value': 'and'}, {'id': '315', 'type': 'attribute', 'children': ['316', '319']}; {'id': '316', 'type': 'attribute', 'children': ['317', '318']}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'pushed_conf'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'log_active_checks'}; {'id': '320', 'type': 'not_operator', 'children': ['321']}, {'id': '321', 'type': 'attribute', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'chk'}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'passive_check'}; {'id': '324', 'type': 'for_statement', 'children': ['325', '326', '327']}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'check'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'dep_checks'}, {'id': '327', 'type': 'block', 'children': ['328']}; {'id': '328', 'type': 'expression_statement', 'children': ['329']}, {'id': '329', 'type': 'call', 'children': ['330', '333']}; {'id': '330', 'type': 'attribute', 'children': ['331', '332']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'add'}, {'id': '333', 'type': 'argument_list', 'children': ['334']} | def consume_results(self):
queue_size = self.waiting_results.qsize()
for _ in range(queue_size):
self.manage_results(self.waiting_results.get())
for chk in list(self.checks.values()):
if chk.status == ACT_STATUS_WAIT_CONSUME:
logger.debug("Consuming: %s", chk)
item = self.find_item_by_id(chk.ref)
notification_period = None
if getattr(item, 'notification_period', None) is not None:
notification_period = self.timeperiods[item.notification_period]
dep_checks = item.consume_result(chk, notification_period, self.hosts,
self.services, self.timeperiods,
self.macromodulations, self.checkmodulations,
self.businessimpactmodulations,
self.resultmodulations, self.checks,
self.pushed_conf.log_active_checks and
not chk.passive_check)
for check in dep_checks:
logger.debug("-> raised a dependency check: %s", chk)
self.add(check)
have_resolved_checks = True
while have_resolved_checks:
have_resolved_checks = False
for chk in list(self.checks.values()):
if chk.status == ACT_STATUS_WAITING_ME:
for dependent_checks in chk.depend_on_me:
dependent_checks.depend_on.remove(chk.uuid)
have_resolved_checks = True
chk.status = ACT_STATUS_ZOMBIE
for chk in list(self.checks.values()):
if chk.status == ACT_STATUS_WAIT_DEPEND and not chk.depend_on:
item = self.find_item_by_id(chk.ref)
notification_period = None
if getattr(item, 'notification_period', None) is not None:
notification_period = self.timeperiods[item.notification_period]
dep_checks = item.consume_result(chk, notification_period, self.hosts,
self.services, self.timeperiods,
self.macromodulations, self.checkmodulations,
self.businessimpactmodulations,
self.resultmodulations, self.checks,
self.pushed_conf.log_active_checks and
not chk.passive_check)
for check in dep_checks:
self.add(check) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'send_broks_to_modules'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '14', '18', '22', '65', '70', '81', '143', '185']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 't00'}, {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '13', 'type': 'argument_list', 'children': []}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'nb_sent'}, {'id': '17', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'broks'}, {'id': '21', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '22', 'type': 'for_statement', 'children': ['23', '24', '36']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'broker_link'}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'call', 'children': ['28', '35']}; {'id': '28', 'type': 'attribute', 'children': ['29', '34']}, {'id': '29', 'type': 'attribute', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'my_daemon'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'brokers'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '35', 'type': 'argument_list', 'children': []}; {'id': '36', 'type': 'block', 'children': ['37']}, {'id': '37', 'type': 'for_statement', 'children': ['38', '39', '42']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'brok'}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'broker_link'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'broks'}; {'id': '42', 'type': 'block', 'children': ['43']}, {'id': '43', 'type': 'if_statement', 'children': ['44', '51']}; {'id': '44', 'type': 'not_operator', 'children': ['45']}, {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '47', 'type': 'argument_list', 'children': ['48', '49', '50']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'brok'}, {'id': '49', 'type': 'string', 'children': [], 'value': "'sent_to_externals'"}; {'id': '50', 'type': 'False', 'children': []}, {'id': '51', 'type': 'block', 'children': ['52', '58']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'brok'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'to_send'}, {'id': '57', 'type': 'True', 'children': []}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'broks'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'brok'}, {'id': '65', 'type': 'if_statement', 'children': ['66', '68']}; {'id': '66', 'type': 'not_operator', 'children': ['67']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'broks'}; {'id': '68', 'type': 'block', 'children': ['69']}, {'id': '69', 'type': 'return_statement', 'children': []}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '75', 'type': 'argument_list', 'children': ['76', '77']}; {'id': '76', 'type': 'string', 'children': [], 'value': '"sending %d broks to modules..."'}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'broks'}, {'id': '81', 'type': 'for_statement', 'children': ['82', '83', '92']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'mod'}, {'id': '83', 'type': 'call', 'children': ['84', '91']}; {'id': '84', 'type': 'attribute', 'children': ['85', '90']}, {'id': '85', 'type': 'attribute', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'my_daemon'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'modules_manager'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'get_external_instances'}, {'id': '91', 'type': 'argument_list', 'children': []}; {'id': '92', 'type': 'block', 'children': ['93', '105', '111']}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'call', 'children': ['95', '98']}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '98', 'type': 'argument_list', 'children': ['99', '100']}, {'id': '99', 'type': 'string', 'children': [], 'value': '"Look for sending to module %s"'}; {'id': '100', 'type': 'call', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'mod'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'get_name'}; {'id': '104', 'type': 'argument_list', 'children': []}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'module_queue'}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'mod'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'to_q'}, {'id': '111', 'type': 'if_statement', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'module_queue'}, {'id': '113', 'type': 'block', 'children': ['114', '129', '136']}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'to_send'}, {'id': '117', 'type': 'list_comprehension', 'children': ['118', '119', '122']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '119', 'type': 'for_in_clause', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'broks'}; {'id': '122', 'type': 'if_clause', 'children': ['123']}, {'id': '123', 'type': 'call', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'mod'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'want_brok'}, {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'b'}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'call', 'children': ['131', '134']}, {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'module_queue'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'put'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'to_send'}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'id': '137', 'type': 'augmented_assignment', 'children': ['138', '139'], 'value': '+='}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'nb_sent'}, {'id': '139', 'type': 'call', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'to_send'}, {'id': '143', 'type': 'for_statement', 'children': ['144', '145', '157']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'broker_link'}, {'id': '145', 'type': 'call', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'call', 'children': ['149', '156']}, {'id': '149', 'type': 'attribute', 'children': ['150', '155']}; {'id': '150', 'type': 'attribute', 'children': ['151', '154']}, {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'my_daemon'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'brokers'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '156', 'type': 'argument_list', 'children': []}, {'id': '157', 'type': 'block', 'children': ['158']}; {'id': '158', 'type': 'for_statement', 'children': ['159', '160', '163']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'brok'}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'broker_link'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'broks'}, {'id': '163', 'type': 'block', 'children': ['164']}; {'id': '164', 'type': 'if_statement', 'children': ['165', '172']}, {'id': '165', 'type': 'not_operator', 'children': ['166']}; {'id': '166', 'type': 'call', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '168', 'type': 'argument_list', 'children': ['169', '170', '171']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'brok'}; {'id': '170', 'type': 'string', 'children': [], 'value': "'sent_to_externals'"}, {'id': '171', 'type': 'False', 'children': []}; {'id': '172', 'type': 'block', 'children': ['173', '179']}, {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'assignment', 'children': ['175', '178']}, {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'brok'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'to_send'}; {'id': '178', 'type': 'False', 'children': []}, {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '184']}, {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'brok'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'sent_to_externals'}; {'id': '184', 'type': 'True', 'children': []}, {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'call', 'children': ['187', '190']}, {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '190', 'type': 'argument_list', 'children': ['191', '192', '193']}, {'id': '191', 'type': 'string', 'children': [], 'value': '"Time to send %d broks (after %d secs)"'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'nb_sent'}, {'id': '193', 'type': 'binary_operator', 'children': ['194', '199'], 'value': '-'}; {'id': '194', 'type': 'call', 'children': ['195', '198']}, {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '198', 'type': 'argument_list', 'children': []}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 't00'} | def send_broks_to_modules(self):
t00 = time.time()
nb_sent = 0
broks = []
for broker_link in list(self.my_daemon.brokers.values()):
for brok in broker_link.broks:
if not getattr(brok, 'sent_to_externals', False):
brok.to_send = True
broks.append(brok)
if not broks:
return
logger.debug("sending %d broks to modules...", len(broks))
for mod in self.my_daemon.modules_manager.get_external_instances():
logger.debug("Look for sending to module %s", mod.get_name())
module_queue = mod.to_q
if module_queue:
to_send = [b for b in broks if mod.want_brok(b)]
module_queue.put(to_send)
nb_sent += len(to_send)
for broker_link in list(self.my_daemon.brokers.values()):
for brok in broker_link.broks:
if not getattr(brok, 'sent_to_externals', False):
brok.to_send = False
brok.sent_to_externals = True
logger.debug("Time to send %d broks (after %d secs)", nb_sent, time.time() - t00) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'push_external_commands_to_schedulers'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '13', '19', '25', '33', '44', '96', '100', '104', '271', '279']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '11']}, {'id': '7', 'type': 'not_operator', 'children': ['8']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'unprocessed_external_commands'}, {'id': '11', 'type': 'block', 'children': ['12']}; {'id': '12', 'type': 'return_statement', 'children': []}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'commands_to_process'}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'unprocessed_external_commands'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '24']}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'unprocessed_external_commands'}; {'id': '24', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}, {'id': '31', 'type': 'string', 'children': [], 'value': '"Commands: %s"'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'commands_to_process'}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '40']}, {'id': '39', 'type': 'string', 'children': [], 'value': '"Commands to process: %d commands"'}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'commands_to_process'}; {'id': '44', 'type': 'for_statement', 'children': ['45', '46', '47']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'ext_cmd'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'commands_to_process'}, {'id': '47', 'type': 'block', 'children': ['48', '59', '70']}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}, {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '51', 'type': 'call', 'children': ['52', '57']}; {'id': '52', 'type': 'attribute', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'external_commands_manager'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'resolve_command'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'ext_cmd'}, {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '64', 'type': 'argument_list', 'children': ['65', '66', '69']}, {'id': '65', 'type': 'string', 'children': [], 'value': '"Resolved command: %s, result: %s"'}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'ext_cmd'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'cmd_line'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '70', 'type': 'if_statement', 'children': ['71', '76']}, {'id': '71', 'type': 'boolean_operator', 'children': ['72', '73'], 'value': 'and'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '73', 'type': 'subscript', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '75', 'type': 'string', 'children': [], 'value': "'global'"}; {'id': '76', 'type': 'block', 'children': ['77']}, {'id': '77', 'type': 'for_statement', 'children': ['78', '79', '82']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'scheduler_link_uuid'}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'schedulers'}; {'id': '82', 'type': 'block', 'children': ['83']}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'call', 'children': ['85', '94']}, {'id': '85', 'type': 'attribute', 'children': ['86', '93']}; {'id': '86', 'type': 'attribute', 'children': ['87', '92']}, {'id': '87', 'type': 'subscript', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'schedulers'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'scheduler_link_uuid'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'pushed_commands'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'ext_cmd'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'count_pushed_commands'}, {'id': '99', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'count_failed_commands'}, {'id': '103', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '104', 'type': 'for_statement', 'children': ['105', '106', '109']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'scheduler_link_uuid'}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'schedulers'}, {'id': '109', 'type': 'block', 'children': ['110', '118', '137', '149', '164', '178', '182', '203', '209']}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'assignment', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'link'}, {'id': '113', 'type': 'subscript', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'schedulers'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'scheduler_link_uuid'}; {'id': '118', 'type': 'if_statement', 'children': ['119', '123']}, {'id': '119', 'type': 'not_operator', 'children': ['120']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'active'}, {'id': '123', 'type': 'block', 'children': ['124', '136']}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'call', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '129', 'type': 'argument_list', 'children': ['130', '133']}; {'id': '130', 'type': 'concatenated_string', 'children': ['131', '132']}, {'id': '131', 'type': 'string', 'children': [], 'value': '"The scheduler \'%s\' is not active, it is not possible to push "'}; {'id': '132', 'type': 'string', 'children': [], 'value': '"external commands to its connection!"'}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'link'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '136', 'type': 'continue_statement', 'children': []}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'assignment', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'commands'}; {'id': '140', 'type': 'list_comprehension', 'children': ['141', '144']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'ext_cmd'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'cmd_line'}; {'id': '144', 'type': 'for_in_clause', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'ext_cmd'}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'pushed_commands'}, {'id': '149', 'type': 'if_statement', 'children': ['150', '152']}; {'id': '150', 'type': 'not_operator', 'children': ['151']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'commands'}; {'id': '152', 'type': 'block', 'children': ['153', '163']}, {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'call', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '158', 'type': 'argument_list', 'children': ['159', '160']}, {'id': '159', 'type': 'string', 'children': [], 'value': '"The scheduler \'%s\' has no commands."'}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '163', 'type': 'continue_statement', 'children': []}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}, {'id': '165', 'type': 'call', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '169', 'type': 'argument_list', 'children': ['170', '171', '175']}; {'id': '170', 'type': 'string', 'children': [], 'value': '"Sending %d commands to scheduler %s"'}, {'id': '171', 'type': 'call', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'commands'}, {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'link'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}, {'id': '179', 'type': 'assignment', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'sent'}, {'id': '181', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '182', 'type': 'try_statement', 'children': ['183', '193']}, {'id': '183', 'type': 'block', 'children': ['184']}; {'id': '184', 'type': 'expression_statement', 'children': ['185']}, {'id': '185', 'type': 'assignment', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'sent'}, {'id': '187', 'type': 'call', 'children': ['188', '191']}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'push_external_commands'}, {'id': '191', 'type': 'argument_list', 'children': ['192']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'commands'}, {'id': '193', 'type': 'except_clause', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'LinkError'}, {'id': '195', 'type': 'block', 'children': ['196']}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'call', 'children': ['198', '201']}; {'id': '198', 'type': 'attribute', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '201', 'type': 'argument_list', 'children': ['202']}; {'id': '202', 'type': 'string', 'children': [], 'value': '"Scheduler connection failed, I could not push external commands!"'}, {'id': '203', 'type': 'expression_statement', 'children': ['204']}; {'id': '204', 'type': 'assignment', 'children': ['205', '208']}, {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'link'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'pushed_commands'}; {'id': '208', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '209', 'type': 'if_statement', 'children': ['210', '211', '236']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'sent'}, {'id': '211', 'type': 'block', 'children': ['212', '227']}; {'id': '212', 'type': 'expression_statement', 'children': ['213']}, {'id': '213', 'type': 'call', 'children': ['214', '217']}; {'id': '214', 'type': 'attribute', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'statsmgr'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'gauge'}, {'id': '217', 'type': 'argument_list', 'children': ['218', '223']}; {'id': '218', 'type': 'binary_operator', 'children': ['219', '220'], 'value': '%'}, {'id': '219', 'type': 'string', 'children': [], 'value': "'external-commands.pushed.%s'"}; {'id': '220', 'type': 'attribute', 'children': ['221', '222']}, {'id': '221', 'type': 'identifier', 'children': [], 'value': 'link'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '223', 'type': 'call', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '225', 'type': 'argument_list', 'children': ['226']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'commands'}, {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'assignment', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'count_pushed_commands'}; {'id': '230', 'type': 'binary_operator', 'children': ['231', '232'], 'value': '+'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'count_pushed_commands'}; {'id': '232', 'type': 'call', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '234', 'type': 'argument_list', 'children': ['235']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'commands'}; {'id': '236', 'type': 'else_clause', 'children': ['237']}, {'id': '237', 'type': 'block', 'children': ['238', '247', '262']}; {'id': '238', 'type': 'expression_statement', 'children': ['239']}, {'id': '239', 'type': 'assignment', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'count_failed_commands'}, {'id': '241', 'type': 'binary_operator', 'children': ['242', '243'], 'value': '+'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'count_failed_commands'}, {'id': '243', 'type': 'call', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '245', 'type': 'argument_list', 'children': ['246']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'commands'}, {'id': '247', 'type': 'expression_statement', 'children': ['248']}; {'id': '248', 'type': 'call', 'children': ['249', '252']}, {'id': '249', 'type': 'attribute', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'statsmgr'}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'gauge'}; {'id': '252', 'type': 'argument_list', 'children': ['253', '258']}, {'id': '253', 'type': 'binary_operator', 'children': ['254', '255'], 'value': '%'}; {'id': '254', 'type': 'string', 'children': [], 'value': "'external-commands.failed.%s'"}, {'id': '255', 'type': 'attribute', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'link'}, {'id': '257', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '258', 'type': 'call', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '260', 'type': 'argument_list', 'children': ['261']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'commands'}; {'id': '262', 'type': 'expression_statement', 'children': ['263']}, {'id': '263', 'type': 'call', 'children': ['264', '269']}; {'id': '264', 'type': 'attribute', 'children': ['265', '268']}, {'id': '265', 'type': 'attribute', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'external_commands'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '269', 'type': 'argument_list', 'children': ['270']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'commands'}, {'id': '271', 'type': 'expression_statement', 'children': ['272']}; {'id': '272', 'type': 'call', 'children': ['273', '276']}, {'id': '273', 'type': 'attribute', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'statsmgr'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'gauge'}; {'id': '276', 'type': 'argument_list', 'children': ['277', '278']}, {'id': '277', 'type': 'string', 'children': [], 'value': "'external-commands.pushed.all'"}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'count_pushed_commands'}, {'id': '279', 'type': 'expression_statement', 'children': ['280']}; {'id': '280', 'type': 'call', 'children': ['281', '284']}, {'id': '281', 'type': 'attribute', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'statsmgr'}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'gauge'}; {'id': '284', 'type': 'argument_list', 'children': ['285', '286']}, {'id': '285', 'type': 'string', 'children': [], 'value': "'external-commands.failed.all'"} | def push_external_commands_to_schedulers(self):
if not self.unprocessed_external_commands:
return
commands_to_process = self.unprocessed_external_commands
self.unprocessed_external_commands = []
logger.debug("Commands: %s", commands_to_process)
logger.debug("Commands to process: %d commands", len(commands_to_process))
for ext_cmd in commands_to_process:
cmd = self.external_commands_manager.resolve_command(ext_cmd)
logger.debug("Resolved command: %s, result: %s", ext_cmd.cmd_line, cmd)
if cmd and cmd['global']:
for scheduler_link_uuid in self.schedulers:
self.schedulers[scheduler_link_uuid].pushed_commands.append(ext_cmd)
count_pushed_commands = 0
count_failed_commands = 0
for scheduler_link_uuid in self.schedulers:
link = self.schedulers[scheduler_link_uuid]
if not link.active:
logger.debug("The scheduler '%s' is not active, it is not possible to push "
"external commands to its connection!", link.name)
continue
commands = [ext_cmd.cmd_line for ext_cmd in link.pushed_commands]
if not commands:
logger.debug("The scheduler '%s' has no commands.", link.name)
continue
logger.debug("Sending %d commands to scheduler %s", len(commands), link.name)
sent = []
try:
sent = link.push_external_commands(commands)
except LinkError:
logger.warning("Scheduler connection failed, I could not push external commands!")
link.pushed_commands = []
if sent:
statsmgr.gauge('external-commands.pushed.%s' % link.name, len(commands))
count_pushed_commands = count_pushed_commands + len(commands)
else:
count_failed_commands = count_failed_commands + len(commands)
statsmgr.gauge('external-commands.failed.%s' % link.name, len(commands))
self.external_commands.extend(commands)
statsmgr.gauge('external-commands.pushed.all', count_pushed_commands)
statsmgr.gauge('external-commands.failed.all', count_failed_commands) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_groupnames'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'hostgroups'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '34']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'group_names'}; {'id': '10', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '11', 'type': 'for_statement', 'children': ['12', '13', '16']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'hostgroup_id'}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'hostgroups'}; {'id': '16', 'type': 'block', 'children': ['17', '23']}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'hostgroup'}; {'id': '20', 'type': 'subscript', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'hostgroups'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'hostgroup_id'}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'group_names'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'hostgroup'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'get_name'}, {'id': '33', 'type': 'argument_list', 'children': []}; {'id': '34', 'type': 'return_statement', 'children': ['35']}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'string', 'children': [], 'value': "','"}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'group_names'} | def get_groupnames(self, hostgroups):
group_names = []
for hostgroup_id in self.hostgroups:
hostgroup = hostgroups[hostgroup_id]
group_names.append(hostgroup.get_name())
return ','.join(sorted(group_names)) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_groupaliases'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'hostgroups'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '32']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'group_aliases'}; {'id': '10', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '11', 'type': 'for_statement', 'children': ['12', '13', '16']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'hostgroup_id'}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'hostgroups'}; {'id': '16', 'type': 'block', 'children': ['17', '23']}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'hostgroup'}; {'id': '20', 'type': 'subscript', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'hostgroups'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'hostgroup_id'}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'group_aliases'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'hostgroup'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'alias'}; {'id': '32', 'type': 'return_statement', 'children': ['33']}, {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'string', 'children': [], 'value': "','"}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'group_aliases'} | def get_groupaliases(self, hostgroups):
group_aliases = []
for hostgroup_id in self.hostgroups:
hostgroup = hostgroups[hostgroup_id]
group_aliases.append(hostgroup.alias)
return ','.join(sorted(group_aliases)) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_overall_state'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '68', '107']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'overall_state'}; {'id': '10', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '11', 'type': 'if_statement', 'children': ['12', '16', '21', '30', '39']}; {'id': '12', 'type': 'not_operator', 'children': ['13']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'monitored'}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'overall_state'}; {'id': '20', 'type': 'integer', 'children': [], 'value': '5'}, {'id': '21', 'type': 'elif_clause', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'acknowledged'}, {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'overall_state'}, {'id': '29', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '30', 'type': 'elif_clause', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'downtimed'}; {'id': '34', 'type': 'block', 'children': ['35']}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'overall_state'}; {'id': '38', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '39', 'type': 'elif_clause', 'children': ['40', '45']}; {'id': '40', 'type': 'comparison_operator', 'children': ['41', '44'], 'value': '=='}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'state_type'}; {'id': '44', 'type': 'string', 'children': [], 'value': "'HARD'"}, {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'if_statement', 'children': ['47', '52', '57']}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '51'], 'value': '=='}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'state'}, {'id': '51', 'type': 'string', 'children': [], 'value': "'UNREACHABLE'"}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'overall_state'}; {'id': '56', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '57', 'type': 'elif_clause', 'children': ['58', '63']}; {'id': '58', 'type': 'comparison_operator', 'children': ['59', '62'], 'value': '=='}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '62', 'type': 'string', 'children': [], 'value': "'DOWN'"}, {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'overall_state'}, {'id': '67', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '68', 'type': 'if_statement', 'children': ['69', '72']}, {'id': '69', 'type': 'comparison_operator', 'children': ['70', '71'], 'value': '<='}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'overall_state'}, {'id': '71', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '72', 'type': 'block', 'children': ['73']}, {'id': '73', 'type': 'for_statement', 'children': ['74', '75', '78']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '78', 'type': 'block', 'children': ['79']}, {'id': '79', 'type': 'if_statement', 'children': ['80', '83']}; {'id': '80', 'type': 'comparison_operator', 'children': ['81', '82'], 'value': 'in'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '83', 'type': 'block', 'children': ['84', '90']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '87', 'type': 'subscript', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '90', 'type': 'if_statement', 'children': ['91', '96']}, {'id': '91', 'type': 'comparison_operator', 'children': ['92', '95'], 'value': '<'}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'overall_state_id'}, {'id': '95', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '96', 'type': 'block', 'children': ['97']}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'overall_state'}; {'id': '100', 'type': 'call', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '102', 'type': 'argument_list', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'overall_state'}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'overall_state_id'}, {'id': '107', 'type': 'return_statement', 'children': ['108']} | def get_overall_state(self, services):
overall_state = 0
if not self.monitored:
overall_state = 5
elif self.acknowledged:
overall_state = 1
elif self.downtimed:
overall_state = 2
elif self.state_type == 'HARD':
if self.state == 'UNREACHABLE':
overall_state = 3
elif self.state == 'DOWN':
overall_state = 4
if overall_state <= 2:
for service in self.services:
if service in services:
service = services[service]
if service.overall_state_id < 5:
overall_state = max(overall_state, service.overall_state_id)
return overall_state |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'do_loop_turn'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '154']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '11']}, {'id': '7', 'type': 'not_operator', 'children': ['8']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'first_scheduling'}, {'id': '11', 'type': 'block', 'children': ['12', '19', '27', '35', '43', '57', '64', '102', '140', '148']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'string', 'children': [], 'value': '"First scheduling launched"'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': '_t0'}; {'id': '22', 'type': 'call', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '26', 'type': 'argument_list', 'children': []}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '34']}, {'id': '29', 'type': 'attribute', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'sched'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'initial_program_status'}; {'id': '34', 'type': 'argument_list', 'children': []}, {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '42']}, {'id': '37', 'type': 'attribute', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'sched'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'schedule'}; {'id': '42', 'type': 'argument_list', 'children': []}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'call', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'statsmgr'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'timer'}; {'id': '48', 'type': 'argument_list', 'children': ['49', '50']}, {'id': '49', 'type': 'string', 'children': [], 'value': "'first_scheduling'"}; {'id': '50', 'type': 'binary_operator', 'children': ['51', '56'], 'value': '-'}, {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '55', 'type': 'argument_list', 'children': []}; {'id': '56', 'type': 'identifier', 'children': [], 'value': '_t0'}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'string', 'children': [], 'value': '"First scheduling done"'}; {'id': '64', 'type': 'for_statement', 'children': ['65', '66', '84']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'satellite'}; {'id': '66', 'type': 'list_comprehension', 'children': ['67', '68', '80']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '68', 'type': 'for_in_clause', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'call', 'children': ['74', '79']}; {'id': '74', 'type': 'attribute', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'pollers'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '79', 'type': 'argument_list', 'children': []}; {'id': '80', 'type': 'if_clause', 'children': ['81']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'passive'}; {'id': '84', 'type': 'block', 'children': ['85']}, {'id': '85', 'type': 'if_statement', 'children': ['86', '93']}; {'id': '86', 'type': 'not_operator', 'children': ['87']}, {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'daemon_connection_init'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'satellite'}, {'id': '93', 'type': 'block', 'children': ['94']}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '99', 'type': 'argument_list', 'children': ['100', '101']}; {'id': '100', 'type': 'string', 'children': [], 'value': '"Passive satellite connection failed: %s"'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'satellite'}; {'id': '102', 'type': 'for_statement', 'children': ['103', '104', '122']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'satellite'}; {'id': '104', 'type': 'list_comprehension', 'children': ['105', '106', '118']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '106', 'type': 'for_in_clause', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '108', 'type': 'call', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}, {'id': '111', 'type': 'call', 'children': ['112', '117']}; {'id': '112', 'type': 'attribute', 'children': ['113', '116']}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'reactionners'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '117', 'type': 'argument_list', 'children': []}; {'id': '118', 'type': 'if_clause', 'children': ['119']}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'passive'}; {'id': '122', 'type': 'block', 'children': ['123']}, {'id': '123', 'type': 'if_statement', 'children': ['124', '131']}; {'id': '124', 'type': 'not_operator', 'children': ['125']}, {'id': '125', 'type': 'call', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'daemon_connection_init'}, {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'satellite'}, {'id': '131', 'type': 'block', 'children': ['132']}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'call', 'children': ['134', '137']}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '137', 'type': 'argument_list', 'children': ['138', '139']}; {'id': '138', 'type': 'string', 'children': [], 'value': '"Passive satellite connection failed: %s"'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'satellite'}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'assignment', 'children': ['142', '147']}; {'id': '142', 'type': 'attribute', 'children': ['143', '146']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'sched'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'ticks'}, {'id': '147', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'assignment', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'first_scheduling'}, {'id': '153', 'type': 'True', 'children': []}; {'id': '154', 'type': 'if_statement', 'children': ['155', '160', '193']}, {'id': '155', 'type': 'attribute', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'sched'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'pushed_conf'}; {'id': '160', 'type': 'block', 'children': ['161', '185']}, {'id': '161', 'type': 'if_statement', 'children': ['162', '168']}; {'id': '162', 'type': 'not_operator', 'children': ['163']}, {'id': '163', 'type': 'attribute', 'children': ['164', '167']}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'sched'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'must_schedule'}; {'id': '168', 'type': 'block', 'children': ['169', '177']}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'call', 'children': ['171', '176']}, {'id': '171', 'type': 'attribute', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'sched'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'start_scheduling'}; {'id': '176', 'type': 'argument_list', 'children': []}, {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'call', 'children': ['179', '184']}, {'id': '179', 'type': 'attribute', 'children': ['180', '183']}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'sched'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'before_run'}; {'id': '184', 'type': 'argument_list', 'children': []}, {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'call', 'children': ['187', '192']}, {'id': '187', 'type': 'attribute', 'children': ['188', '191']}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'sched'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'run'}; {'id': '192', 'type': 'argument_list', 'children': []}, {'id': '193', 'type': 'else_clause', 'children': ['194', '201']}; {'id': '194', 'type': 'ERROR', 'children': ['195', '198']}, {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '198', 'type': 'attribute', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'loop_count'}, {'id': '201', 'type': 'block', 'children': [], 'value': ''} | def do_loop_turn(self):
if not self.first_scheduling:
logger.info("First scheduling launched")
_t0 = time.time()
self.sched.initial_program_status()
self.sched.schedule()
statsmgr.timer('first_scheduling', time.time() - _t0)
logger.info("First scheduling done")
for satellite in [s for s in list(self.pollers.values()) if s.passive]:
if not self.daemon_connection_init(satellite):
logger.error("Passive satellite connection failed: %s", satellite)
for satellite in [s for s in list(self.reactionners.values()) if s.passive]:
if not self.daemon_connection_init(satellite):
logger.error("Passive satellite connection failed: %s", satellite)
self.sched.ticks = 0
self.first_scheduling = True
if self.sched.pushed_conf:
if not self.sched.must_schedule:
self.sched.start_scheduling()
self.sched.before_run()
self.sched.run()
else:
logger.warning("
self.loop_count) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_failed_check_attempt'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'reason'}, {'id': '7', 'type': 'string', 'children': [], 'value': "''"}; {'id': '8', 'type': 'block', 'children': ['9', '15', '25', '42', '88']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'reachable'}; {'id': '14', 'type': 'False', 'children': []}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'attempt'}; {'id': '20', 'type': 'binary_operator', 'children': ['21', '24'], 'value': '+'}, {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'attempt'}; {'id': '24', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32', '35', '38', '41']}, {'id': '31', 'type': 'string', 'children': [], 'value': '"Failed attempt for %s (%d/%d), reason: %s"'}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'attempt'}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'max_check_attempts'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'reason'}; {'id': '42', 'type': 'if_statement', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'alive'}; {'id': '46', 'type': 'block', 'children': ['47']}, {'id': '47', 'type': 'if_statement', 'children': ['48', '52', '70']}; {'id': '48', 'type': 'not_operator', 'children': ['49']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'stopping'}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '60', '63', '66', '69']}, {'id': '59', 'type': 'string', 'children': [], 'value': '"Add failed attempt for %s (%d/%d) - %s"'}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'attempt'}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'max_check_attempts'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'reason'}; {'id': '70', 'type': 'else_clause', 'children': ['71']}, {'id': '71', 'type': 'block', 'children': ['72']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '77', 'type': 'argument_list', 'children': ['78', '79', '82', '85']}; {'id': '78', 'type': 'string', 'children': [], 'value': '"Stopping... failed attempt for %s (%d/%d) - also probably stopping"'}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'attempt'}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'max_check_attempts'}; {'id': '88', 'type': 'if_statement', 'children': ['89', '96']}, {'id': '89', 'type': 'comparison_operator', 'children': ['90', '93'], 'value': '>='}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'attempt'}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'max_check_attempts'}; {'id': '96', 'type': 'block', 'children': ['97', '132']}, {'id': '97', 'type': 'if_statement', 'children': ['98', '102', '117']}; {'id': '98', 'type': 'not_operator', 'children': ['99']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'stopping'}; {'id': '102', 'type': 'block', 'children': ['103']}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'call', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '108', 'type': 'argument_list', 'children': ['109', '110', '113', '116']}, {'id': '109', 'type': 'string', 'children': [], 'value': '"Set %s as dead, too much failed attempts (%d), last problem is: %s"'}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'max_check_attempts'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'reason'}, {'id': '117', 'type': 'else_clause', 'children': ['118']}; {'id': '118', 'type': 'block', 'children': ['119']}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'call', 'children': ['121', '124']}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '124', 'type': 'argument_list', 'children': ['125', '126', '129']}, {'id': '125', 'type': 'string', 'children': [], 'value': '"Stopping... set %s as dead, too much failed attempts (%d)"'}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'max_check_attempts'}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'call', 'children': ['134', '137']}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'set_dead'}, {'id': '137', 'type': 'argument_list', 'children': []} | def add_failed_check_attempt(self, reason=''):
self.reachable = False
self.attempt = self.attempt + 1
logger.debug("Failed attempt for %s (%d/%d), reason: %s",
self.name, self.attempt, self.max_check_attempts, reason)
if self.alive:
if not self.stopping:
logger.warning("Add failed attempt for %s (%d/%d) - %s",
self.name, self.attempt, self.max_check_attempts, reason)
else:
logger.info("Stopping... failed attempt for %s (%d/%d) - also probably stopping",
self.name, self.attempt, self.max_check_attempts)
if self.attempt >= self.max_check_attempts:
if not self.stopping:
logger.warning("Set %s as dead, too much failed attempts (%d), last problem is: %s",
self.name, self.max_check_attempts, reason)
else:
logger.info("Stopping... set %s as dead, too much failed attempts (%d)",
self.name, self.max_check_attempts)
self.set_dead() |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_links_for_a_broker'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'pollers'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'reactionners'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'receivers'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'realms'}, {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'manage_sub_realms'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '26', '52', '78', '104', '197']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '16', 'type': 'dictionary', 'children': ['17', '20', '23']}, {'id': '17', 'type': 'pair', 'children': ['18', '19']}; {'id': '18', 'type': 'string', 'children': [], 'value': "'pollers'"}, {'id': '19', 'type': 'dictionary', 'children': []}; {'id': '20', 'type': 'pair', 'children': ['21', '22']}, {'id': '21', 'type': 'string', 'children': [], 'value': "'reactionners'"}; {'id': '22', 'type': 'dictionary', 'children': []}, {'id': '23', 'type': 'pair', 'children': ['24', '25']}; {'id': '24', 'type': 'string', 'children': [], 'value': "'receivers'"}, {'id': '25', 'type': 'dictionary', 'children': []}; {'id': '26', 'type': 'for_statement', 'children': ['27', '28', '31']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'poller_id'}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'pollers'}, {'id': '31', 'type': 'block', 'children': ['32', '38']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'poller'}, {'id': '35', 'type': 'subscript', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'pollers'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'poller_id'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '47']}; {'id': '40', 'type': 'subscript', 'children': ['41', '44']}, {'id': '41', 'type': 'subscript', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'cfg'}, {'id': '43', 'type': 'string', 'children': [], 'value': "'pollers'"}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'poller'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'uuid'}, {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'poller'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'give_satellite_cfg'}, {'id': '51', 'type': 'argument_list', 'children': []}; {'id': '52', 'type': 'for_statement', 'children': ['53', '54', '57']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'reactionner_id'}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'reactionners'}, {'id': '57', 'type': 'block', 'children': ['58', '64']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'reactionner'}, {'id': '61', 'type': 'subscript', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'reactionners'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'reactionner_id'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '73']}; {'id': '66', 'type': 'subscript', 'children': ['67', '70']}, {'id': '67', 'type': 'subscript', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'cfg'}, {'id': '69', 'type': 'string', 'children': [], 'value': "'reactionners'"}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'reactionner'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'uuid'}, {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'reactionner'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'give_satellite_cfg'}, {'id': '77', 'type': 'argument_list', 'children': []}; {'id': '78', 'type': 'for_statement', 'children': ['79', '80', '83']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'receiver_id'}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'receivers'}, {'id': '83', 'type': 'block', 'children': ['84', '90']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'receiver'}, {'id': '87', 'type': 'subscript', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'receivers'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'receiver_id'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}, {'id': '91', 'type': 'assignment', 'children': ['92', '99']}; {'id': '92', 'type': 'subscript', 'children': ['93', '96']}, {'id': '93', 'type': 'subscript', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'cfg'}, {'id': '95', 'type': 'string', 'children': [], 'value': "'receivers'"}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'receiver'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'uuid'}, {'id': '99', 'type': 'call', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'receiver'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'give_satellite_cfg'}, {'id': '103', 'type': 'argument_list', 'children': []}; {'id': '104', 'type': 'if_statement', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'manage_sub_realms'}; {'id': '106', 'type': 'block', 'children': ['107', '137', '167']}, {'id': '107', 'type': 'for_statement', 'children': ['108', '109', '116']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'poller_id'}, {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'get_all_subs_satellites_by_type'}, {'id': '113', 'type': 'argument_list', 'children': ['114', '115']}; {'id': '114', 'type': 'string', 'children': [], 'value': "'pollers'"}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'realms'}; {'id': '116', 'type': 'block', 'children': ['117', '123']}, {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'assignment', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'poller'}; {'id': '120', 'type': 'subscript', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'pollers'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'poller_id'}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '132']}, {'id': '125', 'type': 'subscript', 'children': ['126', '129']}; {'id': '126', 'type': 'subscript', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '128', 'type': 'string', 'children': [], 'value': "'pollers'"}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'poller'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '132', 'type': 'call', 'children': ['133', '136']}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'poller'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'give_satellite_cfg'}; {'id': '136', 'type': 'argument_list', 'children': []}, {'id': '137', 'type': 'for_statement', 'children': ['138', '139', '146']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'reactionner_id'}, {'id': '139', 'type': 'call', 'children': ['140', '143']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'get_all_subs_satellites_by_type'}, {'id': '143', 'type': 'argument_list', 'children': ['144', '145']}; {'id': '144', 'type': 'string', 'children': [], 'value': "'reactionners'"}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'realms'}; {'id': '146', 'type': 'block', 'children': ['147', '153']}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'assignment', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'reactionner'}; {'id': '150', 'type': 'subscript', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'reactionners'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'reactionner_id'}, {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'assignment', 'children': ['155', '162']}, {'id': '155', 'type': 'subscript', 'children': ['156', '159']}; {'id': '156', 'type': 'subscript', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '158', 'type': 'string', 'children': [], 'value': "'reactionners'"}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'reactionner'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '162', 'type': 'call', 'children': ['163', '166']}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'reactionner'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'give_satellite_cfg'}; {'id': '166', 'type': 'argument_list', 'children': []}, {'id': '167', 'type': 'for_statement', 'children': ['168', '169', '176']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'receiver_id'}, {'id': '169', 'type': 'call', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'get_all_subs_satellites_by_type'}, {'id': '173', 'type': 'argument_list', 'children': ['174', '175']}; {'id': '174', 'type': 'string', 'children': [], 'value': "'receivers'"}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'realms'}; {'id': '176', 'type': 'block', 'children': ['177', '183']}, {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'assignment', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'receiver'}; {'id': '180', 'type': 'subscript', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'receivers'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'receiver_id'}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '192']}, {'id': '185', 'type': 'subscript', 'children': ['186', '189']}; {'id': '186', 'type': 'subscript', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '188', 'type': 'string', 'children': [], 'value': "'receivers'"}, {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'receiver'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '192', 'type': 'call', 'children': ['193', '196']}, {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'receiver'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'give_satellite_cfg'}; {'id': '196', 'type': 'argument_list', 'children': []}, {'id': '197', 'type': 'return_statement', 'children': ['198']} | def get_links_for_a_broker(self, pollers, reactionners, receivers, realms,
manage_sub_realms=False):
cfg = {
'pollers': {},
'reactionners': {},
'receivers': {},
}
for poller_id in self.pollers:
poller = pollers[poller_id]
cfg['pollers'][poller.uuid] = poller.give_satellite_cfg()
for reactionner_id in self.reactionners:
reactionner = reactionners[reactionner_id]
cfg['reactionners'][reactionner.uuid] = reactionner.give_satellite_cfg()
for receiver_id in self.receivers:
receiver = receivers[receiver_id]
cfg['receivers'][receiver.uuid] = receiver.give_satellite_cfg()
if manage_sub_realms:
for poller_id in self.get_all_subs_satellites_by_type('pollers', realms):
poller = pollers[poller_id]
cfg['pollers'][poller.uuid] = poller.give_satellite_cfg()
for reactionner_id in self.get_all_subs_satellites_by_type('reactionners', realms):
reactionner = reactionners[reactionner_id]
cfg['reactionners'][reactionner.uuid] = reactionner.give_satellite_cfg()
for receiver_id in self.get_all_subs_satellites_by_type('receivers', realms):
receiver = receivers[receiver_id]
cfg['receivers'][receiver.uuid] = receiver.give_satellite_cfg()
return cfg |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_links_for_a_scheduler'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'pollers'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'reactionners'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'brokers'}; {'id': '8', 'type': 'block', 'children': ['9', '22', '155']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '12', 'type': 'dictionary', 'children': ['13', '16', '19']}, {'id': '13', 'type': 'pair', 'children': ['14', '15']}; {'id': '14', 'type': 'string', 'children': [], 'value': "'pollers'"}, {'id': '15', 'type': 'dictionary', 'children': []}; {'id': '16', 'type': 'pair', 'children': ['17', '18']}, {'id': '17', 'type': 'string', 'children': [], 'value': "'reactionners'"}; {'id': '18', 'type': 'dictionary', 'children': []}, {'id': '19', 'type': 'pair', 'children': ['20', '21']}; {'id': '20', 'type': 'string', 'children': [], 'value': "'brokers'"}, {'id': '21', 'type': 'dictionary', 'children': []}; {'id': '22', 'type': 'try_statement', 'children': ['23', '141']}, {'id': '23', 'type': 'block', 'children': ['24', '63', '102']}; {'id': '24', 'type': 'for_statement', 'children': ['25', '26', '37']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'poller'}; {'id': '26', 'type': 'binary_operator', 'children': ['27', '30'], 'value': '+'}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'pollers'}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'get_potential_satellites_by_type'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'pollers'}; {'id': '36', 'type': 'string', 'children': [], 'value': '"poller"'}, {'id': '37', 'type': 'block', 'children': ['38', '49']}; {'id': '38', 'type': 'if_statement', 'children': ['39', '42']}, {'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': 'in'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'poller'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'pollers'}; {'id': '42', 'type': 'block', 'children': ['43']}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'poller'}; {'id': '46', 'type': 'subscript', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'pollers'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'poller'}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '58']}, {'id': '51', 'type': 'subscript', 'children': ['52', '55']}; {'id': '52', 'type': 'subscript', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '54', 'type': 'string', 'children': [], 'value': "'pollers'"}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'poller'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '58', 'type': 'call', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'poller'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'give_satellite_cfg'}; {'id': '62', 'type': 'argument_list', 'children': []}, {'id': '63', 'type': 'for_statement', 'children': ['64', '65', '76']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'reactionner'}, {'id': '65', 'type': 'binary_operator', 'children': ['66', '69'], 'value': '+'}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'reactionners'}, {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'get_potential_satellites_by_type'}, {'id': '73', 'type': 'argument_list', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'reactionners'}, {'id': '75', 'type': 'string', 'children': [], 'value': '"reactionner"'}; {'id': '76', 'type': 'block', 'children': ['77', '88']}, {'id': '77', 'type': 'if_statement', 'children': ['78', '81']}; {'id': '78', 'type': 'comparison_operator', 'children': ['79', '80'], 'value': 'in'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'reactionner'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'reactionners'}, {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'reactionner'}, {'id': '85', 'type': 'subscript', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'reactionners'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'reactionner'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '97']}; {'id': '90', 'type': 'subscript', 'children': ['91', '94']}, {'id': '91', 'type': 'subscript', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'cfg'}, {'id': '93', 'type': 'string', 'children': [], 'value': "'reactionners'"}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'reactionner'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'uuid'}, {'id': '97', 'type': 'call', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'reactionner'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'give_satellite_cfg'}, {'id': '101', 'type': 'argument_list', 'children': []}; {'id': '102', 'type': 'for_statement', 'children': ['103', '104', '115']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'broker'}; {'id': '104', 'type': 'binary_operator', 'children': ['105', '108'], 'value': '+'}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'brokers'}; {'id': '108', 'type': 'call', 'children': ['109', '112']}, {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'get_potential_satellites_by_type'}; {'id': '112', 'type': 'argument_list', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'brokers'}; {'id': '114', 'type': 'string', 'children': [], 'value': '"broker"'}, {'id': '115', 'type': 'block', 'children': ['116', '127']}; {'id': '116', 'type': 'if_statement', 'children': ['117', '120']}, {'id': '117', 'type': 'comparison_operator', 'children': ['118', '119'], 'value': 'in'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'broker'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'brokers'}; {'id': '120', 'type': 'block', 'children': ['121']}, {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'broker'}; {'id': '124', 'type': 'subscript', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'brokers'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'broker'}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'assignment', 'children': ['129', '136']}, {'id': '129', 'type': 'subscript', 'children': ['130', '133']}; {'id': '130', 'type': 'subscript', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '132', 'type': 'string', 'children': [], 'value': "'brokers'"}, {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'broker'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '136', 'type': 'call', 'children': ['137', '140']}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'broker'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'give_satellite_cfg'}; {'id': '140', 'type': 'argument_list', 'children': []}, {'id': '141', 'type': 'except_clause', 'children': ['142', '146']}; {'id': '142', 'type': 'as_pattern', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '144', 'type': 'as_pattern_target', 'children': ['145']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'exp'}; {'id': '146', 'type': 'block', 'children': ['147']}, {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'call', 'children': ['149', '152']}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'exception'}; {'id': '152', 'type': 'argument_list', 'children': ['153', '154']}, {'id': '153', 'type': 'string', 'children': [], 'value': '"realm.get_links_for_a_scheduler: %s"'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'exp'}, {'id': '155', 'type': 'return_statement', 'children': ['156']} | def get_links_for_a_scheduler(self, pollers, reactionners, brokers):
cfg = {
'pollers': {},
'reactionners': {},
'brokers': {},
}
try:
for poller in self.pollers + self.get_potential_satellites_by_type(pollers, "poller"):
if poller in pollers:
poller = pollers[poller]
cfg['pollers'][poller.uuid] = poller.give_satellite_cfg()
for reactionner in self.reactionners + self.get_potential_satellites_by_type(
reactionners, "reactionner"):
if reactionner in reactionners:
reactionner = reactionners[reactionner]
cfg['reactionners'][reactionner.uuid] = reactionner.give_satellite_cfg()
for broker in self.brokers + self.get_potential_satellites_by_type(brokers, "broker"):
if broker in brokers:
broker = brokers[broker]
cfg['brokers'][broker.uuid] = broker.give_satellite_cfg()
except Exception as exp:
logger.exception("realm.get_links_for_a_scheduler: %s", exp)
return cfg |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_default'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'check'}, {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '13', '43', '119', '125', '203', '209']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'found'}; {'id': '12', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '13', 'type': 'for_statement', 'children': ['14', '15', '27']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'realm'}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'sorted'}, {'id': '17', 'type': 'argument_list', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '21', 'type': 'lambda', 'children': ['22', '24']}; {'id': '22', 'type': 'lambda_parameters', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'level'}, {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'if_statement', 'children': ['29', '35']}, {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '31', 'type': 'argument_list', 'children': ['32', '33', '34']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'realm'}, {'id': '33', 'type': 'string', 'children': [], 'value': "'default'"}; {'id': '34', 'type': 'False', 'children': []}, {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'found'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'realm'}, {'id': '43', 'type': 'if_statement', 'children': ['44', '46']}; {'id': '44', 'type': 'not_operator', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'found'}; {'id': '46', 'type': 'block', 'children': ['47', '62', '77', '83', '92', '98', '105']}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'found_names'}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'list_comprehension', 'children': ['54', '59']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'get_name'}; {'id': '58', 'type': 'argument_list', 'children': []}, {'id': '59', 'type': 'for_in_clause', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'if_statement', 'children': ['63', '65']}, {'id': '63', 'type': 'not_operator', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'found_names'}, {'id': '65', 'type': 'block', 'children': ['66', '75']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'add_error'}, {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'concatenated_string', 'children': ['73', '74']}, {'id': '73', 'type': 'string', 'children': [], 'value': '"No realm is defined in this configuration! "'}; {'id': '74', 'type': 'string', 'children': [], 'value': '"This should not be possible!"'}, {'id': '75', 'type': 'return_statement', 'children': ['76']}; {'id': '76', 'type': 'None', 'children': []}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'default_realm_name'}; {'id': '80', 'type': 'subscript', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'found_names'}; {'id': '82', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'default_realm'}; {'id': '86', 'type': 'call', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'find_by_name'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'default_realm_name'}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'assignment', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'default_realm'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '97', 'type': 'True', 'children': []}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}, {'id': '99', 'type': 'call', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'found'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'default_realm'}, {'id': '105', 'type': 'if_statement', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'check'}, {'id': '107', 'type': 'block', 'children': ['108']}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'add_error'}, {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'binary_operator', 'children': ['115', '118'], 'value': '%'}, {'id': '115', 'type': 'concatenated_string', 'children': ['116', '117']}; {'id': '116', 'type': 'string', 'children': [], 'value': '"No realm is defined as the default one! "'}, {'id': '117', 'type': 'string', 'children': [], 'value': '"I set %s as the default realm"'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'default_realm_name'}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'default_realm'}; {'id': '122', 'type': 'subscript', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'found'}; {'id': '124', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '125', 'type': 'if_statement', 'children': ['126', '132']}; {'id': '126', 'type': 'comparison_operator', 'children': ['127', '131'], 'value': '>'}, {'id': '127', 'type': 'call', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'found'}, {'id': '131', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '132', 'type': 'block', 'children': ['133', '148', '154', '163', '182']}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'found_names'}; {'id': '136', 'type': 'call', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}, {'id': '139', 'type': 'list_comprehension', 'children': ['140', '145']}; {'id': '140', 'type': 'call', 'children': ['141', '144']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'get_name'}; {'id': '144', 'type': 'argument_list', 'children': []}, {'id': '145', 'type': 'for_in_clause', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'r'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'found'}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}, {'id': '149', 'type': 'assignment', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'default_realm_name'}, {'id': '151', 'type': 'subscript', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'found_names'}, {'id': '153', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'assignment', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'default_realm'}, {'id': '157', 'type': 'call', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'find_by_name'}, {'id': '161', 'type': 'argument_list', 'children': ['162']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'default_realm_name'}, {'id': '163', 'type': 'for_statement', 'children': ['164', '165', '166']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'realm'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'found'}; {'id': '166', 'type': 'block', 'children': ['167']}, {'id': '167', 'type': 'if_statement', 'children': ['168', '175']}; {'id': '168', 'type': 'comparison_operator', 'children': ['169', '174'], 'value': '!='}, {'id': '169', 'type': 'call', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'realm'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'get_name'}, {'id': '173', 'type': 'argument_list', 'children': []}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'default_realm_name'}, {'id': '175', 'type': 'block', 'children': ['176']}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'assignment', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'realm'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '181', 'type': 'False', 'children': []}; {'id': '182', 'type': 'if_statement', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'check'}; {'id': '184', 'type': 'block', 'children': ['185']}, {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'call', 'children': ['187', '190']}, {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'add_warning'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}, {'id': '191', 'type': 'binary_operator', 'children': ['192', '195'], 'value': '%'}; {'id': '192', 'type': 'concatenated_string', 'children': ['193', '194']}, {'id': '193', 'type': 'string', 'children': [], 'value': '"More than one realm is defined as the default one: %s. "'}; {'id': '194', 'type': 'string', 'children': [], 'value': '"I set %s as the default realm."'}, {'id': '195', 'type': 'tuple', 'children': ['196', '202']}; {'id': '196', 'type': 'call', 'children': ['197', '200']}, {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'string', 'children': [], 'value': "','"}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '200', 'type': 'argument_list', 'children': ['201']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'found_names'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'default_realm_name'}, {'id': '203', 'type': 'expression_statement', 'children': ['204']}; {'id': '204', 'type': 'assignment', 'children': ['205', '208']}, {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'default'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'default_realm'}, {'id': '209', 'type': 'return_statement', 'children': ['210']} | def get_default(self, check=False):
found = []
for realm in sorted(self, key=lambda r: r.level):
if getattr(realm, 'default', False):
found.append(realm)
if not found:
found_names = sorted([r.get_name() for r in self])
if not found_names:
self.add_error("No realm is defined in this configuration! "
"This should not be possible!")
return None
default_realm_name = found_names[0]
default_realm = self.find_by_name(default_realm_name)
default_realm.default = True
found.append(default_realm)
if check:
self.add_error("No realm is defined as the default one! "
"I set %s as the default realm" % default_realm_name)
default_realm = found[0]
if len(found) > 1:
found_names = sorted([r.get_name() for r in found])
default_realm_name = found_names[0]
default_realm = self.find_by_name(default_realm_name)
for realm in found:
if realm.get_name() != default_realm_name:
realm.default = False
if check:
self.add_warning("More than one realm is defined as the default one: %s. "
"I set %s as the default realm."
% (','.join(found_names), default_realm_name))
self.default = default_realm
return default_realm |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '26']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'command'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'command'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'element'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '16', 'type': 'None', 'children': []}, {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '22', 'type': 'None', 'children': []}, {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'parameters'}, {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'block', 'children': ['27', '53', '169', '181', '188', '206', '237', '304', '315', '323', '335']}, {'id': '27', 'type': 'if_statement', 'children': ['28', '36']}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '34'], 'value': 'in'}, {'id': '29', 'type': 'attribute', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'cherrypy'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '34', 'type': 'list', 'children': ['35'], 'value': '["POST"]'}, {'id': '35', 'type': 'string', 'children': [], 'value': '"POST"'}; {'id': '36', 'type': 'block', 'children': ['37']}, {'id': '37', 'type': 'if_statement', 'children': ['38', '44']}; {'id': '38', 'type': 'not_operator', 'children': ['39']}, {'id': '39', 'type': 'attribute', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'cherrypy'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '44', 'type': 'block', 'children': ['45']}, {'id': '45', 'type': 'return_statement', 'children': ['46']}; {'id': '46', 'type': 'dictionary', 'children': ['47', '50']}, {'id': '47', 'type': 'pair', 'children': ['48', '49']}; {'id': '48', 'type': 'string', 'children': [], 'value': "'_status'"}, {'id': '49', 'type': 'string', 'children': [], 'value': "u'ERR'"}; {'id': '50', 'type': 'pair', 'children': ['51', '52']}, {'id': '51', 'type': 'string', 'children': [], 'value': "'_message'"}; {'id': '52', 'type': 'string', 'children': [], 'value': "u'You must POST parameters on this endpoint.'"}, {'id': '53', 'type': 'if_statement', 'children': ['54', '57']}; {'id': '54', 'type': 'comparison_operator', 'children': ['55', '56'], 'value': 'is'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '56', 'type': 'None', 'children': []}, {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'try_statement', 'children': ['59', '158']}, {'id': '59', 'type': 'block', 'children': ['60', '74', '88', '102', '116', '130', '144']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'command'}, {'id': '63', 'type': 'call', 'children': ['64', '71']}; {'id': '64', 'type': 'attribute', 'children': ['65', '70']}, {'id': '65', 'type': 'attribute', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'cherrypy'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '71', 'type': 'argument_list', 'children': ['72', '73']}; {'id': '72', 'type': 'string', 'children': [], 'value': "'command'"}, {'id': '73', 'type': 'None', 'children': []}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'timestamp'}, {'id': '77', 'type': 'call', 'children': ['78', '85']}; {'id': '78', 'type': 'attribute', 'children': ['79', '84']}, {'id': '79', 'type': 'attribute', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'cherrypy'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '85', 'type': 'argument_list', 'children': ['86', '87']}; {'id': '86', 'type': 'string', 'children': [], 'value': "'timestamp'"}, {'id': '87', 'type': 'None', 'children': []}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'element'}, {'id': '91', 'type': 'call', 'children': ['92', '99']}; {'id': '92', 'type': 'attribute', 'children': ['93', '98']}, {'id': '93', 'type': 'attribute', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'cherrypy'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '99', 'type': 'argument_list', 'children': ['100', '101']}; {'id': '100', 'type': 'string', 'children': [], 'value': "'element'"}, {'id': '101', 'type': 'None', 'children': []}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'host'}, {'id': '105', 'type': 'call', 'children': ['106', '113']}; {'id': '106', 'type': 'attribute', 'children': ['107', '112']}, {'id': '107', 'type': 'attribute', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'cherrypy'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '113', 'type': 'argument_list', 'children': ['114', '115']}; {'id': '114', 'type': 'string', 'children': [], 'value': "'host'"}, {'id': '115', 'type': 'None', 'children': []}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'assignment', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '119', 'type': 'call', 'children': ['120', '127']}; {'id': '120', 'type': 'attribute', 'children': ['121', '126']}, {'id': '121', 'type': 'attribute', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'cherrypy'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '127', 'type': 'argument_list', 'children': ['128', '129']}; {'id': '128', 'type': 'string', 'children': [], 'value': "'service'"}, {'id': '129', 'type': 'None', 'children': []}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}, {'id': '131', 'type': 'assignment', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'user'}, {'id': '133', 'type': 'call', 'children': ['134', '141']}; {'id': '134', 'type': 'attribute', 'children': ['135', '140']}, {'id': '135', 'type': 'attribute', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'cherrypy'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '141', 'type': 'argument_list', 'children': ['142', '143']}; {'id': '142', 'type': 'string', 'children': [], 'value': "'user'"}, {'id': '143', 'type': 'None', 'children': []}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'assignment', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'parameters'}, {'id': '147', 'type': 'call', 'children': ['148', '155']}; {'id': '148', 'type': 'attribute', 'children': ['149', '154']}, {'id': '149', 'type': 'attribute', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'cherrypy'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '155', 'type': 'argument_list', 'children': ['156', '157']}; {'id': '156', 'type': 'string', 'children': [], 'value': "'parameters'"}, {'id': '157', 'type': 'None', 'children': []}; {'id': '158', 'type': 'except_clause', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '160', 'type': 'block', 'children': ['161']}, {'id': '161', 'type': 'return_statement', 'children': ['162']}; {'id': '162', 'type': 'dictionary', 'children': ['163', '166']}, {'id': '163', 'type': 'pair', 'children': ['164', '165']}; {'id': '164', 'type': 'string', 'children': [], 'value': "'_status'"}, {'id': '165', 'type': 'string', 'children': [], 'value': "u'ERR'"}; {'id': '166', 'type': 'pair', 'children': ['167', '168']}, {'id': '167', 'type': 'string', 'children': [], 'value': "'_message'"}; {'id': '168', 'type': 'string', 'children': [], 'value': "u'Missing command parameters'"}, {'id': '169', 'type': 'if_statement', 'children': ['170', '172']}; {'id': '170', 'type': 'not_operator', 'children': ['171']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '172', 'type': 'block', 'children': ['173']}, {'id': '173', 'type': 'return_statement', 'children': ['174']}; {'id': '174', 'type': 'dictionary', 'children': ['175', '178']}, {'id': '175', 'type': 'pair', 'children': ['176', '177']}; {'id': '176', 'type': 'string', 'children': [], 'value': "'_status'"}, {'id': '177', 'type': 'string', 'children': [], 'value': "u'ERR'"}; {'id': '178', 'type': 'pair', 'children': ['179', '180']}, {'id': '179', 'type': 'string', 'children': [], 'value': "'_message'"}; {'id': '180', 'type': 'string', 'children': [], 'value': "u'Missing command parameter'"}, {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'assignment', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '184', 'type': 'call', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'split_semicolon'}; {'id': '186', 'type': 'argument_list', 'children': ['187']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '188', 'type': 'expression_statement', 'children': ['189']}, {'id': '189', 'type': 'assignment', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'command_line'}, {'id': '191', 'type': 'call', 'children': ['192', '195']}; {'id': '192', 'type': 'attribute', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'replace'}, {'id': '195', 'type': 'argument_list', 'children': ['196', '199']}; {'id': '196', 'type': 'subscript', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '198', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '199', 'type': 'call', 'children': ['200', '205']}; {'id': '200', 'type': 'attribute', 'children': ['201', '204']}, {'id': '201', 'type': 'subscript', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '203', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'upper'}, {'id': '205', 'type': 'argument_list', 'children': []}; {'id': '206', 'type': 'if_statement', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '208', 'type': 'block', 'children': ['209', '229']}, {'id': '209', 'type': 'try_statement', 'children': ['210', '218']}; {'id': '210', 'type': 'block', 'children': ['211']}, {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'assignment', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '214', 'type': 'call', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '216', 'type': 'argument_list', 'children': ['217']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '218', 'type': 'except_clause', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '220', 'type': 'block', 'children': ['221']}, {'id': '221', 'type': 'return_statement', 'children': ['222']}; {'id': '222', 'type': 'dictionary', 'children': ['223', '226']}, {'id': '223', 'type': 'pair', 'children': ['224', '225']}; {'id': '224', 'type': 'string', 'children': [], 'value': "'_status'"}, {'id': '225', 'type': 'string', 'children': [], 'value': "u'ERR'"}; {'id': '226', 'type': 'pair', 'children': ['227', '228']}, {'id': '227', 'type': 'string', 'children': [], 'value': "'_message'"}; {'id': '228', 'type': 'string', 'children': [], 'value': "u'Timestamp must be an integer value'"}, {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'assignment', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'command_line'}; {'id': '232', 'type': 'binary_operator', 'children': ['233', '234'], 'value': '%'}, {'id': '233', 'type': 'string', 'children': [], 'value': "'[%d] %s'"}; {'id': '234', 'type': 'tuple', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'command_line'}, {'id': '237', 'type': 'if_statement', 'children': ['238', '243', '277']}; {'id': '238', 'type': 'boolean_operator', 'children': ['239', '242'], 'value': 'or'}, {'id': '239', 'type': 'boolean_operator', 'children': ['240', '241'], 'value': 'or'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'host'}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'user'}, {'id': '243', 'type': 'block', 'children': ['244', '255', '266']}; {'id': '244', 'type': 'if_statement', 'children': ['245', '246']}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '246', 'type': 'block', 'children': ['247']}, {'id': '247', 'type': 'expression_statement', 'children': ['248']}; {'id': '248', 'type': 'assignment', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'command_line'}; {'id': '250', 'type': 'binary_operator', 'children': ['251', '252'], 'value': '%'}, {'id': '251', 'type': 'string', 'children': [], 'value': "'%s;%s'"}; {'id': '252', 'type': 'tuple', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'command_line'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'host'}, {'id': '255', 'type': 'if_statement', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '257', 'type': 'block', 'children': ['258']}; {'id': '258', 'type': 'expression_statement', 'children': ['259']}, {'id': '259', 'type': 'assignment', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'command_line'}, {'id': '261', 'type': 'binary_operator', 'children': ['262', '263'], 'value': '%'}; {'id': '262', 'type': 'string', 'children': [], 'value': "'%s;%s'"}, {'id': '263', 'type': 'tuple', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'command_line'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '266', 'type': 'if_statement', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '268', 'type': 'block', 'children': ['269']}, {'id': '269', 'type': 'expression_statement', 'children': ['270']}; {'id': '270', 'type': 'assignment', 'children': ['271', '272']}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'command_line'}; {'id': '272', 'type': 'binary_operator', 'children': ['273', '274'], 'value': '%'}, {'id': '273', 'type': 'string', 'children': [], 'value': "'%s;%s'"}; {'id': '274', 'type': 'tuple', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'command_line'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'user'}, {'id': '277', 'type': 'elif_clause', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'element'}, {'id': '279', 'type': 'block', 'children': ['280', '296']}; {'id': '280', 'type': 'if_statement', 'children': ['281', '284']}, {'id': '281', 'type': 'comparison_operator', 'children': ['282', '283'], 'value': 'in'}; {'id': '282', 'type': 'string', 'children': [], 'value': "'/'"}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'element'}; {'id': '284', 'type': 'block', 'children': ['285']}, {'id': '285', 'type': 'expression_statement', 'children': ['286']}; {'id': '286', 'type': 'assignment', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'element'}; {'id': '288', 'type': 'call', 'children': ['289', '292']}, {'id': '289', 'type': 'attribute', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'element'}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '292', 'type': 'argument_list', 'children': ['293', '294', '295']}, {'id': '293', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '294', 'type': 'string', 'children': [], 'value': "';'"}, {'id': '295', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '296', 'type': 'expression_statement', 'children': ['297']}, {'id': '297', 'type': 'assignment', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'command_line'}, {'id': '299', 'type': 'binary_operator', 'children': ['300', '301'], 'value': '%'}; {'id': '300', 'type': 'string', 'children': [], 'value': "'%s;%s'"}, {'id': '301', 'type': 'tuple', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'command_line'}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'element'}; {'id': '304', 'type': 'if_statement', 'children': ['305', '306']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'parameters'}; {'id': '306', 'type': 'block', 'children': ['307']}, {'id': '307', 'type': 'expression_statement', 'children': ['308']}; {'id': '308', 'type': 'assignment', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'command_line'}; {'id': '310', 'type': 'binary_operator', 'children': ['311', '312'], 'value': '%'}, {'id': '311', 'type': 'string', 'children': [], 'value': "'%s;%s'"}; {'id': '312', 'type': 'tuple', 'children': ['313', '314']}, {'id': '313', 'type': 'identifier', 'children': [], 'value': 'command_line'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'parameters'}, {'id': '315', 'type': 'expression_statement', 'children': ['316']}; {'id': '316', 'type': 'call', 'children': ['317', '320']}, {'id': '317', 'type': 'attribute', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '320', 'type': 'argument_list', 'children': ['321', '322']}, {'id': '321', 'type': 'string', 'children': [], 'value': '"Got an external command: %s"'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'command_line'}, {'id': '323', 'type': 'expression_statement', 'children': ['324']}; {'id': '324', 'type': 'call', 'children': ['325', '330']}, {'id': '325', 'type': 'attribute', 'children': ['326', '329']}; {'id': '326', 'type': 'attribute', 'children': ['327', '328']}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '330', 'type': 'argument_list', 'children': ['331']}, {'id': '331', 'type': 'call', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'ExternalCommand'}, {'id': '333', 'type': 'argument_list', 'children': ['334']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'command_line'}, {'id': '335', 'type': 'return_statement', 'children': ['336']}; {'id': '336', 'type': 'dictionary', 'children': ['337', '340', '345']}, {'id': '337', 'type': 'pair', 'children': ['338', '339']}; {'id': '338', 'type': 'string', 'children': [], 'value': "'_status'"}, {'id': '339', 'type': 'string', 'children': [], 'value': "u'OK'"}; {'id': '340', 'type': 'pair', 'children': ['341', '342']}, {'id': '341', 'type': 'string', 'children': [], 'value': "'_message'"}; {'id': '342', 'type': 'binary_operator', 'children': ['343', '344'], 'value': '%'}, {'id': '343', 'type': 'string', 'children': [], 'value': 'u"Got command: %s"'}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'command_line'}, {'id': '345', 'type': 'pair', 'children': ['346', '347']}; {'id': '346', 'type': 'string', 'children': [], 'value': "'command'"}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'command_line'} | def command(self, command=None,
timestamp=None, element=None, host=None, service=None, user=None, parameters=None):
if cherrypy.request.method in ["POST"]:
if not cherrypy.request.json:
return {'_status': u'ERR',
'_message': u'You must POST parameters on this endpoint.'}
if command is None:
try:
command = cherrypy.request.json.get('command', None)
timestamp = cherrypy.request.json.get('timestamp', None)
element = cherrypy.request.json.get('element', None)
host = cherrypy.request.json.get('host', None)
service = cherrypy.request.json.get('service', None)
user = cherrypy.request.json.get('user', None)
parameters = cherrypy.request.json.get('parameters', None)
except AttributeError:
return {'_status': u'ERR', '_message': u'Missing command parameters'}
if not command:
return {'_status': u'ERR', '_message': u'Missing command parameter'}
fields = split_semicolon(command)
command_line = command.replace(fields[0], fields[0].upper())
if timestamp:
try:
timestamp = int(timestamp)
except ValueError:
return {'_status': u'ERR', '_message': u'Timestamp must be an integer value'}
command_line = '[%d] %s' % (timestamp, command_line)
if host or service or user:
if host:
command_line = '%s;%s' % (command_line, host)
if service:
command_line = '%s;%s' % (command_line, service)
if user:
command_line = '%s;%s' % (command_line, user)
elif element:
if '/' in element:
element = element.replace('/', ';', 1)
command_line = '%s;%s' % (command_line, element)
if parameters:
command_line = '%s;%s' % (command_line, parameters)
logger.warning("Got an external command: %s", command_line)
self.app.add(ExternalCommand(command_line))
return {'_status': u'OK',
'_message': u"Got command: %s" % command_line,
'command': command_line} |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'satellites_list'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'daemon_type'}, {'id': '7', 'type': 'string', 'children': [], 'value': "''"}; {'id': '8', 'type': 'block', 'children': ['9']}, {'id': '9', 'type': 'with_statement', 'children': ['10', '17']}; {'id': '10', 'type': 'with_clause', 'children': ['11']}, {'id': '11', 'type': 'with_item', 'children': ['12']}; {'id': '12', 'type': 'attribute', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'conf_lock'}, {'id': '17', 'type': 'block', 'children': ['18', '22', '74']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '21', 'type': 'dictionary', 'children': []}; {'id': '22', 'type': 'for_statement', 'children': ['23', '24', '31']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 's_type'}; {'id': '24', 'type': 'list', 'children': ['25', '26', '27', '28', '29', '30'], 'value': "['arbiter', 'scheduler', 'poller', 'reactionner', 'receiver', 'broker']"}, {'id': '25', 'type': 'string', 'children': [], 'value': "'arbiter'"}; {'id': '26', 'type': 'string', 'children': [], 'value': "'scheduler'"}, {'id': '27', 'type': 'string', 'children': [], 'value': "'poller'"}; {'id': '28', 'type': 'string', 'children': [], 'value': "'reactionner'"}, {'id': '29', 'type': 'string', 'children': [], 'value': "'receiver'"}; {'id': '30', 'type': 'string', 'children': [], 'value': "'broker'"}, {'id': '31', 'type': 'block', 'children': ['32', '40', '44', '50']}; {'id': '32', 'type': 'if_statement', 'children': ['33', '38']}, {'id': '33', 'type': 'boolean_operator', 'children': ['34', '35'], 'value': 'and'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'daemon_type'}, {'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': '!='}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'daemon_type'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 's_type'}; {'id': '38', 'type': 'block', 'children': ['39']}, {'id': '39', 'type': 'continue_statement', 'children': []}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'satellite_list'}, {'id': '43', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '49']}; {'id': '46', 'type': 'subscript', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 's_type'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'satellite_list'}; {'id': '50', 'type': 'for_statement', 'children': ['51', '52', '64']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'daemon_link'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '60', '63']}, {'id': '55', 'type': 'attribute', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'conf'}; {'id': '60', 'type': 'binary_operator', 'children': ['61', '62'], 'value': '+'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 's_type'}; {'id': '62', 'type': 'string', 'children': [], 'value': "'s'"}, {'id': '63', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '64', 'type': 'block', 'children': ['65']}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'satellite_list'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'daemon_link'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '74', 'type': 'return_statement', 'children': ['75']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'res'} | def satellites_list(self, daemon_type=''):
with self.app.conf_lock:
res = {}
for s_type in ['arbiter', 'scheduler', 'poller', 'reactionner', 'receiver', 'broker']:
if daemon_type and daemon_type != s_type:
continue
satellite_list = []
res[s_type] = satellite_list
for daemon_link in getattr(self.app.conf, s_type + 's', []):
satellite_list.append(daemon_link.name)
return res |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'fill_default_configuration'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '13', '21', '86', '119', '127', '193', '201']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'call', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'string', 'children': [], 'value': '"Filling the unset properties with their default value:"'}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'types_creations'}; {'id': '16', 'type': 'attribute', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'types_creations'}, {'id': '21', 'type': 'for_statement', 'children': ['22', '23', '24']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'o_type'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'types_creations'}; {'id': '24', 'type': 'block', 'children': ['25', '36', '49', '57', '66', '80']}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '33']}, {'id': '27', 'type': 'tuple_pattern', 'children': ['28', '29', '30', '31', '32']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'inner_property'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '33', 'type': 'subscript', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'types_creations'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'o_type'}; {'id': '36', 'type': 'if_statement', 'children': ['37', '47']}, {'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'in'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'inner_property'}, {'id': '39', 'type': 'list', 'children': ['40', '41', '42', '43', '44', '45', '46'], 'value': "['realms', 'arbiters', 'schedulers', 'reactionners',\n 'pollers', 'brokers', 'receivers']"}; {'id': '40', 'type': 'string', 'children': [], 'value': "'realms'"}, {'id': '41', 'type': 'string', 'children': [], 'value': "'arbiters'"}; {'id': '42', 'type': 'string', 'children': [], 'value': "'schedulers'"}, {'id': '43', 'type': 'string', 'children': [], 'value': "'reactionners'"}; {'id': '44', 'type': 'string', 'children': [], 'value': "'pollers'"}, {'id': '45', 'type': 'string', 'children': [], 'value': "'brokers'"}; {'id': '46', 'type': 'string', 'children': [], 'value': "'receivers'"}, {'id': '47', 'type': 'block', 'children': ['48']}; {'id': '48', 'type': 'continue_statement', 'children': []}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '56']}, {'id': '55', 'type': 'string', 'children': [], 'value': '" . for %s"'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'inner_property'}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'inner_object'}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '62', 'type': 'argument_list', 'children': ['63', '64', '65']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'inner_property'}, {'id': '65', 'type': 'None', 'children': []}; {'id': '66', 'type': 'if_statement', 'children': ['67', '70']}, {'id': '67', 'type': 'comparison_operator', 'children': ['68', '69'], 'value': 'is'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'inner_object'}, {'id': '69', 'type': 'None', 'children': []}; {'id': '70', 'type': 'block', 'children': ['71', '79']}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '76', 'type': 'argument_list', 'children': ['77', '78']}, {'id': '77', 'type': 'string', 'children': [], 'value': '"No %s to fill with default values"'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'inner_property'}, {'id': '79', 'type': 'continue_statement', 'children': []}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'inner_object'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'fill_default'}, {'id': '85', 'type': 'argument_list', 'children': []}; {'id': '86', 'type': 'if_statement', 'children': ['87', '95']}, {'id': '87', 'type': 'comparison_operator', 'children': ['88', '94'], 'value': 'is'}; {'id': '88', 'type': 'call', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '90', 'type': 'argument_list', 'children': ['91', '92', '93']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '92', 'type': 'string', 'children': [], 'value': "'realms'"}, {'id': '93', 'type': 'None', 'children': []}; {'id': '94', 'type': 'None', 'children': []}, {'id': '95', 'type': 'block', 'children': ['96', '102', '110']}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}, {'id': '97', 'type': 'call', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'fill_default_realm'}, {'id': '101', 'type': 'argument_list', 'children': []}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'call', 'children': ['104', '109']}; {'id': '104', 'type': 'attribute', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'realms'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'fill_default'}, {'id': '109', 'type': 'argument_list', 'children': []}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'call', 'children': ['112', '115']}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'fill_default_satellites'}, {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'launch_missing_daemons'}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'types_creations'}; {'id': '122', 'type': 'attribute', 'children': ['123', '126']}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'types_creations'}, {'id': '127', 'type': 'for_statement', 'children': ['128', '129', '130']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'o_type'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'types_creations'}; {'id': '130', 'type': 'block', 'children': ['131', '142', '161']}, {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '139']}, {'id': '133', 'type': 'tuple_pattern', 'children': ['134', '135', '136', '137', '138']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'inner_property'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '139', 'type': 'subscript', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'types_creations'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'o_type'}; {'id': '142', 'type': 'if_statement', 'children': ['143', '151']}, {'id': '143', 'type': 'comparison_operator', 'children': ['144', '150'], 'value': 'is'}; {'id': '144', 'type': 'call', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '146', 'type': 'argument_list', 'children': ['147', '148', '149']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'inner_property'}, {'id': '149', 'type': 'None', 'children': []}; {'id': '150', 'type': 'None', 'children': []}, {'id': '151', 'type': 'block', 'children': ['152', '160']}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'call', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '157', 'type': 'argument_list', 'children': ['158', '159']}; {'id': '158', 'type': 'string', 'children': [], 'value': '"No %s to fill with default values"'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'inner_property'}; {'id': '160', 'type': 'continue_statement', 'children': []}, {'id': '161', 'type': 'if_statement', 'children': ['162', '170']}; {'id': '162', 'type': 'comparison_operator', 'children': ['163', '164'], 'value': 'in'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'inner_property'}; {'id': '164', 'type': 'list', 'children': ['165', '166', '167', '168', '169'], 'value': "['schedulers', 'reactionners', 'pollers', 'brokers', 'receivers']"}, {'id': '165', 'type': 'string', 'children': [], 'value': "'schedulers'"}; {'id': '166', 'type': 'string', 'children': [], 'value': "'reactionners'"}, {'id': '167', 'type': 'string', 'children': [], 'value': "'pollers'"}; {'id': '168', 'type': 'string', 'children': [], 'value': "'brokers'"}, {'id': '169', 'type': 'string', 'children': [], 'value': "'receivers'"}; {'id': '170', 'type': 'block', 'children': ['171', '179', '187']}, {'id': '171', 'type': 'expression_statement', 'children': ['172']}; {'id': '172', 'type': 'call', 'children': ['173', '176']}, {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '176', 'type': 'argument_list', 'children': ['177', '178']}, {'id': '177', 'type': 'string', 'children': [], 'value': '" . for %s"'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'inner_property'}, {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'inner_object'}; {'id': '182', 'type': 'call', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '184', 'type': 'argument_list', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'inner_property'}, {'id': '187', 'type': 'expression_statement', 'children': ['188']}; {'id': '188', 'type': 'call', 'children': ['189', '192']}, {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'inner_object'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'fill_default'}; {'id': '192', 'type': 'argument_list', 'children': []}, {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'call', 'children': ['195', '200']}, {'id': '195', 'type': 'attribute', 'children': ['196', '199']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'hosts'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'fill_predictive_missing_parameters'}; {'id': '200', 'type': 'argument_list', 'children': []}, {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'call', 'children': ['203', '208']}, {'id': '203', 'type': 'attribute', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'fill_predictive_missing_parameters'} | def fill_default_configuration(self):
logger.debug("Filling the unset properties with their default value:")
types_creations = self.__class__.types_creations
for o_type in types_creations:
(_, _, inner_property, _, _) = types_creations[o_type]
if inner_property in ['realms', 'arbiters', 'schedulers', 'reactionners',
'pollers', 'brokers', 'receivers']:
continue
logger.debug(" . for %s", inner_property,)
inner_object = getattr(self, inner_property, None)
if inner_object is None:
logger.debug("No %s to fill with default values", inner_property)
continue
inner_object.fill_default()
if getattr(self, 'realms', None) is not None:
self.fill_default_realm()
self.realms.fill_default()
self.fill_default_satellites(self.launch_missing_daemons)
types_creations = self.__class__.types_creations
for o_type in types_creations:
(_, _, inner_property, _, _) = types_creations[o_type]
if getattr(self, inner_property, None) is None:
logger.debug("No %s to fill with default values", inner_property)
continue
if inner_property in ['schedulers', 'reactionners', 'pollers', 'brokers', 'receivers']:
logger.debug(" . for %s", inner_property,)
inner_object = getattr(self, inner_property)
inner_object.fill_default()
self.hosts.fill_predictive_missing_parameters()
self.services.fill_predictive_missing_parameters() |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'got_arbiter_module_type_defined'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'module_type'}; {'id': '6', 'type': 'block', 'children': ['7', '70']}, {'id': '7', 'type': 'for_statement', 'children': ['8', '9', '12']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'arbiter'}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'arbiters'}; {'id': '12', 'type': 'block', 'children': ['13']}, {'id': '13', 'type': 'for_statement', 'children': ['14', '15', '21']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'module'}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '17', 'type': 'argument_list', 'children': ['18', '19', '20']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'arbiter'}, {'id': '19', 'type': 'string', 'children': [], 'value': "'modules'"}; {'id': '20', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '21', 'type': 'block', 'children': ['22', '30']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'module_name'}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'module'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'get_name'}, {'id': '29', 'type': 'argument_list', 'children': []}; {'id': '30', 'type': 'for_statement', 'children': ['31', '32', '35']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'mod'}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'modules'}, {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'if_statement', 'children': ['37', '53']}, {'id': '37', 'type': 'comparison_operator', 'children': ['38', '48'], 'value': '=='}; {'id': '38', 'type': 'call', 'children': ['39', '47']}, {'id': '39', 'type': 'attribute', 'children': ['40', '46']}; {'id': '40', 'type': 'call', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '44', '45']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'mod'}; {'id': '44', 'type': 'string', 'children': [], 'value': "'python_name'"}, {'id': '45', 'type': 'string', 'children': [], 'value': "''"}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '47', 'type': 'argument_list', 'children': []}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'module_type'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '52', 'type': 'argument_list', 'children': []}, {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'if_statement', 'children': ['55', '67']}, {'id': '55', 'type': 'comparison_operator', 'children': ['56', '66'], 'value': '=='}; {'id': '56', 'type': 'call', 'children': ['57', '65']}, {'id': '57', 'type': 'attribute', 'children': ['58', '64']}; {'id': '58', 'type': 'call', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '60', 'type': 'argument_list', 'children': ['61', '62', '63']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'mod'}; {'id': '62', 'type': 'string', 'children': [], 'value': "'name'"}, {'id': '63', 'type': 'string', 'children': [], 'value': "''"}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '65', 'type': 'argument_list', 'children': []}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'module_name'}, {'id': '67', 'type': 'block', 'children': ['68']}; {'id': '68', 'type': 'return_statement', 'children': ['69']}, {'id': '69', 'type': 'True', 'children': []}; {'id': '70', 'type': 'return_statement', 'children': ['71']}, {'id': '71', 'type': 'False', 'children': []} | def got_arbiter_module_type_defined(self, module_type):
for arbiter in self.arbiters:
for module in getattr(arbiter, 'modules', []):
module_name = module.get_name()
for mod in self.modules:
if getattr(mod, 'python_name', '').strip() == module_type.strip():
if getattr(mod, 'name', '').strip() == module_name:
return True
return False |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'load_modules_configuration_objects'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'raw_objects'}; {'id': '6', 'type': 'block', 'children': ['7']}, {'id': '7', 'type': 'for_statement', 'children': ['8', '9', '14']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'instance'}, {'id': '9', 'type': 'attribute', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'modules_manager'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'instances'}; {'id': '14', 'type': 'block', 'children': ['15', '25', '44', '84', '99', '107']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22']}, {'id': '21', 'type': 'string', 'children': [], 'value': '"Getting objects from the module: %s"'}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '25', 'type': 'if_statement', 'children': ['26', '32']}; {'id': '26', 'type': 'not_operator', 'children': ['27']}, {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '29', 'type': 'argument_list', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'instance'}, {'id': '31', 'type': 'string', 'children': [], 'value': "'get_objects'"}; {'id': '32', 'type': 'block', 'children': ['33', '43']}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'call', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '40']}, {'id': '39', 'type': 'string', 'children': [], 'value': '"The module \'%s\' do not provide any objects."'}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '43', 'type': 'return_statement', 'children': []}; {'id': '44', 'type': 'try_statement', 'children': ['45', '64']}, {'id': '45', 'type': 'block', 'children': ['46', '56']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '51', 'type': 'argument_list', 'children': ['52', '53']}; {'id': '52', 'type': 'string', 'children': [], 'value': '"Getting Alignak monitored configuration objects from module \'%s\'"'}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'instance'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'got_objects'}, {'id': '59', 'type': 'call', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'get_objects'}, {'id': '63', 'type': 'argument_list', 'children': []}; {'id': '64', 'type': 'except_clause', 'children': ['65', '69']}, {'id': '65', 'type': 'as_pattern', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '67', 'type': 'as_pattern_target', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'exp'}, {'id': '69', 'type': 'block', 'children': ['70', '83']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'exception'}, {'id': '75', 'type': 'argument_list', 'children': ['76', '79', '82']}; {'id': '76', 'type': 'concatenated_string', 'children': ['77', '78']}, {'id': '77', 'type': 'string', 'children': [], 'value': '"Module %s get_objects raised an exception %s. "'}; {'id': '78', 'type': 'string', 'children': [], 'value': '"Log and continue to run."'}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'instance'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'exp'}, {'id': '83', 'type': 'continue_statement', 'children': []}; {'id': '84', 'type': 'if_statement', 'children': ['85', '87']}, {'id': '85', 'type': 'not_operator', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'got_objects'}, {'id': '87', 'type': 'block', 'children': ['88', '98']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '93', 'type': 'argument_list', 'children': ['94', '95']}; {'id': '94', 'type': 'string', 'children': [], 'value': '"The module \'%s\' did not provided any objects."'}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'instance'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '98', 'type': 'return_statement', 'children': []}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'types_creations'}; {'id': '102', 'type': 'attribute', 'children': ['103', '106']}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'conf'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'types_creations'}, {'id': '107', 'type': 'for_statement', 'children': ['108', '109', '110']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'o_type'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'types_creations'}; {'id': '110', 'type': 'block', 'children': ['111', '122', '135', '152', '193']}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '119']}, {'id': '113', 'type': 'tuple_pattern', 'children': ['114', '115', '116', '117', '118']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '119', 'type': 'subscript', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'types_creations'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'o_type'}; {'id': '122', 'type': 'if_statement', 'children': ['123', '133']}, {'id': '123', 'type': 'comparison_operator', 'children': ['124', '125'], 'value': 'in'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '125', 'type': 'list', 'children': ['126', '127', '128', '129', '130', '131', '132'], 'value': "['arbiters', 'brokers', 'schedulers',\n 'pollers', 'reactionners', 'receivers', 'modules']"}; {'id': '126', 'type': 'string', 'children': [], 'value': "'arbiters'"}, {'id': '127', 'type': 'string', 'children': [], 'value': "'brokers'"}; {'id': '128', 'type': 'string', 'children': [], 'value': "'schedulers'"}, {'id': '129', 'type': 'string', 'children': [], 'value': "'pollers'"}; {'id': '130', 'type': 'string', 'children': [], 'value': "'reactionners'"}, {'id': '131', 'type': 'string', 'children': [], 'value': "'receivers'"}; {'id': '132', 'type': 'string', 'children': [], 'value': "'modules'"}, {'id': '133', 'type': 'block', 'children': ['134']}; {'id': '134', 'type': 'continue_statement', 'children': []}, {'id': '135', 'type': 'if_statement', 'children': ['136', '139']}; {'id': '136', 'type': 'comparison_operator', 'children': ['137', '138'], 'value': 'not'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'got_objects'}, {'id': '139', 'type': 'block', 'children': ['140', '151']}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'call', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '145', 'type': 'argument_list', 'children': ['146', '147', '148']}; {'id': '146', 'type': 'string', 'children': [], 'value': '"Did not get any \'%s\' objects from %s"'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '151', 'type': 'continue_statement', 'children': []}; {'id': '152', 'type': 'for_statement', 'children': ['153', '154', '157']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '154', 'type': 'subscript', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'got_objects'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '157', 'type': 'block', 'children': ['158', '169', '184']}; {'id': '158', 'type': 'if_statement', 'children': ['159', '162']}, {'id': '159', 'type': 'comparison_operator', 'children': ['160', '161'], 'value': 'not'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'o_type'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'raw_objects'}; {'id': '162', 'type': 'block', 'children': ['163']}, {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'assignment', 'children': ['165', '168']}, {'id': '165', 'type': 'subscript', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'raw_objects'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'o_type'}; {'id': '168', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '169', 'type': 'if_statement', 'children': ['170', '173']}; {'id': '170', 'type': 'comparison_operator', 'children': ['171', '172'], 'value': 'not'}, {'id': '171', 'type': 'string', 'children': [], 'value': "'imported_from'"}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '173', 'type': 'block', 'children': ['174']}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}, {'id': '175', 'type': 'assignment', 'children': ['176', '179']}; {'id': '176', 'type': 'subscript', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '178', 'type': 'string', 'children': [], 'value': "'imported_from'"}, {'id': '179', 'type': 'binary_operator', 'children': ['180', '181'], 'value': '%'}; {'id': '180', 'type': 'string', 'children': [], 'value': "'module:%s'"}, {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'instance'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '184', 'type': 'expression_statement', 'children': ['185']}, {'id': '185', 'type': 'call', 'children': ['186', '191']}; {'id': '186', 'type': 'attribute', 'children': ['187', '190']}, {'id': '187', 'type': 'subscript', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'raw_objects'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'o_type'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '191', 'type': 'argument_list', 'children': ['192']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'obj'}, {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'call', 'children': ['195', '198']}, {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '198', 'type': 'argument_list', 'children': ['199', '200', '206', '207']}, {'id': '199', 'type': 'string', 'children': [], 'value': '"Added %i %s objects from %s"'}; {'id': '200', 'type': 'call', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '202', 'type': 'argument_list', 'children': ['203']}, {'id': '203', 'type': 'subscript', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'got_objects'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'o_type'}, {'id': '207', 'type': 'attribute', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'instance'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'name'} | def load_modules_configuration_objects(self, raw_objects):
for instance in self.modules_manager.instances:
logger.debug("Getting objects from the module: %s", instance.name)
if not hasattr(instance, 'get_objects'):
logger.debug("The module '%s' do not provide any objects.", instance.name)
return
try:
logger.info("Getting Alignak monitored configuration objects from module '%s'",
instance.name)
got_objects = instance.get_objects()
except Exception as exp:
logger.exception("Module %s get_objects raised an exception %s. "
"Log and continue to run.", instance.name, exp)
continue
if not got_objects:
logger.warning("The module '%s' did not provided any objects.", instance.name)
return
types_creations = self.conf.types_creations
for o_type in types_creations:
(_, _, prop, _, _) = types_creations[o_type]
if prop in ['arbiters', 'brokers', 'schedulers',
'pollers', 'reactionners', 'receivers', 'modules']:
continue
if prop not in got_objects:
logger.warning("Did not get any '%s' objects from %s", prop, instance.name)
continue
for obj in got_objects[prop]:
if o_type not in raw_objects:
raw_objects[o_type] = []
if 'imported_from' not in obj:
obj['imported_from'] = 'module:%s' % instance.name
raw_objects[o_type].append(obj)
logger.debug("Added %i %s objects from %s",
len(got_objects[prop]), o_type, instance.name) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'load_modules_alignak_configuration'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '10', '112', '116']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'alignak_cfg'}, {'id': '9', 'type': 'dictionary', 'children': []}; {'id': '10', 'type': 'for_statement', 'children': ['11', '12', '17']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '12', 'type': 'attribute', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'modules_manager'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'instances'}, {'id': '17', 'type': 'block', 'children': ['18', '27']}; {'id': '18', 'type': 'if_statement', 'children': ['19', '25']}, {'id': '19', 'type': 'not_operator', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '22', 'type': 'argument_list', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '24', 'type': 'string', 'children': [], 'value': "'get_alignak_configuration'"}, {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'return_statement', 'children': []}, {'id': '27', 'type': 'try_statement', 'children': ['28', '54']}; {'id': '28', 'type': 'block', 'children': ['29', '39', '47']}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '36']}, {'id': '35', 'type': 'string', 'children': [], 'value': '"Getting Alignak global configuration from module \'%s\'"'}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '42', 'type': 'call', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'instance'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'get_alignak_configuration'}; {'id': '46', 'type': 'argument_list', 'children': []}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'alignak_cfg'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'cfg'}; {'id': '54', 'type': 'except_clause', 'children': ['55', '59']}, {'id': '55', 'type': 'as_pattern', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '57', 'type': 'as_pattern_target', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'exp'}, {'id': '59', 'type': 'block', 'children': ['60', '76', '84', '93', '105', '111']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '65', 'type': 'argument_list', 'children': ['66', '69', '72']}; {'id': '66', 'type': 'concatenated_string', 'children': ['67', '68']}, {'id': '67', 'type': 'string', 'children': [], 'value': '"Module %s get_alignak_configuration raised an exception %s. "'}; {'id': '68', 'type': 'string', 'children': [], 'value': '"Log and continue to run"'}, {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'instance'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '72', 'type': 'call', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'exp'}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'io'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'StringIO'}, {'id': '83', 'type': 'argument_list', 'children': []}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'traceback'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'print_exc'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'keyword_argument', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'file'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'call', 'children': ['95', '98']}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '98', 'type': 'argument_list', 'children': ['99', '100']}, {'id': '99', 'type': 'string', 'children': [], 'value': '"Back trace of this remove: %s"'}; {'id': '100', 'type': 'call', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'getvalue'}; {'id': '104', 'type': 'argument_list', 'children': []}, {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'call', 'children': ['107', '110']}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'close'}; {'id': '110', 'type': 'argument_list', 'children': []}, {'id': '111', 'type': 'continue_statement', 'children': []}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '115', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '116', 'type': 'if_statement', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'alignak_cfg'}; {'id': '118', 'type': 'block', 'children': ['119', '126', '201']}, {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'call', 'children': ['121', '124']}, {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}, {'id': '125', 'type': 'string', 'children': [], 'value': '"Got Alignak global configuration:"'}; {'id': '126', 'type': 'for_statement', 'children': ['127', '130', '138']}, {'id': '127', 'type': 'pattern_list', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '130', 'type': 'call', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}, {'id': '133', 'type': 'call', 'children': ['134', '137']}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'alignak_cfg'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '137', 'type': 'argument_list', 'children': []}; {'id': '138', 'type': 'block', 'children': ['139', '148', '172', '178', '184', '190']}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'call', 'children': ['141', '144']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '144', 'type': 'argument_list', 'children': ['145', '146', '147']}, {'id': '145', 'type': 'string', 'children': [], 'value': '"- %s = %s"'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '148', 'type': 'if_statement', 'children': ['149', '155']}, {'id': '149', 'type': 'call', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'startswith'}, {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'string', 'children': [], 'value': "'_'"}, {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'assignment', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '159', 'type': 'binary_operator', 'children': ['160', '171'], 'value': '+'}; {'id': '160', 'type': 'binary_operator', 'children': ['161', '162'], 'value': '+'}, {'id': '161', 'type': 'string', 'children': [], 'value': "'$'"}; {'id': '162', 'type': 'call', 'children': ['163', '170']}, {'id': '163', 'type': 'attribute', 'children': ['164', '169']}; {'id': '164', 'type': 'subscript', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '166', 'type': 'slice', 'children': ['167', '168']}, {'id': '167', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '168', 'type': 'colon', 'children': []}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'upper'}; {'id': '170', 'type': 'argument_list', 'children': []}, {'id': '171', 'type': 'string', 'children': [], 'value': "'$'"}; {'id': '172', 'type': 'if_statement', 'children': ['173', '176']}, {'id': '173', 'type': 'comparison_operator', 'children': ['174', '175'], 'value': 'is'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '175', 'type': 'None', 'children': []}; {'id': '176', 'type': 'block', 'children': ['177']}, {'id': '177', 'type': 'continue_statement', 'children': []}; {'id': '178', 'type': 'if_statement', 'children': ['179', '182']}, {'id': '179', 'type': 'comparison_operator', 'children': ['180', '181'], 'value': '=='}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '181', 'type': 'string', 'children': [], 'value': "'None'"}; {'id': '182', 'type': 'block', 'children': ['183']}, {'id': '183', 'type': 'continue_statement', 'children': []}; {'id': '184', 'type': 'if_statement', 'children': ['185', '188']}, {'id': '185', 'type': 'comparison_operator', 'children': ['186', '187'], 'value': '=='}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '187', 'type': 'string', 'children': [], 'value': "''"}; {'id': '188', 'type': 'block', 'children': ['189']}, {'id': '189', 'type': 'continue_statement', 'children': []}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}, {'id': '191', 'type': 'call', 'children': ['192', '195']}; {'id': '192', 'type': 'attribute', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '195', 'type': 'argument_list', 'children': ['196']}; {'id': '196', 'type': 'binary_operator', 'children': ['197', '198'], 'value': '%'}, {'id': '197', 'type': 'string', 'children': [], 'value': '"%s=%s"'}; {'id': '198', 'type': 'tuple', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'call', 'children': ['203', '208']}, {'id': '203', 'type': 'attribute', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'conf'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'load_params'}; {'id': '208', 'type': 'argument_list', 'children': ['209']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'params'} | def load_modules_alignak_configuration(self):
alignak_cfg = {}
for instance in self.modules_manager.instances:
if not hasattr(instance, 'get_alignak_configuration'):
return
try:
logger.info("Getting Alignak global configuration from module '%s'", instance.name)
cfg = instance.get_alignak_configuration()
alignak_cfg.update(cfg)
except Exception as exp:
logger.error("Module %s get_alignak_configuration raised an exception %s. "
"Log and continue to run", instance.name, str(exp))
output = io.StringIO()
traceback.print_exc(file=output)
logger.error("Back trace of this remove: %s", output.getvalue())
output.close()
continue
params = []
if alignak_cfg:
logger.info("Got Alignak global configuration:")
for key, value in sorted(alignak_cfg.items()):
logger.info("- %s = %s", key, value)
if key.startswith('_'):
key = '$' + key[1:].upper() + '$'
if value is None:
continue
if value == 'None':
continue
if value == '':
continue
params.append("%s=%s" % (key, value))
self.conf.load_params(params) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'daemons_start'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'run_daemons'}, {'id': '7', 'type': 'True', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '13', '32', '204']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '12', 'type': 'True', 'children': []}, {'id': '13', 'type': 'if_statement', 'children': ['14', '15', '23']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'run_daemons'}, {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'string', 'children': [], 'value': '"Alignak configured daemons start:"'}, {'id': '23', 'type': 'else_clause', 'children': ['24']}; {'id': '24', 'type': 'block', 'children': ['25']}, {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}, {'id': '31', 'type': 'string', 'children': [], 'value': '"Alignak configured daemons check:"'}; {'id': '32', 'type': 'for_statement', 'children': ['33', '34', '65']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'satellites_list'}; {'id': '34', 'type': 'list', 'children': ['35', '40', '45', '50', '55', '60'], 'value': '[self.conf.arbiters, self.conf.receivers, self.conf.reactionners,\n self.conf.pollers, self.conf.brokers, self.conf.schedulers]'}, {'id': '35', 'type': 'attribute', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'conf'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'arbiters'}; {'id': '40', 'type': 'attribute', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'conf'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'receivers'}, {'id': '45', 'type': 'attribute', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'conf'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'reactionners'}; {'id': '50', 'type': 'attribute', 'children': ['51', '54']}, {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'conf'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'pollers'}, {'id': '55', 'type': 'attribute', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'conf'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'brokers'}; {'id': '60', 'type': 'attribute', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'conf'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'schedulers'}, {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'for_statement', 'children': ['67', '68', '69']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'satellite'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'satellites_list'}, {'id': '69', 'type': 'block', 'children': ['70', '86', '94', '131', '136', '150', '169', '189', '198']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '75', 'type': 'argument_list', 'children': ['76', '77', '80', '83']}; {'id': '76', 'type': 'string', 'children': [], 'value': '"- found %s, to be launched: %s, address: %s"'}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'satellite'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'satellite'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'alignak_launched'}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'satellite'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'uri'}; {'id': '86', 'type': 'if_statement', 'children': ['87', '92']}, {'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': '=='}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'satellite'}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'link_to_myself'}; {'id': '92', 'type': 'block', 'children': ['93']}, {'id': '93', 'type': 'continue_statement', 'children': []}; {'id': '94', 'type': 'if_statement', 'children': ['95', '107']}, {'id': '95', 'type': 'boolean_operator', 'children': ['96', '99', '100'], 'value': 'and'}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'satellite'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'alignak_launched'}, {'id': '99', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '100', 'type': 'comparison_operator', 'children': ['101', '104'], 'value': 'not'}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'satellite'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'address'}; {'id': '104', 'type': 'list', 'children': ['105', '106'], 'value': "['127.0.0.1', 'localhost']"}, {'id': '105', 'type': 'string', 'children': [], 'value': "'127.0.0.1'"}; {'id': '106', 'type': 'string', 'children': [], 'value': "'localhost'"}, {'id': '107', 'type': 'block', 'children': ['108', '126', '130']}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}, {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '113', 'type': 'argument_list', 'children': ['114', '117', '120', '123']}; {'id': '114', 'type': 'concatenated_string', 'children': ['115', '116']}, {'id': '115', 'type': 'string', 'children': [], 'value': '"Alignak is required to launch a daemon for %s %s "'}; {'id': '116', 'type': 'string', 'children': [], 'value': '"but the satelitte is defined on an external address: %s"'}, {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'satellite'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'satellite'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'satellite'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'address'}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}, {'id': '127', 'type': 'assignment', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '129', 'type': 'False', 'children': []}; {'id': '130', 'type': 'continue_statement', 'children': []}, {'id': '131', 'type': 'if_statement', 'children': ['132', '134']}; {'id': '132', 'type': 'not_operator', 'children': ['133']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'run_daemons'}; {'id': '134', 'type': 'block', 'children': ['135']}, {'id': '135', 'type': 'continue_statement', 'children': []}; {'id': '136', 'type': 'if_statement', 'children': ['137', '141']}, {'id': '137', 'type': 'not_operator', 'children': ['138']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'satellite'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'alignak_launched'}, {'id': '141', 'type': 'block', 'children': ['142', '149']}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'call', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'string', 'children': [], 'value': '"Alignak will not launch \'%s\'"'}, {'id': '149', 'type': 'continue_statement', 'children': []}; {'id': '150', 'type': 'if_statement', 'children': ['151', '155']}, {'id': '151', 'type': 'not_operator', 'children': ['152']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'satellite'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'active'}, {'id': '155', 'type': 'block', 'children': ['156', '168']}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'call', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '161', 'type': 'argument_list', 'children': ['162', '165']}; {'id': '162', 'type': 'concatenated_string', 'children': ['163', '164']}, {'id': '163', 'type': 'string', 'children': [], 'value': '"- daemon \'%s\' is declared but not set as active, "'}; {'id': '164', 'type': 'string', 'children': [], 'value': '"do not start..."'}, {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'satellite'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '168', 'type': 'continue_statement', 'children': []}, {'id': '169', 'type': 'if_statement', 'children': ['170', '177']}; {'id': '170', 'type': 'comparison_operator', 'children': ['171', '174'], 'value': 'in'}, {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'satellite'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '174', 'type': 'attribute', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'my_daemons'}, {'id': '177', 'type': 'block', 'children': ['178', '188']}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}, {'id': '179', 'type': 'call', 'children': ['180', '183']}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '183', 'type': 'argument_list', 'children': ['184', '185']}; {'id': '184', 'type': 'string', 'children': [], 'value': '"- daemon \'%s\' is already running"'}, {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'satellite'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '188', 'type': 'continue_statement', 'children': []}, {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'assignment', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'started'}; {'id': '192', 'type': 'call', 'children': ['193', '196']}, {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'start_daemon'}; {'id': '196', 'type': 'argument_list', 'children': ['197']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'satellite'}; {'id': '198', 'type': 'expression_statement', 'children': ['199']}, {'id': '199', 'type': 'assignment', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '201', 'type': 'boolean_operator', 'children': ['202', '203'], 'value': 'and'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'started'}; {'id': '204', 'type': 'return_statement', 'children': ['205']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'result'} | def daemons_start(self, run_daemons=True):
result = True
if run_daemons:
logger.info("Alignak configured daemons start:")
else:
logger.info("Alignak configured daemons check:")
for satellites_list in [self.conf.arbiters, self.conf.receivers, self.conf.reactionners,
self.conf.pollers, self.conf.brokers, self.conf.schedulers]:
for satellite in satellites_list:
logger.info("- found %s, to be launched: %s, address: %s",
satellite.name, satellite.alignak_launched, satellite.uri)
if satellite == self.link_to_myself:
continue
if satellite.alignak_launched and \
satellite.address not in ['127.0.0.1', 'localhost']:
logger.error("Alignak is required to launch a daemon for %s %s "
"but the satelitte is defined on an external address: %s",
satellite.type, satellite.name, satellite.address)
result = False
continue
if not run_daemons:
continue
if not satellite.alignak_launched:
logger.debug("Alignak will not launch '%s'")
continue
if not satellite.active:
logger.warning("- daemon '%s' is declared but not set as active, "
"do not start...", satellite.name)
continue
if satellite.name in self.my_daemons:
logger.warning("- daemon '%s' is already running", satellite.name)
continue
started = self.start_daemon(satellite)
result = result and started
return result |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'daemons_stop'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'timeout'}, {'id': '7', 'type': 'integer', 'children': [], 'value': '30'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'kill_children'}; {'id': '10', 'type': 'False', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '30', '34', '274']}; {'id': '12', 'type': 'function_definition', 'children': ['13', '14', '16']}, {'id': '13', 'type': 'function_name', 'children': [], 'value': 'on_terminate'}; {'id': '14', 'type': 'parameters', 'children': ['15']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'proc'}; {'id': '16', 'type': 'block', 'children': ['17']}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '22', 'type': 'argument_list', 'children': ['23', '24', '27']}, {'id': '23', 'type': 'string', 'children': [], 'value': '"process %s terminated with exit code %s"'}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'proc'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'pid'}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'proc'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'returncode'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '33', 'type': 'True', 'children': []}; {'id': '34', 'type': 'if_statement', 'children': ['35', '38']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'my_daemons'}; {'id': '38', 'type': 'block', 'children': ['39', '46', '54', '139', '143', '178', '195', '260']}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'string', 'children': [], 'value': '"Alignak self-launched daemons stop:"'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '53', 'type': 'argument_list', 'children': []}; {'id': '54', 'type': 'for_statement', 'children': ['55', '56', '66']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'daemon'}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'call', 'children': ['60', '65']}; {'id': '60', 'type': 'attribute', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'my_daemons'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '65', 'type': 'argument_list', 'children': []}; {'id': '66', 'type': 'block', 'children': ['67', '71', '84', '93']}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'procs'}; {'id': '70', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '71', 'type': 'if_statement', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'kill_children'}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'procs'}, {'id': '77', 'type': 'call', 'children': ['78', '83']}; {'id': '78', 'type': 'attribute', 'children': ['79', '82']}, {'id': '79', 'type': 'subscript', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'daemon'}, {'id': '81', 'type': 'string', 'children': [], 'value': "'process'"}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'children'}, {'id': '83', 'type': 'argument_list', 'children': []}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'procs'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'subscript', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'daemon'}; {'id': '92', 'type': 'string', 'children': [], 'value': "'process'"}, {'id': '93', 'type': 'for_statement', 'children': ['94', '95', '96']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'process'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'procs'}; {'id': '96', 'type': 'block', 'children': ['97']}, {'id': '97', 'type': 'try_statement', 'children': ['98', '117']}; {'id': '98', 'type': 'block', 'children': ['99', '111']}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'call', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '104', 'type': 'argument_list', 'children': ['105', '106']}, {'id': '105', 'type': 'string', 'children': [], 'value': '"- terminating process %s"'}; {'id': '106', 'type': 'call', 'children': ['107', '110']}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'process'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '110', 'type': 'argument_list', 'children': []}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'call', 'children': ['113', '116']}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'process'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'terminate'}; {'id': '116', 'type': 'argument_list', 'children': []}, {'id': '117', 'type': 'except_clause', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'psutil'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'AccessDenied'}, {'id': '121', 'type': 'block', 'children': ['122']}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'call', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '127', 'type': 'argument_list', 'children': ['128', '129', '134']}; {'id': '128', 'type': 'string', 'children': [], 'value': '"Process %s is %s"'}, {'id': '129', 'type': 'call', 'children': ['130', '133']}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'process'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '133', 'type': 'argument_list', 'children': []}; {'id': '134', 'type': 'call', 'children': ['135', '138']}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'process'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '138', 'type': 'argument_list', 'children': []}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'procs'}; {'id': '142', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '143', 'type': 'for_statement', 'children': ['144', '145', '155']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'daemon'}, {'id': '145', 'type': 'call', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'call', 'children': ['149', '154']}, {'id': '149', 'type': 'attribute', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'my_daemons'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '154', 'type': 'argument_list', 'children': []}, {'id': '155', 'type': 'block', 'children': ['156', '169']}; {'id': '156', 'type': 'if_statement', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'kill_children'}; {'id': '158', 'type': 'block', 'children': ['159']}, {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'assignment', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'procs'}; {'id': '162', 'type': 'call', 'children': ['163', '168']}, {'id': '163', 'type': 'attribute', 'children': ['164', '167']}; {'id': '164', 'type': 'subscript', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'daemon'}; {'id': '166', 'type': 'string', 'children': [], 'value': "'process'"}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '168', 'type': 'argument_list', 'children': []}, {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'call', 'children': ['171', '174']}, {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'procs'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '174', 'type': 'argument_list', 'children': ['175']}, {'id': '175', 'type': 'subscript', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'daemon'}, {'id': '177', 'type': 'string', 'children': [], 'value': "'process'"}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}, {'id': '179', 'type': 'assignment', 'children': ['180', '183']}; {'id': '180', 'type': 'pattern_list', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'alive'}, {'id': '183', 'type': 'call', 'children': ['184', '187']}; {'id': '184', 'type': 'attribute', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'psutil'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'wait_procs'}, {'id': '187', 'type': 'argument_list', 'children': ['188', '189', '192']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'procs'}, {'id': '189', 'type': 'keyword_argument', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'timeout'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '192', 'type': 'keyword_argument', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'callback'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'on_terminate'}, {'id': '195', 'type': 'if_statement', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'alive'}, {'id': '197', 'type': 'block', 'children': ['198', '220', '237']}; {'id': '198', 'type': 'for_statement', 'children': ['199', '200', '201']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'process'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'alive'}, {'id': '201', 'type': 'block', 'children': ['202', '214']}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}, {'id': '203', 'type': 'call', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '207', 'type': 'argument_list', 'children': ['208', '209']}; {'id': '208', 'type': 'string', 'children': [], 'value': '"Process %s did not stopped, trying to kill"'}, {'id': '209', 'type': 'call', 'children': ['210', '213']}; {'id': '210', 'type': 'attribute', 'children': ['211', '212']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'process'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '213', 'type': 'argument_list', 'children': []}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}, {'id': '215', 'type': 'call', 'children': ['216', '219']}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'process'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'kill'}, {'id': '219', 'type': 'argument_list', 'children': []}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}, {'id': '221', 'type': 'assignment', 'children': ['222', '225']}; {'id': '222', 'type': 'pattern_list', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'alive'}, {'id': '225', 'type': 'call', 'children': ['226', '229']}; {'id': '226', 'type': 'attribute', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'psutil'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'wait_procs'}, {'id': '229', 'type': 'argument_list', 'children': ['230', '231', '234']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'alive'}, {'id': '231', 'type': 'keyword_argument', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'timeout'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '234', 'type': 'keyword_argument', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'callback'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'on_terminate'}, {'id': '237', 'type': 'if_statement', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'alive'}, {'id': '239', 'type': 'block', 'children': ['240']}; {'id': '240', 'type': 'for_statement', 'children': ['241', '242', '243']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'process'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'alive'}, {'id': '243', 'type': 'block', 'children': ['244', '256']}; {'id': '244', 'type': 'expression_statement', 'children': ['245']}, {'id': '245', 'type': 'call', 'children': ['246', '249']}; {'id': '246', 'type': 'attribute', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '249', 'type': 'argument_list', 'children': ['250', '251']}; {'id': '250', 'type': 'string', 'children': [], 'value': '"process %s survived SIGKILL; giving up"'}, {'id': '251', 'type': 'call', 'children': ['252', '255']}; {'id': '252', 'type': 'attribute', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'process'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '255', 'type': 'argument_list', 'children': []}; {'id': '256', 'type': 'expression_statement', 'children': ['257']}, {'id': '257', 'type': 'assignment', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'result'}, {'id': '259', 'type': 'False', 'children': []}; {'id': '260', 'type': 'expression_statement', 'children': ['261']}, {'id': '261', 'type': 'call', 'children': ['262', '265']}; {'id': '262', 'type': 'attribute', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '265', 'type': 'argument_list', 'children': ['266', '267']}; {'id': '266', 'type': 'string', 'children': [], 'value': '"Stopping daemons duration: %.2f seconds"'}, {'id': '267', 'type': 'binary_operator', 'children': ['268', '273'], 'value': '-'}; {'id': '268', 'type': 'call', 'children': ['269', '272']}, {'id': '269', 'type': 'attribute', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '272', 'type': 'argument_list', 'children': []}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '274', 'type': 'return_statement', 'children': ['275']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'result'} | def daemons_stop(self, timeout=30, kill_children=False):
def on_terminate(proc):
logger.debug("process %s terminated with exit code %s", proc.pid, proc.returncode)
result = True
if self.my_daemons:
logger.info("Alignak self-launched daemons stop:")
start = time.time()
for daemon in list(self.my_daemons.values()):
procs = []
if kill_children:
procs = daemon['process'].children()
procs.append(daemon['process'])
for process in procs:
try:
logger.info("- terminating process %s", process.name())
process.terminate()
except psutil.AccessDenied:
logger.warning("Process %s is %s", process.name(), process.status())
procs = []
for daemon in list(self.my_daemons.values()):
if kill_children:
procs = daemon['process'].children()
procs.append(daemon['process'])
_, alive = psutil.wait_procs(procs, timeout=timeout, callback=on_terminate)
if alive:
for process in alive:
logger.warning("Process %s did not stopped, trying to kill", process.name())
process.kill()
_, alive = psutil.wait_procs(alive, timeout=timeout, callback=on_terminate)
if alive:
for process in alive:
logger.warning("process %s survived SIGKILL; giving up", process.name())
result = False
logger.debug("Stopping daemons duration: %.2f seconds", time.time() - start)
return result |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'setup_new_conf'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '16', '412']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'call', 'children': ['8', '15']}; {'id': '8', 'type': 'attribute', 'children': ['9', '14']}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'super'}, {'id': '11', 'type': 'argument_list', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'Arbiter'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'setup_new_conf'}, {'id': '15', 'type': 'argument_list', 'children': []}; {'id': '16', 'type': 'with_statement', 'children': ['17', '22']}, {'id': '17', 'type': 'with_clause', 'children': ['18']}; {'id': '18', 'type': 'with_item', 'children': ['19']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'conf_lock'}; {'id': '22', 'type': 'block', 'children': ['23', '30', '38', '50', '60', '68', '75', '94', '102', '112', '122', '128', '136', '229', '245', '254', '262']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}, {'id': '29', 'type': 'string', 'children': [], 'value': '"I received a new configuration from my master"'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'cur_conf'}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'new_conf'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self_conf'}, {'id': '41', 'type': 'call', 'children': ['42', '47']}; {'id': '42', 'type': 'attribute', 'children': ['43', '46']}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'cur_conf'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '47', 'type': 'argument_list', 'children': ['48', '49']}; {'id': '48', 'type': 'string', 'children': [], 'value': "'self_conf'"}, {'id': '49', 'type': 'None', 'children': []}; {'id': '50', 'type': 'if_statement', 'children': ['51', '53']}, {'id': '51', 'type': 'not_operator', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'self_conf'}, {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'self_conf'}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'conf'}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'whole_conf'}, {'id': '63', 'type': 'subscript', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'cur_conf'}, {'id': '67', 'type': 'string', 'children': [], 'value': "'whole_conf'"}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'string', 'children': [], 'value': '"Received a new configuration, containing:"'}, {'id': '75', 'type': 'for_statement', 'children': ['76', '77', '80']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'cur_conf'}; {'id': '80', 'type': 'block', 'children': ['81']}, {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '86', 'type': 'argument_list', 'children': ['87', '88', '89']}, {'id': '87', 'type': 'string', 'children': [], 'value': '"- %s: %s"'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '89', 'type': 'subscript', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'cur_conf'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '99', 'type': 'argument_list', 'children': ['100', '101']}; {'id': '100', 'type': 'string', 'children': [], 'value': '"satellite self configuration part: %s"'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'self_conf'}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'alignak_name'}, {'id': '107', 'type': 'subscript', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'cur_conf'}, {'id': '111', 'type': 'string', 'children': [], 'value': "'alignak_name'"}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}, {'id': '113', 'type': 'call', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '117', 'type': 'argument_list', 'children': ['118', '119']}; {'id': '118', 'type': 'string', 'children': [], 'value': '"My Alignak instance: %s"'}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'alignak_name'}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'assignment', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'new_conf'}, {'id': '127', 'type': 'dictionary', 'children': []}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 't00'}, {'id': '131', 'type': 'call', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '135', 'type': 'argument_list', 'children': []}; {'id': '136', 'type': 'try_statement', 'children': ['137', '145', '184']}, {'id': '137', 'type': 'block', 'children': ['138']}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'received_conf_part'}, {'id': '141', 'type': 'call', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'unserialize'}, {'id': '143', 'type': 'argument_list', 'children': ['144']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'whole_conf'}, {'id': '145', 'type': 'except_clause', 'children': ['146', '150']}; {'id': '146', 'type': 'as_pattern', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'AlignakClassLookupException'}; {'id': '148', 'type': 'as_pattern_target', 'children': ['149']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'exp'}; {'id': '150', 'type': 'block', 'children': ['151', '160', '171', '183']}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'assignment', 'children': ['153', '156']}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'new_conf'}; {'id': '156', 'type': 'dictionary', 'children': ['157']}, {'id': '157', 'type': 'pair', 'children': ['158', '159']}; {'id': '158', 'type': 'string', 'children': [], 'value': '"_status"'}, {'id': '159', 'type': 'string', 'children': [], 'value': '"Cannot un-serialize configuration received from arbiter"'}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}, {'id': '161', 'type': 'call', 'children': ['162', '165']}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '165', 'type': 'argument_list', 'children': ['166']}; {'id': '166', 'type': 'subscript', 'children': ['167', '170']}, {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'new_conf'}; {'id': '170', 'type': 'string', 'children': [], 'value': "'_status'"}, {'id': '171', 'type': 'expression_statement', 'children': ['172']}; {'id': '172', 'type': 'call', 'children': ['173', '176']}, {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '176', 'type': 'argument_list', 'children': ['177', '178']}, {'id': '177', 'type': 'string', 'children': [], 'value': '"Back trace of the error:\\n%s"'}; {'id': '178', 'type': 'call', 'children': ['179', '182']}, {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'traceback'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'format_exc'}; {'id': '182', 'type': 'argument_list', 'children': []}, {'id': '183', 'type': 'return_statement', 'children': []}; {'id': '184', 'type': 'except_clause', 'children': ['185', '189']}, {'id': '185', 'type': 'as_pattern', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'Exception'}, {'id': '187', 'type': 'as_pattern_target', 'children': ['188']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'exp'}, {'id': '189', 'type': 'block', 'children': ['190', '199', '210', '219']}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}, {'id': '191', 'type': 'assignment', 'children': ['192', '195']}; {'id': '192', 'type': 'attribute', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'new_conf'}, {'id': '195', 'type': 'dictionary', 'children': ['196']}; {'id': '196', 'type': 'pair', 'children': ['197', '198']}, {'id': '197', 'type': 'string', 'children': [], 'value': '"_status"'}; {'id': '198', 'type': 'string', 'children': [], 'value': '"Cannot un-serialize configuration received from arbiter"'}, {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'call', 'children': ['201', '204']}, {'id': '201', 'type': 'attribute', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '204', 'type': 'argument_list', 'children': ['205']}, {'id': '205', 'type': 'subscript', 'children': ['206', '209']}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'new_conf'}, {'id': '209', 'type': 'string', 'children': [], 'value': "'_status'"}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}, {'id': '211', 'type': 'call', 'children': ['212', '215']}; {'id': '212', 'type': 'attribute', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '215', 'type': 'argument_list', 'children': ['216']}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'new_conf'}, {'id': '219', 'type': 'expression_statement', 'children': ['220']}; {'id': '220', 'type': 'call', 'children': ['221', '224']}, {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'exit_on_exception'}; {'id': '224', 'type': 'argument_list', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'exp'}; {'id': '226', 'type': 'attribute', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'new_conf'}, {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'call', 'children': ['231', '234']}, {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '234', 'type': 'argument_list', 'children': ['235', '236', '237', '238']}, {'id': '235', 'type': 'string', 'children': [], 'value': '"Monitored configuration %s received at %d. Un-serialized in %d secs"'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'received_conf_part'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 't00'}; {'id': '238', 'type': 'binary_operator', 'children': ['239', '244'], 'value': '-'}, {'id': '239', 'type': 'call', 'children': ['240', '243']}; {'id': '240', 'type': 'attribute', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '243', 'type': 'argument_list', 'children': []}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 't00'}, {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'assignment', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'my_satellites'}; {'id': '248', 'type': 'call', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '250', 'type': 'argument_list', 'children': ['251', '252', '253']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '252', 'type': 'string', 'children': [], 'value': "'arbiters'"}, {'id': '253', 'type': 'dictionary', 'children': []}; {'id': '254', 'type': 'expression_statement', 'children': ['255']}, {'id': '255', 'type': 'assignment', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'received_satellites'}, {'id': '257', 'type': 'subscript', 'children': ['258', '261']}; {'id': '258', 'type': 'attribute', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'cur_conf'}, {'id': '261', 'type': 'string', 'children': [], 'value': "'arbiters'"}; {'id': '262', 'type': 'for_statement', 'children': ['263', '264', '265']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'link_uuid'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'received_satellites'}, {'id': '265', 'type': 'block', 'children': ['266', '272', '288', '296', '300', '304', '308', '312', '316', '356', '366', '374', '382', '388', '394', '400', '406']}; {'id': '266', 'type': 'expression_statement', 'children': ['267']}, {'id': '267', 'type': 'assignment', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'rs_conf'}, {'id': '269', 'type': 'subscript', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'received_satellites'}, {'id': '271', 'type': 'identifier', 'children': [], 'value': 'link_uuid'}; {'id': '272', 'type': 'expression_statement', 'children': ['273']}, {'id': '273', 'type': 'call', 'children': ['274', '277']}; {'id': '274', 'type': 'attribute', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '277', 'type': 'argument_list', 'children': ['278', '279', '282', '285']}; {'id': '278', 'type': 'string', 'children': [], 'value': '"- received %s - %s: %s"'}, {'id': '279', 'type': 'subscript', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'rs_conf'}, {'id': '281', 'type': 'string', 'children': [], 'value': "'instance_id'"}; {'id': '282', 'type': 'subscript', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'rs_conf'}; {'id': '284', 'type': 'string', 'children': [], 'value': "'type'"}, {'id': '285', 'type': 'subscript', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'rs_conf'}, {'id': '287', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '288', 'type': 'expression_statement', 'children': ['289']}, {'id': '289', 'type': 'assignment', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'already_got'}, {'id': '291', 'type': 'comparison_operator', 'children': ['292', '295'], 'value': 'in'}; {'id': '292', 'type': 'subscript', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'rs_conf'}; {'id': '294', 'type': 'string', 'children': [], 'value': "'instance_id'"}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'my_satellites'}; {'id': '296', 'type': 'expression_statement', 'children': ['297']}, {'id': '297', 'type': 'assignment', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'broks'}, {'id': '299', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '300', 'type': 'expression_statement', 'children': ['301']}, {'id': '301', 'type': 'assignment', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'actions'}, {'id': '303', 'type': 'dictionary', 'children': []}; {'id': '304', 'type': 'expression_statement', 'children': ['305']}, {'id': '305', 'type': 'assignment', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'wait_homerun'}, {'id': '307', 'type': 'dictionary', 'children': []}; {'id': '308', 'type': 'expression_statement', 'children': ['309']}, {'id': '309', 'type': 'assignment', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'external_commands'}, {'id': '311', 'type': 'dictionary', 'children': []}; {'id': '312', 'type': 'expression_statement', 'children': ['313']}, {'id': '313', 'type': 'assignment', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'running_id'}, {'id': '315', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '316', 'type': 'if_statement', 'children': ['317', '318']}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'already_got'}; {'id': '318', 'type': 'block', 'children': ['319', '329', '337', '352']}, {'id': '319', 'type': 'expression_statement', 'children': ['320']}; {'id': '320', 'type': 'call', 'children': ['321', '324']}, {'id': '321', 'type': 'attribute', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '323', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '324', 'type': 'argument_list', 'children': ['325', '326']}, {'id': '325', 'type': 'string', 'children': [], 'value': '"I already got: %s"'}; {'id': '326', 'type': 'subscript', 'children': ['327', '328']}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'rs_conf'}; {'id': '328', 'type': 'string', 'children': [], 'value': "'instance_id'"}, {'id': '329', 'type': 'expression_statement', 'children': ['330']}; {'id': '330', 'type': 'assignment', 'children': ['331', '332']}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'running_id'}; {'id': '332', 'type': 'attribute', 'children': ['333', '336']}, {'id': '333', 'type': 'subscript', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'my_satellites'}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'link_uuid'}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'running_id'}, {'id': '337', 'type': 'expression_statement', 'children': ['338']}; {'id': '338', 'type': 'assignment', 'children': ['339', '344', '345']}, {'id': '339', 'type': 'tuple_pattern', 'children': ['340', '341', '342', '343']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'broks'}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'actions'}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'wait_homerun'}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'external_commands'}; {'id': '344', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '345', 'type': 'call', 'children': ['346', '351']}; {'id': '346', 'type': 'attribute', 'children': ['347', '350']}, {'id': '347', 'type': 'subscript', 'children': ['348', '349']}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'my_satellites'}, {'id': '349', 'type': 'identifier', 'children': [], 'value': 'link_uuid'}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'get_and_clear_context'}, {'id': '351', 'type': 'argument_list', 'children': []}; {'id': '352', 'type': 'delete_statement', 'children': ['353']}, {'id': '353', 'type': 'subscript', 'children': ['354', '355']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'my_satellites'}, {'id': '355', 'type': 'identifier', 'children': [], 'value': 'link_uuid'}; {'id': '356', 'type': 'expression_statement', 'children': ['357']}, {'id': '357', 'type': 'assignment', 'children': ['358', '359']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'new_link'}, {'id': '359', 'type': 'call', 'children': ['360', '363']}; {'id': '360', 'type': 'attribute', 'children': ['361', '362']}, {'id': '361', 'type': 'identifier', 'children': [], 'value': 'SatelliteLink'}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'get_a_satellite_link'}, {'id': '363', 'type': 'argument_list', 'children': ['364', '365']}; {'id': '364', 'type': 'string', 'children': [], 'value': "'arbiter'"}, {'id': '365', 'type': 'identifier', 'children': [], 'value': 'rs_conf'}; {'id': '366', 'type': 'expression_statement', 'children': ['367']}, {'id': '367', 'type': 'assignment', 'children': ['368', '373']}; {'id': '368', 'type': 'subscript', 'children': ['369', '370']}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'my_satellites'}; {'id': '370', 'type': 'attribute', 'children': ['371', '372']}, {'id': '371', 'type': 'identifier', 'children': [], 'value': 'new_link'}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'uuid'}, {'id': '373', 'type': 'identifier', 'children': [], 'value': 'new_link'}; {'id': '374', 'type': 'expression_statement', 'children': ['375']}, {'id': '375', 'type': 'call', 'children': ['376', '379']}; {'id': '376', 'type': 'attribute', 'children': ['377', '378']}, {'id': '377', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '379', 'type': 'argument_list', 'children': ['380', '381']}; {'id': '380', 'type': 'string', 'children': [], 'value': '"I got a new arbiter satellite: %s"'}, {'id': '381', 'type': 'identifier', 'children': [], 'value': 'new_link'}; {'id': '382', 'type': 'expression_statement', 'children': ['383']}, {'id': '383', 'type': 'assignment', 'children': ['384', '387']}; {'id': '384', 'type': 'attribute', 'children': ['385', '386']}, {'id': '385', 'type': 'identifier', 'children': [], 'value': 'new_link'}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'running_id'}, {'id': '387', 'type': 'identifier', 'children': [], 'value': 'running_id'}; {'id': '388', 'type': 'expression_statement', 'children': ['389']}, {'id': '389', 'type': 'assignment', 'children': ['390', '393']}; {'id': '390', 'type': 'attribute', 'children': ['391', '392']}, {'id': '391', 'type': 'identifier', 'children': [], 'value': 'new_link'}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'external_commands'}, {'id': '393', 'type': 'identifier', 'children': [], 'value': 'external_commands'}; {'id': '394', 'type': 'expression_statement', 'children': ['395']}, {'id': '395', 'type': 'assignment', 'children': ['396', '399']}; {'id': '396', 'type': 'attribute', 'children': ['397', '398']}, {'id': '397', 'type': 'identifier', 'children': [], 'value': 'new_link'}; {'id': '398', 'type': 'identifier', 'children': [], 'value': 'broks'}, {'id': '399', 'type': 'identifier', 'children': [], 'value': 'broks'}; {'id': '400', 'type': 'expression_statement', 'children': ['401']}, {'id': '401', 'type': 'assignment', 'children': ['402', '405']}; {'id': '402', 'type': 'attribute', 'children': ['403', '404']}, {'id': '403', 'type': 'identifier', 'children': [], 'value': 'new_link'}; {'id': '404', 'type': 'identifier', 'children': [], 'value': 'wait_homerun'}, {'id': '405', 'type': 'identifier', 'children': [], 'value': 'wait_homerun'}; {'id': '406', 'type': 'expression_statement', 'children': ['407']}, {'id': '407', 'type': 'assignment', 'children': ['408', '411']}; {'id': '408', 'type': 'attribute', 'children': ['409', '410']}, {'id': '409', 'type': 'identifier', 'children': [], 'value': 'new_link'}; {'id': '410', 'type': 'identifier', 'children': [], 'value': 'actions'}, {'id': '411', 'type': 'identifier', 'children': [], 'value': 'actions'}; {'id': '412', 'type': 'expression_statement', 'children': ['413']}, {'id': '413', 'type': 'assignment', 'children': ['414', '417']}; {'id': '414', 'type': 'attribute', 'children': ['415', '416']}, {'id': '415', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '416', 'type': 'identifier', 'children': [], 'value': 'have_conf'}, {'id': '417', 'type': 'True', 'children': []} | def setup_new_conf(self):
super(Arbiter, self).setup_new_conf()
with self.conf_lock:
logger.info("I received a new configuration from my master")
self.cur_conf = self.new_conf
self_conf = self.cur_conf.get('self_conf', None)
if not self_conf:
self_conf = self.conf
whole_conf = self.cur_conf['whole_conf']
logger.debug("Received a new configuration, containing:")
for key in self.cur_conf:
logger.debug("- %s: %s", key, self.cur_conf[key])
logger.debug("satellite self configuration part: %s", self_conf)
self.alignak_name = self.cur_conf['alignak_name']
logger.info("My Alignak instance: %s", self.alignak_name)
self.new_conf = {}
t00 = time.time()
try:
received_conf_part = unserialize(whole_conf)
except AlignakClassLookupException as exp:
self.new_conf = {
"_status": "Cannot un-serialize configuration received from arbiter"
}
logger.error(self.new_conf['_status'])
logger.error("Back trace of the error:\n%s", traceback.format_exc())
return
except Exception as exp:
self.new_conf = {
"_status": "Cannot un-serialize configuration received from arbiter"
}
logger.error(self.new_conf['_status'])
logger.error(self.new_conf)
self.exit_on_exception(exp, self.new_conf)
logger.info("Monitored configuration %s received at %d. Un-serialized in %d secs",
received_conf_part, t00, time.time() - t00)
my_satellites = getattr(self, 'arbiters', {})
received_satellites = self.cur_conf['arbiters']
for link_uuid in received_satellites:
rs_conf = received_satellites[link_uuid]
logger.debug("- received %s - %s: %s", rs_conf['instance_id'],
rs_conf['type'], rs_conf['name'])
already_got = rs_conf['instance_id'] in my_satellites
broks = []
actions = {}
wait_homerun = {}
external_commands = {}
running_id = 0
if already_got:
logger.warning("I already got: %s", rs_conf['instance_id'])
running_id = my_satellites[link_uuid].running_id
(broks, actions,
wait_homerun, external_commands) = \
my_satellites[link_uuid].get_and_clear_context()
del my_satellites[link_uuid]
new_link = SatelliteLink.get_a_satellite_link('arbiter', rs_conf)
my_satellites[new_link.uuid] = new_link
logger.info("I got a new arbiter satellite: %s", new_link)
new_link.running_id = running_id
new_link.external_commands = external_commands
new_link.broks = broks
new_link.wait_homerun = wait_homerun
new_link.actions = actions
self.have_conf = True |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'wait_for_master_death'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '13', '17', '27', '31', '56', '64']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'call', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'string', 'children': [], 'value': '"Waiting for master death"'}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '16', 'type': 'float', 'children': [], 'value': '1.0'}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'last_master_ping'}; {'id': '22', 'type': 'call', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '26', 'type': 'argument_list', 'children': []}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'master_timeout'}; {'id': '30', 'type': 'integer', 'children': [], 'value': '300'}, {'id': '31', 'type': 'for_statement', 'children': ['32', '33', '38']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'arbiter_link'}, {'id': '33', 'type': 'attribute', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'conf'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'arbiters'}; {'id': '38', 'type': 'block', 'children': ['39']}, {'id': '39', 'type': 'if_statement', 'children': ['40', '44']}; {'id': '40', 'type': 'not_operator', 'children': ['41']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'arbiter_link'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'spare'}; {'id': '44', 'type': 'block', 'children': ['45']}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48', '49']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'master_timeout'}; {'id': '48', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '49', 'type': 'binary_operator', 'children': ['50', '53'], 'value': '*'}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'arbiter_link'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'spare_check_interval'}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'arbiter_link'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'spare_max_check_attempts'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '61', 'type': 'argument_list', 'children': ['62', '63']}; {'id': '62', 'type': 'string', 'children': [], 'value': '"I\'ll wait master death for %d seconds"'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'master_timeout'}; {'id': '64', 'type': 'while_statement', 'children': ['65', '69']}, {'id': '65', 'type': 'not_operator', 'children': ['66']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'interrupted'}, {'id': '69', 'type': 'block', 'children': ['70', '81', '90', '101', '110', '118', '126']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'assignment', 'children': ['72', '75']}; {'id': '72', 'type': 'pattern_list', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'tcdiff'}, {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'make_a_pause'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'timeout'}, {'id': '81', 'type': 'if_statement', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'tcdiff'}, {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'augmented_assignment', 'children': ['86', '89'], 'value': '+='}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'last_master_ping'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'tcdiff'}; {'id': '90', 'type': 'if_statement', 'children': ['91', '94']}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'new_conf'}; {'id': '94', 'type': 'block', 'children': ['95']}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'call', 'children': ['97', '100']}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'setup_new_conf'}; {'id': '100', 'type': 'argument_list', 'children': []}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'call', 'children': ['103', '108']}, {'id': '103', 'type': 'attribute', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'stdout'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'string', 'children': [], 'value': '"."'}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}, {'id': '111', 'type': 'call', 'children': ['112', '117']}; {'id': '112', 'type': 'attribute', 'children': ['113', '116']}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'sys'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'flush'}, {'id': '117', 'type': 'argument_list', 'children': []}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'assignment', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'now'}, {'id': '121', 'type': 'call', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '125', 'type': 'argument_list', 'children': []}; {'id': '126', 'type': 'if_statement', 'children': ['127', '134']}, {'id': '127', 'type': 'comparison_operator', 'children': ['128', '133'], 'value': '>'}; {'id': '128', 'type': 'binary_operator', 'children': ['129', '130'], 'value': '-'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'last_master_ping'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'master_timeout'}; {'id': '134', 'type': 'block', 'children': ['135', '147', '167', '173']}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'call', 'children': ['137', '140']}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '140', 'type': 'argument_list', 'children': ['141', '142']}, {'id': '141', 'type': 'string', 'children': [], 'value': '"Arbiter Master is dead. The arbiter %s takes the lead!"'}; {'id': '142', 'type': 'attribute', 'children': ['143', '146']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'link_to_myself'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'name'}, {'id': '147', 'type': 'for_statement', 'children': ['148', '149', '154']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'arbiter_link'}, {'id': '149', 'type': 'attribute', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'conf'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'arbiters'}; {'id': '154', 'type': 'block', 'children': ['155']}, {'id': '155', 'type': 'if_statement', 'children': ['156', '160']}; {'id': '156', 'type': 'not_operator', 'children': ['157']}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'arbiter_link'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'spare'}; {'id': '160', 'type': 'block', 'children': ['161']}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '166']}, {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'arbiter_link'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'alive'}; {'id': '166', 'type': 'False', 'children': []}, {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'assignment', 'children': ['169', '172']}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'must_run'}; {'id': '172', 'type': 'True', 'children': []}, {'id': '173', 'type': 'break_statement', 'children': []} | def wait_for_master_death(self):
logger.info("Waiting for master death")
timeout = 1.0
self.last_master_ping = time.time()
master_timeout = 300
for arbiter_link in self.conf.arbiters:
if not arbiter_link.spare:
master_timeout = \
arbiter_link.spare_check_interval * arbiter_link.spare_max_check_attempts
logger.info("I'll wait master death for %d seconds", master_timeout)
while not self.interrupted:
_, tcdiff = self.make_a_pause(timeout)
if tcdiff:
self.last_master_ping += tcdiff
if self.new_conf:
self.setup_new_conf()
sys.stdout.write(".")
sys.stdout.flush()
now = time.time()
if now - self.last_master_ping > master_timeout:
logger.info("Arbiter Master is dead. The arbiter %s takes the lead!",
self.link_to_myself.name)
for arbiter_link in self.conf.arbiters:
if not arbiter_link.spare:
arbiter_link.alive = False
self.must_run = True
break |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'ERROR', 'children': ['2', '257', '261', '268', '408']}; {'id': '2', 'type': 'function_definition', 'children': ['3', '4', '9']}, {'id': '3', 'type': 'function_name', 'children': [], 'value': 'configuration_dispatch'}; {'id': '4', 'type': 'parameters', 'children': ['5', '6']}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'not_configured'}; {'id': '8', 'type': 'None', 'children': []}, {'id': '9', 'type': 'block', 'children': ['10', '179', '187', '199', '213', '221', '228', '236', '250']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '13']}, {'id': '11', 'type': 'not_operator', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'not_configured'}, {'id': '13', 'type': 'block', 'children': ['14', '28', '36', '40', '47']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'dispatcher'}, {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'Dispatcher'}, {'id': '21', 'type': 'argument_list', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'conf'}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'link_to_myself'}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'cur_conf'}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'conf'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'first_connection_try_count'}, {'id': '39', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}, {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'string', 'children': [], 'value': '"Connecting to my satellites..."'}, {'id': '47', 'type': 'while_statement', 'children': ['48', '49']}; {'id': '48', 'type': 'True', 'children': []}, {'id': '49', 'type': 'block', 'children': ['50', '54', '60', '114', '148', '168']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'augmented_assignment', 'children': ['52', '53'], 'value': '+='}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'first_connection_try_count'}, {'id': '53', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'all_connected'}, {'id': '59', 'type': 'True', 'children': []}; {'id': '60', 'type': 'for_statement', 'children': ['61', '62', '67']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'satellite'}; {'id': '62', 'type': 'attribute', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'dispatcher'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'all_daemons_links'}, {'id': '67', 'type': 'block', 'children': ['68', '76', '83', '95', '104']}; {'id': '68', 'type': 'if_statement', 'children': ['69', '74']}, {'id': '69', 'type': 'comparison_operator', 'children': ['70', '71'], 'value': '=='}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'satellite'}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'link_to_myself'}; {'id': '74', 'type': 'block', 'children': ['75']}, {'id': '75', 'type': 'continue_statement', 'children': []}; {'id': '76', 'type': 'if_statement', 'children': ['77', '81']}, {'id': '77', 'type': 'not_operator', 'children': ['78']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'satellite'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'active'}, {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'continue_statement', 'children': []}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'connected'}; {'id': '86', 'type': 'call', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'daemon_connection_init'}; {'id': '90', 'type': 'argument_list', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'satellite'}; {'id': '92', 'type': 'keyword_argument', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'set_wait_new_conf'}; {'id': '94', 'type': 'True', 'children': []}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'call', 'children': ['97', '100']}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '100', 'type': 'argument_list', 'children': ['101', '102', '103']}, {'id': '101', 'type': 'string', 'children': [], 'value': '" %s is %s"'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'satellite'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'connected'}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'all_connected'}, {'id': '109', 'type': 'boolean_operator', 'children': ['110', '113'], 'value': 'and'}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'all_connected'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'connected'}; {'id': '114', 'type': 'if_statement', 'children': ['115', '118', '126', '128']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'all_connected'}; {'id': '118', 'type': 'ERROR', 'children': ['119', '122', '123', '125']}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '122', 'type': 'ERROR', 'children': []}, {'id': '123', 'type': 'unary_operator', 'children': ['124'], 'value': '-'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'satellites'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'connection'}; {'id': '126', 'type': 'block', 'children': ['127']}, {'id': '127', 'type': 'break_statement', 'children': []}; {'id': '128', 'type': 'else_clause', 'children': ['129', '137']}, {'id': '129', 'type': 'ERROR', 'children': ['130', '133', '134', '136']}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '133', 'type': 'ERROR', 'children': []}; {'id': '134', 'type': 'unary_operator', 'children': ['135'], 'value': '-'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'satellites'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'connection'}, {'id': '137', 'type': 'block', 'children': ['138', '140', '142']}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'string', 'children': [], 'value': '"let\'s give another chance after %d seconds..."'}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'first_connection_try_count'}; {'id': '142', 'type': 'ERROR', 'children': ['143']}, {'id': '143', 'type': 'attribute', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'link_to_myself'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'polling_interval'}; {'id': '148', 'type': 'if_statement', 'children': ['149', '152']}, {'id': '149', 'type': 'comparison_operator', 'children': ['150', '151'], 'value': '>='}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'first_connection_try_count'}, {'id': '151', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '152', 'type': 'block', 'children': ['153']}, {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'call', 'children': ['155', '158']}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'request_stop'}; {'id': '158', 'type': 'argument_list', 'children': ['159', '165']}, {'id': '159', 'type': 'binary_operator', 'children': ['160', '164'], 'value': '%'}; {'id': '160', 'type': 'concatenated_string', 'children': ['161', '162', '163']}, {'id': '161', 'type': 'string', 'children': [], 'value': '"All the daemons connections could not be established "'}; {'id': '162', 'type': 'string', 'children': [], 'value': '"despite %d tries! "'}, {'id': '163', 'type': 'string', 'children': [], 'value': '"Sorry, I bail out!"'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'first_connection_try_count'}, {'id': '165', 'type': 'keyword_argument', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'exit_code'}, {'id': '167', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'call', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'sleep'}, {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'attribute', 'children': ['175', '178']}, {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'link_to_myself'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'polling_interval'}, {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': '_t0'}; {'id': '182', 'type': 'call', 'children': ['183', '186']}, {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '186', 'type': 'argument_list', 'children': []}, {'id': '187', 'type': 'expression_statement', 'children': ['188']}; {'id': '188', 'type': 'assignment', 'children': ['189', '192']}, {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'all_connected'}; {'id': '192', 'type': 'call', 'children': ['193', '198']}, {'id': '193', 'type': 'attribute', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'dispatcher'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'check_reachable'}; {'id': '198', 'type': 'argument_list', 'children': []}, {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'call', 'children': ['201', '204']}, {'id': '201', 'type': 'attribute', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'statsmgr'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'timer'}; {'id': '204', 'type': 'argument_list', 'children': ['205', '206']}, {'id': '205', 'type': 'string', 'children': [], 'value': "'dispatcher.check-alive'"}; {'id': '206', 'type': 'binary_operator', 'children': ['207', '212'], 'value': '-'}, {'id': '207', 'type': 'call', 'children': ['208', '211']}; {'id': '208', 'type': 'attribute', 'children': ['209', '210']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '211', 'type': 'argument_list', 'children': []}; {'id': '212', 'type': 'identifier', 'children': [], 'value': '_t0'}, {'id': '213', 'type': 'expression_statement', 'children': ['214']}; {'id': '214', 'type': 'assignment', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': '_t0'}; {'id': '216', 'type': 'call', 'children': ['217', '220']}, {'id': '217', 'type': 'attribute', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '220', 'type': 'argument_list', 'children': []}, {'id': '221', 'type': 'expression_statement', 'children': ['222']}; {'id': '222', 'type': 'call', 'children': ['223', '226']}, {'id': '223', 'type': 'attribute', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '226', 'type': 'argument_list', 'children': ['227']}, {'id': '227', 'type': 'string', 'children': [], 'value': '"Preparing the configuration for dispatching..."'}; {'id': '228', 'type': 'expression_statement', 'children': ['229']}, {'id': '229', 'type': 'call', 'children': ['230', '235']}; {'id': '230', 'type': 'attribute', 'children': ['231', '234']}, {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'dispatcher'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'prepare_dispatch'}, {'id': '235', 'type': 'argument_list', 'children': []}; {'id': '236', 'type': 'expression_statement', 'children': ['237']}, {'id': '237', 'type': 'call', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'statsmgr'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'timer'}, {'id': '241', 'type': 'argument_list', 'children': ['242', '243']}; {'id': '242', 'type': 'string', 'children': [], 'value': "'dispatcher.prepare-dispatch'"}, {'id': '243', 'type': 'binary_operator', 'children': ['244', '249'], 'value': '-'}; {'id': '244', 'type': 'call', 'children': ['245', '248']}, {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '248', 'type': 'argument_list', 'children': []}, {'id': '249', 'type': 'identifier', 'children': [], 'value': '_t0'}; {'id': '250', 'type': 'expression_statement', 'children': ['251']}, {'id': '251', 'type': 'call', 'children': ['252', '255']}; {'id': '252', 'type': 'attribute', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '255', 'type': 'argument_list', 'children': ['256']}; {'id': '256', 'type': 'string', 'children': [], 'value': '"- configuration is ready to dispatch"'}, {'id': '257', 'type': 'expression_statement', 'children': ['258']}; {'id': '258', 'type': 'assignment', 'children': ['259', '260']}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'first_dispatch_try_count'}; {'id': '260', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '261', 'type': 'expression_statement', 'children': ['262']}; {'id': '262', 'type': 'call', 'children': ['263', '266']}, {'id': '263', 'type': 'attribute', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '265', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '266', 'type': 'argument_list', 'children': ['267']}, {'id': '267', 'type': 'string', 'children': [], 'value': '"Dispatching the configuration to my satellites..."'}; {'id': '268', 'type': 'while_statement', 'children': ['269', '270', '385', '393', '395']}, {'id': '269', 'type': 'True', 'children': []}; {'id': '270', 'type': 'ERROR', 'children': ['271', '275', '283', '286', '287', '380']}, {'id': '271', 'type': 'expression_statement', 'children': ['272']}; {'id': '272', 'type': 'augmented_assignment', 'children': ['273', '274'], 'value': '+='}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'first_dispatch_try_count'}; {'id': '274', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '275', 'type': 'expression_statement', 'children': ['276']}; {'id': '276', 'type': 'assignment', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': '_t0'}; {'id': '278', 'type': 'call', 'children': ['279', '282']}, {'id': '279', 'type': 'attribute', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '282', 'type': 'argument_list', 'children': []}, {'id': '283', 'type': 'attribute', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '286', 'type': 'ERROR', 'children': []}, {'id': '287', 'type': 'unary_operator', 'children': ['288', '367'], 'value': '-'}; {'id': '288', 'type': 'ERROR', 'children': ['289', '290', '291', '301', '314', '315', '335', '342', '348', '349', '354', '360']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'configuration'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'dispatching'}, {'id': '291', 'type': 'call', 'children': ['292', '297']}; {'id': '292', 'type': 'attribute', 'children': ['293', '296']}, {'id': '293', 'type': 'attribute', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'dispatcher'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'check_reachable'}, {'id': '297', 'type': 'argument_list', 'children': ['298']}; {'id': '298', 'type': 'keyword_argument', 'children': ['299', '300']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'forced'}; {'id': '300', 'type': 'True', 'children': []}, {'id': '301', 'type': 'call', 'children': ['302', '305']}; {'id': '302', 'type': 'attribute', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'statsmgr'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'timer'}, {'id': '305', 'type': 'argument_list', 'children': ['306', '307']}; {'id': '306', 'type': 'string', 'children': [], 'value': "'dispatcher.dispatch'"}, {'id': '307', 'type': 'binary_operator', 'children': ['308', '313'], 'value': '-'}; {'id': '308', 'type': 'call', 'children': ['309', '312']}, {'id': '309', 'type': 'attribute', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '312', 'type': 'argument_list', 'children': []}, {'id': '313', 'type': 'identifier', 'children': [], 'value': '_t0'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'pause'}, {'id': '315', 'type': 'call', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '317', 'type': 'argument_list', 'children': ['318', '319']}; {'id': '318', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '319', 'type': 'call', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '321', 'type': 'argument_list', 'children': ['322', '327']}; {'id': '322', 'type': 'attribute', 'children': ['323', '326']}, {'id': '323', 'type': 'attribute', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '325', 'type': 'identifier', 'children': [], 'value': 'conf'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'daemons_dispatch_timeout'}, {'id': '327', 'type': 'binary_operator', 'children': ['328', '334'], 'value': '*'}; {'id': '328', 'type': 'call', 'children': ['329', '330']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '330', 'type': 'argument_list', 'children': ['331']}, {'id': '331', 'type': 'attribute', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '333', 'type': 'identifier', 'children': [], 'value': 'my_daemons'}; {'id': '334', 'type': 'float', 'children': [], 'value': '0.5'}, {'id': '335', 'type': 'call', 'children': ['336', '339']}; {'id': '336', 'type': 'attribute', 'children': ['337', '338']}, {'id': '337', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '339', 'type': 'argument_list', 'children': ['340', '341']}; {'id': '340', 'type': 'string', 'children': [], 'value': '"- pausing %d seconds..."'}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'pause'}; {'id': '342', 'type': 'call', 'children': ['343', '346']}, {'id': '343', 'type': 'attribute', 'children': ['344', '345']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '345', 'type': 'identifier', 'children': [], 'value': 'sleep'}; {'id': '346', 'type': 'argument_list', 'children': ['347']}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'pause'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': '_t0'}, {'id': '349', 'type': 'call', 'children': ['350', '353']}; {'id': '350', 'type': 'attribute', 'children': ['351', '352']}, {'id': '351', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '353', 'type': 'argument_list', 'children': []}; {'id': '354', 'type': 'call', 'children': ['355', '358']}, {'id': '355', 'type': 'attribute', 'children': ['356', '357']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '358', 'type': 'argument_list', 'children': ['359']}, {'id': '359', 'type': 'string', 'children': [], 'value': '"- checking configuration dispatch..."'}; {'id': '360', 'type': 'call', 'children': ['361', '366']}, {'id': '361', 'type': 'attribute', 'children': ['362', '365']}; {'id': '362', 'type': 'attribute', 'children': ['363', '364']}, {'id': '363', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'dispatcher'}, {'id': '365', 'type': 'identifier', 'children': [], 'value': 'check_dispatch'}; {'id': '366', 'type': 'argument_list', 'children': []}, {'id': '367', 'type': 'call', 'children': ['368', '371']}; {'id': '368', 'type': 'attribute', 'children': ['369', '370']}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'statsmgr'}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'timer'}, {'id': '371', 'type': 'argument_list', 'children': ['372', '373']}; {'id': '372', 'type': 'string', 'children': [], 'value': "'dispatcher.check-dispatch'"}, {'id': '373', 'type': 'binary_operator', 'children': ['374', '379'], 'value': '-'}; {'id': '374', 'type': 'call', 'children': ['375', '378']}, {'id': '375', 'type': 'attribute', 'children': ['376', '377']}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '377', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '378', 'type': 'argument_list', 'children': []}, {'id': '379', 'type': 'identifier', 'children': [], 'value': '_t0'}; {'id': '380', 'type': 'attribute', 'children': ['381', '384']}, {'id': '381', 'type': 'attribute', 'children': ['382', '383']}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '383', 'type': 'identifier', 'children': [], 'value': 'dispatcher'}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'dispatch_ok'}, {'id': '385', 'type': 'ERROR', 'children': ['386', '389', '390', '392']}; {'id': '386', 'type': 'attribute', 'children': ['387', '388']}, {'id': '387', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'info'}, {'id': '389', 'type': 'ERROR', 'children': []}; {'id': '390', 'type': 'unary_operator', 'children': ['391'], 'value': '-'}, {'id': '391', 'type': 'identifier', 'children': [], 'value': 'configuration'}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'dispatching'}, {'id': '393', 'type': 'block', 'children': ['394']}; {'id': '394', 'type': 'break_statement', 'children': []}, {'id': '395', 'type': 'else_clause', 'children': ['396', '404', '407']}; {'id': '396', 'type': 'ERROR', 'children': ['397', '400', '401', '403']}, {'id': '397', 'type': 'attribute', 'children': ['398', '399']}; {'id': '398', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '399', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '400', 'type': 'ERROR', 'children': []}, {'id': '401', 'type': 'unary_operator', 'children': ['402'], 'value': '-'}; {'id': '402', 'type': 'identifier', 'children': [], 'value': 'configuration'}, {'id': '403', 'type': 'identifier', 'children': [], 'value': 'dispatching'}; {'id': '404', 'type': 'ERROR', 'children': ['405', '406']}, {'id': '405', 'type': 'string', 'children': [], 'value': '"let\'s give another chance..."'}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'first_dispatch_try_count'}, {'id': '407', 'type': 'block', 'children': [], 'value': ''}; {'id': '408', 'type': 'if_statement', 'children': ['409', '412', '428']}, {'id': '409', 'type': 'comparison_operator', 'children': ['410', '411'], 'value': '>='}; {'id': '410', 'type': 'identifier', 'children': [], 'value': 'first_dispatch_try_count'}, {'id': '411', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '412', 'type': 'ERROR', 'children': ['413']}, {'id': '413', 'type': 'block', 'children': ['414']}; {'id': '414', 'type': 'expression_statement', 'children': ['415']}, {'id': '415', 'type': 'call', 'children': ['416', '419']}; {'id': '416', 'type': 'attribute', 'children': ['417', '418']}, {'id': '417', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '418', 'type': 'identifier', 'children': [], 'value': 'request_stop'}, {'id': '419', 'type': 'argument_list', 'children': ['420', '425']}; {'id': '420', 'type': 'binary_operator', 'children': ['421', '424'], 'value': '%'}, {'id': '421', 'type': 'concatenated_string', 'children': ['422', '423']}; {'id': '422', 'type': 'string', 'children': [], 'value': '"The configuration could not be dispatched despite %d tries! "'}, {'id': '423', 'type': 'string', 'children': [], 'value': '"Sorry, I bail out!"'}; {'id': '424', 'type': 'identifier', 'children': [], 'value': 'first_connection_try_count'}, {'id': '425', 'type': 'keyword_argument', 'children': ['426', '427']}; {'id': '426', 'type': 'identifier', 'children': [], 'value': 'exit_code'}, {'id': '427', 'type': 'integer', 'children': [], 'value': '4'} | def configuration_dispatch(self, not_configured=None):
if not not_configured:
self.dispatcher = Dispatcher(self.conf, self.link_to_myself)
self.cur_conf = self.conf
first_connection_try_count = 0
logger.info("Connecting to my satellites...")
while True:
first_connection_try_count += 1
self.all_connected = True
for satellite in self.dispatcher.all_daemons_links:
if satellite == self.link_to_myself:
continue
if not satellite.active:
continue
connected = self.daemon_connection_init(satellite, set_wait_new_conf=True)
logger.debug(" %s is %s", satellite, connected)
self.all_connected = self.all_connected and connected
if self.all_connected:
logger.info("- satellites connection
break
else:
logger.warning("- satellites connection
"let's give another chance after %d seconds...",
first_connection_try_count,
self.link_to_myself.polling_interval)
if first_connection_try_count >= 3:
self.request_stop("All the daemons connections could not be established "
"despite %d tries! "
"Sorry, I bail out!" % first_connection_try_count,
exit_code=4)
time.sleep(self.link_to_myself.polling_interval)
_t0 = time.time()
self.all_connected = self.dispatcher.check_reachable()
statsmgr.timer('dispatcher.check-alive', time.time() - _t0)
_t0 = time.time()
logger.info("Preparing the configuration for dispatching...")
self.dispatcher.prepare_dispatch()
statsmgr.timer('dispatcher.prepare-dispatch', time.time() - _t0)
logger.info("- configuration is ready to dispatch")
first_dispatch_try_count = 0
logger.info("Dispatching the configuration to my satellites...")
while True:
first_dispatch_try_count += 1
_t0 = time.time()
logger.info("- configuration dispatching
self.dispatcher.check_reachable(forced=True)
statsmgr.timer('dispatcher.dispatch', time.time() - _t0)
pause = max(1, max(self.conf.daemons_dispatch_timeout, len(self.my_daemons) * 0.5))
logger.info("- pausing %d seconds...", pause)
time.sleep(pause)
_t0 = time.time()
logger.info("- checking configuration dispatch...")
self.dispatcher.check_dispatch()
statsmgr.timer('dispatcher.check-dispatch', time.time() - _t0)
if self.dispatcher.dispatch_ok:
logger.info("- configuration dispatching
break
else:
logger.warning("- configuration dispatching
"let's give another chance...", first_dispatch_try_count)
if first_dispatch_try_count >= 3:
self.request_stop("The configuration could not be dispatched despite %d tries! "
"Sorry, I bail out!" % first_connection_try_count,
exit_code=4) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'duplicate'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '25', '34', '42', '67', '74', '83', '155', '339']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'duplicates'}; {'id': '10', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '14', 'type': 'call', 'children': ['15', '24']}, {'id': '15', 'type': 'attribute', 'children': ['16', '23']}; {'id': '16', 'type': 'call', 'children': ['17', '22']}, {'id': '17', 'type': 'attribute', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'duplicate_foreach'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '22', 'type': 'argument_list', 'children': []}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'upper'}; {'id': '24', 'type': 'argument_list', 'children': []}, {'id': '25', 'type': 'if_statement', 'children': ['26', '31']}; {'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': 'not'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'customs'}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'return_statement', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'duplicates'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'entry'}, {'id': '37', 'type': 'subscript', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'customs'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'not_entry'}, {'id': '45', 'type': 'call', 'children': ['46', '65']}; {'id': '46', 'type': 'attribute', 'children': ['47', '64']}, {'id': '47', 'type': 'call', 'children': ['48', '53']}; {'id': '48', 'type': 'attribute', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'host'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'customs'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '53', 'type': 'argument_list', 'children': ['54', '63']}; {'id': '54', 'type': 'binary_operator', 'children': ['55', '58'], 'value': '+'}, {'id': '55', 'type': 'binary_operator', 'children': ['56', '57'], 'value': '+'}; {'id': '56', 'type': 'string', 'children': [], 'value': "'_'"}, {'id': '57', 'type': 'string', 'children': [], 'value': "'!'"}; {'id': '58', 'type': 'subscript', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '60', 'type': 'slice', 'children': ['61', '62']}, {'id': '61', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '62', 'type': 'colon', 'children': []}, {'id': '63', 'type': 'string', 'children': [], 'value': "''"}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'string', 'children': [], 'value': "','"}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'not_keys'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'strip_and_uniq'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'not_entry'}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'default_value'}, {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '79', 'type': 'argument_list', 'children': ['80', '81', '82']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '81', 'type': 'string', 'children': [], 'value': "'default_value'"}; {'id': '82', 'type': 'string', 'children': [], 'value': "''"}, {'id': '83', 'type': 'try_statement', 'children': ['84', '96']}; {'id': '84', 'type': 'block', 'children': ['85']}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'key_values'}; {'id': '88', 'type': 'call', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}, {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'generate_key_value_sequences'}, {'id': '93', 'type': 'argument_list', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'entry'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'default_value'}; {'id': '96', 'type': 'except_clause', 'children': ['97', '101']}, {'id': '97', 'type': 'as_pattern', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'KeyValueSyntaxError'}, {'id': '99', 'type': 'as_pattern_target', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'exc'}, {'id': '101', 'type': 'block', 'children': ['102', '129', '139', '146', '153']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'fmt_dict'}, {'id': '105', 'type': 'dictionary', 'children': ['106', '111', '118', '123', '126']}; {'id': '106', 'type': 'pair', 'children': ['107', '108']}, {'id': '107', 'type': 'string', 'children': [], 'value': "'prop'"}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'duplicate_foreach'}, {'id': '111', 'type': 'pair', 'children': ['112', '113']}; {'id': '112', 'type': 'string', 'children': [], 'value': "'host'"}, {'id': '113', 'type': 'call', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'get_name'}, {'id': '117', 'type': 'argument_list', 'children': []}; {'id': '118', 'type': 'pair', 'children': ['119', '120']}, {'id': '119', 'type': 'string', 'children': [], 'value': "'svc'"}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'service_description'}, {'id': '123', 'type': 'pair', 'children': ['124', '125']}; {'id': '124', 'type': 'string', 'children': [], 'value': "'entry'"}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '126', 'type': 'pair', 'children': ['127', '128']}, {'id': '127', 'type': 'string', 'children': [], 'value': "'exc'"}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'exc'}, {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'assignment', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '132', 'type': 'binary_operator', 'children': ['133', '138'], 'value': '%'}, {'id': '133', 'type': 'parenthesized_expression', 'children': ['134']}; {'id': '134', 'type': 'concatenated_string', 'children': ['135', '136', '137']}, {'id': '135', 'type': 'string', 'children': [], 'value': '"The custom property %(prop)r of the "'}; {'id': '136', 'type': 'string', 'children': [], 'value': '"host %(host)r is not a valid entry for a service generator: %(exc)s, "'}, {'id': '137', 'type': 'string', 'children': [], 'value': '"with entry=%(entry)r"'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'fmt_dict'}, {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'call', 'children': ['141', '144']}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'call', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'add_error'}, {'id': '151', 'type': 'argument_list', 'children': ['152']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'err'}, {'id': '153', 'type': 'return_statement', 'children': ['154']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'duplicates'}, {'id': '155', 'type': 'for_statement', 'children': ['156', '157', '158']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'key_value'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'key_values'}; {'id': '158', 'type': 'block', 'children': ['159', '165', '171', '179', '189', '202', '332']}, {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'assignment', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '162', 'type': 'subscript', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'key_value'}; {'id': '164', 'type': 'string', 'children': [], 'value': "'KEY'"}, {'id': '165', 'type': 'if_statement', 'children': ['166', '169']}; {'id': '166', 'type': 'comparison_operator', 'children': ['167', '168'], 'value': 'in'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'not_keys'}, {'id': '169', 'type': 'block', 'children': ['170']}; {'id': '170', 'type': 'continue_statement', 'children': []}, {'id': '171', 'type': 'expression_statement', 'children': ['172']}; {'id': '172', 'type': 'assignment', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'new_s'}; {'id': '174', 'type': 'call', 'children': ['175', '178']}, {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '178', 'type': 'argument_list', 'children': []}, {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '184']}, {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'new_s'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'host_name'}; {'id': '184', 'type': 'call', 'children': ['185', '188']}, {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'host'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'get_name'}; {'id': '188', 'type': 'argument_list', 'children': []}, {'id': '189', 'type': 'if_statement', 'children': ['190', '195']}; {'id': '190', 'type': 'call', 'children': ['191', '194']}, {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'is_tpl'}; {'id': '194', 'type': 'argument_list', 'children': []}, {'id': '195', 'type': 'block', 'children': ['196']}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}, {'id': '197', 'type': 'assignment', 'children': ['198', '201']}; {'id': '198', 'type': 'attribute', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'new_s'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'register'}, {'id': '201', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '202', 'type': 'for_statement', 'children': ['203', '204', '205']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'key_value'}, {'id': '205', 'type': 'block', 'children': ['206', '253', '260', '294']}; {'id': '206', 'type': 'if_statement', 'children': ['207', '210']}, {'id': '207', 'type': 'comparison_operator', 'children': ['208', '209'], 'value': '=='}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '209', 'type': 'string', 'children': [], 'value': "'KEY'"}; {'id': '210', 'type': 'block', 'children': ['211']}, {'id': '211', 'type': 'if_statement', 'children': ['212', '217']}; {'id': '212', 'type': 'call', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '214', 'type': 'argument_list', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '216', 'type': 'string', 'children': [], 'value': "'service_description'"}, {'id': '217', 'type': 'block', 'children': ['218', '235']}; {'id': '218', 'type': 'expression_statement', 'children': ['219']}, {'id': '219', 'type': 'assignment', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'safe_key_value'}, {'id': '221', 'type': 'call', 'children': ['222', '225']}; {'id': '222', 'type': 'attribute', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'sub'}, {'id': '225', 'type': 'argument_list', 'children': ['226', '231', '232']}; {'id': '226', 'type': 'binary_operator', 'children': ['227', '230'], 'value': '+'}, {'id': '227', 'type': 'binary_operator', 'children': ['228', '229'], 'value': '+'}; {'id': '228', 'type': 'string', 'children': [], 'value': "r'['"}, {'id': '229', 'type': 'string', 'children': [], 'value': '"`~!$%^&*\\"|\'<>?,()="'}; {'id': '230', 'type': 'string', 'children': [], 'value': "']+'"}, {'id': '231', 'type': 'string', 'children': [], 'value': "'_'"}; {'id': '232', 'type': 'subscript', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'key_value'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '235', 'type': 'expression_statement', 'children': ['236']}; {'id': '236', 'type': 'assignment', 'children': ['237', '240']}, {'id': '237', 'type': 'attribute', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'new_s'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'service_description'}; {'id': '240', 'type': 'call', 'children': ['241', '246']}, {'id': '241', 'type': 'attribute', 'children': ['242', '245']}; {'id': '242', 'type': 'attribute', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'service_description'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '246', 'type': 'argument_list', 'children': ['247', '252']}, {'id': '247', 'type': 'binary_operator', 'children': ['248', '251'], 'value': '+'}; {'id': '248', 'type': 'binary_operator', 'children': ['249', '250'], 'value': '+'}, {'id': '249', 'type': 'string', 'children': [], 'value': "'$'"}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '251', 'type': 'string', 'children': [], 'value': "'$'"}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'safe_key_value'}, {'id': '253', 'type': 'expression_statement', 'children': ['254']}; {'id': '254', 'type': 'assignment', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': '_the_expandables'}; {'id': '256', 'type': 'list', 'children': ['257', '258', '259'], 'value': "['check_command', 'aggregation', 'event_handler']"}, {'id': '257', 'type': 'string', 'children': [], 'value': "'check_command'"}; {'id': '258', 'type': 'string', 'children': [], 'value': "'aggregation'"}, {'id': '259', 'type': 'string', 'children': [], 'value': "'event_handler'"}; {'id': '260', 'type': 'for_statement', 'children': ['261', '262', '263']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': '_the_expandables'}, {'id': '263', 'type': 'block', 'children': ['264']}; {'id': '264', 'type': 'if_statement', 'children': ['265', '270']}, {'id': '265', 'type': 'call', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '267', 'type': 'argument_list', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '270', 'type': 'block', 'children': ['271']}, {'id': '271', 'type': 'expression_statement', 'children': ['272']}; {'id': '272', 'type': 'call', 'children': ['273', '274']}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'setattr'}; {'id': '274', 'type': 'argument_list', 'children': ['275', '276', '277']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'new_s'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '277', 'type': 'call', 'children': ['278', '285']}; {'id': '278', 'type': 'attribute', 'children': ['279', '284']}, {'id': '279', 'type': 'call', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '281', 'type': 'argument_list', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'new_s'}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'replace'}, {'id': '285', 'type': 'argument_list', 'children': ['286', '291']}; {'id': '286', 'type': 'binary_operator', 'children': ['287', '290'], 'value': '+'}, {'id': '287', 'type': 'binary_operator', 'children': ['288', '289'], 'value': '+'}; {'id': '288', 'type': 'string', 'children': [], 'value': "'$'"}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '290', 'type': 'string', 'children': [], 'value': "'$'"}, {'id': '291', 'type': 'subscript', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'key_value'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '294', 'type': 'if_statement', 'children': ['295', '300']}, {'id': '295', 'type': 'call', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '297', 'type': 'argument_list', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '299', 'type': 'string', 'children': [], 'value': "'service_dependencies'"}; {'id': '300', 'type': 'block', 'children': ['301']}, {'id': '301', 'type': 'for_statement', 'children': ['302', '305', '311']}; {'id': '302', 'type': 'pattern_list', 'children': ['303', '304']}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'servicedep'}, {'id': '305', 'type': 'call', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '307', 'type': 'argument_list', 'children': ['308']}; {'id': '308', 'type': 'attribute', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'new_s'}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'service_dependencies'}, {'id': '311', 'type': 'block', 'children': ['312']}; {'id': '312', 'type': 'expression_statement', 'children': ['313']}, {'id': '313', 'type': 'assignment', 'children': ['314', '319']}; {'id': '314', 'type': 'subscript', 'children': ['315', '318']}, {'id': '315', 'type': 'attribute', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'new_s'}, {'id': '317', 'type': 'identifier', 'children': [], 'value': 'service_dependencies'}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '319', 'type': 'call', 'children': ['320', '323']}; {'id': '320', 'type': 'attribute', 'children': ['321', '322']}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'servicedep'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'replace'}, {'id': '323', 'type': 'argument_list', 'children': ['324', '329']}; {'id': '324', 'type': 'binary_operator', 'children': ['325', '328'], 'value': '+'}, {'id': '325', 'type': 'binary_operator', 'children': ['326', '327'], 'value': '+'}; {'id': '326', 'type': 'string', 'children': [], 'value': "'$'"}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '328', 'type': 'string', 'children': [], 'value': "'$'"}, {'id': '329', 'type': 'subscript', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'key_value'}, {'id': '331', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '332', 'type': 'expression_statement', 'children': ['333']}, {'id': '333', 'type': 'call', 'children': ['334', '337']}; {'id': '334', 'type': 'attribute', 'children': ['335', '336']}, {'id': '335', 'type': 'identifier', 'children': [], 'value': 'duplicates'}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '337', 'type': 'argument_list', 'children': ['338']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'new_s'}, {'id': '339', 'type': 'return_statement', 'children': ['340']} | def duplicate(self, host):
duplicates = []
prop = self.duplicate_foreach.strip().upper()
if prop not in host.customs:
return duplicates
entry = host.customs[prop]
not_entry = host.customs.get('_' + '!' + prop[1:], '').split(',')
not_keys = strip_and_uniq(not_entry)
default_value = getattr(self, 'default_value', '')
try:
key_values = tuple(generate_key_value_sequences(entry, default_value))
except KeyValueSyntaxError as exc:
fmt_dict = {
'prop': self.duplicate_foreach,
'host': host.get_name(),
'svc': self.service_description,
'entry': entry,
'exc': exc,
}
err = (
"The custom property %(prop)r of the "
"host %(host)r is not a valid entry for a service generator: %(exc)s, "
"with entry=%(entry)r") % fmt_dict
logger.warning(err)
host.add_error(err)
return duplicates
for key_value in key_values:
key = key_value['KEY']
if key in not_keys:
continue
new_s = self.copy()
new_s.host_name = host.get_name()
if self.is_tpl():
new_s.register = 1
for key in key_value:
if key == 'KEY':
if hasattr(self, 'service_description'):
safe_key_value = re.sub(r'[' + "`~!$%^&*\"|'<>?,()=" + ']+', '_',
key_value[key])
new_s.service_description = self.service_description.replace(
'$' + key + '$', safe_key_value
)
_the_expandables = ['check_command', 'aggregation', 'event_handler']
for prop in _the_expandables:
if hasattr(self, prop):
setattr(new_s, prop, getattr(new_s, prop).replace('$' + key + '$',
key_value[key]))
if hasattr(self, 'service_dependencies'):
for i, servicedep in enumerate(new_s.service_dependencies):
new_s.service_dependencies[i] = servicedep.replace(
'$' + key + '$', key_value[key]
)
duplicates.append(new_s)
return duplicates |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'explode_services_from_hosts'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'hosts'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'hnames'}; {'id': '8', 'type': 'block', 'children': ['9', '13', '17', '57', '67', '84']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'duplicate_for_hosts'}; {'id': '12', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'not_hosts'}; {'id': '16', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '17', 'type': 'for_statement', 'children': ['18', '19', '20']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'hname'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'hnames'}; {'id': '20', 'type': 'block', 'children': ['21', '29']}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'hname'}; {'id': '24', 'type': 'call', 'children': ['25', '28']}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'hname'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '28', 'type': 'argument_list', 'children': []}, {'id': '29', 'type': 'if_statement', 'children': ['30', '36', '48']}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'hname'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}, {'id': '35', 'type': 'string', 'children': [], 'value': "'!'"}; {'id': '36', 'type': 'block', 'children': ['37']}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '42']}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'not_hosts'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}, {'id': '43', 'type': 'subscript', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'hname'}, {'id': '45', 'type': 'slice', 'children': ['46', '47']}; {'id': '46', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '47', 'type': 'colon', 'children': []}; {'id': '48', 'type': 'else_clause', 'children': ['49']}, {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'duplicate_for_hosts'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'hname'}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'duplicate_for_hosts'}; {'id': '60', 'type': 'call', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'set'}, {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'duplicate_for_hosts'}, {'id': '67', 'type': 'for_statement', 'children': ['68', '69', '70']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'hname'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'not_hosts'}; {'id': '70', 'type': 'block', 'children': ['71']}, {'id': '71', 'type': 'try_statement', 'children': ['72', '80']}; {'id': '72', 'type': 'block', 'children': ['73']}, {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '78']}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'duplicate_for_hosts'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'hname'}; {'id': '80', 'type': 'except_clause', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'IndexError'}; {'id': '82', 'type': 'block', 'children': ['83']}, {'id': '83', 'type': 'pass_statement', 'children': []}; {'id': '84', 'type': 'for_statement', 'children': ['85', '86', '87']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'hname'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'duplicate_for_hosts'}, {'id': '87', 'type': 'block', 'children': ['88', '97', '118', '127', '135', '141']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'host'}, {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'hosts'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'find_by_name'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'hname'}, {'id': '97', 'type': 'if_statement', 'children': ['98', '101']}; {'id': '98', 'type': 'comparison_operator', 'children': ['99', '100'], 'value': 'is'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '100', 'type': 'None', 'children': []}, {'id': '101', 'type': 'block', 'children': ['102', '117']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'add_error'}, {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'binary_operator', 'children': ['109', '110'], 'value': '%'}, {'id': '109', 'type': 'string', 'children': [], 'value': '"Error: The hostname %s is unknown for the service %s!"'}; {'id': '110', 'type': 'tuple', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'hname'}; {'id': '112', 'type': 'call', 'children': ['113', '116']}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'get_name'}; {'id': '116', 'type': 'argument_list', 'children': []}, {'id': '117', 'type': 'continue_statement', 'children': []}; {'id': '118', 'type': 'if_statement', 'children': ['119', '125']}, {'id': '119', 'type': 'call', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'is_excluded_for'}, {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '125', 'type': 'block', 'children': ['126']}; {'id': '126', 'type': 'continue_statement', 'children': []}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'assignment', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'new_s'}; {'id': '130', 'type': 'call', 'children': ['131', '134']}, {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '134', 'type': 'argument_list', 'children': []}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '140']}, {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'new_s'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'host_name'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'hname'}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'call', 'children': ['143', '146']}, {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 'add_item'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'new_s'} | def explode_services_from_hosts(self, hosts, service, hnames):
duplicate_for_hosts = []
not_hosts = []
for hname in hnames:
hname = hname.strip()
if hname.startswith('!'):
not_hosts.append(hname[1:])
else:
duplicate_for_hosts.append(hname)
duplicate_for_hosts = list(set(duplicate_for_hosts))
for hname in not_hosts:
try:
duplicate_for_hosts.remove(hname)
except IndexError:
pass
for hname in duplicate_for_hosts:
host = hosts.find_by_name(hname)
if host is None:
service.add_error("Error: The hostname %s is unknown for the service %s!"
% (hname, service.get_name()))
continue
if host.is_excluded_for(service):
continue
new_s = service.copy()
new_s.host_name = hname
self.add_item(new_s) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'explode'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'hosts'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'hostgroups'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'contactgroups'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'servicegroups'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'servicedependencies'}; {'id': '10', 'type': 'block', 'children': ['11', '24', '132', '162', '179', '212', '216', '248', '259']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'itemkeys'}; {'id': '14', 'type': 'call', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}, {'id': '17', 'type': 'call', 'children': ['18', '23']}; {'id': '18', 'type': 'attribute', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'keys'}, {'id': '23', 'type': 'argument_list', 'children': []}; {'id': '24', 'type': 'for_statement', 'children': ['25', '26', '27']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 's_id'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'itemkeys'}, {'id': '27', 'type': 'block', 'children': ['28', '36', '45', '53', '62', '91']}; {'id': '28', 'type': 'expression_statement', 'children': ['29']}, {'id': '29', 'type': 'assignment', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'serv'}, {'id': '31', 'type': 'subscript', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 's_id'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'explode_host_groups_into_hosts'}, {'id': '41', 'type': 'argument_list', 'children': ['42', '43', '44']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'serv'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'hosts'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'hostgroups'}, {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'explode_contact_groups_into_contacts'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'serv'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'contactgroups'}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'hnames'}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '60', '61']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'serv'}; {'id': '60', 'type': 'string', 'children': [], 'value': '"host_name"'}, {'id': '61', 'type': 'string', 'children': [], 'value': "''"}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'hnames'}, {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}, {'id': '71', 'type': 'list_comprehension', 'children': ['72', '77', '85']}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '76', 'type': 'argument_list', 'children': []}, {'id': '77', 'type': 'for_in_clause', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'hnames'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'string', 'children': [], 'value': "','"}, {'id': '85', 'type': 'if_clause', 'children': ['86']}; {'id': '86', 'type': 'call', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'n'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '90', 'type': 'argument_list', 'children': []}, {'id': '91', 'type': 'if_statement', 'children': ['92', '98', '106']}; {'id': '92', 'type': 'comparison_operator', 'children': ['93', '97'], 'value': '=='}, {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'hnames'}, {'id': '97', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '98', 'type': 'block', 'children': ['99']}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'call', 'children': ['101', '104']}, {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'index_item'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'serv'}; {'id': '106', 'type': 'else_clause', 'children': ['107']}, {'id': '107', 'type': 'block', 'children': ['108', '125']}; {'id': '108', 'type': 'if_statement', 'children': ['109', '115']}, {'id': '109', 'type': 'comparison_operator', 'children': ['110', '114'], 'value': '>='}; {'id': '110', 'type': 'call', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'hnames'}; {'id': '114', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '115', 'type': 'block', 'children': ['116']}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'call', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'explode_services_from_hosts'}, {'id': '121', 'type': 'argument_list', 'children': ['122', '123', '124']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'hosts'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'serv'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'hnames'}, {'id': '125', 'type': 'expression_statement', 'children': ['126']}; {'id': '126', 'type': 'call', 'children': ['127', '130']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'remove_item'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'serv'}; {'id': '132', 'type': 'for_statement', 'children': ['133', '134', '137']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 's_id'}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'templates'}, {'id': '137', 'type': 'block', 'children': ['138', '146', '154']}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'template'}, {'id': '141', 'type': 'subscript', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'templates'}, {'id': '145', 'type': 'identifier', 'children': [], 'value': 's_id'}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'call', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'explode_contact_groups_into_contacts'}, {'id': '151', 'type': 'argument_list', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'template'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'contactgroups'}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'call', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'explode_services_from_templates'}, {'id': '159', 'type': 'argument_list', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'hosts'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'template'}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}, {'id': '163', 'type': 'assignment', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'duplicates'}, {'id': '165', 'type': 'list_comprehension', 'children': ['166', '169', '172']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'serv'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'uuid'}, {'id': '169', 'type': 'for_in_clause', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'serv'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '172', 'type': 'if_clause', 'children': ['173']}, {'id': '173', 'type': 'call', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '175', 'type': 'argument_list', 'children': ['176', '177', '178']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'serv'}, {'id': '177', 'type': 'string', 'children': [], 'value': "'duplicate_foreach'"}; {'id': '178', 'type': 'string', 'children': [], 'value': "''"}, {'id': '179', 'type': 'for_statement', 'children': ['180', '181', '182']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 's_id'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'duplicates'}; {'id': '182', 'type': 'block', 'children': ['183', '191', '199']}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'serv'}; {'id': '186', 'type': 'subscript', 'children': ['187', '190']}, {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 's_id'}, {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'call', 'children': ['193', '196']}, {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'explode_services_duplicates'}; {'id': '196', 'type': 'argument_list', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'hosts'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'serv'}, {'id': '199', 'type': 'if_statement', 'children': ['200', '204']}; {'id': '200', 'type': 'not_operator', 'children': ['201']}, {'id': '201', 'type': 'attribute', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'serv'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'configuration_errors'}; {'id': '204', 'type': 'block', 'children': ['205']}, {'id': '205', 'type': 'expression_statement', 'children': ['206']}; {'id': '206', 'type': 'call', 'children': ['207', '210']}, {'id': '207', 'type': 'attribute', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'remove_item'}; {'id': '210', 'type': 'argument_list', 'children': ['211']}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'serv'}; {'id': '212', 'type': 'expression_statement', 'children': ['213']}, {'id': '213', 'type': 'assignment', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'to_remove'}, {'id': '215', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '216', 'type': 'for_statement', 'children': ['217', '218', '219']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '219', 'type': 'block', 'children': ['220', '231']}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}, {'id': '221', 'type': 'assignment', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'host'}, {'id': '223', 'type': 'call', 'children': ['224', '227']}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'hosts'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'find_by_name'}, {'id': '227', 'type': 'argument_list', 'children': ['228']}; {'id': '228', 'type': 'attribute', 'children': ['229', '230']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'host_name'}, {'id': '231', 'type': 'if_statement', 'children': ['232', '240']}; {'id': '232', 'type': 'boolean_operator', 'children': ['233', '234'], 'value': 'and'}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '234', 'type': 'call', 'children': ['235', '238']}, {'id': '235', 'type': 'attribute', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'host'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'is_excluded_for'}; {'id': '238', 'type': 'argument_list', 'children': ['239']}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '240', 'type': 'block', 'children': ['241']}, {'id': '241', 'type': 'expression_statement', 'children': ['242']}; {'id': '242', 'type': 'call', 'children': ['243', '246']}, {'id': '243', 'type': 'attribute', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'to_remove'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '246', 'type': 'argument_list', 'children': ['247']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '248', 'type': 'for_statement', 'children': ['249', '250', '251']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'to_remove'}, {'id': '251', 'type': 'block', 'children': ['252']}; {'id': '252', 'type': 'expression_statement', 'children': ['253']}, {'id': '253', 'type': 'call', 'children': ['254', '257']}; {'id': '254', 'type': 'attribute', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'remove_item'}, {'id': '257', 'type': 'argument_list', 'children': ['258']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'service'}, {'id': '259', 'type': 'for_statement', 'children': ['260', '261', '262']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'serv'}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '262', 'type': 'block', 'children': ['263', '271']}, {'id': '263', 'type': 'expression_statement', 'children': ['264']}; {'id': '264', 'type': 'call', 'children': ['265', '268']}, {'id': '265', 'type': 'attribute', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'register_service_into_servicegroups'}; {'id': '268', 'type': 'argument_list', 'children': ['269', '270']}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'serv'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'servicegroups'}, {'id': '271', 'type': 'expression_statement', 'children': ['272']}; {'id': '272', 'type': 'call', 'children': ['273', '276']}, {'id': '273', 'type': 'attribute', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'register_service_dependencies'}; {'id': '276', 'type': 'argument_list', 'children': ['277', '278']}, {'id': '277', 'type': 'identifier', 'children': [], 'value': 'serv'} | def explode(self, hosts, hostgroups, contactgroups, servicegroups, servicedependencies):
itemkeys = list(self.items.keys())
for s_id in itemkeys:
serv = self.items[s_id]
self.explode_host_groups_into_hosts(serv, hosts, hostgroups)
self.explode_contact_groups_into_contacts(serv, contactgroups)
hnames = getattr(serv, "host_name", '')
hnames = list(set([n.strip() for n in hnames.split(',') if n.strip()]))
if len(hnames) == 1:
self.index_item(serv)
else:
if len(hnames) >= 2:
self.explode_services_from_hosts(hosts, serv, hnames)
self.remove_item(serv)
for s_id in self.templates:
template = self.templates[s_id]
self.explode_contact_groups_into_contacts(template, contactgroups)
self.explode_services_from_templates(hosts, template)
duplicates = [serv.uuid for serv in self if getattr(serv, 'duplicate_foreach', '')]
for s_id in duplicates:
serv = self.items[s_id]
self.explode_services_duplicates(hosts, serv)
if not serv.configuration_errors:
self.remove_item(serv)
to_remove = []
for service in self:
host = hosts.find_by_name(service.host_name)
if host and host.is_excluded_for(service):
to_remove.append(service)
for service in to_remove:
self.remove_item(service)
for serv in self:
self.register_service_into_servicegroups(serv, servicegroups)
self.register_service_dependencies(serv, servicedependencies) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_next_notif_time'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 't_wished'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'status'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'creation_time'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'interval'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'escal_period'}; {'id': '10', 'type': 'block', 'children': ['11', '45', '53', '68', '78', '85', '100']}, {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'short_states'}; {'id': '14', 'type': 'dictionary', 'children': ['15', '18', '21', '24', '27', '30', '33', '36', '39', '42']}, {'id': '15', 'type': 'pair', 'children': ['16', '17']}; {'id': '16', 'type': 'string', 'children': [], 'value': "u'WARNING'"}, {'id': '17', 'type': 'string', 'children': [], 'value': "'w'"}; {'id': '18', 'type': 'pair', 'children': ['19', '20']}, {'id': '19', 'type': 'string', 'children': [], 'value': "u'UNKNOWN'"}; {'id': '20', 'type': 'string', 'children': [], 'value': "'u'"}, {'id': '21', 'type': 'pair', 'children': ['22', '23']}; {'id': '22', 'type': 'string', 'children': [], 'value': "u'CRITICAL'"}, {'id': '23', 'type': 'string', 'children': [], 'value': "'c'"}; {'id': '24', 'type': 'pair', 'children': ['25', '26']}, {'id': '25', 'type': 'string', 'children': [], 'value': "u'RECOVERY'"}; {'id': '26', 'type': 'string', 'children': [], 'value': "'r'"}, {'id': '27', 'type': 'pair', 'children': ['28', '29']}; {'id': '28', 'type': 'string', 'children': [], 'value': "u'FLAPPING'"}, {'id': '29', 'type': 'string', 'children': [], 'value': "'f'"}; {'id': '30', 'type': 'pair', 'children': ['31', '32']}, {'id': '31', 'type': 'string', 'children': [], 'value': "u'DOWNTIME'"}; {'id': '32', 'type': 'string', 'children': [], 'value': "'s'"}, {'id': '33', 'type': 'pair', 'children': ['34', '35']}; {'id': '34', 'type': 'string', 'children': [], 'value': "u'DOWN'"}, {'id': '35', 'type': 'string', 'children': [], 'value': "'d'"}; {'id': '36', 'type': 'pair', 'children': ['37', '38']}, {'id': '37', 'type': 'string', 'children': [], 'value': "u'UNREACHABLE'"}; {'id': '38', 'type': 'string', 'children': [], 'value': "'u'"}, {'id': '39', 'type': 'pair', 'children': ['40', '41']}; {'id': '40', 'type': 'string', 'children': [], 'value': "u'OK'"}, {'id': '41', 'type': 'string', 'children': [], 'value': "'o'"}; {'id': '42', 'type': 'pair', 'children': ['43', '44']}, {'id': '43', 'type': 'string', 'children': [], 'value': "u'UP'"}; {'id': '44', 'type': 'string', 'children': [], 'value': "'o'"}, {'id': '45', 'type': 'if_statement', 'children': ['46', '50']}; {'id': '46', 'type': 'not_operator', 'children': ['47']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'time_based'}; {'id': '50', 'type': 'block', 'children': ['51']}, {'id': '51', 'type': 'return_statement', 'children': ['52']}; {'id': '52', 'type': 'None', 'children': []}, {'id': '53', 'type': 'if_statement', 'children': ['54', '65']}; {'id': '54', 'type': 'boolean_operator', 'children': ['55', '58'], 'value': 'and'}, {'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': 'in'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'status'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'short_states'}; {'id': '58', 'type': 'comparison_operator', 'children': ['59', '62'], 'value': 'not'}, {'id': '59', 'type': 'subscript', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'short_states'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'escalation_options'}, {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'return_statement', 'children': ['67']}, {'id': '67', 'type': 'None', 'children': []}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '71', 'type': 'binary_operator', 'children': ['72', '77'], 'value': '+'}; {'id': '72', 'type': 'binary_operator', 'children': ['73', '76'], 'value': '*'}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'first_notification_time'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'interval'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'creation_time'}; {'id': '78', 'type': 'if_statement', 'children': ['79', '82']}, {'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': '>'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 't_wished'}; {'id': '82', 'type': 'block', 'children': ['83']}, {'id': '83', 'type': 'return_statement', 'children': ['84']}; {'id': '84', 'type': 'None', 'children': []}, {'id': '85', 'type': 'if_statement', 'children': ['86', '97']}; {'id': '86', 'type': 'boolean_operator', 'children': ['87', '90'], 'value': 'and'}, {'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': 'is'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'escal_period'}, {'id': '89', 'type': 'None', 'children': []}; {'id': '90', 'type': 'not_operator', 'children': ['91']}, {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'escal_period'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'is_time_valid'}, {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'start'}, {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'return_statement', 'children': ['99']}, {'id': '99', 'type': 'None', 'children': []}; {'id': '100', 'type': 'return_statement', 'children': ['101']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'start'} | def get_next_notif_time(self, t_wished, status, creation_time, interval, escal_period):
short_states = {u'WARNING': 'w', u'UNKNOWN': 'u', u'CRITICAL': 'c',
u'RECOVERY': 'r', u'FLAPPING': 'f', u'DOWNTIME': 's',
u'DOWN': 'd', u'UNREACHABLE': 'u', u'OK': 'o', u'UP': 'o'}
if not self.time_based:
return None
if status in short_states and short_states[status] not in self.escalation_options:
return None
start = self.first_notification_time * interval + creation_time
if start > t_wished:
return None
if escal_period is not None and not escal_period.is_time_valid(start):
return None
return start |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'linkify_es_by_s'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '6', 'type': 'block', 'children': ['7']}, {'id': '7', 'type': 'for_statement', 'children': ['8', '9', '10']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'escalation'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'block', 'children': ['11', '20', '32', '48']}, {'id': '11', 'type': 'if_statement', 'children': ['12', '18']}; {'id': '12', 'type': 'not_operator', 'children': ['13']}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '15', 'type': 'argument_list', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'escalation'}, {'id': '17', 'type': 'string', 'children': [], 'value': "'host_name'"}; {'id': '18', 'type': 'block', 'children': ['19']}, {'id': '19', 'type': 'continue_statement', 'children': []}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '25']}; {'id': '22', 'type': 'pattern_list', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'es_hname'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'sdesc'}, {'id': '25', 'type': 'expression_list', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'escalation'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'host_name'}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'escalation'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'service_description'}; {'id': '32', 'type': 'if_statement', 'children': ['33', '46']}, {'id': '33', 'type': 'boolean_operator', 'children': ['34', '40'], 'value': 'or'}; {'id': '34', 'type': 'not_operator', 'children': ['35']}, {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'es_hname'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '39', 'type': 'argument_list', 'children': []}; {'id': '40', 'type': 'not_operator', 'children': ['41']}, {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'sdesc'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '45', 'type': 'argument_list', 'children': []}; {'id': '46', 'type': 'block', 'children': ['47']}, {'id': '47', 'type': 'continue_statement', 'children': []}; {'id': '48', 'type': 'for_statement', 'children': ['49', '50', '59']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'hname'}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'strip_and_uniq'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'es_hname'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'string', 'children': [], 'value': "','"}, {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'if_statement', 'children': ['61', '68', '108']}, {'id': '61', 'type': 'comparison_operator', 'children': ['62', '67'], 'value': '=='}; {'id': '62', 'type': 'call', 'children': ['63', '66']}, {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'sdesc'}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '66', 'type': 'argument_list', 'children': []}, {'id': '67', 'type': 'string', 'children': [], 'value': "'*'"}; {'id': '68', 'type': 'block', 'children': ['69', '78']}, {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'slist'}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'find_srvs_by_hostname'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'hname'}; {'id': '78', 'type': 'if_statement', 'children': ['79', '82']}, {'id': '79', 'type': 'comparison_operator', 'children': ['80', '81'], 'value': 'is'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'slist'}, {'id': '81', 'type': 'None', 'children': []}; {'id': '82', 'type': 'block', 'children': ['83', '93']}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'slist'}; {'id': '86', 'type': 'list_comprehension', 'children': ['87', '90']}, {'id': '87', 'type': 'subscript', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'serv'}; {'id': '90', 'type': 'for_in_clause', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'serv'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'slist'}, {'id': '93', 'type': 'for_statement', 'children': ['94', '95', '96']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'serv'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'slist'}; {'id': '96', 'type': 'block', 'children': ['97']}, {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '104']}, {'id': '99', 'type': 'attribute', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'serv'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'escalations'}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'escalation'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '108', 'type': 'else_clause', 'children': ['109']}, {'id': '109', 'type': 'block', 'children': ['110']}; {'id': '110', 'type': 'for_statement', 'children': ['111', '112', '121']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'sname'}; {'id': '112', 'type': 'call', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'strip_and_uniq'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}, {'id': '115', 'type': 'call', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'sdesc'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'split'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'string', 'children': [], 'value': "','"}, {'id': '121', 'type': 'block', 'children': ['122', '132']}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'assignment', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'serv'}, {'id': '125', 'type': 'call', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'find_srv_by_name_and_hostname'}, {'id': '129', 'type': 'argument_list', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'hname'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'sname'}; {'id': '132', 'type': 'if_statement', 'children': ['133', '136']}, {'id': '133', 'type': 'comparison_operator', 'children': ['134', '135'], 'value': 'is'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'serv'}, {'id': '135', 'type': 'None', 'children': []}; {'id': '136', 'type': 'block', 'children': ['137']}, {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'call', 'children': ['139', '144']}, {'id': '139', 'type': 'attribute', 'children': ['140', '143']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'serv'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'escalations'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'escalation'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'uuid'} | def linkify_es_by_s(self, services):
for escalation in self:
if not hasattr(escalation, 'host_name'):
continue
es_hname, sdesc = escalation.host_name, escalation.service_description
if not es_hname.strip() or not sdesc.strip():
continue
for hname in strip_and_uniq(es_hname.split(',')):
if sdesc.strip() == '*':
slist = services.find_srvs_by_hostname(hname)
if slist is not None:
slist = [services[serv] for serv in slist]
for serv in slist:
serv.escalations.append(escalation.uuid)
else:
for sname in strip_and_uniq(sdesc.split(',')):
serv = services.find_srv_by_name_and_hostname(hname, sname)
if serv is not None:
serv.escalations.append(escalation.uuid) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_contacts_by_explosion'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'contactgroups'}; {'id': '6', 'type': 'block', 'children': ['7', '13', '43', '49', '57', '100', '111']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '12']}, {'id': '9', 'type': 'attribute', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'already_exploded'}; {'id': '12', 'type': 'True', 'children': []}, {'id': '13', 'type': 'if_statement', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'rec_tag'}, {'id': '17', 'type': 'block', 'children': ['18', '30', '41']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'error'}, {'id': '23', 'type': 'argument_list', 'children': ['24', '25']}; {'id': '24', 'type': 'string', 'children': [], 'value': '"[contactgroup::%s] got a loop in contactgroup definition"'}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'get_name'}, {'id': '29', 'type': 'argument_list', 'children': []}; {'id': '30', 'type': 'if_statement', 'children': ['31', '36']}, {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '33', 'type': 'argument_list', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '35', 'type': 'string', 'children': [], 'value': "'members'"}; {'id': '36', 'type': 'block', 'children': ['37']}, {'id': '37', 'type': 'return_statement', 'children': ['38']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'members'}, {'id': '41', 'type': 'return_statement', 'children': ['42']}; {'id': '42', 'type': 'string', 'children': [], 'value': "''"}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '48']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'rec_tag'}; {'id': '48', 'type': 'True', 'children': []}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'cg_mbrs'}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'get_contactgroup_members'}; {'id': '56', 'type': 'argument_list', 'children': []}, {'id': '57', 'type': 'for_statement', 'children': ['58', '59', '60']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'cg_mbr'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'cg_mbrs'}; {'id': '60', 'type': 'block', 'children': ['61', '74']}, {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'contactgroup'}; {'id': '64', 'type': 'call', 'children': ['65', '68']}, {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'contactgroups'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'find_by_name'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}, {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'cg_mbr'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '73', 'type': 'argument_list', 'children': []}; {'id': '74', 'type': 'if_statement', 'children': ['75', '78']}, {'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': 'is'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'contactgroup'}, {'id': '77', 'type': 'None', 'children': []}; {'id': '78', 'type': 'block', 'children': ['79', '88']}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '82', 'type': 'call', 'children': ['83', '86']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'contactgroup'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'get_contacts_by_explosion'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'contactgroups'}; {'id': '88', 'type': 'if_statement', 'children': ['89', '92']}, {'id': '89', 'type': 'comparison_operator', 'children': ['90', '91'], 'value': 'is'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '91', 'type': 'None', 'children': []}; {'id': '92', 'type': 'block', 'children': ['93']}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'call', 'children': ['95', '98']}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'add_members'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '100', 'type': 'if_statement', 'children': ['101', '106']}, {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '103', 'type': 'argument_list', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '105', 'type': 'string', 'children': [], 'value': "'members'"}; {'id': '106', 'type': 'block', 'children': ['107']}, {'id': '107', 'type': 'return_statement', 'children': ['108']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'members'}, {'id': '111', 'type': 'return_statement', 'children': ['112']} | def get_contacts_by_explosion(self, contactgroups):
self.already_exploded = True
if self.rec_tag:
logger.error("[contactgroup::%s] got a loop in contactgroup definition",
self.get_name())
if hasattr(self, 'members'):
return self.members
return ''
self.rec_tag = True
cg_mbrs = self.get_contactgroup_members()
for cg_mbr in cg_mbrs:
contactgroup = contactgroups.find_by_name(cg_mbr.strip())
if contactgroup is not None:
value = contactgroup.get_contacts_by_explosion(contactgroups)
if value is not None:
self.add_members(value)
if hasattr(self, 'members'):
return self.members
return '' |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'do_check_freshness'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'hosts'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'timeperiods'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'macromodulations'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'checkmodulations'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'checks'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'when'}; {'id': '12', 'type': 'block', 'children': ['13', '17', '23', '329']}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'when'}, {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': '__class__'}, {'id': '23', 'type': 'if_statement', 'children': ['24', '37']}; {'id': '24', 'type': 'boolean_operator', 'children': ['25', '33'], 'value': 'and'}, {'id': '25', 'type': 'boolean_operator', 'children': ['26', '30'], 'value': 'and'}; {'id': '26', 'type': 'not_operator', 'children': ['27']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'in_checking'}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'freshness_threshold'}, {'id': '33', 'type': 'not_operator', 'children': ['34']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'freshness_expired'}, {'id': '37', 'type': 'block', 'children': ['38', '59', '74']}; {'id': '38', 'type': 'if_statement', 'children': ['39', '46']}, {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'getenv'}, {'id': '43', 'type': 'argument_list', 'children': ['44', '45']}; {'id': '44', 'type': 'string', 'children': [], 'value': "'ALIGNAK_LOG_CHECKS'"}, {'id': '45', 'type': 'None', 'children': []}; {'id': '46', 'type': 'block', 'children': ['47']}, {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '52', 'type': 'argument_list', 'children': ['53', '54']}, {'id': '53', 'type': 'string', 'children': [], 'value': '"--ALC-- -> checking freshness for: %s"'}; {'id': '54', 'type': 'call', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'get_full_name'}; {'id': '58', 'type': 'argument_list', 'children': []}, {'id': '59', 'type': 'if_statement', 'children': ['60', '64']}; {'id': '60', 'type': 'not_operator', 'children': ['61']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'last_state_update'}; {'id': '64', 'type': 'block', 'children': ['65']}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'last_state_update'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '74', 'type': 'if_statement', 'children': ['75', '90']}, {'id': '75', 'type': 'comparison_operator', 'children': ['76', '79'], 'value': '<'}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'last_state_update'}, {'id': '79', 'type': 'binary_operator', 'children': ['80', '81', '82'], 'value': '-'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'now'}, {'id': '81', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '82', 'type': 'parenthesized_expression', 'children': ['83']}, {'id': '83', 'type': 'binary_operator', 'children': ['84', '87'], 'value': '+'}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'freshness_threshold'}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'additional_freshness_latency'}; {'id': '90', 'type': 'block', 'children': ['91', '99']}, {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'timeperiod'}; {'id': '94', 'type': 'subscript', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'timeperiods'}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'check_period'}, {'id': '99', 'type': 'if_statement', 'children': ['100', '110', '313']}; {'id': '100', 'type': 'boolean_operator', 'children': ['101', '104'], 'value': 'or'}, {'id': '101', 'type': 'comparison_operator', 'children': ['102', '103'], 'value': 'is'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'timeperiod'}, {'id': '103', 'type': 'None', 'children': []}; {'id': '104', 'type': 'call', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'timeperiod'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'is_time_valid'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '110', 'type': 'block', 'children': ['111', '126', '140', '146', '156', '180', '311']}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'chk'}; {'id': '114', 'type': 'call', 'children': ['115', '118']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'launch_check'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '120', '121', '122', '123', '124', '125']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'hosts'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'timeperiods'}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'macromodulations'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'checkmodulations'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'checks'}; {'id': '126', 'type': 'if_statement', 'children': ['127', '129']}, {'id': '127', 'type': 'not_operator', 'children': ['128']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'chk'}, {'id': '129', 'type': 'block', 'children': ['130', '138']}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}, {'id': '131', 'type': 'call', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'warning'}, {'id': '135', 'type': 'argument_list', 'children': ['136', '137']}; {'id': '136', 'type': 'string', 'children': [], 'value': '"No raised freshness check for: %s"'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '138', 'type': 'return_statement', 'children': ['139']}, {'id': '139', 'type': 'None', 'children': []}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}, {'id': '141', 'type': 'assignment', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'chk'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'freshness_expiry_check'}, {'id': '145', 'type': 'True', 'children': []}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}, {'id': '147', 'type': 'assignment', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'chk'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'check_time'}, {'id': '151', 'type': 'call', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '155', 'type': 'argument_list', 'children': []}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'assignment', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'chk'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '161', 'type': 'binary_operator', 'children': ['162', '163'], 'value': '%'}; {'id': '162', 'type': 'string', 'children': [], 'value': '"Freshness period expired: %s"'}, {'id': '163', 'type': 'parenthesized_expression', 'children': ['164']}; {'id': '164', 'type': 'call', 'children': ['165', '178']}, {'id': '165', 'type': 'attribute', 'children': ['166', '177']}; {'id': '166', 'type': 'call', 'children': ['167', '170']}, {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'datetime'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'utcfromtimestamp'}; {'id': '170', 'type': 'argument_list', 'children': ['171']}, {'id': '171', 'type': 'call', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'attribute', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'chk'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'check_time'}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'strftime'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}, {'id': '179', 'type': 'string', 'children': [], 'value': '"%Y-%m-%d %H:%M:%S %Z"'}; {'id': '180', 'type': 'if_statement', 'children': ['181', '186', '236']}, {'id': '181', 'type': 'comparison_operator', 'children': ['182', '185'], 'value': '=='}; {'id': '182', 'type': 'attribute', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'my_type'}, {'id': '185', 'type': 'string', 'children': [], 'value': "'host'"}; {'id': '186', 'type': 'block', 'children': ['187']}, {'id': '187', 'type': 'if_statement', 'children': ['188', '193', '200', '213', '228']}; {'id': '188', 'type': 'comparison_operator', 'children': ['189', '192'], 'value': '=='}, {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'freshness_state'}; {'id': '192', 'type': 'string', 'children': [], 'value': "'o'"}, {'id': '193', 'type': 'block', 'children': ['194']}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}, {'id': '195', 'type': 'assignment', 'children': ['196', '199']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'chk'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'exit_status'}, {'id': '199', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '200', 'type': 'elif_clause', 'children': ['201', '206']}, {'id': '201', 'type': 'comparison_operator', 'children': ['202', '205'], 'value': '=='}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'freshness_state'}, {'id': '205', 'type': 'string', 'children': [], 'value': "'d'"}; {'id': '206', 'type': 'block', 'children': ['207']}, {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'assignment', 'children': ['209', '212']}, {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'chk'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'exit_status'}; {'id': '212', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '213', 'type': 'elif_clause', 'children': ['214', '221']}; {'id': '214', 'type': 'comparison_operator', 'children': ['215', '218'], 'value': 'in'}, {'id': '215', 'type': 'attribute', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'freshness_state'}; {'id': '218', 'type': 'list', 'children': ['219', '220'], 'value': "['u', 'x']"}, {'id': '219', 'type': 'string', 'children': [], 'value': "'u'"}; {'id': '220', 'type': 'string', 'children': [], 'value': "'x'"}, {'id': '221', 'type': 'block', 'children': ['222']}; {'id': '222', 'type': 'expression_statement', 'children': ['223']}, {'id': '223', 'type': 'assignment', 'children': ['224', '227']}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'chk'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'exit_status'}, {'id': '227', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '228', 'type': 'else_clause', 'children': ['229']}, {'id': '229', 'type': 'block', 'children': ['230']}; {'id': '230', 'type': 'expression_statement', 'children': ['231']}, {'id': '231', 'type': 'assignment', 'children': ['232', '235']}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'chk'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'exit_status'}, {'id': '235', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '236', 'type': 'else_clause', 'children': ['237']}, {'id': '237', 'type': 'block', 'children': ['238']}; {'id': '238', 'type': 'if_statement', 'children': ['239', '244', '251', '264', '277', '290', '303']}, {'id': '239', 'type': 'comparison_operator', 'children': ['240', '243'], 'value': '=='}; {'id': '240', 'type': 'attribute', 'children': ['241', '242']}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'freshness_state'}, {'id': '243', 'type': 'string', 'children': [], 'value': "'o'"}; {'id': '244', 'type': 'block', 'children': ['245']}, {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'assignment', 'children': ['247', '250']}, {'id': '247', 'type': 'attribute', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'chk'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'exit_status'}; {'id': '250', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '251', 'type': 'elif_clause', 'children': ['252', '257']}; {'id': '252', 'type': 'comparison_operator', 'children': ['253', '256'], 'value': '=='}, {'id': '253', 'type': 'attribute', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'freshness_state'}; {'id': '256', 'type': 'string', 'children': [], 'value': "'w'"}, {'id': '257', 'type': 'block', 'children': ['258']}; {'id': '258', 'type': 'expression_statement', 'children': ['259']}, {'id': '259', 'type': 'assignment', 'children': ['260', '263']}; {'id': '260', 'type': 'attribute', 'children': ['261', '262']}, {'id': '261', 'type': 'identifier', 'children': [], 'value': 'chk'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'exit_status'}, {'id': '263', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '264', 'type': 'elif_clause', 'children': ['265', '270']}, {'id': '265', 'type': 'comparison_operator', 'children': ['266', '269'], 'value': '=='}; {'id': '266', 'type': 'attribute', 'children': ['267', '268']}, {'id': '267', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'freshness_state'}, {'id': '269', 'type': 'string', 'children': [], 'value': "'c'"}; {'id': '270', 'type': 'block', 'children': ['271']}, {'id': '271', 'type': 'expression_statement', 'children': ['272']}; {'id': '272', 'type': 'assignment', 'children': ['273', '276']}, {'id': '273', 'type': 'attribute', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'chk'}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'exit_status'}; {'id': '276', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '277', 'type': 'elif_clause', 'children': ['278', '283']}; {'id': '278', 'type': 'comparison_operator', 'children': ['279', '282'], 'value': '=='}, {'id': '279', 'type': 'attribute', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'freshness_state'}; {'id': '282', 'type': 'string', 'children': [], 'value': "'u'"}, {'id': '283', 'type': 'block', 'children': ['284']}; {'id': '284', 'type': 'expression_statement', 'children': ['285']}, {'id': '285', 'type': 'assignment', 'children': ['286', '289']}; {'id': '286', 'type': 'attribute', 'children': ['287', '288']}, {'id': '287', 'type': 'identifier', 'children': [], 'value': 'chk'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'exit_status'}, {'id': '289', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '290', 'type': 'elif_clause', 'children': ['291', '296']}, {'id': '291', 'type': 'comparison_operator', 'children': ['292', '295'], 'value': '=='}; {'id': '292', 'type': 'attribute', 'children': ['293', '294']}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'freshness_state'}, {'id': '295', 'type': 'string', 'children': [], 'value': "'x'"}; {'id': '296', 'type': 'block', 'children': ['297']}, {'id': '297', 'type': 'expression_statement', 'children': ['298']}; {'id': '298', 'type': 'assignment', 'children': ['299', '302']}, {'id': '299', 'type': 'attribute', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'chk'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'exit_status'}; {'id': '302', 'type': 'integer', 'children': [], 'value': '4'}, {'id': '303', 'type': 'else_clause', 'children': ['304']}; {'id': '304', 'type': 'block', 'children': ['305']}, {'id': '305', 'type': 'expression_statement', 'children': ['306']}; {'id': '306', 'type': 'assignment', 'children': ['307', '310']}, {'id': '307', 'type': 'attribute', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'chk'}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'exit_status'}; {'id': '310', 'type': 'integer', 'children': [], 'value': '3'}, {'id': '311', 'type': 'return_statement', 'children': ['312']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'chk'}, {'id': '313', 'type': 'else_clause', 'children': ['314']}; {'id': '314', 'type': 'block', 'children': ['315']}, {'id': '315', 'type': 'expression_statement', 'children': ['316']}; {'id': '316', 'type': 'call', 'children': ['317', '320']}, {'id': '317', 'type': 'attribute', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '320', 'type': 'argument_list', 'children': ['321', '324']}, {'id': '321', 'type': 'concatenated_string', 'children': ['322', '323']}; {'id': '322', 'type': 'string', 'children': [], 'value': '"Ignored freshness check for %s, because "'}, {'id': '323', 'type': 'string', 'children': [], 'value': '"we are not in the check period."'}; {'id': '324', 'type': 'call', 'children': ['325', '328']}, {'id': '325', 'type': 'attribute', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '327', 'type': 'identifier', 'children': [], 'value': 'get_full_name'}; {'id': '328', 'type': 'argument_list', 'children': []}, {'id': '329', 'type': 'return_statement', 'children': ['330']} | def do_check_freshness(self, hosts, services, timeperiods, macromodulations, checkmodulations,
checks, when):
now = when
cls = self.__class__
if not self.in_checking and self.freshness_threshold and not self.freshness_expired:
if os.getenv('ALIGNAK_LOG_CHECKS', None):
logger.info("--ALC-- -> checking freshness for: %s", self.get_full_name())
if not self.last_state_update:
self.last_state_update = int(now)
if self.last_state_update < now - \
(self.freshness_threshold + cls.additional_freshness_latency):
timeperiod = timeperiods[self.check_period]
if timeperiod is None or timeperiod.is_time_valid(now):
chk = self.launch_check(now, hosts, services, timeperiods,
macromodulations, checkmodulations, checks)
if not chk:
logger.warning("No raised freshness check for: %s", self)
return None
chk.freshness_expiry_check = True
chk.check_time = time.time()
chk.output = "Freshness period expired: %s" % (
datetime.utcfromtimestamp(int(chk.check_time)).strftime(
"%Y-%m-%d %H:%M:%S %Z"))
if self.my_type == 'host':
if self.freshness_state == 'o':
chk.exit_status = 0
elif self.freshness_state == 'd':
chk.exit_status = 2
elif self.freshness_state in ['u', 'x']:
chk.exit_status = 4
else:
chk.exit_status = 3
else:
if self.freshness_state == 'o':
chk.exit_status = 0
elif self.freshness_state == 'w':
chk.exit_status = 1
elif self.freshness_state == 'c':
chk.exit_status = 2
elif self.freshness_state == 'u':
chk.exit_status = 3
elif self.freshness_state == 'x':
chk.exit_status = 4
else:
chk.exit_status = 3
return chk
else:
logger.debug("Ignored freshness check for %s, because "
"we are not in the check period.", self.get_full_name())
return None |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'update_business_impact_value'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'hosts'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'timeperiods'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'bi_modulations'}, {'id': '9', 'type': 'block', 'children': ['10', '26', '30', '83', '143']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '17']}, {'id': '11', 'type': 'comparison_operator', 'children': ['12', '15'], 'value': '=='}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'my_own_business_impact'}, {'id': '15', 'type': 'unary_operator', 'children': ['16'], 'value': '-'}; {'id': '16', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'my_own_business_impact'}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'business_impact'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}, {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'in_modulation'}, {'id': '29', 'type': 'False', 'children': []}; {'id': '30', 'type': 'for_statement', 'children': ['31', '32', '35']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'bi_modulation_id'}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'business_impact_modulations'}, {'id': '35', 'type': 'block', 'children': ['36', '42', '50', '58']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'bi_modulation'}, {'id': '39', 'type': 'subscript', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'bi_modulations'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'bi_modulation_id'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'now'}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '49', 'type': 'argument_list', 'children': []}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'period'}, {'id': '53', 'type': 'subscript', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'timeperiods'}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'bi_modulation'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'modulation_period'}; {'id': '58', 'type': 'if_statement', 'children': ['59', '69']}, {'id': '59', 'type': 'boolean_operator', 'children': ['60', '63'], 'value': 'or'}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'is'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'period'}; {'id': '62', 'type': 'None', 'children': []}, {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'period'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'is_time_valid'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'now'}, {'id': '69', 'type': 'block', 'children': ['70', '78', '82']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'assignment', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'business_impact'}, {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'bi_modulation'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'business_impact'}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'in_modulation'}, {'id': '81', 'type': 'True', 'children': []}; {'id': '82', 'type': 'break_statement', 'children': []}, {'id': '83', 'type': 'if_statement', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'impacts'}, {'id': '87', 'type': 'block', 'children': ['88', '106', '127', '142']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}, {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'bp_impacts'}, {'id': '91', 'type': 'list_comprehension', 'children': ['92', '97', '102']}; {'id': '92', 'type': 'attribute', 'children': ['93', '96']}, {'id': '93', 'type': 'subscript', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'hosts'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'elem'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'business_impact'}, {'id': '97', 'type': 'for_in_clause', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'elem'}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'impacts'}; {'id': '102', 'type': 'if_clause', 'children': ['103']}, {'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': 'in'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'elem'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'hosts'}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}, {'id': '107', 'type': 'call', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'bp_impacts'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'extend'}, {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'list_comprehension', 'children': ['113', '118', '123']}, {'id': '113', 'type': 'attribute', 'children': ['114', '117']}; {'id': '114', 'type': 'subscript', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'elem'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'business_impact'}; {'id': '118', 'type': 'for_in_clause', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'elem'}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'impacts'}, {'id': '123', 'type': 'if_clause', 'children': ['124']}; {'id': '124', 'type': 'comparison_operator', 'children': ['125', '126'], 'value': 'in'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'elem'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'assignment', 'children': ['129', '132']}, {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'business_impact'}; {'id': '132', 'type': 'call', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '134', 'type': 'argument_list', 'children': ['135', '138']}, {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'business_impact'}; {'id': '138', 'type': 'call', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'bp_impacts'}; {'id': '142', 'type': 'return_statement', 'children': []}, {'id': '143', 'type': 'if_statement', 'children': ['144', '153']}; {'id': '144', 'type': 'boolean_operator', 'children': ['145', '151'], 'value': 'and'}, {'id': '145', 'type': 'comparison_operator', 'children': ['146', '149'], 'value': '!='}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'my_own_business_impact'}, {'id': '149', 'type': 'unary_operator', 'children': ['150'], 'value': '-'}; {'id': '150', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '151', 'type': 'not_operator', 'children': ['152']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'in_modulation'}, {'id': '153', 'type': 'block', 'children': ['154']}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}, {'id': '155', 'type': 'assignment', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'business_impact'}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'my_own_business_impact'} | def update_business_impact_value(self, hosts, services, timeperiods, bi_modulations):
if self.my_own_business_impact == -1:
self.my_own_business_impact = self.business_impact
in_modulation = False
for bi_modulation_id in self.business_impact_modulations:
bi_modulation = bi_modulations[bi_modulation_id]
now = time.time()
period = timeperiods[bi_modulation.modulation_period]
if period is None or period.is_time_valid(now):
self.business_impact = bi_modulation.business_impact
in_modulation = True
break
if self.impacts:
bp_impacts = [hosts[elem].business_impact for elem in self.impacts if elem in hosts]
bp_impacts.extend([services[elem].business_impact for elem in self.impacts
if elem in services])
self.business_impact = max(self.business_impact, max(bp_impacts))
return
if self.my_own_business_impact != -1 and not in_modulation:
self.business_impact = self.my_own_business_impact |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'register_a_problem'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'prob'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'hosts'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'timeperiods'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'bi_modulations'}; {'id': '10', 'type': 'block', 'children': ['11', '22', '30', '36', '42', '46', '205']}, {'id': '11', 'type': 'if_statement', 'children': ['12', '19']}; {'id': '12', 'type': 'comparison_operator', 'children': ['13', '16'], 'value': 'in'}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'prob'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'source_problems'}, {'id': '19', 'type': 'block', 'children': ['20']}; {'id': '20', 'type': 'return_statement', 'children': ['21']}, {'id': '21', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'now'}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '29', 'type': 'argument_list', 'children': []}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'was_an_impact'}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'is_impact'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}, {'id': '37', 'type': 'assignment', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'is_impact'}, {'id': '41', 'type': 'True', 'children': []}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'impacts'}, {'id': '45', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '46', 'type': 'if_statement', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'is_impact'}; {'id': '50', 'type': 'block', 'children': ['51', '59', '74', '84', '93', '113', '192']}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'logger'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '58']}, {'id': '57', 'type': 'string', 'children': [], 'value': '"I am impacted: %s"'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '59', 'type': 'if_statement', 'children': ['60', '63']}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'is_problem'}, {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'no_more_a_problem'}, {'id': '69', 'type': 'argument_list', 'children': ['70', '71', '72', '73']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'hosts'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'timeperiods'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'bi_modulations'}; {'id': '74', 'type': 'if_statement', 'children': ['75', '77']}, {'id': '75', 'type': 'not_operator', 'children': ['76']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'was_an_impact'}, {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'set_impact_state'}, {'id': '83', 'type': 'argument_list', 'children': []}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'impacts'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'uuid'}, {'id': '93', 'type': 'if_statement', 'children': ['94', '101']}; {'id': '94', 'type': 'comparison_operator', 'children': ['95', '98'], 'value': 'not'}, {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'prob'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'source_problems'}, {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'call', 'children': ['104', '109']}; {'id': '104', 'type': 'attribute', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'source_problems'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'prob'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'uuid'}, {'id': '113', 'type': 'for_statement', 'children': ['114', '119', '122']}; {'id': '114', 'type': 'tuple_pattern', 'children': ['115', '116', '117', '118']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'impacted_item_id'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'status'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'timeperiod_id'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'act_depend_of_me'}; {'id': '122', 'type': 'block', 'children': ['123', '142', '148']}, {'id': '123', 'type': 'if_statement', 'children': ['124', '127', '134']}; {'id': '124', 'type': 'comparison_operator', 'children': ['125', '126'], 'value': 'in'}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'impacted_item_id'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'hosts'}, {'id': '127', 'type': 'block', 'children': ['128']}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}, {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'impact'}, {'id': '131', 'type': 'subscript', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'hosts'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'impacted_item_id'}; {'id': '134', 'type': 'else_clause', 'children': ['135']}, {'id': '135', 'type': 'block', 'children': ['136']}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'id': '137', 'type': 'assignment', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'impact'}, {'id': '139', 'type': 'subscript', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'impacted_item_id'}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'assignment', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'timeperiod'}, {'id': '145', 'type': 'subscript', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'timeperiods'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'timeperiod_id'}; {'id': '148', 'type': 'for_statement', 'children': ['149', '150', '151']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'stat'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'status'}, {'id': '151', 'type': 'block', 'children': ['152']}; {'id': '152', 'type': 'if_statement', 'children': ['153', '159']}, {'id': '153', 'type': 'call', 'children': ['154', '157']}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'is_state'}, {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'stat'}, {'id': '159', 'type': 'block', 'children': ['160']}; {'id': '160', 'type': 'if_statement', 'children': ['161', '171']}, {'id': '161', 'type': 'boolean_operator', 'children': ['162', '165'], 'value': 'or'}; {'id': '162', 'type': 'comparison_operator', 'children': ['163', '164'], 'value': 'is'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'timeperiod'}; {'id': '164', 'type': 'None', 'children': []}, {'id': '165', 'type': 'call', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'timeperiod'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'is_time_valid'}, {'id': '169', 'type': 'argument_list', 'children': ['170']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'now'}, {'id': '171', 'type': 'block', 'children': ['172', '185']}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}, {'id': '173', 'type': 'assignment', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'new_impacts'}, {'id': '175', 'type': 'call', 'children': ['176', '179']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'impact'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'register_a_problem'}, {'id': '179', 'type': 'argument_list', 'children': ['180', '181', '182', '183', '184']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'prob'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'hosts'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'timeperiods'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'bi_modulations'}, {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'call', 'children': ['187', '190']}, {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'impacts'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'new_impacts'}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}, {'id': '193', 'type': 'call', 'children': ['194', '199']}; {'id': '194', 'type': 'attribute', 'children': ['195', '198']}, {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'broks'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '199', 'type': 'argument_list', 'children': ['200']}; {'id': '200', 'type': 'call', 'children': ['201', '204']}, {'id': '201', 'type': 'attribute', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'get_update_status_brok'}; {'id': '204', 'type': 'argument_list', 'children': []}, {'id': '205', 'type': 'return_statement', 'children': ['206']} | def register_a_problem(self, prob, hosts, services, timeperiods, bi_modulations):
if prob.uuid in self.source_problems:
return []
now = time.time()
was_an_impact = self.is_impact
self.is_impact = True
impacts = []
if self.is_impact:
logger.debug("I am impacted: %s", self)
if self.is_problem:
self.no_more_a_problem(hosts, services, timeperiods, bi_modulations)
if not was_an_impact:
self.set_impact_state()
impacts.append(self.uuid)
if prob.uuid not in self.source_problems:
self.source_problems.append(prob.uuid)
for (impacted_item_id, status, timeperiod_id, _) in self.act_depend_of_me:
if impacted_item_id in hosts:
impact = hosts[impacted_item_id]
else:
impact = services[impacted_item_id]
timeperiod = timeperiods[timeperiod_id]
for stat in status:
if self.is_state(stat):
if timeperiod is None or timeperiod.is_time_valid(now):
new_impacts = impact.register_a_problem(prob, hosts,
services, timeperiods,
bi_modulations)
impacts.extend(new_impacts)
self.broks.append(self.get_update_status_brok())
return impacts |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'is_enable_action_dependent'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'hosts'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '7', 'type': 'block', 'children': ['8', '12', '86']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'enable_action'}, {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'for_statement', 'children': ['13', '18', '21']}, {'id': '13', 'type': 'tuple_pattern', 'children': ['14', '15', '16', '17']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'dep_id'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'act_depend_of'}, {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'if_statement', 'children': ['23', '26', '31']}, {'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': 'in'}; {'id': '24', 'type': 'string', 'children': [], 'value': "'n'"}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'enable_action'}; {'id': '30', 'type': 'True', 'children': []}, {'id': '31', 'type': 'else_clause', 'children': ['32']}; {'id': '32', 'type': 'block', 'children': ['33', '52', '56', '69', '78']}, {'id': '33', 'type': 'if_statement', 'children': ['34', '37', '44']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'in'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'dep_id'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'hosts'}, {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'dep'}, {'id': '41', 'type': 'subscript', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'hosts'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'dep_id'}; {'id': '44', 'type': 'else_clause', 'children': ['45']}, {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'dep'}, {'id': '49', 'type': 'subscript', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'dep_id'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'p_is_down'}, {'id': '55', 'type': 'False', 'children': []}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'dep_match'}, {'id': '59', 'type': 'list_comprehension', 'children': ['60', '66']}; {'id': '60', 'type': 'call', 'children': ['61', '64']}, {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'dep'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'is_state'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'stat'}; {'id': '66', 'type': 'for_in_clause', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'stat'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'status'}, {'id': '69', 'type': 'if_statement', 'children': ['70', '73']}; {'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': 'in'}, {'id': '71', 'type': 'True', 'children': []}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'dep_match'}, {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'p_is_down'}, {'id': '77', 'type': 'True', 'children': []}; {'id': '78', 'type': 'if_statement', 'children': ['79', '81']}, {'id': '79', 'type': 'not_operator', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'p_is_down'}, {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'enable_action'}, {'id': '85', 'type': 'True', 'children': []}; {'id': '86', 'type': 'return_statement', 'children': ['87']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'enable_action'} | def is_enable_action_dependent(self, hosts, services):
enable_action = False
for (dep_id, status, _, _) in self.act_depend_of:
if 'n' in status:
enable_action = True
else:
if dep_id in hosts:
dep = hosts[dep_id]
else:
dep = services[dep_id]
p_is_down = False
dep_match = [dep.is_state(stat) for stat in status]
if True in dep_match:
p_is_down = True
if not p_is_down:
enable_action = True
return enable_action |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'update_hard_unknown_phase_state'}, {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'block', 'children': ['6', '14', '33', '101']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}, {'id': '7', 'type': 'assignment', 'children': ['8', '11']}; {'id': '8', 'type': 'attribute', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'was_in_hard_unknown_reach_phase'}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'in_hard_unknown_reach_phase'}; {'id': '14', 'type': 'if_statement', 'children': ['15', '26']}, {'id': '15', 'type': 'boolean_operator', 'children': ['16', '21'], 'value': 'or'}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '20'], 'value': '!='}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'state_type'}; {'id': '20', 'type': 'string', 'children': [], 'value': "'HARD'"}, {'id': '21', 'type': 'comparison_operator', 'children': ['22', '25'], 'value': '!='}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'last_state_type'}, {'id': '25', 'type': 'string', 'children': [], 'value': "'HARD'"}; {'id': '26', 'type': 'block', 'children': ['27']}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'in_hard_unknown_reach_phase'}; {'id': '32', 'type': 'False', 'children': []}, {'id': '33', 'type': 'if_statement', 'children': ['34', '38', '80']}; {'id': '34', 'type': 'not_operator', 'children': ['35']}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'in_hard_unknown_reach_phase'}; {'id': '38', 'type': 'block', 'children': ['39']}, {'id': '39', 'type': 'if_statement', 'children': ['40', '64']}; {'id': '40', 'type': 'boolean_operator', 'children': ['41', '52', '53'], 'value': 'or'}, {'id': '41', 'type': 'boolean_operator', 'children': ['42', '47'], 'value': 'and'}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '46'], 'value': '=='}, {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '46', 'type': 'string', 'children': [], 'value': "'UNKNOWN'"}, {'id': '47', 'type': 'comparison_operator', 'children': ['48', '51'], 'value': '!='}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'last_state'}, {'id': '51', 'type': 'string', 'children': [], 'value': "'UNKNOWN'"}; {'id': '52', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '53', 'type': 'boolean_operator', 'children': ['54', '59'], 'value': 'and'}; {'id': '54', 'type': 'comparison_operator', 'children': ['55', '58'], 'value': '=='}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '58', 'type': 'string', 'children': [], 'value': "'UNREACHABLE'"}, {'id': '59', 'type': 'comparison_operator', 'children': ['60', '63'], 'value': '!='}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'last_state'}, {'id': '63', 'type': 'string', 'children': [], 'value': "'UNREACHABLE'"}; {'id': '64', 'type': 'block', 'children': ['65', '71', '79']}, {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'in_hard_unknown_reach_phase'}; {'id': '70', 'type': 'True', 'children': []}, {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'state_before_hard_unknown_reach_phase'}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'last_state'}, {'id': '79', 'type': 'return_statement', 'children': []}; {'id': '80', 'type': 'else_clause', 'children': ['81']}, {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'if_statement', 'children': ['83', '94']}, {'id': '83', 'type': 'boolean_operator', 'children': ['84', '89'], 'value': 'and'}; {'id': '84', 'type': 'comparison_operator', 'children': ['85', '88'], 'value': '!='}, {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '88', 'type': 'string', 'children': [], 'value': "'UNKNOWN'"}, {'id': '89', 'type': 'comparison_operator', 'children': ['90', '93'], 'value': '!='}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'state'}, {'id': '93', 'type': 'string', 'children': [], 'value': "'UNREACHABLE'"}; {'id': '94', 'type': 'block', 'children': ['95']}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '100']}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'in_hard_unknown_reach_phase'}; {'id': '100', 'type': 'False', 'children': []}, {'id': '101', 'type': 'if_statement', 'children': ['102', '110']}; {'id': '102', 'type': 'boolean_operator', 'children': ['103', '107'], 'value': 'and'}, {'id': '103', 'type': 'not_operator', 'children': ['104']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'in_hard_unknown_reach_phase'}, {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'was_in_hard_unknown_reach_phase'}; {'id': '110', 'type': 'block', 'children': ['111']}, {'id': '111', 'type': 'if_statement', 'children': ['112', '119']}; {'id': '112', 'type': 'comparison_operator', 'children': ['113', '116'], 'value': '!='}, {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'state_before_hard_unknown_reach_phase'}, {'id': '119', 'type': 'block', 'children': ['120']}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}, {'id': '121', 'type': 'assignment', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'was_in_hard_unknown_reach_phase'}, {'id': '125', 'type': 'False', 'children': []} | def update_hard_unknown_phase_state(self):
self.was_in_hard_unknown_reach_phase = self.in_hard_unknown_reach_phase
if self.state_type != 'HARD' or self.last_state_type != 'HARD':
self.in_hard_unknown_reach_phase = False
if not self.in_hard_unknown_reach_phase:
if self.state == 'UNKNOWN' and self.last_state != 'UNKNOWN' \
or self.state == 'UNREACHABLE' and self.last_state != 'UNREACHABLE':
self.in_hard_unknown_reach_phase = True
self.state_before_hard_unknown_reach_phase = self.last_state
return
else:
if self.state != 'UNKNOWN' and self.state != 'UNREACHABLE':
self.in_hard_unknown_reach_phase = False
if not self.in_hard_unknown_reach_phase and self.was_in_hard_unknown_reach_phase:
if self.state != self.state_before_hard_unknown_reach_phase:
self.was_in_hard_unknown_reach_phase = False |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_next_notification_time'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'notif'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'escalations'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'timeperiods'}; {'id': '8', 'type': 'block', 'children': ['9', '13', '21', '27', '33', '45', '107', '119', '134', '138', '144', '152', '214']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '12', 'type': 'None', 'children': []}, {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '20', 'type': 'argument_list', 'children': []}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': '__class__'}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'notification_interval'}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'notification_interval'}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'in_notif_time'}; {'id': '36', 'type': 'binary_operator', 'children': ['37', '42'], 'value': '-'}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '41', 'type': 'argument_list', 'children': []}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'notif'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'creation_time'}, {'id': '45', 'type': 'for_statement', 'children': ['46', '47', '50']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'escalation_id'}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'escalations'}; {'id': '50', 'type': 'block', 'children': ['51', '57', '65']}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'escalation'}; {'id': '54', 'type': 'subscript', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'escalations'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'escalation_id'}, {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'escalation_period'}; {'id': '60', 'type': 'subscript', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'timeperiods'}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'escalation'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'escalation_period'}, {'id': '65', 'type': 'if_statement', 'children': ['66', '85']}; {'id': '66', 'type': 'call', 'children': ['67', '70']}, {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'escalation'}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'is_eligible'}; {'id': '70', 'type': 'argument_list', 'children': ['71', '74', '77', '80', '81', '84']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'notif'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 't_to_go'}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'state'}, {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'notif'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'notif_nb'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'in_notif_time'}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'interval_length'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'escalation_period'}, {'id': '85', 'type': 'block', 'children': ['86']}; {'id': '86', 'type': 'if_statement', 'children': ['87', '100']}, {'id': '87', 'type': 'boolean_operator', 'children': ['88', '94', '95'], 'value': 'and'}; {'id': '88', 'type': 'comparison_operator', 'children': ['89', '92'], 'value': '!='}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'escalation'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'notification_interval'}; {'id': '92', 'type': 'unary_operator', 'children': ['93'], 'value': '-'}, {'id': '93', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '94', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '95', 'type': 'comparison_operator', 'children': ['96', '99'], 'value': '<'}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'escalation'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'notification_interval'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'notification_interval'}; {'id': '100', 'type': 'block', 'children': ['101']}, {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'notification_interval'}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'escalation'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'notification_interval'}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'std_time'}; {'id': '110', 'type': 'binary_operator', 'children': ['111', '114'], 'value': '+'}, {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'notif'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 't_to_go'}; {'id': '114', 'type': 'binary_operator', 'children': ['115', '116'], 'value': '*'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'notification_interval'}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'interval_length'}, {'id': '119', 'type': 'if_statement', 'children': ['120', '123']}; {'id': '120', 'type': 'comparison_operator', 'children': ['121', '122'], 'value': '<'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'std_time'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'now'}, {'id': '123', 'type': 'block', 'children': ['124']}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'std_time'}, {'id': '127', 'type': 'binary_operator', 'children': ['128', '129'], 'value': '+'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'now'}, {'id': '129', 'type': 'binary_operator', 'children': ['130', '131'], 'value': '*'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'notification_interval'}, {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'cls'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'interval_length'}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'std_time'}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'creation_time'}, {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'notif'}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'creation_time'}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'assignment', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'in_notif_time'}, {'id': '147', 'type': 'binary_operator', 'children': ['148', '149'], 'value': '-'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'now'}, {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'notif'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'creation_time'}; {'id': '152', 'type': 'for_statement', 'children': ['153', '154', '157']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'escalation_id'}; {'id': '154', 'type': 'attribute', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'escalations'}, {'id': '157', 'type': 'block', 'children': ['158', '164']}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}, {'id': '159', 'type': 'assignment', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'escalation'}, {'id': '161', 'type': 'subscript', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'escalations'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'escalation_id'}; {'id': '164', 'type': 'if_statement', 'children': ['165', '174']}, {'id': '165', 'type': 'comparison_operator', 'children': ['166', '171'], 'value': 'not'}; {'id': '166', 'type': 'call', 'children': ['167', '170']}, {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'escalation'}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'get_name'}; {'id': '170', 'type': 'argument_list', 'children': []}, {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'notif'}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'already_start_escalations'}; {'id': '174', 'type': 'block', 'children': ['175', '183', '200']}, {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'assignment', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'escalation_period'}; {'id': '178', 'type': 'subscript', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'timeperiods'}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'escalation'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'escalation_period'}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'next_t'}; {'id': '186', 'type': 'call', 'children': ['187', '190']}, {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'escalation'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'get_next_notif_time'}; {'id': '190', 'type': 'argument_list', 'children': ['191', '192', '195', '196', '199']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'std_time'}; {'id': '192', 'type': 'attribute', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'state'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'creation_time'}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'interval_length'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'escalation_period'}; {'id': '200', 'type': 'if_statement', 'children': ['201', '209']}, {'id': '201', 'type': 'boolean_operator', 'children': ['202', '205'], 'value': 'and'}; {'id': '202', 'type': 'comparison_operator', 'children': ['203', '204'], 'value': 'is'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'next_t'}; {'id': '204', 'type': 'None', 'children': []}, {'id': '205', 'type': 'comparison_operator', 'children': ['206', '207', '208'], 'value': '<'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'now'}, {'id': '207', 'type': 'identifier', 'children': [], 'value': 'next_t'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '209', 'type': 'block', 'children': ['210']}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}, {'id': '211', 'type': 'assignment', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'next_t'}; {'id': '214', 'type': 'return_statement', 'children': ['215']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'res'} | def get_next_notification_time(self, notif, escalations, timeperiods):
res = None
now = time.time()
cls = self.__class__
notification_interval = self.notification_interval
in_notif_time = time.time() - notif.creation_time
for escalation_id in self.escalations:
escalation = escalations[escalation_id]
escalation_period = timeperiods[escalation.escalation_period]
if escalation.is_eligible(notif.t_to_go, self.state, notif.notif_nb,
in_notif_time, cls.interval_length, escalation_period):
if escalation.notification_interval != -1 and \
escalation.notification_interval < notification_interval:
notification_interval = escalation.notification_interval
std_time = notif.t_to_go + notification_interval * cls.interval_length
if std_time < now:
std_time = now + notification_interval * cls.interval_length
res = std_time
creation_time = notif.creation_time
in_notif_time = now - notif.creation_time
for escalation_id in self.escalations:
escalation = escalations[escalation_id]
if escalation.get_name() not in notif.already_start_escalations:
escalation_period = timeperiods[escalation.escalation_period]
next_t = escalation.get_next_notif_time(std_time, self.state,
creation_time, cls.interval_length,
escalation_period)
if next_t is not None and now < next_t < res:
res = next_t
return res |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_business_rule_output'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'hosts'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'macromodulations'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'timeperiods'}, {'id': '9', 'type': 'block', 'children': ['10', '19', '32', '38', '44', '50', '60', '76', '80', '84', '94', '153', '165', '176', '185', '197']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'got_business_rule'}, {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '15', 'type': 'argument_list', 'children': ['16', '17', '18']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '17', 'type': 'string', 'children': [], 'value': "'got_business_rule'"}; {'id': '18', 'type': 'False', 'children': []}, {'id': '19', 'type': 'if_statement', 'children': ['20', '29']}; {'id': '20', 'type': 'boolean_operator', 'children': ['21', '24'], 'value': 'or'}, {'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'is'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'got_business_rule'}, {'id': '23', 'type': 'False', 'children': []}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '28'], 'value': 'is'}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'business_rule'}; {'id': '28', 'type': 'None', 'children': []}, {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'return_statement', 'children': ['31']}, {'id': '31', 'type': 'string', 'children': [], 'value': '""'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'output_template'}, {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'business_rule_output_template'}; {'id': '38', 'type': 'if_statement', 'children': ['39', '41']}, {'id': '39', 'type': 'not_operator', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'output_template'}, {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'return_statement', 'children': ['43']}, {'id': '43', 'type': 'string', 'children': [], 'value': '""'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}, {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'macroresolver'}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'MacroResolver'}, {'id': '49', 'type': 'argument_list', 'children': []}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'elts'}, {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'findall'}, {'id': '57', 'type': 'argument_list', 'children': ['58', '59']}; {'id': '58', 'type': 'string', 'children': [], 'value': 'r"\\$\\((.*)\\)\\$"'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'output_template'}; {'id': '60', 'type': 'if_statement', 'children': ['61', '63', '68']}, {'id': '61', 'type': 'not_operator', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'elts'}, {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'child_template_string'}, {'id': '67', 'type': 'string', 'children': [], 'value': '""'}; {'id': '68', 'type': 'else_clause', 'children': ['69']}, {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'child_template_string'}, {'id': '73', 'type': 'subscript', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'elts'}, {'id': '75', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}, {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'children_output'}, {'id': '79', 'type': 'string', 'children': [], 'value': '""'}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'ok_count'}, {'id': '83', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '87', 'type': 'call', 'children': ['88', '93']}; {'id': '88', 'type': 'attribute', 'children': ['89', '92']}, {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'business_rule'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'list_all_elements'}, {'id': '93', 'type': 'argument_list', 'children': []}; {'id': '94', 'type': 'for_statement', 'children': ['95', '96', '97']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'item_uuid'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'items'}, {'id': '97', 'type': 'block', 'children': ['98', '120', '132', '141']}; {'id': '98', 'type': 'if_statement', 'children': ['99', '102', '109']}, {'id': '99', 'type': 'comparison_operator', 'children': ['100', '101'], 'value': 'in'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'item_uuid'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'hosts'}; {'id': '102', 'type': 'block', 'children': ['103']}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '106', 'type': 'subscript', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'hosts'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'item_uuid'}, {'id': '109', 'type': 'elif_clause', 'children': ['110', '113']}; {'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': 'in'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'item_uuid'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'item'}, {'id': '117', 'type': 'subscript', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'item_uuid'}; {'id': '120', 'type': 'if_statement', 'children': ['121', '126']}, {'id': '121', 'type': 'comparison_operator', 'children': ['122', '125'], 'value': '=='}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'last_hard_state_id'}, {'id': '125', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '126', 'type': 'block', 'children': ['127', '131']}, {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'augmented_assignment', 'children': ['129', '130'], 'value': '+='}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'ok_count'}; {'id': '130', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '131', 'type': 'continue_statement', 'children': []}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '135', 'type': 'call', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'get_data_for_checks'}, {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'hosts'}, {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'augmented_assignment', 'children': ['143', '144'], 'value': '+='}, {'id': '143', 'type': 'identifier', 'children': [], 'value': 'children_output'}; {'id': '144', 'type': 'call', 'children': ['145', '148']}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'macroresolver'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'resolve_simple_macros_in_string'}; {'id': '148', 'type': 'argument_list', 'children': ['149', '150', '151', '152']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'child_template_string'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'macromodulations'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'timeperiods'}, {'id': '153', 'type': 'if_statement', 'children': ['154', '160']}; {'id': '154', 'type': 'comparison_operator', 'children': ['155', '156'], 'value': '=='}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'ok_count'}; {'id': '156', 'type': 'call', 'children': ['157', '158']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '158', 'type': 'argument_list', 'children': ['159']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '160', 'type': 'block', 'children': ['161']}, {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'children_output'}; {'id': '164', 'type': 'string', 'children': [], 'value': '"all checks were successful."'}, {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'assignment', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'template_string'}; {'id': '168', 'type': 'call', 'children': ['169', '172']}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 're'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'sub'}; {'id': '172', 'type': 'argument_list', 'children': ['173', '174', '175']}, {'id': '173', 'type': 'string', 'children': [], 'value': 'r"\\$\\(.*\\)\\$"'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'children_output'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'output_template'}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'assignment', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '179', 'type': 'call', 'children': ['180', '183']}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'get_data_for_checks'}, {'id': '183', 'type': 'argument_list', 'children': ['184']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'hosts'}, {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'assignment', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'output'}; {'id': '188', 'type': 'call', 'children': ['189', '192']}, {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'macroresolver'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'resolve_simple_macros_in_string'}; {'id': '192', 'type': 'argument_list', 'children': ['193', '194', '195', '196']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'template_string'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'macromodulations'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'timeperiods'}, {'id': '197', 'type': 'return_statement', 'children': ['198']}; {'id': '198', 'type': 'call', 'children': ['199', '202']}, {'id': '199', 'type': 'attribute', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'output'}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'strip'} | def get_business_rule_output(self, hosts, services, macromodulations, timeperiods):
got_business_rule = getattr(self, 'got_business_rule', False)
if got_business_rule is False or self.business_rule is None:
return ""
output_template = self.business_rule_output_template
if not output_template:
return ""
macroresolver = MacroResolver()
elts = re.findall(r"\$\((.*)\)\$", output_template)
if not elts:
child_template_string = ""
else:
child_template_string = elts[0]
children_output = ""
ok_count = 0
items = self.business_rule.list_all_elements()
for item_uuid in items:
if item_uuid in hosts:
item = hosts[item_uuid]
elif item_uuid in services:
item = services[item_uuid]
if item.last_hard_state_id == 0:
ok_count += 1
continue
data = item.get_data_for_checks(hosts)
children_output += macroresolver.resolve_simple_macros_in_string(child_template_string,
data,
macromodulations,
timeperiods)
if ok_count == len(items):
children_output = "all checks were successful."
template_string = re.sub(r"\$\(.*\)\$", children_output, output_template)
data = self.get_data_for_checks(hosts)
output = macroresolver.resolve_simple_macros_in_string(template_string, data,
macromodulations, timeperiods)
return output.strip() |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'business_rule_notification_is_blocked'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'hosts'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '7', 'type': 'block', 'children': ['8', '12', '93']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'acknowledged'}, {'id': '11', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '12', 'type': 'for_statement', 'children': ['13', '14', '17']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'src_prob_id'}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'source_problems'}, {'id': '17', 'type': 'block', 'children': ['18', '37']}; {'id': '18', 'type': 'if_statement', 'children': ['19', '22', '29']}, {'id': '19', 'type': 'comparison_operator', 'children': ['20', '21'], 'value': 'in'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'src_prob_id'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'hosts'}; {'id': '22', 'type': 'block', 'children': ['23']}, {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'src_prob'}; {'id': '26', 'type': 'subscript', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'hosts'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'src_prob_id'}, {'id': '29', 'type': 'else_clause', 'children': ['30']}; {'id': '30', 'type': 'block', 'children': ['31']}, {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'src_prob'}; {'id': '34', 'type': 'subscript', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'src_prob_id'}, {'id': '37', 'type': 'if_statement', 'children': ['38', '43']}; {'id': '38', 'type': 'comparison_operator', 'children': ['39', '42'], 'value': '!='}, {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'src_prob'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'last_hard_state_id'}; {'id': '42', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'if_statement', 'children': ['45', '48', '53']}, {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'src_prob'}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'problem_has_been_acknowledged'}; {'id': '48', 'type': 'block', 'children': ['49']}, {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'augmented_assignment', 'children': ['51', '52'], 'value': '+='}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'acknowledged'}; {'id': '52', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '53', 'type': 'elif_clause', 'children': ['54', '59']}; {'id': '54', 'type': 'comparison_operator', 'children': ['55', '58'], 'value': 'is'}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'business_rule_downtime_as_ack'}; {'id': '58', 'type': 'True', 'children': []}, {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'if_statement', 'children': ['61', '66', '71']}, {'id': '61', 'type': 'comparison_operator', 'children': ['62', '65'], 'value': '>'}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'src_prob'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'scheduled_downtime_depth'}, {'id': '65', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '66', 'type': 'block', 'children': ['67']}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'augmented_assignment', 'children': ['69', '70'], 'value': '+='}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'acknowledged'}; {'id': '70', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '71', 'type': 'elif_clause', 'children': ['72', '88']}; {'id': '72', 'type': 'boolean_operator', 'children': ['73', '78', '79'], 'value': 'and'}, {'id': '73', 'type': 'call', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '75', 'type': 'argument_list', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'src_prob'}, {'id': '77', 'type': 'string', 'children': [], 'value': '"host"'}; {'id': '78', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '79', 'type': 'comparison_operator', 'children': ['80', '87'], 'value': '>'}; {'id': '80', 'type': 'attribute', 'children': ['81', '86']}, {'id': '81', 'type': 'subscript', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'hosts'}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'src_prob'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'host'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'scheduled_downtime_depth'}, {'id': '87', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '88', 'type': 'block', 'children': ['89']}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'augmented_assignment', 'children': ['91', '92'], 'value': '+='}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'acknowledged'}; {'id': '92', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '93', 'type': 'return_statement', 'children': ['94']}; {'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': '=='}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'acknowledged'}; {'id': '96', 'type': 'call', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}, {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'source_problems'} | def business_rule_notification_is_blocked(self, hosts, services):
acknowledged = 0
for src_prob_id in self.source_problems:
if src_prob_id in hosts:
src_prob = hosts[src_prob_id]
else:
src_prob = services[src_prob_id]
if src_prob.last_hard_state_id != 0:
if src_prob.problem_has_been_acknowledged:
acknowledged += 1
elif self.business_rule_downtime_as_ack is True:
if src_prob.scheduled_downtime_depth > 0:
acknowledged += 1
elif hasattr(src_prob, "host") and \
hosts[src_prob.host].scheduled_downtime_depth > 0:
acknowledged += 1
return acknowledged == len(self.source_problems) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'acknowledge_problem'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '11', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'notification_period'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'hosts'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'sticky'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'notify'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'author'}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'comment'}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}, {'id': '13', 'type': 'identifier', 'children': [], 'value': 'end_time'}; {'id': '14', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '15', 'type': 'block', 'children': ['16', '20', '35', '275', '310']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}, {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'comm'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '25', 'type': 'argument_list', 'children': ['26', '27', '30']}; {'id': '26', 'type': 'string', 'children': [], 'value': '"Acknowledge requested for %s %s."'}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'my_type'}; {'id': '30', 'type': 'call', 'children': ['31', '34']}, {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'get_name'}; {'id': '34', 'type': 'argument_list', 'children': []}, {'id': '35', 'type': 'if_statement', 'children': ['36', '43', '258']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '40'], 'value': '!='}, {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'state'}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'ok_up'}, {'id': '43', 'type': 'block', 'children': ['44', '67', '80', '86', '92', '116', '125', '185', '212', '219', '229', '239', '252']}; {'id': '44', 'type': 'if_statement', 'children': ['45', '52']}, {'id': '45', 'type': 'boolean_operator', 'children': ['46', '49'], 'value': 'and'}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'problem_has_been_acknowledged'}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'acknowledgement'}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'del_comment'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '61', 'type': 'argument_list', 'children': ['62', '65', '66']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'acknowledgement'}, {'id': '65', 'type': 'string', 'children': [], 'value': "'comment_id'"}; {'id': '66', 'type': 'None', 'children': []}, {'id': '67', 'type': 'if_statement', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'notify'}, {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}, {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'create_notifications'}, {'id': '75', 'type': 'argument_list', 'children': ['76', '77', '78', '79']}; {'id': '76', 'type': 'string', 'children': [], 'value': "'ACKNOWLEDGEMENT'"}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'notification_period'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'hosts'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'assignment', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'problem_has_been_acknowledged'}, {'id': '85', 'type': 'True', 'children': []}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'sticky'}, {'id': '89', 'type': 'comparison_operator', 'children': ['90', '91'], 'value': '=='}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'sticky'}, {'id': '91', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}, {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '95', 'type': 'dictionary', 'children': ['96', '101', '104', '107', '110', '113']}; {'id': '96', 'type': 'pair', 'children': ['97', '98']}, {'id': '97', 'type': 'string', 'children': [], 'value': "'ref'"}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'uuid'}, {'id': '101', 'type': 'pair', 'children': ['102', '103']}; {'id': '102', 'type': 'string', 'children': [], 'value': "'sticky'"}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'sticky'}; {'id': '104', 'type': 'pair', 'children': ['105', '106']}, {'id': '105', 'type': 'string', 'children': [], 'value': "'author'"}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'author'}, {'id': '107', 'type': 'pair', 'children': ['108', '109']}; {'id': '108', 'type': 'string', 'children': [], 'value': "'comment'"}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'comment'}; {'id': '110', 'type': 'pair', 'children': ['111', '112']}, {'id': '111', 'type': 'string', 'children': [], 'value': "'end_time'"}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'end_time'}, {'id': '113', 'type': 'pair', 'children': ['114', '115']}; {'id': '114', 'type': 'string', 'children': [], 'value': "'notify'"}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'notify'}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}, {'id': '117', 'type': 'assignment', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'acknowledgement'}, {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'Acknowledge'}, {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '125', 'type': 'if_statement', 'children': ['126', '131', '156']}; {'id': '126', 'type': 'comparison_operator', 'children': ['127', '130'], 'value': '=='}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'my_type'}; {'id': '130', 'type': 'string', 'children': [], 'value': "'host'"}, {'id': '131', 'type': 'block', 'children': ['132', '136']}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'comment_type'}, {'id': '135', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'id': '137', 'type': 'call', 'children': ['138', '143']}; {'id': '138', 'type': 'attribute', 'children': ['139', '142']}, {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'broks'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '143', 'type': 'argument_list', 'children': ['144']}; {'id': '144', 'type': 'call', 'children': ['145', '150']}, {'id': '145', 'type': 'attribute', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'acknowledgement'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'get_raise_brok'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}, {'id': '151', 'type': 'call', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'get_name'}, {'id': '155', 'type': 'argument_list', 'children': []}; {'id': '156', 'type': 'else_clause', 'children': ['157']}, {'id': '157', 'type': 'block', 'children': ['158', '162']}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}, {'id': '159', 'type': 'assignment', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'comment_type'}, {'id': '161', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}, {'id': '163', 'type': 'call', 'children': ['164', '169']}; {'id': '164', 'type': 'attribute', 'children': ['165', '168']}, {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'broks'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '169', 'type': 'argument_list', 'children': ['170']}; {'id': '170', 'type': 'call', 'children': ['171', '176']}, {'id': '171', 'type': 'attribute', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}, {'id': '173', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'acknowledgement'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'get_raise_brok'}; {'id': '176', 'type': 'argument_list', 'children': ['177', '180']}, {'id': '177', 'type': 'attribute', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'host_name'}; {'id': '180', 'type': 'call', 'children': ['181', '184']}, {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'get_name'}; {'id': '184', 'type': 'argument_list', 'children': []}, {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'assignment', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '188', 'type': 'dictionary', 'children': ['189', '192', '195', '198', '201', '204', '207']}, {'id': '189', 'type': 'pair', 'children': ['190', '191']}; {'id': '190', 'type': 'string', 'children': [], 'value': "'author'"}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'author'}; {'id': '192', 'type': 'pair', 'children': ['193', '194']}, {'id': '193', 'type': 'string', 'children': [], 'value': "'comment'"}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'comment'}, {'id': '195', 'type': 'pair', 'children': ['196', '197']}; {'id': '196', 'type': 'string', 'children': [], 'value': "'comment_type'"}, {'id': '197', 'type': 'identifier', 'children': [], 'value': 'comment_type'}; {'id': '198', 'type': 'pair', 'children': ['199', '200']}, {'id': '199', 'type': 'string', 'children': [], 'value': "'entry_type'"}; {'id': '200', 'type': 'integer', 'children': [], 'value': '4'}, {'id': '201', 'type': 'pair', 'children': ['202', '203']}; {'id': '202', 'type': 'string', 'children': [], 'value': "'source'"}, {'id': '203', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '204', 'type': 'pair', 'children': ['205', '206']}, {'id': '205', 'type': 'string', 'children': [], 'value': "'expires'"}; {'id': '206', 'type': 'False', 'children': []}, {'id': '207', 'type': 'pair', 'children': ['208', '209']}; {'id': '208', 'type': 'string', 'children': [], 'value': "'ref'"}, {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '212', 'type': 'expression_statement', 'children': ['213']}, {'id': '213', 'type': 'assignment', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'comm'}, {'id': '215', 'type': 'call', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'Comment'}, {'id': '217', 'type': 'argument_list', 'children': ['218']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '219', 'type': 'expression_statement', 'children': ['220']}; {'id': '220', 'type': 'assignment', 'children': ['221', '226']}, {'id': '221', 'type': 'attribute', 'children': ['222', '225']}; {'id': '222', 'type': 'attribute', 'children': ['223', '224']}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'acknowledgement'}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'comment_id'}; {'id': '226', 'type': 'attribute', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'comm'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'uuid'}, {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'assignment', 'children': ['231', '238']}, {'id': '231', 'type': 'subscript', 'children': ['232', '235']}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'comments'}, {'id': '235', 'type': 'attribute', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'comm'}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'comm'}, {'id': '239', 'type': 'expression_statement', 'children': ['240']}; {'id': '240', 'type': 'call', 'children': ['241', '246']}, {'id': '241', 'type': 'attribute', 'children': ['242', '245']}; {'id': '242', 'type': 'attribute', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'broks'}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '246', 'type': 'argument_list', 'children': ['247']}, {'id': '247', 'type': 'call', 'children': ['248', '251']}; {'id': '248', 'type': 'attribute', 'children': ['249', '250']}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'get_update_status_brok'}, {'id': '251', 'type': 'argument_list', 'children': []}; {'id': '252', 'type': 'expression_statement', 'children': ['253']}, {'id': '253', 'type': 'call', 'children': ['254', '257']}; {'id': '254', 'type': 'attribute', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'raise_acknowledge_log_entry'}, {'id': '257', 'type': 'argument_list', 'children': []}; {'id': '258', 'type': 'else_clause', 'children': ['259']}, {'id': '259', 'type': 'block', 'children': ['260']}; {'id': '260', 'type': 'expression_statement', 'children': ['261']}, {'id': '261', 'type': 'call', 'children': ['262', '265']}; {'id': '262', 'type': 'attribute', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'debug'}, {'id': '265', 'type': 'argument_list', 'children': ['266', '267', '270']}; {'id': '266', 'type': 'string', 'children': [], 'value': '"Acknowledge requested for %s %s but element state is OK/UP."'}, {'id': '267', 'type': 'attribute', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '269', 'type': 'identifier', 'children': [], 'value': 'my_type'}; {'id': '270', 'type': 'call', 'children': ['271', '274']}, {'id': '271', 'type': 'attribute', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '273', 'type': 'identifier', 'children': [], 'value': 'get_name'}; {'id': '274', 'type': 'argument_list', 'children': []}, {'id': '275', 'type': 'if_statement', 'children': ['276', '281']}; {'id': '276', 'type': 'comparison_operator', 'children': ['277', '280'], 'value': '=='}, {'id': '277', 'type': 'attribute', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '279', 'type': 'identifier', 'children': [], 'value': 'my_type'}; {'id': '280', 'type': 'string', 'children': [], 'value': "'host'"}, {'id': '281', 'type': 'block', 'children': ['282']}; {'id': '282', 'type': 'for_statement', 'children': ['283', '284', '287']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'service_uuid'}; {'id': '284', 'type': 'attribute', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '287', 'type': 'block', 'children': ['288', '294']}; {'id': '288', 'type': 'if_statement', 'children': ['289', '292']}, {'id': '289', 'type': 'comparison_operator', 'children': ['290', '291'], 'value': 'not'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'service_uuid'}, {'id': '291', 'type': 'identifier', 'children': [], 'value': 'services'}; {'id': '292', 'type': 'block', 'children': ['293']}, {'id': '293', 'type': 'continue_statement', 'children': []}; {'id': '294', 'type': 'expression_statement', 'children': ['295']}, {'id': '295', 'type': 'call', 'children': ['296', '301']}; {'id': '296', 'type': 'attribute', 'children': ['297', '300']}, {'id': '297', 'type': 'subscript', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'service_uuid'}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'acknowledge_problem'}, {'id': '301', 'type': 'argument_list', 'children': ['302', '303', '304', '305', '306', '307', '308', '309']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'notification_period'}, {'id': '303', 'type': 'identifier', 'children': [], 'value': 'hosts'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'services'}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'sticky'}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'notify'}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'author'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'comment'}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'end_time'}; {'id': '310', 'type': 'return_statement', 'children': ['311']}, {'id': '311', 'type': 'identifier', 'children': [], 'value': 'comm'} | def acknowledge_problem(self, notification_period, hosts, services, sticky, notify, author,
comment, end_time=0):
comm = None
logger.debug("Acknowledge requested for %s %s.", self.my_type, self.get_name())
if self.state != self.ok_up:
if self.problem_has_been_acknowledged and self.acknowledgement:
self.del_comment(getattr(self.acknowledgement, 'comment_id', None))
if notify:
self.create_notifications('ACKNOWLEDGEMENT',
notification_period, hosts, services)
self.problem_has_been_acknowledged = True
sticky = sticky == 2
data = {
'ref': self.uuid, 'sticky': sticky, 'author': author, 'comment': comment,
'end_time': end_time, 'notify': notify
}
self.acknowledgement = Acknowledge(data)
if self.my_type == 'host':
comment_type = 1
self.broks.append(self.acknowledgement.get_raise_brok(self.get_name()))
else:
comment_type = 2
self.broks.append(self.acknowledgement.get_raise_brok(self.host_name,
self.get_name()))
data = {
'author': author, 'comment': comment, 'comment_type': comment_type, 'entry_type': 4,
'source': 0, 'expires': False, 'ref': self.uuid
}
comm = Comment(data)
self.acknowledgement.comment_id = comm.uuid
self.comments[comm.uuid] = comm
self.broks.append(self.get_update_status_brok())
self.raise_acknowledge_log_entry()
else:
logger.debug("Acknowledge requested for %s %s but element state is OK/UP.",
self.my_type, self.get_name())
if self.my_type == 'host':
for service_uuid in self.services:
if service_uuid not in services:
continue
services[service_uuid].acknowledge_problem(notification_period, hosts, services,
sticky, notify, author, comment,
end_time)
return comm |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'setup_logger'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'logger_configuration_file'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'log_dir'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'process_name'}; {'id': '10', 'type': 'string', 'children': [], 'value': "''"}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'log_file'}, {'id': '13', 'type': 'string', 'children': [], 'value': "''"}; {'id': '14', 'type': 'block', 'children': ['15', '24']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'logger_'}; {'id': '18', 'type': 'call', 'children': ['19', '22']}, {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'logging'}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'getLogger'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'ALIGNAK_LOGGER_NAME'}; {'id': '24', 'type': 'for_statement', 'children': ['25', '26', '29', '117']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'handler'}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'logger_'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'handlers'}, {'id': '29', 'type': 'block', 'children': ['30', '35']}; {'id': '30', 'type': 'if_statement', 'children': ['31', '33']}, {'id': '31', 'type': 'not_operator', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'process_name'}, {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'break_statement', 'children': []}, {'id': '35', 'type': 'if_statement', 'children': ['36', '44']}; {'id': '36', 'type': 'comparison_operator', 'children': ['37', '43'], 'value': '=='}, {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '39', 'type': 'argument_list', 'children': ['40', '41', '42']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'handler'}, {'id': '41', 'type': 'string', 'children': [], 'value': "'_name'"}; {'id': '42', 'type': 'None', 'children': []}, {'id': '43', 'type': 'string', 'children': [], 'value': "'daemons'"}; {'id': '44', 'type': 'block', 'children': ['45', '116']}, {'id': '45', 'type': 'for_statement', 'children': ['46', '47', '50']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'hdlr'}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'logger_'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'handlers'}; {'id': '50', 'type': 'block', 'children': ['51', '86']}, {'id': '51', 'type': 'if_statement', 'children': ['52', '59']}; {'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': 'in'}, {'id': '53', 'type': 'string', 'children': [], 'value': "'alignak_tests'"}; {'id': '54', 'type': 'attribute', 'children': ['55', '58']}, {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'hdlr'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'formatter'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': '_fmt'}, {'id': '59', 'type': 'block', 'children': ['60', '79']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'formatter'}, {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'Formatter'}, {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '76']}, {'id': '69', 'type': 'attribute', 'children': ['70', '75']}; {'id': '70', 'type': 'attribute', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'hdlr'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'formatter'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': '_fmt'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '76', 'type': 'argument_list', 'children': ['77', '78']}, {'id': '77', 'type': 'string', 'children': [], 'value': '"alignak_tests"'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'process_name'}, {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'hdlr'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'setFormatter'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'formatter'}; {'id': '86', 'type': 'if_statement', 'children': ['87', '99']}, {'id': '87', 'type': 'boolean_operator', 'children': ['88', '94'], 'value': 'and'}; {'id': '88', 'type': 'call', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '90', 'type': 'argument_list', 'children': ['91', '92', '93']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'hdlr'}; {'id': '92', 'type': 'string', 'children': [], 'value': "'filename'"}, {'id': '93', 'type': 'None', 'children': []}; {'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': 'in'}, {'id': '95', 'type': 'string', 'children': [], 'value': "'alignak_tests'"}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'hdlr'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}, {'id': '101', 'type': 'assignment', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'hdlr'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '105', 'type': 'call', 'children': ['106', '113']}; {'id': '106', 'type': 'attribute', 'children': ['107', '112']}, {'id': '107', 'type': 'attribute', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'hdlr'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '111', 'type': 'identifier', 'children': [], 'value': '_fmt'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'replace'}, {'id': '113', 'type': 'argument_list', 'children': ['114', '115']}; {'id': '114', 'type': 'string', 'children': [], 'value': '"alignak_tests"'}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'process_name'}; {'id': '116', 'type': 'break_statement', 'children': []}, {'id': '117', 'type': 'else_clause', 'children': ['118']}; {'id': '118', 'type': 'block', 'children': ['119', '141', '355']}, {'id': '119', 'type': 'if_statement', 'children': ['120', '132']}; {'id': '120', 'type': 'boolean_operator', 'children': ['121', '123'], 'value': 'or'}, {'id': '121', 'type': 'not_operator', 'children': ['122']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'logger_configuration_file'}, {'id': '123', 'type': 'not_operator', 'children': ['124']}; {'id': '124', 'type': 'call', 'children': ['125', '130']}, {'id': '125', 'type': 'attribute', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'logger_configuration_file'}; {'id': '132', 'type': 'block', 'children': ['133', '140']}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'call', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '136', 'type': 'argument_list', 'children': ['137']}, {'id': '137', 'type': 'binary_operator', 'children': ['138', '139'], 'value': '%'}; {'id': '138', 'type': 'string', 'children': [], 'value': '"The logger configuration file does not exist: %s"'}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'logger_configuration_file'}; {'id': '140', 'type': 'return_statement', 'children': []}, {'id': '141', 'type': 'with_statement', 'children': ['142', '152']}; {'id': '142', 'type': 'with_clause', 'children': ['143']}, {'id': '143', 'type': 'with_item', 'children': ['144']}; {'id': '144', 'type': 'as_pattern', 'children': ['145', '150']}, {'id': '145', 'type': 'call', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'open'}, {'id': '147', 'type': 'argument_list', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'logger_configuration_file'}, {'id': '149', 'type': 'string', 'children': [], 'value': "'rt'"}; {'id': '150', 'type': 'as_pattern_target', 'children': ['151']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': '_file'}; {'id': '152', 'type': 'block', 'children': ['153', '162', '166', '177', '185', '193', '232']}, {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'assignment', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '156', 'type': 'call', 'children': ['157', '160']}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'json'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'load'}; {'id': '160', 'type': 'argument_list', 'children': ['161']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': '_file'}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}, {'id': '163', 'type': 'assignment', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'truncate'}, {'id': '165', 'type': 'False', 'children': []}; {'id': '166', 'type': 'if_statement', 'children': ['167', '172']}, {'id': '167', 'type': 'boolean_operator', 'children': ['168', '170'], 'value': 'and'}; {'id': '168', 'type': 'not_operator', 'children': ['169']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'process_name'}; {'id': '170', 'type': 'not_operator', 'children': ['171']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'log_dir'}; {'id': '172', 'type': 'block', 'children': ['173']}, {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'assignment', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'truncate'}; {'id': '176', 'type': 'True', 'children': []}, {'id': '177', 'type': 'if_statement', 'children': ['178', '180']}; {'id': '178', 'type': 'not_operator', 'children': ['179']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'process_name'}; {'id': '180', 'type': 'block', 'children': ['181']}, {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'assignment', 'children': ['183', '184']}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'process_name'}; {'id': '184', 'type': 'string', 'children': [], 'value': "'alignak_tests'"}, {'id': '185', 'type': 'if_statement', 'children': ['186', '188']}; {'id': '186', 'type': 'not_operator', 'children': ['187']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'log_dir'}; {'id': '188', 'type': 'block', 'children': ['189']}, {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'assignment', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'log_dir'}; {'id': '192', 'type': 'string', 'children': [], 'value': "'/tmp'"}, {'id': '193', 'type': 'for_statement', 'children': ['194', '195', '198']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'formatter'}, {'id': '195', 'type': 'subscript', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '197', 'type': 'string', 'children': [], 'value': "'formatters'"}; {'id': '198', 'type': 'block', 'children': ['199', '209']}, {'id': '199', 'type': 'if_statement', 'children': ['200', '207']}; {'id': '200', 'type': 'comparison_operator', 'children': ['201', '202'], 'value': 'not'}, {'id': '201', 'type': 'string', 'children': [], 'value': "'format'"}; {'id': '202', 'type': 'subscript', 'children': ['203', '206']}, {'id': '203', 'type': 'subscript', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '205', 'type': 'string', 'children': [], 'value': "'formatters'"}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'formatter'}, {'id': '207', 'type': 'block', 'children': ['208']}; {'id': '208', 'type': 'continue_statement', 'children': []}, {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'assignment', 'children': ['211', '218', '219']}, {'id': '211', 'type': 'subscript', 'children': ['212', '217']}; {'id': '212', 'type': 'subscript', 'children': ['213', '216']}, {'id': '213', 'type': 'subscript', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '215', 'type': 'string', 'children': [], 'value': "'formatters'"}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'formatter'}, {'id': '217', 'type': 'string', 'children': [], 'value': "'format'"}; {'id': '218', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '219', 'type': 'call', 'children': ['220', '229']}; {'id': '220', 'type': 'attribute', 'children': ['221', '228']}, {'id': '221', 'type': 'subscript', 'children': ['222', '227']}; {'id': '222', 'type': 'subscript', 'children': ['223', '226']}, {'id': '223', 'type': 'subscript', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '225', 'type': 'string', 'children': [], 'value': "'formatters'"}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'formatter'}, {'id': '227', 'type': 'string', 'children': [], 'value': "'format'"}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'replace'}, {'id': '229', 'type': 'argument_list', 'children': ['230', '231']}; {'id': '230', 'type': 'string', 'children': [], 'value': '"%(daemon)s"'}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'process_name'}; {'id': '232', 'type': 'for_statement', 'children': ['233', '234', '237']}, {'id': '233', 'type': 'identifier', 'children': [], 'value': 'hdlr'}; {'id': '234', 'type': 'subscript', 'children': ['235', '236']}, {'id': '235', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '236', 'type': 'string', 'children': [], 'value': "'handlers'"}, {'id': '237', 'type': 'block', 'children': ['238', '248', '290', '313']}; {'id': '238', 'type': 'if_statement', 'children': ['239', '246']}, {'id': '239', 'type': 'comparison_operator', 'children': ['240', '241'], 'value': 'not'}; {'id': '240', 'type': 'string', 'children': [], 'value': "'filename'"}, {'id': '241', 'type': 'subscript', 'children': ['242', '245']}; {'id': '242', 'type': 'subscript', 'children': ['243', '244']}, {'id': '243', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '244', 'type': 'string', 'children': [], 'value': "'handlers'"}, {'id': '245', 'type': 'identifier', 'children': [], 'value': 'hdlr'}; {'id': '246', 'type': 'block', 'children': ['247']}, {'id': '247', 'type': 'continue_statement', 'children': []}; {'id': '248', 'type': 'if_statement', 'children': ['249', '254', '265']}, {'id': '249', 'type': 'boolean_operator', 'children': ['250', '251'], 'value': 'and'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'log_file'}, {'id': '251', 'type': 'comparison_operator', 'children': ['252', '253'], 'value': '=='}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'hdlr'}, {'id': '253', 'type': 'string', 'children': [], 'value': "'daemons'"}; {'id': '254', 'type': 'block', 'children': ['255']}, {'id': '255', 'type': 'expression_statement', 'children': ['256']}; {'id': '256', 'type': 'assignment', 'children': ['257', '264']}, {'id': '257', 'type': 'subscript', 'children': ['258', '263']}; {'id': '258', 'type': 'subscript', 'children': ['259', '262']}, {'id': '259', 'type': 'subscript', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '261', 'type': 'string', 'children': [], 'value': "'handlers'"}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'hdlr'}, {'id': '263', 'type': 'string', 'children': [], 'value': "'filename'"}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'log_file'}, {'id': '265', 'type': 'else_clause', 'children': ['266']}; {'id': '266', 'type': 'block', 'children': ['267']}, {'id': '267', 'type': 'expression_statement', 'children': ['268']}; {'id': '268', 'type': 'assignment', 'children': ['269', '276', '277']}, {'id': '269', 'type': 'subscript', 'children': ['270', '275']}; {'id': '270', 'type': 'subscript', 'children': ['271', '274']}, {'id': '271', 'type': 'subscript', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '273', 'type': 'string', 'children': [], 'value': "'handlers'"}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'hdlr'}, {'id': '275', 'type': 'string', 'children': [], 'value': "'filename'"}; {'id': '276', 'type': 'line_continuation', 'children': [], 'value': '\\'}, {'id': '277', 'type': 'call', 'children': ['278', '287']}; {'id': '278', 'type': 'attribute', 'children': ['279', '286']}, {'id': '279', 'type': 'subscript', 'children': ['280', '285']}; {'id': '280', 'type': 'subscript', 'children': ['281', '284']}, {'id': '281', 'type': 'subscript', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '283', 'type': 'string', 'children': [], 'value': "'handlers'"}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'hdlr'}, {'id': '285', 'type': 'string', 'children': [], 'value': "'filename'"}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'replace'}, {'id': '287', 'type': 'argument_list', 'children': ['288', '289']}; {'id': '288', 'type': 'string', 'children': [], 'value': '"%(logdir)s"'}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'log_dir'}; {'id': '290', 'type': 'expression_statement', 'children': ['291']}, {'id': '291', 'type': 'assignment', 'children': ['292', '299', '300']}; {'id': '292', 'type': 'subscript', 'children': ['293', '298']}, {'id': '293', 'type': 'subscript', 'children': ['294', '297']}; {'id': '294', 'type': 'subscript', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '296', 'type': 'string', 'children': [], 'value': "'handlers'"}, {'id': '297', 'type': 'identifier', 'children': [], 'value': 'hdlr'}; {'id': '298', 'type': 'string', 'children': [], 'value': "'filename'"}, {'id': '299', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '300', 'type': 'call', 'children': ['301', '310']}, {'id': '301', 'type': 'attribute', 'children': ['302', '309']}; {'id': '302', 'type': 'subscript', 'children': ['303', '308']}, {'id': '303', 'type': 'subscript', 'children': ['304', '307']}; {'id': '304', 'type': 'subscript', 'children': ['305', '306']}, {'id': '305', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '306', 'type': 'string', 'children': [], 'value': "'handlers'"}, {'id': '307', 'type': 'identifier', 'children': [], 'value': 'hdlr'}; {'id': '308', 'type': 'string', 'children': [], 'value': "'filename'"}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '310', 'type': 'argument_list', 'children': ['311', '312']}, {'id': '311', 'type': 'string', 'children': [], 'value': '"%(daemon)s"'}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'process_name'}, {'id': '313', 'type': 'if_statement', 'children': ['314', '330']}; {'id': '314', 'type': 'boolean_operator', 'children': ['315', '316'], 'value': 'and'}, {'id': '315', 'type': 'identifier', 'children': [], 'value': 'truncate'}; {'id': '316', 'type': 'call', 'children': ['317', '322']}, {'id': '317', 'type': 'attribute', 'children': ['318', '321']}; {'id': '318', 'type': 'attribute', 'children': ['319', '320']}, {'id': '319', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '321', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '322', 'type': 'argument_list', 'children': ['323']}, {'id': '323', 'type': 'subscript', 'children': ['324', '329']}; {'id': '324', 'type': 'subscript', 'children': ['325', '328']}, {'id': '325', 'type': 'subscript', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'config'}, {'id': '327', 'type': 'string', 'children': [], 'value': "'handlers'"}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'hdlr'}, {'id': '329', 'type': 'string', 'children': [], 'value': "'filename'"}; {'id': '330', 'type': 'block', 'children': ['331']}, {'id': '331', 'type': 'with_statement', 'children': ['332', '348']}; {'id': '332', 'type': 'with_clause', 'children': ['333']}, {'id': '333', 'type': 'with_item', 'children': ['334']}; {'id': '334', 'type': 'as_pattern', 'children': ['335', '346']}, {'id': '335', 'type': 'call', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'open'}, {'id': '337', 'type': 'argument_list', 'children': ['338', '345']}; {'id': '338', 'type': 'subscript', 'children': ['339', '344']}, {'id': '339', 'type': 'subscript', 'children': ['340', '343']}; {'id': '340', 'type': 'subscript', 'children': ['341', '342']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'config'}; {'id': '342', 'type': 'string', 'children': [], 'value': "'handlers'"}, {'id': '343', 'type': 'identifier', 'children': [], 'value': 'hdlr'}; {'id': '344', 'type': 'string', 'children': [], 'value': "'filename'"}, {'id': '345', 'type': 'string', 'children': [], 'value': '"w"'}; {'id': '346', 'type': 'as_pattern_target', 'children': ['347']}, {'id': '347', 'type': 'identifier', 'children': [], 'value': 'file_log_file'}; {'id': '348', 'type': 'block', 'children': ['349']}, {'id': '349', 'type': 'expression_statement', 'children': ['350']}; {'id': '350', 'type': 'call', 'children': ['351', '354']}, {'id': '351', 'type': 'attribute', 'children': ['352', '353']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'file_log_file'}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'truncate'}; {'id': '354', 'type': 'argument_list', 'children': []}, {'id': '355', 'type': 'expression_statement', 'children': ['356']}; {'id': '356', 'type': 'call', 'children': ['357', '358']}, {'id': '357', 'type': 'identifier', 'children': [], 'value': 'logger_dictConfig'}; {'id': '358', 'type': 'argument_list', 'children': ['359']}, {'id': '359', 'type': 'identifier', 'children': [], 'value': 'config'} | def setup_logger(logger_configuration_file, log_dir=None, process_name='', log_file=''):
logger_ = logging.getLogger(ALIGNAK_LOGGER_NAME)
for handler in logger_.handlers:
if not process_name:
break
if getattr(handler, '_name', None) == 'daemons':
for hdlr in logger_.handlers:
if 'alignak_tests' in hdlr.formatter._fmt:
formatter = logging.Formatter(hdlr.formatter._fmt.replace("alignak_tests",
process_name))
hdlr.setFormatter(formatter)
if getattr(hdlr, 'filename', None) and 'alignak_tests' in hdlr.filename:
hdlr.filename = hdlr.filename._fmt.replace("alignak_tests", process_name)
break
else:
if not logger_configuration_file or not os.path.exists(logger_configuration_file):
print("The logger configuration file does not exist: %s" % logger_configuration_file)
return
with open(logger_configuration_file, 'rt') as _file:
config = json.load(_file)
truncate = False
if not process_name and not log_dir:
truncate = True
if not process_name:
process_name = 'alignak_tests'
if not log_dir:
log_dir = '/tmp'
for formatter in config['formatters']:
if 'format' not in config['formatters'][formatter]:
continue
config['formatters'][formatter]['format'] = \
config['formatters'][formatter]['format'].replace("%(daemon)s", process_name)
for hdlr in config['handlers']:
if 'filename' not in config['handlers'][hdlr]:
continue
if log_file and hdlr == 'daemons':
config['handlers'][hdlr]['filename'] = log_file
else:
config['handlers'][hdlr]['filename'] = \
config['handlers'][hdlr]['filename'].replace("%(logdir)s", log_dir)
config['handlers'][hdlr]['filename'] = \
config['handlers'][hdlr]['filename'].replace("%(daemon)s", process_name)
if truncate and os.path.exists(config['handlers'][hdlr]['filename']):
with open(config['handlers'][hdlr]['filename'], "w") as file_log_file:
file_log_file.truncate()
logger_dictConfig(config) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'want_service_notification'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'notifways'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'timeperiods'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'state'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'n_type'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'business_impact'}, {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '23', '50', '56', '87']}, {'id': '15', 'type': 'if_statement', 'children': ['16', '20']}; {'id': '16', 'type': 'not_operator', 'children': ['17']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'service_notifications_enabled'}; {'id': '20', 'type': 'block', 'children': ['21']}, {'id': '21', 'type': 'return_statement', 'children': ['22']}; {'id': '22', 'type': 'False', 'children': []}, {'id': '23', 'type': 'for_statement', 'children': ['24', '25', '28']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'downtime_id'}, {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'downtimes'}; {'id': '28', 'type': 'block', 'children': ['29', '37']}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'downtime'}; {'id': '32', 'type': 'subscript', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'downtimes'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'downtime_id'}, {'id': '37', 'type': 'if_statement', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'downtime'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'is_in_effect'}, {'id': '41', 'type': 'block', 'children': ['42', '48']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'in_scheduled_downtime'}, {'id': '47', 'type': 'True', 'children': []}; {'id': '48', 'type': 'return_statement', 'children': ['49']}, {'id': '49', 'type': 'False', 'children': []}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}, {'id': '51', 'type': 'assignment', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'in_scheduled_downtime'}, {'id': '55', 'type': 'False', 'children': []}; {'id': '56', 'type': 'for_statement', 'children': ['57', '58', '61']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'notifway_id'}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'notificationways'}, {'id': '61', 'type': 'block', 'children': ['62', '68', '82']}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}, {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'notifway'}, {'id': '65', 'type': 'subscript', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'notifways'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'notifway_id'}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}, {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'nw_b'}, {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'notifway'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'want_service_notification'}, {'id': '75', 'type': 'argument_list', 'children': ['76', '77', '78', '79', '80', '81']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'timeperiods'}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'timestamp'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'state'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'n_type'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'business_impact'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '82', 'type': 'if_statement', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'nw_b'}; {'id': '84', 'type': 'block', 'children': ['85']}, {'id': '85', 'type': 'return_statement', 'children': ['86']}; {'id': '86', 'type': 'True', 'children': []}, {'id': '87', 'type': 'return_statement', 'children': ['88']} | def want_service_notification(self, notifways, timeperiods,
timestamp, state, n_type, business_impact, cmd=None):
if not self.service_notifications_enabled:
return False
for downtime_id in self.downtimes:
downtime = self.downtimes[downtime_id]
if downtime.is_in_effect:
self.in_scheduled_downtime = True
return False
self.in_scheduled_downtime = False
for notifway_id in self.notificationways:
notifway = notifways[notifway_id]
nw_b = notifway.want_service_notification(timeperiods, timestamp,
state, n_type, business_impact, cmd)
if nw_b:
return True
return False |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'explode'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'contactgroups'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'notificationways'}, {'id': '7', 'type': 'block', 'children': ['8', '15', '34', '74']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}, {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'apply_partial_inheritance'}, {'id': '13', 'type': 'argument_list', 'children': ['14']}; {'id': '14', 'type': 'string', 'children': [], 'value': "'contactgroups'"}, {'id': '15', 'type': 'for_statement', 'children': ['16', '17', '20']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'prop'}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'Contact'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'special_properties'}; {'id': '20', 'type': 'block', 'children': ['21', '27']}, {'id': '21', 'type': 'if_statement', 'children': ['22', '25']}; {'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': '=='}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '24', 'type': 'string', 'children': [], 'value': "'contact_name'"}, {'id': '25', 'type': 'block', 'children': ['26']}; {'id': '26', 'type': 'continue_statement', 'children': []}, {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'apply_partial_inheritance'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'prop'}; {'id': '34', 'type': 'for_statement', 'children': ['35', '36', '37']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'contact'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '37', 'type': 'block', 'children': ['38', '54']}; {'id': '38', 'type': 'if_statement', 'children': ['39', '52']}, {'id': '39', 'type': 'not_operator', 'children': ['40']}; {'id': '40', 'type': 'parenthesized_expression', 'children': ['41']}, {'id': '41', 'type': 'boolean_operator', 'children': ['42', '47'], 'value': 'and'}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'contact'}; {'id': '46', 'type': 'string', 'children': [], 'value': "'contact_name'"}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '49', 'type': 'argument_list', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'contact'}, {'id': '51', 'type': 'string', 'children': [], 'value': "'contactgroups'"}; {'id': '52', 'type': 'block', 'children': ['53']}, {'id': '53', 'type': 'continue_statement', 'children': []}; {'id': '54', 'type': 'for_statement', 'children': ['55', '56', '59']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'contactgroup'}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'contact'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'contactgroups'}, {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}, {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'contactgroups'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'add_member'}, {'id': '65', 'type': 'argument_list', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'contact'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'contact_name'}, {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'contactgroup'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '73', 'type': 'argument_list', 'children': []}; {'id': '74', 'type': 'for_statement', 'children': ['75', '76', '77']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'contact'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '77', 'type': 'block', 'children': ['78', '82', '86', '135']}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}, {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'need_notificationway'}, {'id': '81', 'type': 'False', 'children': []}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '85', 'type': 'dictionary', 'children': []}; {'id': '86', 'type': 'for_statement', 'children': ['87', '88', '91']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'Contact'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'simple_way_parameters'}, {'id': '91', 'type': 'block', 'children': ['92']}; {'id': '92', 'type': 'if_statement', 'children': ['93', '98', '113']}, {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'hasattr'}, {'id': '95', 'type': 'argument_list', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'contact'}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '98', 'type': 'block', 'children': ['99', '103']}, {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'assignment', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'need_notificationway'}; {'id': '102', 'type': 'True', 'children': []}, {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '108']}, {'id': '105', 'type': 'subscript', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'params'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '108', 'type': 'call', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '110', 'type': 'argument_list', 'children': ['111', '112']}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'contact'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'param'}, {'id': '113', 'type': 'elif_clause', 'children': ['114', '121']}; {'id': '114', 'type': 'attribute', 'children': ['115', '120']}, {'id': '115', 'type': 'subscript', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'contact'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'properties'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'has_default'}, {'id': '121', 'type': 'block', 'children': ['122']}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'call', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'setattr'}, {'id': '125', 'type': 'argument_list', 'children': ['126', '127', '128']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'contact'}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '128', 'type': 'attribute', 'children': ['129', '134']}, {'id': '129', 'type': 'subscript', 'children': ['130', '133']}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'contact'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'properties'}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'param'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'default'}, {'id': '135', 'type': 'if_statement', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'need_notificationway'}, {'id': '137', 'type': 'block', 'children': ['138', '152', '158', '166']}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}, {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'cname'}, {'id': '141', 'type': 'call', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'getattr'}, {'id': '143', 'type': 'argument_list', 'children': ['144', '145', '146']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'contact'}, {'id': '145', 'type': 'string', 'children': [], 'value': "'contact_name'"}; {'id': '146', 'type': 'call', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '148', 'type': 'argument_list', 'children': ['149', '150', '151']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'contact'}; {'id': '150', 'type': 'string', 'children': [], 'value': "'alias'"}, {'id': '151', 'type': 'string', 'children': [], 'value': "''"}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}, {'id': '153', 'type': 'assignment', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'nw_name'}, {'id': '155', 'type': 'binary_operator', 'children': ['156', '157'], 'value': '+'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'cname'}, {'id': '157', 'type': 'string', 'children': [], 'value': "'_inner_nw'"}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}, {'id': '159', 'type': 'call', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'notificationways'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'new_inner_member'}, {'id': '163', 'type': 'argument_list', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'nw_name'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '166', 'type': 'if_statement', 'children': ['167', '173', '181']}, {'id': '167', 'type': 'not_operator', 'children': ['168']}; {'id': '168', 'type': 'call', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '170', 'type': 'argument_list', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'contact'}; {'id': '172', 'type': 'string', 'children': [], 'value': "'notificationways'"}, {'id': '173', 'type': 'block', 'children': ['174']}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}, {'id': '175', 'type': 'assignment', 'children': ['176', '179']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}, {'id': '177', 'type': 'identifier', 'children': [], 'value': 'contact'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'notificationways'}, {'id': '179', 'type': 'list', 'children': ['180'], 'value': '[nw_name]'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'nw_name'}, {'id': '181', 'type': 'else_clause', 'children': ['182']}; {'id': '182', 'type': 'block', 'children': ['183', '194']}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '188']}, {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'contact'}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'notificationways'}; {'id': '188', 'type': 'call', 'children': ['189', '190']}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}, {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'contact'}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'notificationways'}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}, {'id': '195', 'type': 'call', 'children': ['196', '201']}; {'id': '196', 'type': 'attribute', 'children': ['197', '200']}, {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'contact'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'notificationways'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '201', 'type': 'argument_list', 'children': ['202']} | def explode(self, contactgroups, notificationways):
self.apply_partial_inheritance('contactgroups')
for prop in Contact.special_properties:
if prop == 'contact_name':
continue
self.apply_partial_inheritance(prop)
for contact in self:
if not (hasattr(contact, 'contact_name') and hasattr(contact, 'contactgroups')):
continue
for contactgroup in contact.contactgroups:
contactgroups.add_member(contact.contact_name, contactgroup.strip())
for contact in self:
need_notificationway = False
params = {}
for param in Contact.simple_way_parameters:
if hasattr(contact, param):
need_notificationway = True
params[param] = getattr(contact, param)
elif contact.properties[param].has_default:
setattr(contact, param, contact.properties[param].default)
if need_notificationway:
cname = getattr(contact, 'contact_name', getattr(contact, 'alias', ''))
nw_name = cname + '_inner_nw'
notificationways.new_inner_member(nw_name, params)
if not hasattr(contact, 'notificationways'):
contact.notificationways = [nw_name]
else:
contact.notificationways = list(contact.notificationways)
contact.notificationways.append(nw_name) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'receive'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'arg_formats'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '14', '18', '22', '26', '155', '174', '216', '229', '243', '287', '291', '336', '350', '386', '390', '419', '427']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '12', 'type': 'list', 'children': ['13'], 'value': '[[]]'}, {'id': '13', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}, {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'raw_msg'}, {'id': '17', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}, {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'escaped'}, {'id': '21', 'type': 'False', 'children': []}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}, {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'command_sep_found'}, {'id': '25', 'type': 'False', 'children': []}; {'id': '26', 'type': 'while_statement', 'children': ['27', '28']}, {'id': '27', 'type': 'True', 'children': []}; {'id': '28', 'type': 'block', 'children': ['29', '39', '46']}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '32', 'type': 'call', 'children': ['33', '38']}, {'id': '33', 'type': 'attribute', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'board'}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '38', 'type': 'argument_list', 'children': []}, {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'raw_msg'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '46', 'type': 'if_statement', 'children': ['47', '48', '98']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'escaped'}; {'id': '48', 'type': 'block', 'children': ['49']}, {'id': '49', 'type': 'if_statement', 'children': ['50', '55', '70']}; {'id': '50', 'type': 'comparison_operator', 'children': ['51', '52'], 'value': 'in'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': '_escaped_characters'}, {'id': '55', 'type': 'block', 'children': ['56', '66']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}, {'id': '57', 'type': 'call', 'children': ['58', '64']}; {'id': '58', 'type': 'attribute', 'children': ['59', '63']}, {'id': '59', 'type': 'subscript', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '61', 'type': 'unary_operator', 'children': ['62'], 'value': '-'}; {'id': '62', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}, {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'escaped'}, {'id': '69', 'type': 'False', 'children': []}; {'id': '70', 'type': 'else_clause', 'children': ['71']}, {'id': '71', 'type': 'block', 'children': ['72', '84', '94']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'call', 'children': ['74', '80']}; {'id': '74', 'type': 'attribute', 'children': ['75', '79']}, {'id': '75', 'type': 'subscript', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '77', 'type': 'unary_operator', 'children': ['78'], 'value': '-'}; {'id': '78', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': '_byte_escape_sep'}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}, {'id': '85', 'type': 'call', 'children': ['86', '92']}; {'id': '86', 'type': 'attribute', 'children': ['87', '91']}, {'id': '87', 'type': 'subscript', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '89', 'type': 'unary_operator', 'children': ['90'], 'value': '-'}; {'id': '90', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}, {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'escaped'}, {'id': '97', 'type': 'False', 'children': []}; {'id': '98', 'type': 'else_clause', 'children': ['99']}, {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'if_statement', 'children': ['101', '106', '111', '125', '137', '143']}, {'id': '101', 'type': 'comparison_operator', 'children': ['102', '103'], 'value': '=='}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': '_byte_escape_sep'}; {'id': '106', 'type': 'block', 'children': ['107']}, {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '110']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'escaped'}; {'id': '110', 'type': 'True', 'children': []}, {'id': '111', 'type': 'elif_clause', 'children': ['112', '117']}; {'id': '112', 'type': 'comparison_operator', 'children': ['113', '114'], 'value': '=='}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}, {'id': '115', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': '_byte_field_sep'}, {'id': '117', 'type': 'block', 'children': ['118']}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}, {'id': '119', 'type': 'call', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '125', 'type': 'elif_clause', 'children': ['126', '131']}; {'id': '126', 'type': 'comparison_operator', 'children': ['127', '128'], 'value': '=='}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': '_byte_command_sep'}, {'id': '131', 'type': 'block', 'children': ['132', '136']}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}, {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'command_sep_found'}, {'id': '135', 'type': 'True', 'children': []}; {'id': '136', 'type': 'break_statement', 'children': []}, {'id': '137', 'type': 'elif_clause', 'children': ['138', '141']}; {'id': '138', 'type': 'comparison_operator', 'children': ['139', '140'], 'value': '=='}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'tmp'}; {'id': '140', 'type': 'string', 'children': [], 'value': "b''"}, {'id': '141', 'type': 'block', 'children': ['142']}; {'id': '142', 'type': 'break_statement', 'children': []}, {'id': '143', 'type': 'else_clause', 'children': ['144']}; {'id': '144', 'type': 'block', 'children': ['145']}, {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'call', 'children': ['147', '153']}, {'id': '147', 'type': 'attribute', 'children': ['148', '152']}; {'id': '148', 'type': 'subscript', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '150', 'type': 'unary_operator', 'children': ['151'], 'value': '-'}, {'id': '151', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'tmp'}, {'id': '155', 'type': 'if_statement', 'children': ['156', '171']}; {'id': '156', 'type': 'boolean_operator', 'children': ['157', '163'], 'value': 'and'}, {'id': '157', 'type': 'comparison_operator', 'children': ['158', '162'], 'value': '=='}; {'id': '158', 'type': 'call', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '160', 'type': 'argument_list', 'children': ['161']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '162', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '163', 'type': 'comparison_operator', 'children': ['164', '170'], 'value': '=='}; {'id': '164', 'type': 'call', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}, {'id': '167', 'type': 'subscript', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '169', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '170', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '171', 'type': 'block', 'children': ['172']}; {'id': '172', 'type': 'return_statement', 'children': ['173']}, {'id': '173', 'type': 'None', 'children': []}; {'id': '174', 'type': 'if_statement', 'children': ['175', '177']}, {'id': '175', 'type': 'not_operator', 'children': ['176']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'command_sep_found'}, {'id': '177', 'type': 'block', 'children': ['178', '187', '198', '211']}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}, {'id': '179', 'type': 'assignment', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'joined_raw'}, {'id': '181', 'type': 'call', 'children': ['182', '185']}; {'id': '182', 'type': 'attribute', 'children': ['183', '184']}, {'id': '183', 'type': 'string', 'children': [], 'value': "b''"}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'join'}, {'id': '185', 'type': 'argument_list', 'children': ['186']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'raw_msg'}, {'id': '187', 'type': 'if_statement', 'children': ['188', '195']}; {'id': '188', 'type': 'comparison_operator', 'children': ['189', '194'], 'value': '=='}, {'id': '189', 'type': 'call', 'children': ['190', '193']}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'joined_raw'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '193', 'type': 'argument_list', 'children': []}; {'id': '194', 'type': 'string', 'children': [], 'value': "b''"}, {'id': '195', 'type': 'block', 'children': ['196']}; {'id': '196', 'type': 'return_statement', 'children': ['197']}, {'id': '197', 'type': 'None', 'children': []}; {'id': '198', 'type': 'expression_statement', 'children': ['199']}, {'id': '199', 'type': 'assignment', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'err'}, {'id': '201', 'type': 'call', 'children': ['202', '205']}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}, {'id': '203', 'type': 'string', 'children': [], 'value': '"Incomplete message ({})"'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '205', 'type': 'argument_list', 'children': ['206']}; {'id': '206', 'type': 'call', 'children': ['207', '210']}, {'id': '207', 'type': 'attribute', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'joined_raw'}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '210', 'type': 'argument_list', 'children': []}, {'id': '211', 'type': 'raise_statement', 'children': ['212']}; {'id': '212', 'type': 'call', 'children': ['213', '214']}, {'id': '213', 'type': 'identifier', 'children': [], 'value': 'EOFError'}; {'id': '214', 'type': 'argument_list', 'children': ['215']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}, {'id': '217', 'type': 'assignment', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '219', 'type': 'list_comprehension', 'children': ['220', '226']}; {'id': '220', 'type': 'call', 'children': ['221', '224']}, {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'string', 'children': [], 'value': "b''"}, {'id': '223', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '224', 'type': 'argument_list', 'children': ['225']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '226', 'type': 'for_in_clause', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'msg'}, {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'assignment', 'children': ['231', '232']}, {'id': '231', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '232', 'type': 'call', 'children': ['233', '242']}, {'id': '233', 'type': 'attribute', 'children': ['234', '241']}; {'id': '234', 'type': 'call', 'children': ['235', '240']}, {'id': '235', 'type': 'attribute', 'children': ['236', '239']}; {'id': '236', 'type': 'subscript', 'children': ['237', '238']}, {'id': '237', 'type': 'identifier', 'children': [], 'value': 'fields'}; {'id': '238', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '239', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '240', 'type': 'argument_list', 'children': []}, {'id': '241', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '242', 'type': 'argument_list', 'children': []}, {'id': '243', 'type': 'try_statement', 'children': ['244', '256']}; {'id': '244', 'type': 'block', 'children': ['245']}, {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'assignment', 'children': ['247', '248']}, {'id': '247', 'type': 'identifier', 'children': [], 'value': 'cmd_name'}; {'id': '248', 'type': 'subscript', 'children': ['249', '252']}, {'id': '249', 'type': 'attribute', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '251', 'type': 'identifier', 'children': [], 'value': '_int_to_cmd_name'}; {'id': '252', 'type': 'call', 'children': ['253', '254']}, {'id': '253', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '254', 'type': 'argument_list', 'children': ['255']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'cmd'}; {'id': '256', 'type': 'except_clause', 'children': ['257', '260']}, {'id': '257', 'type': 'tuple', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'IndexError'}; {'id': '260', 'type': 'block', 'children': ['261']}, {'id': '261', 'type': 'if_statement', 'children': ['262', '265']}; {'id': '262', 'type': 'attribute', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'give_warnings'}, {'id': '265', 'type': 'block', 'children': ['266', '270', '279']}; {'id': '266', 'type': 'expression_statement', 'children': ['267']}, {'id': '267', 'type': 'assignment', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'cmd_name'}, {'id': '269', 'type': 'string', 'children': [], 'value': '"unknown"'}; {'id': '270', 'type': 'expression_statement', 'children': ['271']}, {'id': '271', 'type': 'assignment', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'w'}, {'id': '273', 'type': 'call', 'children': ['274', '277']}; {'id': '274', 'type': 'attribute', 'children': ['275', '276']}, {'id': '275', 'type': 'string', 'children': [], 'value': '"Recieved unrecognized command ({})."'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '277', 'type': 'argument_list', 'children': ['278']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'cmd'}, {'id': '279', 'type': 'expression_statement', 'children': ['280']}; {'id': '280', 'type': 'call', 'children': ['281', '284']}, {'id': '281', 'type': 'attribute', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'warnings'}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '284', 'type': 'argument_list', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'Warning'}, {'id': '287', 'type': 'expression_statement', 'children': ['288']}; {'id': '288', 'type': 'assignment', 'children': ['289', '290']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'arg_format_list'}; {'id': '290', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '291', 'type': 'if_statement', 'children': ['292', '295', '303']}; {'id': '292', 'type': 'comparison_operator', 'children': ['293', '294'], 'value': '!='}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'arg_formats'}; {'id': '294', 'type': 'None', 'children': []}, {'id': '295', 'type': 'block', 'children': ['296']}; {'id': '296', 'type': 'expression_statement', 'children': ['297']}, {'id': '297', 'type': 'assignment', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'arg_format_list'}, {'id': '299', 'type': 'call', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '301', 'type': 'argument_list', 'children': ['302']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'arg_formats'}, {'id': '303', 'type': 'else_clause', 'children': ['304']}; {'id': '304', 'type': 'block', 'children': ['305']}, {'id': '305', 'type': 'try_statement', 'children': ['306', '315']}; {'id': '306', 'type': 'block', 'children': ['307']}, {'id': '307', 'type': 'expression_statement', 'children': ['308']}; {'id': '308', 'type': 'assignment', 'children': ['309', '310']}, {'id': '309', 'type': 'identifier', 'children': [], 'value': 'arg_format_list'}; {'id': '310', 'type': 'subscript', 'children': ['311', '314']}, {'id': '311', 'type': 'attribute', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '313', 'type': 'identifier', 'children': [], 'value': '_cmd_name_to_format'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'cmd_name'}, {'id': '315', 'type': 'except_clause', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'KeyError'}, {'id': '317', 'type': 'block', 'children': ['318']}; {'id': '318', 'type': 'expression_statement', 'children': ['319']}, {'id': '319', 'type': 'assignment', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'arg_format_list'}, {'id': '321', 'type': 'list_comprehension', 'children': ['322', '323']}; {'id': '322', 'type': 'string', 'children': [], 'value': '"g"'}, {'id': '323', 'type': 'for_in_clause', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '325', 'type': 'call', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '327', 'type': 'argument_list', 'children': ['328']}; {'id': '328', 'type': 'call', 'children': ['329', '330']}, {'id': '329', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '330', 'type': 'argument_list', 'children': ['331']}, {'id': '331', 'type': 'subscript', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '333', 'type': 'slice', 'children': ['334', '335']}; {'id': '334', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '335', 'type': 'colon', 'children': []}; {'id': '336', 'type': 'expression_statement', 'children': ['337']}, {'id': '337', 'type': 'assignment', 'children': ['338', '339']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'arg_format_list'}, {'id': '339', 'type': 'call', 'children': ['340', '343']}; {'id': '340', 'type': 'attribute', 'children': ['341', '342']}, {'id': '341', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '342', 'type': 'identifier', 'children': [], 'value': '_treat_star_format'}, {'id': '343', 'type': 'argument_list', 'children': ['344', '345']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'arg_format_list'}, {'id': '345', 'type': 'subscript', 'children': ['346', '347']}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '347', 'type': 'slice', 'children': ['348', '349']}; {'id': '348', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '349', 'type': 'colon', 'children': []}; {'id': '350', 'type': 'if_statement', 'children': ['351', '361']}, {'id': '351', 'type': 'comparison_operator', 'children': ['352', '360'], 'value': '>'}; {'id': '352', 'type': 'call', 'children': ['353', '354']}, {'id': '353', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '354', 'type': 'argument_list', 'children': ['355']}, {'id': '355', 'type': 'subscript', 'children': ['356', '357']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '357', 'type': 'slice', 'children': ['358', '359']}; {'id': '358', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '359', 'type': 'colon', 'children': []}; {'id': '360', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '361', 'type': 'block', 'children': ['362']}; {'id': '362', 'type': 'if_statement', 'children': ['363', '376']}, {'id': '363', 'type': 'comparison_operator', 'children': ['364', '368'], 'value': '!='}; {'id': '364', 'type': 'call', 'children': ['365', '366']}, {'id': '365', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '366', 'type': 'argument_list', 'children': ['367']}, {'id': '367', 'type': 'identifier', 'children': [], 'value': 'arg_format_list'}; {'id': '368', 'type': 'call', 'children': ['369', '370']}, {'id': '369', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '370', 'type': 'argument_list', 'children': ['371']}, {'id': '371', 'type': 'subscript', 'children': ['372', '373']}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '373', 'type': 'slice', 'children': ['374', '375']}; {'id': '374', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '375', 'type': 'colon', 'children': []}; {'id': '376', 'type': 'block', 'children': ['377', '381']}, {'id': '377', 'type': 'expression_statement', 'children': ['378']}; {'id': '378', 'type': 'assignment', 'children': ['379', '380']}, {'id': '379', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '380', 'type': 'string', 'children': [], 'value': '"Number of argument formats must match the number of recieved arguments."'}, {'id': '381', 'type': 'raise_statement', 'children': ['382']}; {'id': '382', 'type': 'call', 'children': ['383', '384']}, {'id': '383', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '384', 'type': 'argument_list', 'children': ['385']}, {'id': '385', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '386', 'type': 'expression_statement', 'children': ['387']}, {'id': '387', 'type': 'assignment', 'children': ['388', '389']}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'received'}, {'id': '389', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '390', 'type': 'for_statement', 'children': ['391', '394', '402']}, {'id': '391', 'type': 'pattern_list', 'children': ['392', '393']}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '393', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '394', 'type': 'call', 'children': ['395', '396']}, {'id': '395', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '396', 'type': 'argument_list', 'children': ['397']}, {'id': '397', 'type': 'subscript', 'children': ['398', '399']}; {'id': '398', 'type': 'identifier', 'children': [], 'value': 'fields'}, {'id': '399', 'type': 'slice', 'children': ['400', '401']}; {'id': '400', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '401', 'type': 'colon', 'children': []}; {'id': '402', 'type': 'block', 'children': ['403']}, {'id': '403', 'type': 'expression_statement', 'children': ['404']}; {'id': '404', 'type': 'call', 'children': ['405', '408']}, {'id': '405', 'type': 'attribute', 'children': ['406', '407']}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'received'}, {'id': '407', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '408', 'type': 'argument_list', 'children': ['409']}, {'id': '409', 'type': 'call', 'children': ['410', '417']}; {'id': '410', 'type': 'subscript', 'children': ['411', '414']}, {'id': '411', 'type': 'attribute', 'children': ['412', '413']}; {'id': '412', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '413', 'type': 'identifier', 'children': [], 'value': '_recv_methods'}; {'id': '414', 'type': 'subscript', 'children': ['415', '416']}, {'id': '415', 'type': 'identifier', 'children': [], 'value': 'arg_format_list'}; {'id': '416', 'type': 'identifier', 'children': [], 'value': 'i'}, {'id': '417', 'type': 'argument_list', 'children': ['418']}; {'id': '418', 'type': 'identifier', 'children': [], 'value': 'f'}, {'id': '419', 'type': 'expression_statement', 'children': ['420']}; {'id': '420', 'type': 'assignment', 'children': ['421', '422']}, {'id': '421', 'type': 'identifier', 'children': [], 'value': 'message_time'}; {'id': '422', 'type': 'call', 'children': ['423', '426']}, {'id': '423', 'type': 'attribute', 'children': ['424', '425']}; {'id': '424', 'type': 'identifier', 'children': [], 'value': 'time'}, {'id': '425', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '426', 'type': 'argument_list', 'children': []}, {'id': '427', 'type': 'return_statement', 'children': ['428']}; {'id': '428', 'type': 'expression_list', 'children': ['429', '430', '431']}, {'id': '429', 'type': 'identifier', 'children': [], 'value': 'cmd_name'}; {'id': '430', 'type': 'identifier', 'children': [], 'value': 'received'}, {'id': '431', 'type': 'identifier', 'children': [], 'value': 'message_time'} | def receive(self,arg_formats=None):
msg = [[]]
raw_msg = []
escaped = False
command_sep_found = False
while True:
tmp = self.board.read()
raw_msg.append(tmp)
if escaped:
if tmp in self._escaped_characters:
msg[-1].append(tmp)
escaped = False
else:
msg[-1].append(self._byte_escape_sep)
msg[-1].append(tmp)
escaped = False
else:
if tmp == self._byte_escape_sep:
escaped = True
elif tmp == self._byte_field_sep:
msg.append([])
elif tmp == self._byte_command_sep:
command_sep_found = True
break
elif tmp == b'':
break
else:
msg[-1].append(tmp)
if len(msg) == 1 and len(msg[0]) == 0:
return None
if not command_sep_found:
joined_raw = b''.join(raw_msg)
if joined_raw.strip() == b'':
return None
err = "Incomplete message ({})".format(joined_raw.decode())
raise EOFError(err)
fields = [b''.join(m) for m in msg]
cmd = fields[0].strip().decode()
try:
cmd_name = self._int_to_cmd_name[int(cmd)]
except (ValueError,IndexError):
if self.give_warnings:
cmd_name = "unknown"
w = "Recieved unrecognized command ({}).".format(cmd)
warnings.warn(w,Warning)
arg_format_list = []
if arg_formats != None:
arg_format_list = list(arg_formats)
else:
try:
arg_format_list = self._cmd_name_to_format[cmd_name]
except KeyError:
arg_format_list = ["g" for i in range(len(fields[1:]))]
arg_format_list = self._treat_star_format(arg_format_list,fields[1:])
if len(fields[1:]) > 0:
if len(arg_format_list) != len(fields[1:]):
err = "Number of argument formats must match the number of recieved arguments."
raise ValueError(err)
received = []
for i, f in enumerate(fields[1:]):
received.append(self._recv_methods[arg_format_list[i]](f))
message_time = time.time()
return cmd_name, received, message_time |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'update_share'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'share_id'}; {'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '8', 'type': 'block', 'children': ['9', '19', '29', '39', '58', '72', '82', '86', '95', '110', '136', '157', '166']}, {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'perms'}; {'id': '12', 'type': 'call', 'children': ['13', '16']}, {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18']}, {'id': '17', 'type': 'string', 'children': [], 'value': "'perms'"}; {'id': '18', 'type': 'None', 'children': []}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'password'}; {'id': '22', 'type': 'call', 'children': ['23', '26']}, {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '28']}, {'id': '27', 'type': 'string', 'children': [], 'value': "'password'"}; {'id': '28', 'type': 'None', 'children': []}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'public_upload'}; {'id': '32', 'type': 'call', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '38']}, {'id': '37', 'type': 'string', 'children': [], 'value': "'public_upload'"}; {'id': '38', 'type': 'None', 'children': []}, {'id': '39', 'type': 'if_statement', 'children': ['40', '53']}; {'id': '40', 'type': 'boolean_operator', 'children': ['41', '47'], 'value': 'and'}, {'id': '41', 'type': 'parenthesized_expression', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '44']}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '44', 'type': 'argument_list', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'perms'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '47', 'type': 'parenthesized_expression', 'children': ['48']}; {'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': '>'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'perms'}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'OCS_PERMISSION_ALL'}, {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}, {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'perms'}, {'id': '57', 'type': 'None', 'children': []}; {'id': '58', 'type': 'if_statement', 'children': ['59', '69']}, {'id': '59', 'type': 'not_operator', 'children': ['60']}; {'id': '60', 'type': 'parenthesized_expression', 'children': ['61']}, {'id': '61', 'type': 'boolean_operator', 'children': ['62', '65'], 'value': 'or'}; {'id': '62', 'type': 'boolean_operator', 'children': ['63', '64'], 'value': 'or'}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'perms'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'password'}, {'id': '65', 'type': 'parenthesized_expression', 'children': ['66']}; {'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': 'is'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'public_upload'}; {'id': '68', 'type': 'None', 'children': []}, {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'return_statement', 'children': ['71']}, {'id': '71', 'type': 'False', 'children': []}; {'id': '72', 'type': 'if_statement', 'children': ['73', '79']}, {'id': '73', 'type': 'not_operator', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '76', 'type': 'argument_list', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'share_id'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'int'}, {'id': '79', 'type': 'block', 'children': ['80']}; {'id': '80', 'type': 'return_statement', 'children': ['81']}, {'id': '81', 'type': 'False', 'children': []}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}, {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '85', 'type': 'dictionary', 'children': []}; {'id': '86', 'type': 'if_statement', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'perms'}; {'id': '88', 'type': 'block', 'children': ['89']}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '94']}, {'id': '91', 'type': 'subscript', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '93', 'type': 'string', 'children': [], 'value': "'permissions'"}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'perms'}, {'id': '95', 'type': 'if_statement', 'children': ['96', '103']}; {'id': '96', 'type': 'call', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '98', 'type': 'argument_list', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'password'}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}, {'id': '101', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'string_types'}, {'id': '103', 'type': 'block', 'children': ['104']}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '109']}; {'id': '106', 'type': 'subscript', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '108', 'type': 'string', 'children': [], 'value': "'password'"}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'password'}; {'id': '110', 'type': 'if_statement', 'children': ['111', '122']}, {'id': '111', 'type': 'boolean_operator', 'children': ['112', '116'], 'value': 'and'}; {'id': '112', 'type': 'parenthesized_expression', 'children': ['113']}, {'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': 'is'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'public_upload'}, {'id': '115', 'type': 'None', 'children': []}; {'id': '116', 'type': 'parenthesized_expression', 'children': ['117']}, {'id': '117', 'type': 'call', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '119', 'type': 'argument_list', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'public_upload'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '122', 'type': 'block', 'children': ['123']}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '128']}, {'id': '125', 'type': 'subscript', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '127', 'type': 'string', 'children': [], 'value': "'publicUpload'"}; {'id': '128', 'type': 'call', 'children': ['129', '135']}, {'id': '129', 'type': 'attribute', 'children': ['130', '134']}; {'id': '130', 'type': 'call', 'children': ['131', '132']}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'public_upload'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'lower'}, {'id': '135', 'type': 'argument_list', 'children': []}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}, {'id': '137', 'type': 'assignment', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '139', 'type': 'call', 'children': ['140', '143']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': '_make_ocs_request'}, {'id': '143', 'type': 'argument_list', 'children': ['144', '145', '148', '154']}; {'id': '144', 'type': 'string', 'children': [], 'value': "'PUT'"}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'OCS_SERVICE_SHARE'}; {'id': '148', 'type': 'binary_operator', 'children': ['149', '150'], 'value': '+'}, {'id': '149', 'type': 'string', 'children': [], 'value': "'shares/'"}; {'id': '150', 'type': 'call', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'share_id'}; {'id': '154', 'type': 'keyword_argument', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '157', 'type': 'if_statement', 'children': ['158', '163']}; {'id': '158', 'type': 'comparison_operator', 'children': ['159', '162'], 'value': '=='}, {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'status_code'}; {'id': '162', 'type': 'integer', 'children': [], 'value': '200'}, {'id': '163', 'type': 'block', 'children': ['164']}; {'id': '164', 'type': 'return_statement', 'children': ['165']}, {'id': '165', 'type': 'True', 'children': []}; {'id': '166', 'type': 'raise_statement', 'children': ['167']}, {'id': '167', 'type': 'call', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'HTTPResponseError'}, {'id': '169', 'type': 'argument_list', 'children': ['170']} | def update_share(self, share_id, **kwargs):
perms = kwargs.get('perms', None)
password = kwargs.get('password', None)
public_upload = kwargs.get('public_upload', None)
if (isinstance(perms, int)) and (perms > self.OCS_PERMISSION_ALL):
perms = None
if not (perms or password or (public_upload is not None)):
return False
if not isinstance(share_id, int):
return False
data = {}
if perms:
data['permissions'] = perms
if isinstance(password, six.string_types):
data['password'] = password
if (public_upload is not None) and (isinstance(public_upload, bool)):
data['publicUpload'] = str(public_upload).lower()
res = self._make_ocs_request(
'PUT',
self.OCS_SERVICE_SHARE,
'shares/' + str(share_id),
data=data
)
if res.status_code == 200:
return True
raise HTTPResponseError(res) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_shares'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '7', 'type': 'string', 'children': [], 'value': "''"}; {'id': '8', 'type': 'dictionary_splat_pattern', 'children': ['9']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '10', 'type': 'block', 'children': ['11', '24', '28', '153', '166', '225']}, {'id': '11', 'type': 'if_statement', 'children': ['12', '21']}; {'id': '12', 'type': 'not_operator', 'children': ['13']}, {'id': '13', 'type': 'parenthesized_expression', 'children': ['14']}; {'id': '14', 'type': 'call', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'string_types'}, {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'return_statement', 'children': ['23']}, {'id': '23', 'type': 'None', 'children': []}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}, {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '27', 'type': 'string', 'children': [], 'value': "'shares'"}; {'id': '28', 'type': 'if_statement', 'children': ['29', '32']}, {'id': '29', 'type': 'comparison_operator', 'children': ['30', '31'], 'value': '!='}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '31', 'type': 'string', 'children': [], 'value': "''"}; {'id': '32', 'type': 'block', 'children': ['33', '37', '51', '58', '68', '83', '93', '115', '125', '144']}, {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'augmented_assignment', 'children': ['35', '36'], 'value': '+='}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '36', 'type': 'string', 'children': [], 'value': "'?'"}, {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '40', 'type': 'call', 'children': ['41', '44']}, {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': '_encode_string'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}, {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}, {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': '_normalize_path'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '54', 'type': 'dictionary', 'children': ['55']}, {'id': '55', 'type': 'pair', 'children': ['56', '57']}; {'id': '56', 'type': 'string', 'children': [], 'value': "'path'"}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}, {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'reshares'}, {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '65', 'type': 'argument_list', 'children': ['66', '67']}; {'id': '66', 'type': 'string', 'children': [], 'value': "'reshares'"}, {'id': '67', 'type': 'False', 'children': []}; {'id': '68', 'type': 'if_statement', 'children': ['69', '76']}, {'id': '69', 'type': 'boolean_operator', 'children': ['70', '75'], 'value': 'and'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '72', 'type': 'argument_list', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'reshares'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'bool'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'reshares'}; {'id': '76', 'type': 'block', 'children': ['77']}, {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '82']}, {'id': '79', 'type': 'subscript', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '81', 'type': 'string', 'children': [], 'value': "'reshares'"}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'reshares'}, {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'subfiles'}; {'id': '86', 'type': 'call', 'children': ['87', '90']}, {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '90', 'type': 'argument_list', 'children': ['91', '92']}, {'id': '91', 'type': 'string', 'children': [], 'value': "'subfiles'"}; {'id': '92', 'type': 'False', 'children': []}, {'id': '93', 'type': 'if_statement', 'children': ['94', '101']}; {'id': '94', 'type': 'boolean_operator', 'children': ['95', '100'], 'value': 'and'}, {'id': '95', 'type': 'call', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '97', 'type': 'argument_list', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'subfiles'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'subfiles'}, {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}, {'id': '103', 'type': 'assignment', 'children': ['104', '107']}; {'id': '104', 'type': 'subscript', 'children': ['105', '106']}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '106', 'type': 'string', 'children': [], 'value': "'subfiles'"}, {'id': '107', 'type': 'call', 'children': ['108', '114']}; {'id': '108', 'type': 'attribute', 'children': ['109', '113']}, {'id': '109', 'type': 'call', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'str'}, {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'subfiles'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '114', 'type': 'argument_list', 'children': []}, {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'shared_with_me'}; {'id': '118', 'type': 'call', 'children': ['119', '122']}, {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '122', 'type': 'argument_list', 'children': ['123', '124']}, {'id': '123', 'type': 'string', 'children': [], 'value': "'shared_with_me'"}; {'id': '124', 'type': 'False', 'children': []}, {'id': '125', 'type': 'if_statement', 'children': ['126', '133']}; {'id': '126', 'type': 'boolean_operator', 'children': ['127', '132'], 'value': 'and'}, {'id': '127', 'type': 'call', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '129', 'type': 'argument_list', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'shared_with_me'}, {'id': '131', 'type': 'identifier', 'children': [], 'value': 'bool'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'shared_with_me'}, {'id': '133', 'type': 'block', 'children': ['134', '140']}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}, {'id': '135', 'type': 'assignment', 'children': ['136', '139']}; {'id': '136', 'type': 'subscript', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '138', 'type': 'string', 'children': [], 'value': "'shared_with_me'"}, {'id': '139', 'type': 'string', 'children': [], 'value': '"true"'}; {'id': '140', 'type': 'delete_statement', 'children': ['141']}, {'id': '141', 'type': 'subscript', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '143', 'type': 'string', 'children': [], 'value': "'path'"}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'augmented_assignment', 'children': ['146', '147'], 'value': '+='}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '147', 'type': 'call', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'parse'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'urlencode'}, {'id': '151', 'type': 'argument_list', 'children': ['152']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'args'}, {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'assignment', 'children': ['155', '156']}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '156', 'type': 'call', 'children': ['157', '160']}, {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': '_make_ocs_request'}; {'id': '160', 'type': 'argument_list', 'children': ['161', '162', '165']}, {'id': '161', 'type': 'string', 'children': [], 'value': "'GET'"}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'OCS_SERVICE_SHARE'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '166', 'type': 'if_statement', 'children': ['167', '172']}, {'id': '167', 'type': 'comparison_operator', 'children': ['168', '171'], 'value': '=='}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}, {'id': '169', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'status_code'}, {'id': '171', 'type': 'integer', 'children': [], 'value': '200'}; {'id': '172', 'type': 'block', 'children': ['173', '184', '191', '195', '223']}, {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'assignment', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '176', 'type': 'call', 'children': ['177', '180']}, {'id': '177', 'type': 'attribute', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'ET'}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'fromstring'}; {'id': '180', 'type': 'argument_list', 'children': ['181']}, {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '183', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '184', 'type': 'expression_statement', 'children': ['185']}, {'id': '185', 'type': 'call', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': '_check_ocs_status'}, {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'assignment', 'children': ['193', '194']}, {'id': '193', 'type': 'identifier', 'children': [], 'value': 'shares'}; {'id': '194', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '195', 'type': 'for_statement', 'children': ['196', '197', '208']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'element'}, {'id': '197', 'type': 'call', 'children': ['198', '206']}; {'id': '198', 'type': 'attribute', 'children': ['199', '205']}, {'id': '199', 'type': 'call', 'children': ['200', '203']}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'find'}, {'id': '203', 'type': 'argument_list', 'children': ['204']}; {'id': '204', 'type': 'string', 'children': [], 'value': "'data'"}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'iter'}; {'id': '206', 'type': 'argument_list', 'children': ['207']}, {'id': '207', 'type': 'string', 'children': [], 'value': "'element'"}; {'id': '208', 'type': 'block', 'children': ['209', '211']}, {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'string', 'children': [], 'value': "'''share_attr = {}\n for child in element:\n key = child.tag\n value = child.text\n share_attr[key] = value\n shares.append(share_attr)'''"}, {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'call', 'children': ['213', '216']}, {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'shares'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '216', 'type': 'argument_list', 'children': ['217']}, {'id': '217', 'type': 'call', 'children': ['218', '221']}; {'id': '218', 'type': 'attribute', 'children': ['219', '220']}, {'id': '219', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': '_get_shareinfo'}, {'id': '221', 'type': 'argument_list', 'children': ['222']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'element'}, {'id': '223', 'type': 'return_statement', 'children': ['224']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'shares'}, {'id': '225', 'type': 'raise_statement', 'children': ['226']}; {'id': '226', 'type': 'call', 'children': ['227', '228']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'HTTPResponseError'}; {'id': '228', 'type': 'argument_list', 'children': ['229']}, {'id': '229', 'type': 'identifier', 'children': [], 'value': 'res'} | def get_shares(self, path='', **kwargs):
if not (isinstance(path, six.string_types)):
return None
data = 'shares'
if path != '':
data += '?'
path = self._encode_string(self._normalize_path(path))
args = {'path': path}
reshares = kwargs.get('reshares', False)
if isinstance(reshares, bool) and reshares:
args['reshares'] = reshares
subfiles = kwargs.get('subfiles', False)
if isinstance(subfiles, bool) and subfiles:
args['subfiles'] = str(subfiles).lower()
shared_with_me = kwargs.get('shared_with_me', False)
if isinstance(shared_with_me, bool) and shared_with_me:
args['shared_with_me'] = "true"
del args['path']
data += parse.urlencode(args)
res = self._make_ocs_request(
'GET',
self.OCS_SERVICE_SHARE,
data
)
if res.status_code == 200:
tree = ET.fromstring(res.content)
self._check_ocs_status(tree)
shares = []
for element in tree.find('data').iter('element'):
'''share_attr = {}
for child in element:
key = child.tag
value = child.text
share_attr[key] = value
shares.append(share_attr)'''
shares.append(self._get_shareinfo(element))
return shares
raise HTTPResponseError(res) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'share_file_with_user'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'user'}, {'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '9', 'type': 'block', 'children': ['10', '20', '32', '68', '86', '95', '123', '139', '158', '213']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'remote_user'}, {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}, {'id': '15', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '17', 'type': 'argument_list', 'children': ['18', '19']}; {'id': '18', 'type': 'string', 'children': [], 'value': "'remote_user'"}, {'id': '19', 'type': 'False', 'children': []}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}, {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'perms'}, {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '27', 'type': 'argument_list', 'children': ['28', '29']}; {'id': '28', 'type': 'string', 'children': [], 'value': "'perms'"}, {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'OCS_PERMISSION_READ'}; {'id': '32', 'type': 'if_statement', 'children': ['33', '65']}, {'id': '33', 'type': 'parenthesized_expression', 'children': ['34']}; {'id': '34', 'type': 'boolean_operator', 'children': ['35', '50'], 'value': 'or'}, {'id': '35', 'type': 'parenthesized_expression', 'children': ['36']}; {'id': '36', 'type': 'boolean_operator', 'children': ['37', '44'], 'value': 'or'}, {'id': '37', 'type': 'parenthesized_expression', 'children': ['38']}; {'id': '38', 'type': 'not_operator', 'children': ['39']}, {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'isinstance'}, {'id': '41', 'type': 'argument_list', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'perms'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '44', 'type': 'parenthesized_expression', 'children': ['45']}, {'id': '45', 'type': 'comparison_operator', 'children': ['46', '47'], 'value': '>'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'perms'}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'OCS_PERMISSION_ALL'}; {'id': '50', 'type': 'parenthesized_expression', 'children': ['51']}, {'id': '51', 'type': 'boolean_operator', 'children': ['52', '61'], 'value': 'or'}; {'id': '52', 'type': 'parenthesized_expression', 'children': ['53']}, {'id': '53', 'type': 'not_operator', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '56']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'six'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'string_types'}, {'id': '61', 'type': 'parenthesized_expression', 'children': ['62']}; {'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': '=='}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '64', 'type': 'string', 'children': [], 'value': "''"}, {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'return_statement', 'children': ['67']}, {'id': '67', 'type': 'False', 'children': []}; {'id': '68', 'type': 'if_statement', 'children': ['69', '79']}, {'id': '69', 'type': 'boolean_operator', 'children': ['70', '71'], 'value': 'and'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'remote_user'}, {'id': '71', 'type': 'parenthesized_expression', 'children': ['72']}; {'id': '72', 'type': 'not_operator', 'children': ['73']}, {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'endswith'}, {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'string', 'children': [], 'value': "'/'"}, {'id': '79', 'type': 'block', 'children': ['80']}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}, {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'user'}, {'id': '83', 'type': 'binary_operator', 'children': ['84', '85'], 'value': '+'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'user'}, {'id': '85', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': '_normalize_path'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'post_data'}; {'id': '98', 'type': 'dictionary', 'children': ['99', '109', '112', '120']}, {'id': '99', 'type': 'pair', 'children': ['100', '101']}; {'id': '100', 'type': 'string', 'children': [], 'value': "'shareType'"}, {'id': '101', 'type': 'conditional_expression', 'children': ['102', '105', '106'], 'value': 'if'}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'OCS_SHARE_TYPE_REMOTE'}, {'id': '105', 'type': 'identifier', 'children': [], 'value': 'remote_user'}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'OCS_SHARE_TYPE_USER'}, {'id': '109', 'type': 'pair', 'children': ['110', '111']}; {'id': '110', 'type': 'string', 'children': [], 'value': "'shareWith'"}, {'id': '111', 'type': 'identifier', 'children': [], 'value': 'user'}; {'id': '112', 'type': 'pair', 'children': ['113', '114']}, {'id': '113', 'type': 'string', 'children': [], 'value': "'path'"}; {'id': '114', 'type': 'call', 'children': ['115', '118']}, {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '117', 'type': 'identifier', 'children': [], 'value': '_encode_string'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '120', 'type': 'pair', 'children': ['121', '122']}, {'id': '121', 'type': 'string', 'children': [], 'value': "'permissions'"}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'perms'}, {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '126', 'type': 'call', 'children': ['127', '130']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': '_make_ocs_request'}; {'id': '130', 'type': 'argument_list', 'children': ['131', '132', '135', '136']}, {'id': '131', 'type': 'string', 'children': [], 'value': "'POST'"}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'OCS_SERVICE_SHARE'}, {'id': '135', 'type': 'string', 'children': [], 'value': "'shares'"}; {'id': '136', 'type': 'keyword_argument', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'post_data'}, {'id': '139', 'type': 'if_statement', 'children': ['140', '143']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': '_debug'}, {'id': '143', 'type': 'block', 'children': ['144']}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}, {'id': '145', 'type': 'call', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'binary_operator', 'children': ['149', '152'], 'value': '%'}, {'id': '149', 'type': 'concatenated_string', 'children': ['150', '151']}; {'id': '150', 'type': 'string', 'children': [], 'value': "'OCS share_file request for file %s with permissions %i '"}, {'id': '151', 'type': 'string', 'children': [], 'value': "'returned: %i'"}; {'id': '152', 'type': 'tuple', 'children': ['153', '154', '155']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'perms'}, {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'status_code'}; {'id': '158', 'type': 'if_statement', 'children': ['159', '164']}, {'id': '159', 'type': 'comparison_operator', 'children': ['160', '163'], 'value': '=='}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'status_code'}, {'id': '163', 'type': 'integer', 'children': [], 'value': '200'}; {'id': '164', 'type': 'block', 'children': ['165', '176', '183', '192']}, {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'assignment', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '168', 'type': 'call', 'children': ['169', '172']}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'ET'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'fromstring'}; {'id': '172', 'type': 'argument_list', 'children': ['173']}, {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'call', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}, {'id': '179', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': '_check_ocs_status'}, {'id': '181', 'type': 'argument_list', 'children': ['182']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'data_el'}; {'id': '186', 'type': 'call', 'children': ['187', '190']}, {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '189', 'type': 'identifier', 'children': [], 'value': 'find'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}, {'id': '191', 'type': 'string', 'children': [], 'value': "'data'"}; {'id': '192', 'type': 'return_statement', 'children': ['193']}, {'id': '193', 'type': 'call', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'ShareInfo'}, {'id': '195', 'type': 'argument_list', 'children': ['196']}; {'id': '196', 'type': 'dictionary', 'children': ['197', '207', '210']}, {'id': '197', 'type': 'pair', 'children': ['198', '199']}; {'id': '198', 'type': 'string', 'children': [], 'value': "'id'"}, {'id': '199', 'type': 'attribute', 'children': ['200', '206']}; {'id': '200', 'type': 'call', 'children': ['201', '204']}, {'id': '201', 'type': 'attribute', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'data_el'}, {'id': '203', 'type': 'identifier', 'children': [], 'value': 'find'}; {'id': '204', 'type': 'argument_list', 'children': ['205']}, {'id': '205', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '207', 'type': 'pair', 'children': ['208', '209']}; {'id': '208', 'type': 'string', 'children': [], 'value': "'path'"}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '210', 'type': 'pair', 'children': ['211', '212']}, {'id': '211', 'type': 'string', 'children': [], 'value': "'permissions'"}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'perms'}, {'id': '213', 'type': 'raise_statement', 'children': ['214']}; {'id': '214', 'type': 'call', 'children': ['215', '216']}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'HTTPResponseError'}; {'id': '216', 'type': 'argument_list', 'children': ['217']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'res'} | def share_file_with_user(self, path, user, **kwargs):
remote_user = kwargs.get('remote_user', False)
perms = kwargs.get('perms', self.OCS_PERMISSION_READ)
if (((not isinstance(perms, int)) or (perms > self.OCS_PERMISSION_ALL))
or ((not isinstance(user, six.string_types)) or (user == ''))):
return False
if remote_user and (not user.endswith('/')):
user = user + '/'
path = self._normalize_path(path)
post_data = {
'shareType': self.OCS_SHARE_TYPE_REMOTE if remote_user else
self.OCS_SHARE_TYPE_USER,
'shareWith': user,
'path': self._encode_string(path),
'permissions': perms
}
res = self._make_ocs_request(
'POST',
self.OCS_SERVICE_SHARE,
'shares',
data=post_data
)
if self._debug:
print('OCS share_file request for file %s with permissions %i '
'returned: %i' % (path, perms, res.status_code))
if res.status_code == 200:
tree = ET.fromstring(res.content)
self._check_ocs_status(tree)
data_el = tree.find('data')
return ShareInfo(
{
'id': data_el.find('id').text,
'path': path,
'permissions': perms
}
)
raise HTTPResponseError(res) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_attribute'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '10', 'type': 'None', 'children': []}, {'id': '11', 'type': 'block', 'children': ['12', '16', '55', '68', '197']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '15', 'type': 'string', 'children': [], 'value': "'getattribute'"}; {'id': '16', 'type': 'if_statement', 'children': ['17', '20']}, {'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'is'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'app'}, {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21', '33']}, {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'augmented_assignment', 'children': ['23', '24'], 'value': '+='}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '24', 'type': 'binary_operator', 'children': ['25', '26'], 'value': '+'}, {'id': '25', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '26', 'type': 'call', 'children': ['27', '30']}, {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'parse'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'quote'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '32', 'type': 'string', 'children': [], 'value': "''"}, {'id': '33', 'type': 'if_statement', 'children': ['34', '37']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'is'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '36', 'type': 'None', 'children': []}, {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}, {'id': '39', 'type': 'augmented_assignment', 'children': ['40', '41'], 'value': '+='}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '41', 'type': 'binary_operator', 'children': ['42', '43'], 'value': '+'}; {'id': '42', 'type': 'string', 'children': [], 'value': "'/'"}, {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'parse'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'quote'}, {'id': '47', 'type': 'argument_list', 'children': ['48', '54']}; {'id': '48', 'type': 'call', 'children': ['49', '52']}, {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '51', 'type': 'identifier', 'children': [], 'value': '_encode_string'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '54', 'type': 'string', 'children': [], 'value': "''"}, {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '58', 'type': 'call', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': '_make_ocs_request'}; {'id': '62', 'type': 'argument_list', 'children': ['63', '64', '67']}, {'id': '63', 'type': 'string', 'children': [], 'value': "'GET'"}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'OCS_SERVICE_PRIVATEDATA'}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '68', 'type': 'if_statement', 'children': ['69', '74']}, {'id': '69', 'type': 'comparison_operator', 'children': ['70', '73'], 'value': '=='}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'status_code'}, {'id': '73', 'type': 'integer', 'children': [], 'value': '200'}; {'id': '74', 'type': 'block', 'children': ['75', '86', '93', '97', '181', '195']}, {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '78', 'type': 'call', 'children': ['79', '82']}, {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'ET'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'fromstring'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}, {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'content'}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': '_check_ocs_status'}, {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'tree'}, {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '96', 'type': 'list', 'children': [], 'value': '[]'}, {'id': '97', 'type': 'for_statement', 'children': ['98', '99', '110']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'element'}, {'id': '99', 'type': 'call', 'children': ['100', '108']}; {'id': '100', 'type': 'attribute', 'children': ['101', '107']}, {'id': '101', 'type': 'call', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}, {'id': '103', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'find'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'string', 'children': [], 'value': "'data'"}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'iter'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'string', 'children': [], 'value': "'element'"}; {'id': '110', 'type': 'block', 'children': ['111', '122', '133', '146']}, {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'app_text'}; {'id': '114', 'type': 'attribute', 'children': ['115', '121']}, {'id': '115', 'type': 'call', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}, {'id': '117', 'type': 'identifier', 'children': [], 'value': 'element'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'find'}, {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'string', 'children': [], 'value': "'app'"}, {'id': '121', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}, {'id': '123', 'type': 'assignment', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'key_text'}, {'id': '125', 'type': 'attribute', 'children': ['126', '132']}; {'id': '126', 'type': 'call', 'children': ['127', '130']}, {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'element'}, {'id': '129', 'type': 'identifier', 'children': [], 'value': 'find'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}, {'id': '131', 'type': 'string', 'children': [], 'value': "'key'"}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'value_text'}; {'id': '136', 'type': 'boolean_operator', 'children': ['137', '145'], 'value': 'or'}, {'id': '137', 'type': 'attribute', 'children': ['138', '144']}; {'id': '138', 'type': 'call', 'children': ['139', '142']}, {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'element'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'find'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}, {'id': '143', 'type': 'string', 'children': [], 'value': "'value'"}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'text'}, {'id': '145', 'type': 'string', 'children': [], 'value': "''"}; {'id': '146', 'type': 'if_statement', 'children': ['147', '150', '177']}, {'id': '147', 'type': 'comparison_operator', 'children': ['148', '149'], 'value': 'is'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '149', 'type': 'None', 'children': []}; {'id': '150', 'type': 'block', 'children': ['151']}, {'id': '151', 'type': 'if_statement', 'children': ['152', '155', '166']}; {'id': '152', 'type': 'comparison_operator', 'children': ['153', '154'], 'value': 'is'}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'app'}; {'id': '154', 'type': 'None', 'children': []}, {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}, {'id': '157', 'type': 'call', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '161', 'type': 'argument_list', 'children': ['162']}; {'id': '162', 'type': 'tuple', 'children': ['163', '164', '165']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'app_text'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'key_text'}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'value_text'}; {'id': '166', 'type': 'else_clause', 'children': ['167']}, {'id': '167', 'type': 'block', 'children': ['168']}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}, {'id': '169', 'type': 'call', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'append'}, {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'tuple', 'children': ['175', '176']}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'key_text'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'value_text'}, {'id': '177', 'type': 'else_clause', 'children': ['178']}; {'id': '178', 'type': 'block', 'children': ['179']}, {'id': '179', 'type': 'return_statement', 'children': ['180']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'value_text'}, {'id': '181', 'type': 'if_statement', 'children': ['182', '192']}; {'id': '182', 'type': 'boolean_operator', 'children': ['183', '189'], 'value': 'and'}, {'id': '183', 'type': 'comparison_operator', 'children': ['184', '188'], 'value': '=='}; {'id': '184', 'type': 'call', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '186', 'type': 'argument_list', 'children': ['187']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '188', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '189', 'type': 'comparison_operator', 'children': ['190', '191'], 'value': 'is'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'key'}, {'id': '191', 'type': 'None', 'children': []}; {'id': '192', 'type': 'block', 'children': ['193']}, {'id': '193', 'type': 'return_statement', 'children': ['194']}; {'id': '194', 'type': 'None', 'children': []}, {'id': '195', 'type': 'return_statement', 'children': ['196']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'values'}, {'id': '197', 'type': 'raise_statement', 'children': ['198']}; {'id': '198', 'type': 'call', 'children': ['199', '200']}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'HTTPResponseError'}; {'id': '200', 'type': 'argument_list', 'children': ['201']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'res'} | def get_attribute(self, app=None, key=None):
path = 'getattribute'
if app is not None:
path += '/' + parse.quote(app, '')
if key is not None:
path += '/' + parse.quote(self._encode_string(key), '')
res = self._make_ocs_request(
'GET',
self.OCS_SERVICE_PRIVATEDATA,
path
)
if res.status_code == 200:
tree = ET.fromstring(res.content)
self._check_ocs_status(tree)
values = []
for element in tree.find('data').iter('element'):
app_text = element.find('app').text
key_text = element.find('key').text
value_text = element.find('value').text or ''
if key is None:
if app is None:
values.append((app_text, key_text, value_text))
else:
values.append((key_text, value_text))
else:
return value_text
if len(values) == 0 and key is not None:
return None
return values
raise HTTPResponseError(res) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_make_dav_request'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'path'}, {'id': '7', 'type': 'dictionary_splat_pattern', 'children': ['8']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'kwargs'}, {'id': '9', 'type': 'block', 'children': ['10', '43', '52', '80', '94', '110', '121']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '14']}, {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '13', 'type': 'identifier', 'children': [], 'value': '_debug'}; {'id': '14', 'type': 'block', 'children': ['15', '24']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}, {'id': '19', 'type': 'binary_operator', 'children': ['20', '21'], 'value': '%'}; {'id': '20', 'type': 'string', 'children': [], 'value': "'DAV request: %s %s'"}, {'id': '21', 'type': 'tuple', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '24', 'type': 'if_statement', 'children': ['25', '31']}, {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'string', 'children': [], 'value': "'headers'"}, {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}, {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'print'}, {'id': '35', 'type': 'argument_list', 'children': ['36', '37']}; {'id': '36', 'type': 'string', 'children': [], 'value': "'Headers: '"}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'get'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'string', 'children': [], 'value': "'headers'"}, {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '46', 'type': 'call', 'children': ['47', '50']}, {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '49', 'type': 'identifier', 'children': [], 'value': '_normalize_path'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}, {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '55', 'type': 'call', 'children': ['56', '61']}; {'id': '56', 'type': 'attribute', 'children': ['57', '60']}, {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '59', 'type': 'identifier', 'children': [], 'value': '_session'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'request'}, {'id': '61', 'type': 'argument_list', 'children': ['62', '63', '78']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'method'}, {'id': '63', 'type': 'binary_operator', 'children': ['64', '67'], 'value': '+'}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}, {'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': '_webdav_url'}, {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'parse'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'quote'}, {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '76']}, {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '75', 'type': 'identifier', 'children': [], 'value': '_encode_string'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '78', 'type': 'dictionary_splat', 'children': ['79']}, {'id': '79', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '80', 'type': 'if_statement', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': '_debug'}; {'id': '84', 'type': 'block', 'children': ['85']}, {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'binary_operator', 'children': ['90', '91'], 'value': '%'}; {'id': '90', 'type': 'string', 'children': [], 'value': "'DAV status: %i'"}, {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'res'}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'status_code'}; {'id': '94', 'type': 'if_statement', 'children': ['95', '102']}, {'id': '95', 'type': 'comparison_operator', 'children': ['96', '99'], 'value': 'in'}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}, {'id': '97', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'status_code'}, {'id': '99', 'type': 'list', 'children': ['100', '101'], 'value': '[200, 207]'}; {'id': '100', 'type': 'integer', 'children': [], 'value': '200'}, {'id': '101', 'type': 'integer', 'children': [], 'value': '207'}; {'id': '102', 'type': 'block', 'children': ['103']}, {'id': '103', 'type': 'return_statement', 'children': ['104']}; {'id': '104', 'type': 'call', 'children': ['105', '108']}, {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'self'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': '_parse_dav_response'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '110', 'type': 'if_statement', 'children': ['111', '118']}, {'id': '111', 'type': 'comparison_operator', 'children': ['112', '115'], 'value': 'in'}; {'id': '112', 'type': 'attribute', 'children': ['113', '114']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'status_code'}, {'id': '115', 'type': 'list', 'children': ['116', '117'], 'value': '[204, 201]'}; {'id': '116', 'type': 'integer', 'children': [], 'value': '204'}, {'id': '117', 'type': 'integer', 'children': [], 'value': '201'}; {'id': '118', 'type': 'block', 'children': ['119']}, {'id': '119', 'type': 'return_statement', 'children': ['120']}; {'id': '120', 'type': 'True', 'children': []}, {'id': '121', 'type': 'raise_statement', 'children': ['122']}; {'id': '122', 'type': 'call', 'children': ['123', '124']}, {'id': '123', 'type': 'identifier', 'children': [], 'value': 'HTTPResponseError'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'res'} | def _make_dav_request(self, method, path, **kwargs):
if self._debug:
print('DAV request: %s %s' % (method, path))
if kwargs.get('headers'):
print('Headers: ', kwargs.get('headers'))
path = self._normalize_path(path)
res = self._session.request(
method,
self._webdav_url + parse.quote(self._encode_string(path)),
**kwargs
)
if self._debug:
print('DAV status: %i' % res.status_code)
if res.status_code in [200, 207]:
return self._parse_dav_response(res)
if res.status_code in [204, 201]:
return True
raise HTTPResponseError(res) |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'load_delimited'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'converters'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'delimiter'}; {'id': '8', 'type': 'string', 'children': [], 'value': "r'\\s+'"}, {'id': '9', 'type': 'block', 'children': ['10', '12', '19', '34', '43', '158']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}, {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'n_columns'}, {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'converters'}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '24', 'type': 'generator_expression', 'children': ['25', '28']}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'list'}, {'id': '27', 'type': 'argument_list', 'children': []}; {'id': '28', 'type': 'for_in_clause', 'children': ['29', '30']}, {'id': '29', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '30', 'type': 'call', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'n_columns'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}, {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'splitter'}, {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'compile'}, {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'delimiter'}, {'id': '43', 'type': 'with_statement', 'children': ['44', '56']}; {'id': '44', 'type': 'with_clause', 'children': ['45']}, {'id': '45', 'type': 'with_item', 'children': ['46']}; {'id': '46', 'type': 'as_pattern', 'children': ['47', '54']}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': '_open'}, {'id': '49', 'type': 'argument_list', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '51', 'type': 'keyword_argument', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'mode'}, {'id': '53', 'type': 'string', 'children': [], 'value': "'r'"}; {'id': '54', 'type': 'as_pattern_target', 'children': ['55']}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'input_file'}; {'id': '56', 'type': 'block', 'children': ['57']}, {'id': '57', 'type': 'for_statement', 'children': ['58', '61', '66']}; {'id': '58', 'type': 'pattern_list', 'children': ['59', '60']}, {'id': '59', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'enumerate'}, {'id': '63', 'type': 'argument_list', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'input_file'}, {'id': '65', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '66', 'type': 'block', 'children': ['67', '83', '110']}, {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}, {'id': '69', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '70', 'type': 'call', 'children': ['71', '74']}, {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'splitter'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '74', 'type': 'argument_list', 'children': ['75', '80']}, {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'strip'}, {'id': '79', 'type': 'argument_list', 'children': []}; {'id': '80', 'type': 'binary_operator', 'children': ['81', '82'], 'value': '-'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'n_columns'}; {'id': '82', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '83', 'type': 'if_statement', 'children': ['84', '90']}; {'id': '84', 'type': 'comparison_operator', 'children': ['85', '86'], 'value': '!='}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'n_columns'}; {'id': '86', 'type': 'call', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}, {'id': '89', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '90', 'type': 'block', 'children': ['91']}, {'id': '91', 'type': 'raise_statement', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '94']}, {'id': '93', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}, {'id': '95', 'type': 'call', 'children': ['96', '101']}; {'id': '96', 'type': 'attribute', 'children': ['97', '100']}, {'id': '97', 'type': 'concatenated_string', 'children': ['98', '99']}; {'id': '98', 'type': 'string', 'children': [], 'value': "'Expected {} columns, got {} at '"}, {'id': '99', 'type': 'string', 'children': [], 'value': "'{}:{:d}:\\n\\t{}'"}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '101', 'type': 'argument_list', 'children': ['102', '103', '107', '108', '109']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'n_columns'}, {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '107', 'type': 'identifier', 'children': [], 'value': 'filename'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'row'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'line'}; {'id': '110', 'type': 'for_statement', 'children': ['111', '115', '121']}, {'id': '111', 'type': 'pattern_list', 'children': ['112', '113', '114']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'column'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'converter'}, {'id': '115', 'type': 'call', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'zip'}, {'id': '117', 'type': 'argument_list', 'children': ['118', '119', '120']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'data'}, {'id': '119', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'converters'}, {'id': '121', 'type': 'block', 'children': ['122', '151']}; {'id': '122', 'type': 'try_statement', 'children': ['123', '131']}, {'id': '123', 'type': 'block', 'children': ['124']}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'converted_value'}, {'id': '127', 'type': 'call', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'converter'}, {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '131', 'type': 'except_clause', 'children': ['132']}; {'id': '132', 'type': 'block', 'children': ['133']}, {'id': '133', 'type': 'raise_statement', 'children': ['134']}; {'id': '134', 'type': 'call', 'children': ['135', '136']}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '136', 'type': 'argument_list', 'children': ['137']}, {'id': '137', 'type': 'call', 'children': ['138', '143']}; {'id': '138', 'type': 'attribute', 'children': ['139', '142']}, {'id': '139', 'type': 'concatenated_string', 'children': ['140', '141']}; {'id': '140', 'type': 'string', 'children': [], 'value': '"Couldn\'t convert value {} using {} "'}, {'id': '141', 'type': 'string', 'children': [], 'value': '"found at {}:{:d}:\\n\\t{}"'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'format'}, {'id': '143', 'type': 'argument_list', 'children': ['144', '145', '148', '149', '150']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'value'}, {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'converter'}, {'id': '147', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'filename'}, {'id': '149', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'line'}, {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'call', 'children': ['153', '156']}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'column'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '156', 'type': 'argument_list', 'children': ['157']}, {'id': '157', 'type': 'identifier', 'children': [], 'value': 'converted_value'}; {'id': '158', 'type': 'if_statement', 'children': ['159', '162', '167']}, {'id': '159', 'type': 'comparison_operator', 'children': ['160', '161'], 'value': '=='}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'n_columns'}, {'id': '161', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '162', 'type': 'block', 'children': ['163']}, {'id': '163', 'type': 'return_statement', 'children': ['164']}; {'id': '164', 'type': 'subscript', 'children': ['165', '166']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '166', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '167', 'type': 'else_clause', 'children': ['168']}; {'id': '168', 'type': 'block', 'children': ['169']}, {'id': '169', 'type': 'return_statement', 'children': ['170']} | def load_delimited(filename, converters, delimiter=r'\s+'):
r
n_columns = len(converters)
columns = tuple(list() for _ in range(n_columns))
splitter = re.compile(delimiter)
with _open(filename, mode='r') as input_file:
for row, line in enumerate(input_file, 1):
data = splitter.split(line.strip(), n_columns - 1)
if n_columns != len(data):
raise ValueError('Expected {} columns, got {} at '
'{}:{:d}:\n\t{}'.format(n_columns, len(data),
filename, row, line))
for value, column, converter in zip(data, columns, converters):
try:
converted_value = converter(value)
except:
raise ValueError("Couldn't convert value {} using {} "
"found at {}:{:d}:\n\t{}".format(
value, converter.__name__, filename,
row, line))
column.append(converted_value)
if n_columns == 1:
return columns[0]
else:
return columns |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'validate'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'reference_patterns'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'estimated_patterns'}; {'id': '6', 'type': 'block', 'children': ['7', '22', '37']}, {'id': '7', 'type': 'if_statement', 'children': ['8', '14']}; {'id': '8', 'type': 'comparison_operator', 'children': ['9', '13'], 'value': '=='}, {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': '_n_onset_midi'}, {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'reference_patterns'}, {'id': '13', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '14', 'type': 'block', 'children': ['15']}, {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '20']}, {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'warnings'}, {'id': '19', 'type': 'identifier', 'children': [], 'value': 'warn'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}, {'id': '21', 'type': 'string', 'children': [], 'value': "'Reference patterns are empty.'"}; {'id': '22', 'type': 'if_statement', 'children': ['23', '29']}, {'id': '23', 'type': 'comparison_operator', 'children': ['24', '28'], 'value': '=='}; {'id': '24', 'type': 'call', 'children': ['25', '26']}, {'id': '25', 'type': 'identifier', 'children': [], 'value': '_n_onset_midi'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}, {'id': '27', 'type': 'identifier', 'children': [], 'value': 'estimated_patterns'}; {'id': '28', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}, {'id': '33', 'type': 'identifier', 'children': [], 'value': 'warnings'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'warn'}, {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'string', 'children': [], 'value': "'Estimated patterns are empty.'"}, {'id': '37', 'type': 'for_statement', 'children': ['38', '39', '42']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'patterns'}, {'id': '39', 'type': 'list', 'children': ['40', '41'], 'value': '[reference_patterns, estimated_patterns]'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'reference_patterns'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'estimated_patterns'}; {'id': '42', 'type': 'block', 'children': ['43']}, {'id': '43', 'type': 'for_statement', 'children': ['44', '45', '46']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'patterns'}; {'id': '46', 'type': 'block', 'children': ['47', '62']}, {'id': '47', 'type': 'if_statement', 'children': ['48', '54']}; {'id': '48', 'type': 'comparison_operator', 'children': ['49', '53'], 'value': '<='}, {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'id': '53', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '54', 'type': 'block', 'children': ['55']}, {'id': '55', 'type': 'raise_statement', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '58']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}, {'id': '59', 'type': 'concatenated_string', 'children': ['60', '61']}; {'id': '60', 'type': 'string', 'children': [], 'value': '"Each pattern must contain at least one "'}, {'id': '61', 'type': 'string', 'children': [], 'value': '"occurrence."'}; {'id': '62', 'type': 'for_statement', 'children': ['63', '64', '65']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'occurrence'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'pattern'}, {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'for_statement', 'children': ['67', '68', '69']}, {'id': '67', 'type': 'identifier', 'children': [], 'value': 'onset_midi'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'occurrence'}, {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'if_statement', 'children': ['71', '77']}, {'id': '71', 'type': 'comparison_operator', 'children': ['72', '76'], 'value': '!='}; {'id': '72', 'type': 'call', 'children': ['73', '74']}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}, {'id': '75', 'type': 'identifier', 'children': [], 'value': 'onset_midi'}; {'id': '76', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'raise_statement', 'children': ['79']}, {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'concatenated_string', 'children': ['83', '84']}, {'id': '83', 'type': 'string', 'children': [], 'value': '"The (onset, midi) tuple must "'} | def validate(reference_patterns, estimated_patterns):
if _n_onset_midi(reference_patterns) == 0:
warnings.warn('Reference patterns are empty.')
if _n_onset_midi(estimated_patterns) == 0:
warnings.warn('Estimated patterns are empty.')
for patterns in [reference_patterns, estimated_patterns]:
for pattern in patterns:
if len(pattern) <= 0:
raise ValueError("Each pattern must contain at least one "
"occurrence.")
for occurrence in pattern:
for onset_midi in occurrence:
if len(onset_midi) != 2:
raise ValueError("The (onset, midi) tuple must "
"contain exactly 2 elements.") |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'three_layer_FPR'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'reference_patterns'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'estimated_patterns'}; {'id': '6', 'type': 'block', 'children': ['7', '13', '58', '110', '221', '242', '253', '270', '287', '297']}, {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'call', 'children': ['9', '10']}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'validate'}; {'id': '10', 'type': 'argument_list', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'reference_patterns'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'estimated_patterns'}, {'id': '13', 'type': 'function_definition', 'children': ['14', '15', '18']}; {'id': '14', 'type': 'function_name', 'children': [], 'value': 'compute_first_layer_PR'}, {'id': '15', 'type': 'parameters', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'ref_occs'}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'est_occs'}; {'id': '18', 'type': 'block', 'children': ['19', '30', '42', '54']}, {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}, {'id': '21', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}, {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': '_occurrence_intersection'}, {'id': '27', 'type': 'argument_list', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'ref_occs'}, {'id': '29', 'type': 'identifier', 'children': [], 'value': 'est_occs'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}, {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'precision'}, {'id': '33', 'type': 'binary_operator', 'children': ['34', '35'], 'value': '/'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'call', 'children': ['39', '40']}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'ref_occs'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}, {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'recall'}, {'id': '45', 'type': 'binary_operator', 'children': ['46', '47'], 'value': '/'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 's'}, {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'float'}, {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'call', 'children': ['51', '52']}, {'id': '51', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}, {'id': '53', 'type': 'identifier', 'children': [], 'value': 'est_occs'}; {'id': '54', 'type': 'return_statement', 'children': ['55']}, {'id': '55', 'type': 'expression_list', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'precision'}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'recall'}; {'id': '58', 'type': 'function_definition', 'children': ['59', '60', '63']}, {'id': '59', 'type': 'function_name', 'children': [], 'value': 'compute_second_layer_PR'}; {'id': '60', 'type': 'parameters', 'children': ['61', '62']}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'ref_pattern'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'est_pattern'}, {'id': '63', 'type': 'block', 'children': ['64', '72', '89', '106']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'F_1'}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'compute_layer'}, {'id': '69', 'type': 'argument_list', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'ref_pattern'}, {'id': '71', 'type': 'identifier', 'children': [], 'value': 'est_pattern'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}, {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'precision'}, {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}, {'id': '77', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'mean'}, {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '84']}, {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '84', 'type': 'argument_list', 'children': ['85', '86']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'F_1'}; {'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']}, {'id': '87', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '88', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'recall'}; {'id': '92', 'type': 'call', 'children': ['93', '96']}, {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '95', 'type': 'identifier', 'children': [], 'value': 'mean'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}, {'id': '97', 'type': 'call', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '101', 'type': 'argument_list', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'F_1'}, {'id': '103', 'type': 'keyword_argument', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '105', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '106', 'type': 'return_statement', 'children': ['107']}, {'id': '107', 'type': 'expression_list', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'precision'}, {'id': '109', 'type': 'identifier', 'children': [], 'value': 'recall'}; {'id': '110', 'type': 'function_definition', 'children': ['111', '112', '118']}, {'id': '111', 'type': 'function_name', 'children': [], 'value': 'compute_layer'}; {'id': '112', 'type': 'parameters', 'children': ['113', '114', '115']}, {'id': '113', 'type': 'identifier', 'children': [], 'value': 'ref_elements'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'est_elements'}, {'id': '115', 'type': 'default_parameter', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'layer'}, {'id': '117', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '118', 'type': 'block', 'children': ['119', '135', '142', '149', '160', '219']}, {'id': '119', 'type': 'if_statement', 'children': ['120', '127']}; {'id': '120', 'type': 'boolean_operator', 'children': ['121', '124'], 'value': 'and'}, {'id': '121', 'type': 'comparison_operator', 'children': ['122', '123'], 'value': '!='}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'layer'}, {'id': '123', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '124', 'type': 'comparison_operator', 'children': ['125', '126'], 'value': '!='}, {'id': '125', 'type': 'identifier', 'children': [], 'value': 'layer'}; {'id': '126', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '127', 'type': 'block', 'children': ['128']}; {'id': '128', 'type': 'raise_statement', 'children': ['129']}, {'id': '129', 'type': 'call', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'ValueError'}, {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'binary_operator', 'children': ['133', '134'], 'value': '%'}, {'id': '133', 'type': 'string', 'children': [], 'value': '"Layer (%d) must be an integer between 1 and 2"'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'layer'}, {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '138']}, {'id': '137', 'type': 'identifier', 'children': [], 'value': 'nP'}; {'id': '138', 'type': 'call', 'children': ['139', '140']}, {'id': '139', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'ref_elements'}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}, {'id': '143', 'type': 'assignment', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'nQ'}, {'id': '145', 'type': 'call', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'len'}, {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'est_elements'}, {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'assignment', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'F'}; {'id': '152', 'type': 'call', 'children': ['153', '156']}, {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'zeros'}; {'id': '156', 'type': 'argument_list', 'children': ['157']}, {'id': '157', 'type': 'tuple', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'nP'}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'nQ'}; {'id': '160', 'type': 'for_statement', 'children': ['161', '162', '166']}, {'id': '161', 'type': 'identifier', 'children': [], 'value': 'iP'}; {'id': '162', 'type': 'call', 'children': ['163', '164']}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}, {'id': '165', 'type': 'identifier', 'children': [], 'value': 'nP'}; {'id': '166', 'type': 'block', 'children': ['167']}, {'id': '167', 'type': 'for_statement', 'children': ['168', '169', '173']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'iQ'}, {'id': '169', 'type': 'call', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'range'}, {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'nQ'}, {'id': '173', 'type': 'block', 'children': ['174', '192', '206']}; {'id': '174', 'type': 'if_statement', 'children': ['175', '178', '183']}, {'id': '175', 'type': 'comparison_operator', 'children': ['176', '177'], 'value': '=='}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'layer'}, {'id': '177', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '178', 'type': 'block', 'children': ['179']}, {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '182']}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'compute_first_layer_PR'}, {'id': '183', 'type': 'elif_clause', 'children': ['184', '187']}; {'id': '184', 'type': 'comparison_operator', 'children': ['185', '186'], 'value': '=='}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'layer'}; {'id': '186', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '187', 'type': 'block', 'children': ['188']}; {'id': '188', 'type': 'expression_statement', 'children': ['189']}, {'id': '189', 'type': 'assignment', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'compute_second_layer_PR'}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}, {'id': '193', 'type': 'assignment', 'children': ['194', '197']}; {'id': '194', 'type': 'pattern_list', 'children': ['195', '196']}, {'id': '195', 'type': 'identifier', 'children': [], 'value': 'precision'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'recall'}, {'id': '197', 'type': 'call', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'func'}, {'id': '199', 'type': 'argument_list', 'children': ['200', '203']}; {'id': '200', 'type': 'subscript', 'children': ['201', '202']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'ref_elements'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'iP'}, {'id': '203', 'type': 'subscript', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'est_elements'}, {'id': '205', 'type': 'identifier', 'children': [], 'value': 'iQ'}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}, {'id': '207', 'type': 'assignment', 'children': ['208', '212']}; {'id': '208', 'type': 'subscript', 'children': ['209', '210', '211']}, {'id': '209', 'type': 'identifier', 'children': [], 'value': 'F'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'iP'}, {'id': '211', 'type': 'identifier', 'children': [], 'value': 'iQ'}; {'id': '212', 'type': 'call', 'children': ['213', '216']}, {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'util'}, {'id': '215', 'type': 'identifier', 'children': [], 'value': 'f_measure'}; {'id': '216', 'type': 'argument_list', 'children': ['217', '218']}, {'id': '217', 'type': 'identifier', 'children': [], 'value': 'precision'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'recall'}, {'id': '219', 'type': 'return_statement', 'children': ['220']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'F'}, {'id': '221', 'type': 'if_statement', 'children': ['222', '236']}; {'id': '222', 'type': 'boolean_operator', 'children': ['223', '229', '230'], 'value': 'or'}, {'id': '223', 'type': 'comparison_operator', 'children': ['224', '228'], 'value': '=='}; {'id': '224', 'type': 'call', 'children': ['225', '226']}, {'id': '225', 'type': 'identifier', 'children': [], 'value': '_n_onset_midi'}; {'id': '226', 'type': 'argument_list', 'children': ['227']}, {'id': '227', 'type': 'identifier', 'children': [], 'value': 'reference_patterns'}; {'id': '228', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '229', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '230', 'type': 'comparison_operator', 'children': ['231', '235'], 'value': '=='}, {'id': '231', 'type': 'call', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': '_n_onset_midi'}, {'id': '233', 'type': 'argument_list', 'children': ['234']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'estimated_patterns'}, {'id': '235', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '236', 'type': 'block', 'children': ['237']}, {'id': '237', 'type': 'return_statement', 'children': ['238']}; {'id': '238', 'type': 'expression_list', 'children': ['239', '240', '241']}, {'id': '239', 'type': 'float', 'children': [], 'value': '0.'}; {'id': '240', 'type': 'float', 'children': [], 'value': '0.'}, {'id': '241', 'type': 'float', 'children': [], 'value': '0.'}; {'id': '242', 'type': 'expression_statement', 'children': ['243']}, {'id': '243', 'type': 'assignment', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'F_2'}, {'id': '245', 'type': 'call', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'compute_layer'}, {'id': '247', 'type': 'argument_list', 'children': ['248', '249', '250']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'reference_patterns'}, {'id': '249', 'type': 'identifier', 'children': [], 'value': 'estimated_patterns'}; {'id': '250', 'type': 'keyword_argument', 'children': ['251', '252']}, {'id': '251', 'type': 'identifier', 'children': [], 'value': 'layer'}; {'id': '252', 'type': 'integer', 'children': [], 'value': '2'}, {'id': '253', 'type': 'expression_statement', 'children': ['254']}; {'id': '254', 'type': 'assignment', 'children': ['255', '256']}, {'id': '255', 'type': 'identifier', 'children': [], 'value': 'precision_3'}; {'id': '256', 'type': 'call', 'children': ['257', '260']}, {'id': '257', 'type': 'attribute', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '259', 'type': 'identifier', 'children': [], 'value': 'mean'}; {'id': '260', 'type': 'argument_list', 'children': ['261']}, {'id': '261', 'type': 'call', 'children': ['262', '265']}; {'id': '262', 'type': 'attribute', 'children': ['263', '264']}, {'id': '263', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '265', 'type': 'argument_list', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'F_2'}, {'id': '267', 'type': 'keyword_argument', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'axis'}, {'id': '269', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '270', 'type': 'expression_statement', 'children': ['271']}, {'id': '271', 'type': 'assignment', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'recall_3'}, {'id': '273', 'type': 'call', 'children': ['274', '277']}; {'id': '274', 'type': 'attribute', 'children': ['275', '276']}, {'id': '275', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'mean'}, {'id': '277', 'type': 'argument_list', 'children': ['278']}; {'id': '278', 'type': 'call', 'children': ['279', '282']}, {'id': '279', 'type': 'attribute', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '281', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '282', 'type': 'argument_list', 'children': ['283', '284']}, {'id': '283', 'type': 'identifier', 'children': [], 'value': 'F_2'}; {'id': '284', 'type': 'keyword_argument', 'children': ['285', '286']}, {'id': '285', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '286', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '287', 'type': 'expression_statement', 'children': ['288']}; {'id': '288', 'type': 'assignment', 'children': ['289', '290']}, {'id': '289', 'type': 'identifier', 'children': [], 'value': 'f_measure_3'}; {'id': '290', 'type': 'call', 'children': ['291', '294']}, {'id': '291', 'type': 'attribute', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'util'}, {'id': '293', 'type': 'identifier', 'children': [], 'value': 'f_measure'}; {'id': '294', 'type': 'argument_list', 'children': ['295', '296']}, {'id': '295', 'type': 'identifier', 'children': [], 'value': 'precision_3'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'recall_3'}, {'id': '297', 'type': 'return_statement', 'children': ['298']}; {'id': '298', 'type': 'expression_list', 'children': ['299', '300', '301']}, {'id': '299', 'type': 'identifier', 'children': [], 'value': 'f_measure_3'}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'precision_3'}, {'id': '301', 'type': 'identifier', 'children': [], 'value': 'recall_3'} | def three_layer_FPR(reference_patterns, estimated_patterns):
validate(reference_patterns, estimated_patterns)
def compute_first_layer_PR(ref_occs, est_occs):
s = len(_occurrence_intersection(ref_occs, est_occs))
precision = s / float(len(ref_occs))
recall = s / float(len(est_occs))
return precision, recall
def compute_second_layer_PR(ref_pattern, est_pattern):
F_1 = compute_layer(ref_pattern, est_pattern)
precision = np.mean(np.max(F_1, axis=0))
recall = np.mean(np.max(F_1, axis=1))
return precision, recall
def compute_layer(ref_elements, est_elements, layer=1):
if layer != 1 and layer != 2:
raise ValueError("Layer (%d) must be an integer between 1 and 2"
% layer)
nP = len(ref_elements)
nQ = len(est_elements)
F = np.zeros((nP, nQ))
for iP in range(nP):
for iQ in range(nQ):
if layer == 1:
func = compute_first_layer_PR
elif layer == 2:
func = compute_second_layer_PR
precision, recall = func(ref_elements[iP], est_elements[iQ])
F[iP, iQ] = util.f_measure(precision, recall)
return F
if _n_onset_midi(reference_patterns) == 0 or \
_n_onset_midi(estimated_patterns) == 0:
return 0., 0., 0.
F_2 = compute_layer(reference_patterns, estimated_patterns, layer=2)
precision_3 = np.mean(np.max(F_2, axis=0))
recall_3 = np.mean(np.max(F_2, axis=1))
f_measure_3 = util.f_measure(precision_3, recall_3)
return f_measure_3, precision_3, recall_3 |
{'id': '0', 'type': 'module', 'children': ['1']}, {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '28']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'match_notes'}, {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '9', '10', '13', '16', '19', '22', '25']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'ref_intervals'}, {'id': '5', 'type': 'identifier', 'children': [], 'value': 'ref_pitches'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'ref_velocities'}, {'id': '7', 'type': 'identifier', 'children': [], 'value': 'est_intervals'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'est_pitches'}, {'id': '9', 'type': 'identifier', 'children': [], 'value': 'est_velocities'}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}, {'id': '11', 'type': 'identifier', 'children': [], 'value': 'onset_tolerance'}; {'id': '12', 'type': 'float', 'children': [], 'value': '0.05'}, {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'pitch_tolerance'}, {'id': '15', 'type': 'float', 'children': [], 'value': '50.0'}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}, {'id': '17', 'type': 'identifier', 'children': [], 'value': 'offset_ratio'}; {'id': '18', 'type': 'float', 'children': [], 'value': '0.2'}, {'id': '19', 'type': 'default_parameter', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'offset_min_tolerance'}, {'id': '21', 'type': 'float', 'children': [], 'value': '0.05'}; {'id': '22', 'type': 'default_parameter', 'children': ['23', '24']}, {'id': '23', 'type': 'identifier', 'children': [], 'value': 'strict'}; {'id': '24', 'type': 'False', 'children': []}, {'id': '25', 'type': 'default_parameter', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'velocity_tolerance'}, {'id': '27', 'type': 'float', 'children': [], 'value': '0.1'}; {'id': '28', 'type': 'block', 'children': ['29', '46', '64', '74', '86', '95', '104', '114', '124', '157', '165', '176', '183', '189', '200']}, {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}, {'id': '31', 'type': 'identifier', 'children': [], 'value': 'matching'}; {'id': '32', 'type': 'call', 'children': ['33', '36']}, {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'transcription'}, {'id': '35', 'type': 'identifier', 'children': [], 'value': 'match_notes'}; {'id': '36', 'type': 'argument_list', 'children': ['37', '38', '39', '40', '41', '42', '43', '44', '45']}, {'id': '37', 'type': 'identifier', 'children': [], 'value': 'ref_intervals'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'ref_pitches'}, {'id': '39', 'type': 'identifier', 'children': [], 'value': 'est_intervals'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'est_pitches'}, {'id': '41', 'type': 'identifier', 'children': [], 'value': 'onset_tolerance'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'pitch_tolerance'}, {'id': '43', 'type': 'identifier', 'children': [], 'value': 'offset_ratio'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'offset_min_tolerance'}, {'id': '45', 'type': 'identifier', 'children': [], 'value': 'strict'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}, {'id': '47', 'type': 'assignment', 'children': ['48', '51']}; {'id': '48', 'type': 'pattern_list', 'children': ['49', '50']}, {'id': '49', 'type': 'identifier', 'children': [], 'value': 'min_velocity'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'max_velocity'}, {'id': '51', 'type': 'expression_list', 'children': ['52', '58']}; {'id': '52', 'type': 'call', 'children': ['53', '56']}, {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '55', 'type': 'identifier', 'children': [], 'value': 'min'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}, {'id': '57', 'type': 'identifier', 'children': [], 'value': 'ref_velocities'}; {'id': '58', 'type': 'call', 'children': ['59', '62']}, {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '61', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}, {'id': '63', 'type': 'identifier', 'children': [], 'value': 'ref_velocities'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}, {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'velocity_range'}, {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'max'}, {'id': '69', 'type': 'argument_list', 'children': ['70', '71']}; {'id': '70', 'type': 'integer', 'children': [], 'value': '1'}, {'id': '71', 'type': 'binary_operator', 'children': ['72', '73'], 'value': '-'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'max_velocity'}, {'id': '73', 'type': 'identifier', 'children': [], 'value': 'min_velocity'}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}, {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'ref_velocities'}, {'id': '77', 'type': 'binary_operator', 'children': ['78', '82'], 'value': '/'}; {'id': '78', 'type': 'parenthesized_expression', 'children': ['79']}, {'id': '79', 'type': 'binary_operator', 'children': ['80', '81'], 'value': '-'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'ref_velocities'}, {'id': '81', 'type': 'identifier', 'children': [], 'value': 'min_velocity'}; {'id': '82', 'type': 'call', 'children': ['83', '84']}, {'id': '83', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}, {'id': '85', 'type': 'identifier', 'children': [], 'value': 'velocity_range'}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}, {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'matching'}, {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}, {'id': '91', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'array'}, {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'matching'}, {'id': '95', 'type': 'if_statement', 'children': ['96', '101']}; {'id': '96', 'type': 'comparison_operator', 'children': ['97', '100'], 'value': '=='}, {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'matching'}, {'id': '99', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '100', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'return_statement', 'children': ['103']}, {'id': '103', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}, {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'ref_matched_velocities'}, {'id': '107', 'type': 'subscript', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'ref_velocities'}, {'id': '109', 'type': 'subscript', 'children': ['110', '111', '113']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'matching'}, {'id': '111', 'type': 'slice', 'children': ['112']}; {'id': '112', 'type': 'colon', 'children': []}, {'id': '113', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}, {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'est_matched_velocities'}, {'id': '117', 'type': 'subscript', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'est_velocities'}, {'id': '119', 'type': 'subscript', 'children': ['120', '121', '123']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'matching'}, {'id': '121', 'type': 'slice', 'children': ['122']}; {'id': '122', 'type': 'colon', 'children': []}, {'id': '123', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}, {'id': '125', 'type': 'assignment', 'children': ['126', '129']}; {'id': '126', 'type': 'pattern_list', 'children': ['127', '128']}, {'id': '127', 'type': 'identifier', 'children': [], 'value': 'slope'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'intercept'}, {'id': '129', 'type': 'subscript', 'children': ['130', '156']}; {'id': '130', 'type': 'call', 'children': ['131', '136']}, {'id': '131', 'type': 'attribute', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}, {'id': '133', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'linalg'}, {'id': '135', 'type': 'identifier', 'children': [], 'value': 'lstsq'}; {'id': '136', 'type': 'argument_list', 'children': ['137', '155']}, {'id': '137', 'type': 'attribute', 'children': ['138', '154']}; {'id': '138', 'type': 'call', 'children': ['139', '142']}, {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '141', 'type': 'identifier', 'children': [], 'value': 'vstack'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}, {'id': '143', 'type': 'list', 'children': ['144', '145'], 'value': '[est_matched_velocities,\n np.ones(len(est_matched_velocities))]'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'est_matched_velocities'}, {'id': '145', 'type': 'call', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}, {'id': '147', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'ones'}, {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'call', 'children': ['151', '152']}, {'id': '151', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}, {'id': '153', 'type': 'identifier', 'children': [], 'value': 'est_matched_velocities'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'T'}, {'id': '155', 'type': 'identifier', 'children': [], 'value': 'ref_matched_velocities'}; {'id': '156', 'type': 'integer', 'children': [], 'value': '0'}, {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '160']}, {'id': '159', 'type': 'identifier', 'children': [], 'value': 'est_matched_velocities'}; {'id': '160', 'type': 'binary_operator', 'children': ['161', '164'], 'value': '+'}, {'id': '161', 'type': 'binary_operator', 'children': ['162', '163'], 'value': '*'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'slope'}, {'id': '163', 'type': 'identifier', 'children': [], 'value': 'est_matched_velocities'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'intercept'}, {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'assignment', 'children': ['167', '168']}, {'id': '167', 'type': 'identifier', 'children': [], 'value': 'velocity_diff'}; {'id': '168', 'type': 'call', 'children': ['169', '172']}, {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'np'}, {'id': '171', 'type': 'identifier', 'children': [], 'value': 'abs'}; {'id': '172', 'type': 'argument_list', 'children': ['173']}, {'id': '173', 'type': 'binary_operator', 'children': ['174', '175'], 'value': '-'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'est_matched_velocities'}, {'id': '175', 'type': 'identifier', 'children': [], 'value': 'ref_matched_velocities'}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}, {'id': '177', 'type': 'assignment', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'velocity_within_tolerance'}, {'id': '179', 'type': 'parenthesized_expression', 'children': ['180']}; {'id': '180', 'type': 'comparison_operator', 'children': ['181', '182'], 'value': '<'}, {'id': '181', 'type': 'identifier', 'children': [], 'value': 'velocity_diff'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'velocity_tolerance'}, {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '186']}, {'id': '185', 'type': 'identifier', 'children': [], 'value': 'matching'}; {'id': '186', 'type': 'subscript', 'children': ['187', '188']}, {'id': '187', 'type': 'identifier', 'children': [], 'value': 'matching'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'velocity_within_tolerance'}, {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'assignment', 'children': ['191', '192']}, {'id': '191', 'type': 'identifier', 'children': [], 'value': 'matching'}; {'id': '192', 'type': 'list_comprehension', 'children': ['193', '197']}, {'id': '193', 'type': 'call', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'tuple'}, {'id': '195', 'type': 'argument_list', 'children': ['196']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '197', 'type': 'for_in_clause', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': '_'}, {'id': '199', 'type': 'identifier', 'children': [], 'value': 'matching'}; {'id': '200', 'type': 'return_statement', 'children': ['201']}, {'id': '201', 'type': 'identifier', 'children': [], 'value': 'matching'} | def match_notes(
ref_intervals, ref_pitches, ref_velocities, est_intervals, est_pitches,
est_velocities, onset_tolerance=0.05, pitch_tolerance=50.0,
offset_ratio=0.2, offset_min_tolerance=0.05, strict=False,
velocity_tolerance=0.1):
matching = transcription.match_notes(
ref_intervals, ref_pitches, est_intervals, est_pitches,
onset_tolerance, pitch_tolerance, offset_ratio, offset_min_tolerance,
strict)
min_velocity, max_velocity = np.min(ref_velocities), np.max(ref_velocities)
velocity_range = max(1, max_velocity - min_velocity)
ref_velocities = (ref_velocities - min_velocity)/float(velocity_range)
matching = np.array(matching)
if matching.size == 0:
return []
ref_matched_velocities = ref_velocities[matching[:, 0]]
est_matched_velocities = est_velocities[matching[:, 1]]
slope, intercept = np.linalg.lstsq(
np.vstack([est_matched_velocities,
np.ones(len(est_matched_velocities))]).T,
ref_matched_velocities)[0]
est_matched_velocities = slope*est_matched_velocities + intercept
velocity_diff = np.abs(est_matched_velocities - ref_matched_velocities)
velocity_within_tolerance = (velocity_diff < velocity_tolerance)
matching = matching[velocity_within_tolerance]
matching = [tuple(_) for _ in matching]
return matching |
Subsets and Splits