Changeset 66481


Ignore:
Timestamp:
Oct 12, 2015, 5:34:33 PM (9 years ago)
Author:
wenzeslaus
Message:

don't change links for the actual HTML files, don't guess from addon names

r66479 and r66480 were doing nothing as the actual HTMLs are in docs/html directory.

Adding path to existing HTMLs as a 3rd parameter to update_manual.py. In this
way it is possible to test it locally.

The tree is traversed for every file to find existing HTMLs (as opposed to
having one script to fix all files or storing filenames in a file).
With all HTMLs in trunk's dist dir and searching in trunk including dist dir
it takes real 3m45.726s, user 2m16.512s, sys 1m23.124s. The addons case
should be smaller.

Location:
grass-addons/tools/addons
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • grass-addons/tools/addons/grass-addons-build.sh

    r65890 r66481  
    3131        if [ -d $dir/docs/html ] ; then
    3232            for f in `pwd`/$dir/docs/html/*.html ; do
    33                 ${SRC}grass-addons/tools/addons/update_manual.py $f http://grass.osgeo.org/grass${1}${2}/manuals
     33                ${SRC}grass-addons/tools/addons/update_manual.py $f http://grass.osgeo.org/grass${1}${2}/manuals `pwd`
    3434            done
    3535            cp -r $dir/docs/html/* $HTMLDIR/ 2>/dev/null
  • grass-addons/tools/addons/update_manual.py

    r66480 r66481  
    99
    1010
    11 def get_addons(path):
    12     """Get list of addons
     11def get_pages(path):
     12    """Get list of HTML pages in the given directory and its subdirectories
    1313
    14     Goes two levels deep to get directory names which are assumed
    15     to be addon names.
     14    Only filenames are returned, not the paths.
    1615    """
    17     top_directories = os.walk(path).next()[1]
    18     addons = []
    19     for directory in top_directories:
    20         addons.extend(os.walk(directory).next()[1])
    21     addons.extend(top_directories)
    22     return addons
     16    matches = []
     17    for root, dirnames, filenames in os.walk(path):
     18        for filename in filenames:
     19            if filename.endswith('.html'):
     20                matches.append(filename)
     21    return matches
    2322
    2423
    25 def main(htmlfile, prefix):
     24def main(htmlfile, prefix, html_directory):
    2625    try:
    2726        f = open(htmlfile)
     
    3635    # find URIs
    3736    pattern = r'''<a href="([^"]+)">([^>]+)</a>'''
    38     # TODO: replace the magic 4 by passing the base addons dir as parameter
    39     addons = get_addons(os.sep.join(htmlfile.split(os.sep)[:4]))
     37    addon_pages = get_pages(html_directory)
    4038    for match in re.finditer(pattern, shtml):
    4139        # most common URLs
     
    4947        # TODO: perhaps we could match any *://
    5048        # link to other addon
    51         if match.group(1).replace('.html', '') in addons:
     49        if match.group(1) in addon_pages:
    5250            continue
    5351        pos.append(match.start(1))
     
    7371
    7472if __name__ == "__main__":
    75     if len(sys.argv) != 3:
    76         sys.exit("provide file and url")
    77     main(sys.argv[1], sys.argv[2])
     73    if len(sys.argv) != 4:
     74        sys.exit("Provide file, URL and directory with other HTML files")
     75    main(sys.argv[1], sys.argv[2], sys.argv[3])
Note: See TracChangeset for help on using the changeset viewer.