Esempio n. 1
0
    def get_snapshot_line(self, snapshot_entry):
        """
        Turns raw line from snapshot into a translated version for flat_log with style dictionary at end
        :param snapshot_entry: A line in the snapshot part of the log
        :return: line entry for flat_log with style dictionary at end
        """
        line = []
        for key in gsuite.CHUNKED_ORDER:
            line.append(snapshot_entry[key])

        action_type = mappings.remap(snapshot_entry['ty'])
        style_mod = json.dumps(self.rename_keys(snapshot_entry['sm']))
        line.append(action_type)
        line.append(style_mod)

        return line
Esempio n. 2
0
    def rename_keys(self, log_dict):
        """rename minified variables using mappings in `mappings.py`. preserves order"""
        log_dict = OrderedDict(log_dict)
        for key in log_dict.keys():
            try:
                new_key = mappings.remap(key)
                log_dict[new_key] = log_dict.pop(key)

                # recursively replace deep dictionaries
                if isinstance(log_dict[new_key], dict):
                    log_dict[new_key] = self.rename_keys(log_dict[new_key])
            except KeyError:
                # if key is not in mappings, leave old key unchanged.
                pass

        return log_dict
Esempio n. 3
0
    def flatten_mts(self, entry, line_copy, line):
        """ Recursively flatten multiset entry.

      Args:
        entry: an entry in changelog
        line_copy: a flattened list of each mts action appended to line
        line:  shared info for the entry( id, revision, timestamp, etc)
      Returns:
        None.  line_copy contains flattened entries to be appended to log.
      """
        if 'mts' not in entry:
            new_line = list(line)
            mts_action = mappings.remap(entry['ty'])

            # add action & action dictionary with descriptive keys
            new_line.append(mts_action)
            new_line.append(json.dumps(self.rename_keys(entry)))
            line_copy.append(new_line)

        else:
            for item in entry['mts']:
                self.flatten_mts(item, line_copy, line)
Esempio n. 4
0
    def parse_log(self, c_log, flat_log):
        """parses changelog part of log"""

        flat_log.append('changelog')
        for entry in c_log:
            action_dict = entry[0]
            ts_id_info = entry[1:-1]
            line = ts_id_info

            # break up multiset into components
            if 'mts' in action_dict:
                line_copy = []
                self.flatten_mts(action_dict, line_copy, line)
                for item in line_copy:
                    flat_log.append(
                        self.delimiter.join(str(col) for col in item))
            else:
                action_type = mappings.remap(action_dict['ty'])
                line.append(action_type)
                line.append(json.dumps(self.rename_keys(action_dict)))
                flat_log.append(self.delimiter.join(
                    str(item) for item in line))