Commits

Takafumi Arakaki committed 7c2f3dc

added `file` option to `table-data`, `table-data-and-image`,
`dictdiff`, `find-images`, and `grid-images`.

Comments (0)

Files changed (3)

doc/source/changelog.rst

 v0.0.4
 ^^^^^^
 
+- Added `file` option to :rst:dir:`table-data`,
+  :rst:dir:`table-data-and-image`, :rst:dir:`dictdiff`,
+  :rst:dir:`find-images`, and :rst:dir:`grid-images`.
 - Added `ftype-{pickle,python,yaml,json}` options to
   :rst:dir:`table-data`, :rst:dir:`table-data-and-image` and
   :rst:dir:`dictdiff` so that they can read the data files

doc/source/index.rst

                            2011-03-*/data.json
               :base: my/experiment
 
-       will search the files matches to
-       ``my/experiment/2011-02-*/data.json`` and
+       will search the files which match to
+       ``my/experiment/2011-02-*/data.json`` or
+       ``my/experiment/2011-03-*/data.json``.
+
+   file : string (newlines removed)
+       This is an optional parameter to specify the name of the
+       data file.  If the tailing parts of the arguments are the
+       you can specify it using this option.
+
+       For example,
+
+       .. sourcecode:: rst
+
+           .. table-data:: 2011-02-* 2011-03-*
+              :file: data.json
+              :base: my/experiment
+
+       will search the files which matche to
+       ``my/experiment/2011-02-*/data.json`` or
        ``my/experiment/2011-03-*/data.json``.
 
    data : text [, text, ...]
        where the data files are searched from.
        See :rst:dir:`table-data` for the details.
 
+   file : string (newlines removed)
+       Specifies the tailing part of the directory where the data
+       files are searched from.
+       See :rst:dir:`table-data` for the details.
+
    data : text [, text, ...]
        A comma- or space-separated list of the :term:`dictionary path`.
        See :rst:dir:`table-data` for the details.
        where the data files are searched from.
        See :rst:dir:`table-data` for the details.
 
+   file : string (newlines removed)
+       Specifies the tailing part of the directory where the data
+       files are searched from.
+       See :rst:dir:`table-data` for the details.
+
    link : text [, text]
        A comma- or space-separated list of path to the link(s).
        See :rst:dir:`table-data` for the details.
        where the data files are searched from.
        See :rst:dir:`table-data` for the details.
 
+   file : string (newlines removed)
+       Specifies the tailing part of the directory where the data
+       files are searched from.
+       See :rst:dir:`table-data` for the details.
+
    param : text [, text]
        A comma- or space-separated list of the :term:`dictionary path`
        for the axes of the grid.
        where the data files are searched from.
        See :rst:dir:`table-data` for the details.
 
+   file : string (newlines removed)
+       Specifies the tailing part of the directory where the data
+       files are searched from.
+       See :rst:dir:`table-data` for the details.
+
    .. seealso:: :ref:`examples/find-images`
 
 
    Insert list of sub-pages.
 
 
-Recently Update Sub-pages - :rst:dir:`recent-pages`
----------------------------------------------------
+Recently Updated Sub-pages - :rst:dir:`recent-pages`
+----------------------------------------------------
 
 .. rst:directive:: .. recent-pages::
 
-   Insert list of recently update sub-pages.
+   Insert list of recently updated sub-pages.
 
    num : int
        Number of pages to show (default is 10).
         datadir = self._web.app.config['DATADIRPATH']
         base_syspath = path.join(datadir, node.get('base', ''))
         data_syspath_list = self._glob_list(
-            [path.join(base_syspath,
-                       directives.uri(arg)) for arg in arguments],
+            get_syspath_list(
+                arguments, base_syspath, node.get('file')),
             glob_list_sorted)
         link = node.get('link', [])
 
                 'relpath': path.relpath(parent_syspath, base_syspath),
                 })
             from_base = path.relpath(data_syspath, base_syspath)
+            if 'file' in node:
+                from_base = path.dirname(from_base)
             table_row = (
                 [from_base] +
                 [diff_data[keystr].get(data_syspath, '')
             title=title_from_path(
                 arguments,
                 node.get('base'),
+                node.get('file'),
                 'Diff of data found in: %s',
                 ))
         node.replace_self(table_node)
     return globed
 
 
-def title_from_path(pathlist, base=None, format='%s'):
+def get_syspath_list(path_list, base_syspath, filename=None):
+    syspath_list = [path.join(base_syspath, p) for p in path_list]
+    if filename is not None:
+        syspath_list = [path.join(p, filename) for p in syspath_list]
+    return syspath_list
+
+
+def title_from_path(pathlist, base=None, filename=None, format='%s'):
     """
     Format title string for searched path
 
     '{one, two}'
     >>> title_from_path(['one', 'two'], base='with_base')
     'with_base/{one, two}'
+    >>> title_from_path(['one', 'two'], base='with_base', filename='file.txt')
+    'with_base/{one, two}/file.txt'
 
     """
     base = '' if base is None else base
             base,
             '{%s}' % ', '.join(
                 [arg.strip(path.sep) for arg in pathlist]))
