def __init__(self, file_ids=None, sheet_name=None): self.gsuite_secret_id = 'gsuite_gsbot_user' self.file_id = Misc.array_get(file_ids, 0) self.other_files = file_ids self.sheet_name = sheet_name self.gsheets = GSheets(self.gsuite_secret_id) self.gsheets_sync = API_Jira_Sheets_Sync(self.file_id, self.gsuite_secret_id) self.jira_api_rest = API_Jira_Rest() self.gsheets_create = API_Jira_Sheets_Create(self.file_id)
def test_array_get(self): array = ['1', 2, '3'] assert Misc.array_get(array, 0) == '1' assert Misc.array_get(array, 1) == 2 assert Misc.array_get(array, 2) == '3' assert Misc.array_get(array, -1) is None assert Misc.array_get(array, 3) is None assert Misc.array_get(array, None) is None assert Misc.array_get(None, None) is None
def handle_block_action(self,event): # todo: refactor in to separate method handler (specially when adding the lambda capability) channel = Misc.get_value(Misc.get_value(event,'channel'),'id') team_id = Misc.get_value(Misc.get_value(event,'team'),'id') actions = event.get('actions') handlers = { 'Jira_View_Issue': Jira_View_Issue} def send_message(message): if channel: slack_message(message,[], channel, team_id) else: return message try: for action in actions: split_action = action.get('action_id').split('::') action_type = Misc.array_get(split_action, 0) action_class = Misc.array_get(split_action, 1) action_method = Misc.array_get(split_action, 2) if action_type == 'class_method': if action_class and action_method: target = handlers.get(action_class) if target: try: method = getattr(target, action_method) #slack_message(':point_right: Invoking method `{0}.{1}`'.format(action_class,action_method), [], channel, team_id) try: target_obj = target(channel=channel,team_id=team_id, event=event) return method(target_obj, action) except Exception as error: return send_message(':red_circle: Error in `handle_block_action` invocation of method `{0}.{1}`: `{2}`'.format(action_class,action_method, error)) except: return send_message(':red_circle: Error in `handle_block_action` could not resolve method: `{0}.{1}`'.format(action_class,action_method)) else: return send_message(':red_circle: Error in `handle_block_action` could not resolve class action: `{0}`'.format(action_class)) else: return send_message(':red_circle: Error in `handle_block_action` could not resolve action: `{0}`'.format(action)) #elif action_type == 'lambda': else: return send_message(':red_circle: Error in `handle_block_action` un-supported action type: `{0}`'.format(split_action)) return None except Exception as error: return send_message(":red_circle: error in handle_block_action: `{0}` . Actions value was `{1}`".format(error,actions))
def parse_ps_aux(raw_data): import re regex = re.compile('[\s]+') lines = raw_data.split('\n') headers = regex.split(lines.pop(0)) data = [] for line in lines: item = {} for index, header in enumerate(headers): values = regex.split(line) item[header] = Misc.array_get(values, index) data.append(item) return data