[GRASS-dev] [GRASS GIS] #2864: Add link to source code in the documentation pages.

GRASS GIS trac at osgeo.org
Tue Jan 12 09:27:51 PST 2016


#2864: Add link to source code in the documentation pages.
--------------------------+----------------------------------
  Reporter:  pmav99       |      Owner:  grass-dev@…
      Type:  enhancement  |     Status:  new
  Priority:  normal       |  Milestone:  7.0.4
 Component:  Docs         |    Version:  svn-releasebranch70
Resolution:               |   Keywords:  open science, access
       CPU:  Unspecified  |   Platform:  Unspecified
--------------------------+----------------------------------

Comment (by pmav99):

 I am afraid that this still does not work with scripts like those in
 `raster/r.li/r.li.*` and `imagery/i.ortho.photo/i.ortho.*`. Anyway,
 instead of adding special cases all over the place, wouldn't a single
 function be a cleaner solution?

 This should also work with addons (at least I don't see why it wouldn't).
 Efficiency is not really relevant in documentation generation code and
 even if it is it should be addressed as a separate issue (get it working
 first, fast later).
 {{{
 import os
 import urlparse


 def get_source_code_url(pgm, base_url, root_path):
     """
     Return a url to the source code of `pgm`.

     If the link cannot be constructed, return the url to the repo's root
 directory.

     Parameters
     ----------
     pgm: str
         The name of the GRASS command.
     base_url: str
         The base url of the online source code browser.
     root_path: str
         The relative path to repository's root directory.

     """
     url = base_url
     for root, dirs, files in os.walk(root_path):
         for name in dirs:
             if name == pgm:
                 pgm_path = os.path.join(root, name)
                 url = urlparse.urljoin(base_url, pgm_path)
                 return url
     return url
 }}}

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2864#comment:13>
GRASS GIS <https://grass.osgeo.org>



More information about the grass-dev mailing list