+    if filename:
+        pathstr = path.join(pathstr, filename)
     return format % pathstr
 
 
     final_argument_whitespace = True
     option_spec = {'data': parse_text_list,
                    'base': directives.path,
+                   'file': directives.path,
                    'link': parse_text_list,
                    'widths': directives.positive_int_list,
                    'path-order': choice_from('sort', 'sort_r'),
         base_syspath = path.join(datadir,
                                  self.options.get('base', ''))
         data_syspath_list = self._glob_list(
-            [path.join(base_syspath,
-                       directives.uri(arg))
-             for arg in self.arguments],
+            get_syspath_list(
+                self.arguments, base_syspath, self.options.get('file')),
             glob_list_sorted)
         from_base_list = [
             path.relpath(x, base_syspath) for x in data_syspath_list]
+        if 'file' in self.options:
+            from_base_list = map(path.dirname, from_base_list)
 
         data_keys = self.options.get('data', [])
         colwidths = self.options.get('widths')
                            title=title_from_path(
                                self.arguments,
                                self.options.get('base'),
+                               self.options.get('file'),
                                'Data found in: %s'),
                            colwidths=colwidths)] + messages
 
     option_spec = {'data': parse_text_list,
                    'image': parse_text_list,
                    'base': directives.path,
+                   'file': directives.path,
                    'link': parse_text_list,
                    'path-order': choice_from('sort', 'sort_r'),
                    'sort': parse_text_list,
         base_syspath = path.join(datadir,
                                  self.options.get('base', ''))
         data_syspath_list = self._glob_list(
-            [path.join(base_syspath,
-                       directives.uri(arg))
-             for arg in self.arguments],
+            get_syspath_list(
+                self.arguments, base_syspath, self.options.get('file')),
             glob_list_sorted)
 
         data_keys = self.options.get('data', [])
             rows_highlight = [
                 i for (i, kv) in enumerate(key_val_list)
                 if kv[0] in diffkeys]
+            subtitle = path.relpath(data_syspath, base_syspath)
+            if 'file' in self.options:
+                subtitle = path.dirname(subtitle)
             subtable = gene_table(
                 key_val_list,
-                title=path.relpath(data_syspath, base_syspath),
+                title=subtitle,
                 rows_highlight=rows_highlight)
             # subtable = gene_table(
             #     data_table.get_nested_fnmatch(data_syspath, data_keys),
                            title=title_from_path(
                                self.arguments,
                                self.options.get('base'),
+                               self.options.get('file'),
                                'Data found in: %s'),
                            colwidths=colwidths)] + messages
 
     optional_arguments = OPTIONAL_ARGUMENTS_INF
     final_argument_whitespace = True
     option_spec = {'base': directives.path,
+                   'file': directives.path,
                    'link': parse_text_list,
                    'include': parse_text_list,
                    'exclude': parse_text_list,
     required_arguments = 1
     optional_arguments = OPTIONAL_ARGUMENTS_INF
     final_argument_whitespace = True
-    option_spec = {'base': directives.path}
+    option_spec = {'base': directives.path,
+                   'file': directives.path}
     has_content = False
 
     def run(self):
         base_syspath = path.join(datadir,
                                  self.options.get('base', ''))
         image_syspath_list = self._glob_list(
-            [path.join(base_syspath,
-                       directives.uri(arg))
-             for arg in self.arguments])
+            get_syspath_list(
+                self.arguments, base_syspath, self.options.get('file')))
 
         def gene_image(relpath):
             image_node = nodes.image(
     final_argument_whitespace = True
     option_spec = {'param': parse_text_list,
                    'image': parse_text_list,
-                   'base': directives.path}
+                   'base': directives.path,
+                   'file': directives.path}
     has_content = False
 
     def run(self):
         base_syspath = path.join(datadir,
                                  self.options.get('base', ''))
         data_syspath_list = self._glob_list(
-            [path.join(base_syspath, directives.uri(arg))
-             for arg in self.arguments])
+            get_syspath_list(
+                self.arguments, base_syspath, self.options.get('file')))
         data_table = self._DictTable.from_path_list(data_syspath_list)
         grid_dict = data_table.grid_dict(param)
 
 
         title = title_from_path(self.arguments,
                                 self.options.get('base'),
+                                self.options.get('file'),
                                 'Comparing images of data found in: %s')
 
         return [gene_table_from_grid_dict(grid_dict,