a helper method for parsing docker ps output

def _ps(self, sys_output):
        
        ''' a helper method for parsing docker ps output '''
        
        import re
        gap_pattern = re.compile('\t|\s{2,}')
        container_list = []
        output_lines = sys_output.split('\n')
        column_headers = gap_pattern.split(output_lines[0])
        for i in range(1,len(output_lines)):
            columns = gap_pattern.split(output_lines[i])
            container_details = {}
            if len(columns) > 1:
                for j in range(len(column_headers)):
                    container_details[column_headers[j]] = ''
                    if j <= len(columns) - 1:
                        container_details[column_headers[j]] = columns[j]
        # stupid hack for possible empty port column
                if container_details['PORTS'] and not container_details['NAMES']:
                    from copy import deepcopy
                    container_details['NAMES'] = deepcopy(container_details['PORTS'])
                    container_details['PORTS'] = ''
                container_list.append(container_details)
    
        return container_list