summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--grc/base/Platform.py8
-rw-r--r--grc/python/Block.py6
-rw-r--r--grc/python/Makefile.am1
-rw-r--r--grc/python/expr_utils.py2
-rw-r--r--grc/python/extract_category.py61
-rw-r--r--grc/python/extract_docs.py4
6 files changed, 75 insertions, 7 deletions
diff --git a/grc/base/Platform.py b/grc/base/Platform.py
index 6cbe741dd..3050e5e47 100644
--- a/grc/base/Platform.py
+++ b/grc/base/Platform.py
@@ -19,7 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
import os
import sys
-from .. base import ParseXML
+from .. base import ParseXML, odict
from Element import Element as _Element
from FlowGraph import FlowGraph as _FlowGraph
from Connection import Connection as _Connection
@@ -66,11 +66,11 @@ class Platform(_Element):
if os.path.isfile(block_path): xml_files.append(block_path)
elif os.path.isdir(block_path):
for dirpath, dirnames, filenames in os.walk(block_path):
- for filename in filter(lambda f: f.endswith('.xml'), filenames):
+ for filename in sorted(filter(lambda f: f.endswith('.xml'), filenames)):
xml_files.append(os.path.join(dirpath, filename))
#load the blocks
- self._blocks = dict()
- self._blocks_n = dict()
+ self._blocks = odict()
+ self._blocks_n = odict()
self._block_tree_files = list()
for xml_file in xml_files:
try: #try to add the xml file as a block wrapper
diff --git a/grc/python/Block.py b/grc/python/Block.py
index a9e999491..6d7595777 100644
--- a/grc/python/Block.py
+++ b/grc/python/Block.py
@@ -19,6 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
from .. base.Block import Block as _Block
import extract_docs
+import extract_category
class Block(_Block):
@@ -128,6 +129,11 @@ class Block(_Block):
#merge custom doc with doxygen docs
return '\n'.join([doc, extract_docs.extract(self.get_key())]).strip('\n')
+ def get_category(self):
+ #category = extract_category.extract(self.get_key())
+ #if category: return category
+ return _Block.get_category(self)
+
def get_imports(self):
"""
Resolve all import statements.
diff --git a/grc/python/Makefile.am b/grc/python/Makefile.am
index e6d253f5c..0a62c0825 100644
--- a/grc/python/Makefile.am
+++ b/grc/python/Makefile.am
@@ -25,6 +25,7 @@ ourpythondir = $(grc_src_prefix)/python
ourpython_PYTHON = \
convert_hier.py \
expr_utils.py \
+ extract_category.py \
extract_docs.py \
Block.py \
Connection.py \
diff --git a/grc/python/expr_utils.py b/grc/python/expr_utils.py
index 1880c8f9c..1bee22497 100644
--- a/grc/python/expr_utils.py
+++ b/grc/python/expr_utils.py
@@ -1,5 +1,5 @@
"""
-Copyright 2008 Free Software Foundation, Inc.
+Copyright 2008, 2009 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
diff --git a/grc/python/extract_category.py b/grc/python/extract_category.py
new file mode 100644
index 000000000..f9358f616
--- /dev/null
+++ b/grc/python/extract_category.py
@@ -0,0 +1,61 @@
+"""
+Copyright 2009 Free Software Foundation, Inc.
+This file is part of GNU Radio
+
+GNU Radio Companion is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+GNU Radio Companion is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+"""
+
+from Constants import DOCS_DIR
+from lxml import etree
+import os
+import re
+
+DOXYGEN_TITLE_XPATH = '/doxygen/compounddef/title'
+DOXYGEN_CLASS_XPATH = '/doxygen/compounddef/innerclass'
+
+#map a group/category to a list of blocks
+_category_map = dict()
+
+#extract the group/category information
+docs_dir = os.path.join(DOCS_DIR, 'xml')
+if os.path.exists(docs_dir):
+ group_file_matcher = re.compile('^group__\w*\..*$') #xml or xml.gz
+ matches = filter(lambda f: group_file_matcher.match(f), os.listdir(docs_dir))
+ for match in matches:
+ try:
+ xml_file = os.path.join(docs_dir, match)
+ xml = etree.parse(xml_file)
+ category = xml.xpath(DOXYGEN_TITLE_XPATH)[0].text
+ blocks = map(lambda x: x.text, xml.xpath(DOXYGEN_CLASS_XPATH))
+ _category_map[category] = blocks
+ except: pass
+
+def extract(key):
+ """
+ Match the given key to a key in an existing category.
+ If no match can be made, return an empty string.
+ @param key the block key
+ @return the category or empty string
+ """
+ pattern = key.replace('_', '_*').replace('x', '\w')
+ class_name_matcher = re.compile('^%s$'%pattern)
+ for category, blocks in _category_map.iteritems():
+ for block in blocks:
+ if class_name_matcher.match(block): return category
+ return ''
+
+if __name__ == '__main__':
+ import sys
+ print extract(sys.argv[1])
diff --git a/grc/python/extract_docs.py b/grc/python/extract_docs.py
index fa9140bdf..f0c1e749c 100644
--- a/grc/python/extract_docs.py
+++ b/grc/python/extract_docs.py
@@ -52,8 +52,8 @@ def _extract(key):
if not os.path.exists(docs_dir): return ''
#extract matches
pattern = key.replace('_', '_*').replace('x', '\w')
- prog = re.compile('^class%s\..*$'%pattern)
- matches = filter(lambda f: prog.match(f), os.listdir(docs_dir))
+ class_file_matcher = re.compile('^class%s\..*$'%pattern) #xml or xml.gz
+ matches = filter(lambda f: class_file_matcher.match(f), os.listdir(docs_dir))
#combine all matches
doc_strs = list()
for match in matches: