diff options
| -rw-r--r-- | blockext/__init__.py | 6 | ||||
| -rw-r--r-- | blockext/scratch.py | 23 |
2 files changed, 19 insertions, 10 deletions
diff --git a/blockext/__init__.py b/blockext/__init__.py index adff2b1..84c677a 100644 --- a/blockext/__init__.py +++ b/blockext/__init__.py @@ -59,8 +59,10 @@ class Blockext(BaseHTTPRequestHandler): requests = {} def log_message(self, format, *args): - if isinstance(args[0], str) and args[0].startswith("GET /poll"): - return + if isinstance(args[0], str): + words = args[0].split(" ") + if words[0] == "GET" and words[1] in ("/poll"): #, "/get_specs"): + return return BaseHTTPRequestHandler.log_message(self, format, *args) @classmethod diff --git a/blockext/scratch.py b/blockext/scratch.py index b4440ec..0a0b848 100644 --- a/blockext/scratch.py +++ b/blockext/scratch.py @@ -24,21 +24,25 @@ BLOCK_SHAPES = { "predicate": "b", } +def generate_specs(): + blockspecs = [] + for name, block in Blockext.blocks.items(): + if block.is_hidden: continue + shape = BLOCK_SHAPES[block.shape] + if block.shape == "command" and block.is_blocking: + shape = "w" + blockspec = [shape, block.text, name] + block.defaults + blockspecs.append(blockspec) + return blockspecs + @handler("scratch_{filename}.s2e", display="Download Scratch 2.0 extension") def generate_s2e(is_browser=False): extension = { "extensionName": Blockext.name, "extensionPort": Blockext.port, - "blockSpecs": [], + "blockSpecs": generate_specs(), "menus": Blockext.menus, } - for name, block in Blockext.blocks.items(): - if block.is_hidden: continue - shape = BLOCK_SHAPES[block.shape] - if block.shape == "command" and block.is_blocking: - shape = "w" - blockspec = [shape, block.text, name] + block.defaults - extension["blockSpecs"].append(blockspec) return ("application/octet-stream", json.dumps(extension)) @@ -74,3 +78,6 @@ def poll(is_browser=False): def _busy(): return " ".join(map(str, Blockext.requests)) +@handler("get_specs", hidden=True) +def _get_specs(is_browser=False): + return generate_s2e(is_browser) |
