summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorblob8108 <blob8108@gmail.com>2014-02-04 16:27:05 +0000
committerblob8108 <blob8108@gmail.com>2014-02-04 16:27:05 +0000
commita9899d723f84accaaaf7e7319bbe8133f4a892b3 (patch)
tree3c7f637d55947bfcf1bdec823c420162ba038106
parentc0f175accef3dacfd50bb873f957aeb0bb414e69 (diff)
downloadblockext-get-specs.tar.gz
blockext-get-specs.zip
Implement Scratch 2.0 `get_specs` commandget-specs
-rw-r--r--blockext/__init__.py6
-rw-r--r--blockext/scratch.py23
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)