コード例 #1
0
    def render_POST(self, request):
        #
        # Turn a path or show command into a set of candidate protobuf definitions.
        # If it looks like a show command, then schema-describe it, get the set of
        # paths, and run the GPB generation on each one. Otherwise, just run that on
        # the sole provided path.
        #
        path = request.args['path'][0].strip()
        if path.startswith('sh'):
            d = scrape.schema_describe(path, request.sdata)
        else:
            d = defer.succeed([path])
        
        def request_protobufs(paths):
            print('### PROTOBUF PATHS = {}'.format(paths))
            ds = []
            for path in reversed(paths):
                path = re.sub('\(.*?\)', '', path)
                ds.append(request.sdata.api.cli_exec(
                            'run telemetry_generate_gpb "{}"'.format(path)))
            return defer.DeferredList(ds)
        d.addCallback(request_protobufs)

        def get_protobufs(replies):
            line = '-' * 77
            sep = '\n//\n// ' + line + '\n//\n\n'
            text = sep.join([reply[1]['result'] for reply in replies])
            request.sdata.set_text('#protobuf_result', text)
            request.sdata.add_to_push_queue('stop_current_spinner')
            request.sdata.highlight('#protobuf_result')
        d.addCallback(get_protobufs)

        request.setHeader('Content-Type', 'application/json')
        return '{}'
コード例 #2
0
 def handle_misses(self, request, mapper, map_misses):
     self.num_misses = len(map_misses)
     self.found_values = []
     for i, miss in enumerate(map_misses):
         progress_indicator(
             request,
             "Incomplete mapping from cache, calculating remainder [{}/{}]..."
                 .format(i + 1, self.num_misses))
         print('### FETCHING MISS {}/{}: {}'.format(i, self.num_misses, miss))
         d = scrape.schema_describe('config ' + miss, request.sdata)
         def got_miss_reply(result, key):
             result = [re.sub("'", '"', path) for path in result]
             if len(result) == 0:
                 result = None
             print('### GOT RESULT ({} remaining, {} saved) {} -> {}'.format(
                     self.num_misses, len(self.found_values), key, result))
             self.found_values.append((key, result))
             self.num_misses -= 1
             if self.num_misses == 0:
                 # Got everything!
                 mapper.populate_cache(self.found_values)
                 self.attempt_map(request, second_attempt=True)
         d.addCallback(got_miss_reply, miss)
コード例 #3
0
    def render_POST(self, request):
        #
        # Turn a path or show command into a set of candidate protobuf definitions.
        # If it looks like a show command, then schema-describe it, get the set of
        # paths, and run the GPB generation on each one. Otherwise, just run that on
        # the sole provided path.
        #
        path = request.args['path'][0].strip()
        if path.startswith('sh'):
            d = scrape.schema_describe(path, request.sdata)
        else:
            d = defer.succeed([path])

        def request_protobufs(paths):
            print('### PROTOBUF PATHS = {}'.format(paths))
            ds = []
            for path in reversed(paths):
                path = re.sub('\(.*?\)', '', path)
                ds.append(
                    request.sdata.api.cli_exec(
                        'run telemetry_generate_gpb "{}"'.format(path)))
            return defer.DeferredList(ds)

        d.addCallback(request_protobufs)

        def get_protobufs(replies):
            line = '-' * 77
            sep = '\n//\n// ' + line + '\n//\n\n'
            text = sep.join([reply[1]['result'] for reply in replies])
            request.sdata.set_text('#protobuf_result', text)
            request.sdata.add_to_push_queue('stop_current_spinner')
            request.sdata.highlight('#protobuf_result')

        d.addCallback(get_protobufs)

        request.setHeader('Content-Type', 'application/json')
        return '{}'