www-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

www/server/source/linc linc.py


From: Ineiev
Subject: www/server/source/linc linc.py
Date: Mon, 8 Nov 2021 05:09:15 -0500 (EST)

CVSROOT:        /web/www
Module name:    www
Changes by:     Ineiev <ineiev> 21/11/08 05:09:15

Modified files:
        server/source/linc: linc.py 

Log message:
        Make the '-s' option work, fix line number output, normalize paths,
        use os.path routines to get directory names.

CVSWeb URLs:
http://web.cvs.savannah.gnu.org/viewcvs/www/server/source/linc/linc.py?cvsroot=www&r1=1.33&r2=1.34

Patches:
Index: linc.py
===================================================================
RCS file: /web/www/www/server/source/linc/linc.py,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -b -r1.33 -r1.34
--- linc.py     8 Dec 2016 07:18:08 -0000       1.33
+++ linc.py     8 Nov 2021 10:09:15 -0000       1.34
@@ -3,7 +3,7 @@
 #
 # LINC - LINC Is Not Checklink
 # Copyright © 2011, 2012 Wacław Jacek
-# Copyright © 2013, 2014, 2015, 2016 Free Software Foundation, Inc.
+# Copyright © 2013, 2014, 2015, 2016, 2021 Free Software Foundation, Inc.
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -20,13 +20,13 @@
 
 from __future__ import print_function
 
-LINC_VERSION = 'LINC 0.29'
+LINC_VERSION = 'LINC 0.30'
 USAGE = \
 '''Usage: %prog [options] [BASE_DIRECTORY]
 Check links in HTML files from BASE_DIRECTORY.'''
 COPYRIGHT= \
 '''Copyright (C) 2011, 2012 Waclaw Jacek
-Copyright (C) 2013, 2014, 2015, 2016 Free Software Foundation, Inc.
+Copyright (C) 2013, 2014, 2015, 2016, 2021 Free Software Foundation, Inc.
 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
 This is free software: you are free to change and redistribute it.
 There is NO WARRANTY, to the extent permitted by law.
@@ -114,7 +114,7 @@
 LINK_REGEXP = \
 [ '(?is)^<a(\s.+?)?\shref="(?P<link>[^"]+)"(\s.+?)?>',
   "(?is)^<a(\s.+?)?\shref='(?P<link>[^']+)'(\s.+?)?>"]
-TRANSLATION_REGEXP = '\.(?P<langcode>[a-z]{2}|[a-z]{2}-[a-z]{2})\.[^.]+$'
+TRANSLATION_REGEXP = '\.(?P<langcode>[a-z]{2}|[a-z]{2}-[a-z]{2})\.html$'
 SYMLINK_REGEXP='^\s*(?P<to>[^\s]*)\s+(?P<from>[^\s]*).*$'
 EOH_MARK = '\r\n\r\n'
 REFRESH_REGEXP = '''(?is)^\s*<meta\s[^>]*http-equiv=['"]refresh['"]'''
@@ -153,7 +153,7 @@
 def format_error(symlink, filename, line_number, link, error_message):
        if symlink != None:
                filename += ' <- ' + symlink
-       return filename + ':' + str(line_number) + ': ' \
+       return filename + line_number \
               + link.replace(' ', '%20') + ' ' + error_message + '\n'
 
 def get_ftp_link_error(link):
@@ -384,11 +384,9 @@
        elif link[0] == '/':
                link = remote_site + link[1:]
        else:
-               subdir = ''
-               pos = dir_name.rfind('/')
-               if pos != -1:
-                       subdir = dir_name[: pos] + '/'
-               link = remote_base_directory + subdir + link
+               subdir = os.path.join (remote_base_directory, \
+                                      os.path.dirname (dir_name))
+               link = subdir + link
        return [link_type, link]
 
 def scan_file(root, file_to_check, symlink = None):
@@ -420,7 +418,7 @@
                if link_type == 'unsupported':
                        continue
                links_to_check.append({'symlink': symlink, 'URL': url,
-                                      'filename': file_to_check,
+                                      'filename': os.path.normpath 
(file_to_check),
                                       'line_number': str(line_no),
                                       'link': match.group('link'),
                                       'is_inside_comment': commented})
@@ -445,6 +443,8 @@
                        continue
                if not re.search(FILENAMES_TO_CHECK_REGEXP, element_name):
                        continue
+               if SKIP_TRANSLATION_FILES and re.search(TRANSLATION_REGEXP, 
element_name):
+                       continue
                if re.search(EXCLUDED_FILENAMES_REGEXP, relative_path):
                        continue
                scan_file(root, relative_path)
@@ -465,13 +465,8 @@
        path = os.path.join(directory, destination)
        if path[0] == '/':
                path = path[1:]
-       pos = path.rfind('/')
-       if pos == -1:
-               dest = path
-               new_dir = ""
-       else:
-               dest = path[pos + 1:]
-               new_dir = path[:pos]
+       new_dir = os.path.dirname (path)
+       dest = os.path.basename (path)
        while re.search('[^/]*/../', new_dir):
                new_dir = re.sub('[^/]*/../', '', new_dir)
        if os.path.exists(os.path.join(root, path)):
@@ -514,8 +509,8 @@
        if link_type == 'unsupported':
                return
        links_to_check.append({'symlink': None, 'URL': url,
-                              'filename': file_to_check,
-                              'line_number': 
symlinks[directory][source]['line'],
+                              'filename': os.path.normpath (file_to_check),
+                              'line_number': str 
(symlinks[directory][source]['line']),
                               'link': destination,
                               'is_inside_comment': False})
        if not url in urls_to_check:
@@ -687,11 +682,10 @@
 if len(args) != 0:
        BASE_DIRECTORY = args[0]
 else:
-       prog_dir = sys.argv[0]
-       pos = prog_dir.rfind('/')
-       prog_dir = prog_dir[ : pos] if (pos != -1) else './'
-       # This script's place is /server/source/linc
-       BASE_DIRECTORY = os.path.abspath(os.path.join(prog_dir, '../../..'))
+       prog_dir = os.path.dirname (sys.argv[0])
+       # This script's place is /server/source/linc.
+       BASE_DIRECTORY = os.path.abspath (os.path.join (prog_dir, '../../..'))
+       BASE_DIRECTORY = os.path.normpath (BASE_DIRECTORY)
 
 if options.quiet != None:
        VERBOSE -= options.quiet
@@ -855,7 +849,7 @@
 
 for i, link_container in enumerate(links_to_check):
        filename = link_container['filename']
-       line_number = link_container['line_number']
+       line_number = ':' + link_container['line_number'] + ': '
        url = link_container['URL']
        link = link_container['link']
        commented = link_container['is_inside_comment']
@@ -866,14 +860,14 @@
                continue
 
        if link[0] != '/' and not re.search('^[^/]*:', link):
-               report (2, filename + ':' + line_number \
-                       + ': link ' + str(i) + ' `' + link + "' is relative")
+               report (2, filename + line_number \
+                       + 'link ' + str(i) + ' `' + link + "' is relative")
 
        if url in checked_urls:
                link_error = checked_urls[url]
        else:
-               report (-3, filename + ':' + line_number \
-                        + ': Unchecked link `' + url + "' detected.")
+               report (-3, filename + line_number \
+                        + 'Unchecked link `' + url + "' detected.")
                if WICKED > 0:
                        print ('Aborting due to an unchecked link.')
                        exit(1)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]