]> Savannah Git Hosting - gnulib.git/commitdiff
gnulib-tool.py: Make option --version work.
authorBruno Haible <bruno@clisp.org>
Fri, 5 Aug 2022 12:17:35 +0000 (14:17 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 5 Aug 2022 13:06:26 +0000 (15:06 +0200)
* pygnulib/constants.py (__copyright__): Bump copyright year.
* pygnulib/GLInfo.py (GLInfo.authors): Add a comma after the
second-to-last author.
(GLInfo.copyright): Show only the last modification year.
(GLInfo.date): Check whether git and GNU date are available. Use
'git log ChangeLog', not 'git log'. Run 'git log' in the gnulib
directory, not in the current directory. Search for 'Date:' only at the
beginning of a line. As a fallback, look at the first ChangeLog entry.
(GLInfo.version): Check whether git is available. Run git-version-gen in
the gnulib directory, not in the current directory. Replace '-dirty'
with '-modified'. As a fallback, return the empty string.
* gnulib-tool.py (main) [--version]: Add a space before the version.

ChangeLog
gnulib-tool.py
gnulib-tool.py.TODO
pygnulib/GLInfo.py
pygnulib/constants.py

index e504d85215125fd6a98a6919e69a599567894804..81871735d2989e2d83a4d84e9ccdadbd2ee67d43 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
 2022-08-05  Bruno Haible  <bruno@clisp.org>
 
+       gnulib-tool.py: Make option --version work.
+       * pygnulib/constants.py (__copyright__): Bump copyright year.
+       * pygnulib/GLInfo.py (GLInfo.authors): Add a comma after the
+       second-to-last author.
+       (GLInfo.copyright): Show only the last modification year.
+       (GLInfo.date): Check whether git and GNU date are available. Use
+       'git log ChangeLog', not 'git log'. Run 'git log' in the gnulib
+       directory, not in the current directory. Search for 'Date:' only at the
+       beginning of a line. As a fallback, look at the first ChangeLog entry.
+       (GLInfo.version): Check whether git is available. Run git-version-gen in
+       the gnulib directory, not in the current directory. Replace '-dirty'
+       with '-modified'. As a fallback, return the empty string.
+       * gnulib-tool.py (main) [--version]: Add a space before the version.
+
        gnulib-tool.py: Simplify.
        * pygnulib/constants.py (compiler): Remove function.
        * gnulib-tool.py: Use re.compile directly instead.
index 1a6bd9e948886d96e805c86d9a768f011e1982ec..c4386133a62c4f3a21a7be00078cc0e2804d5cd0 100755 (executable)
@@ -397,8 +397,11 @@ def main():
         print(info.usage())
         sys.exit(0)
     if cmdargs.version != None:
+        version = info.version()
+        if version != '':
+            version = ' ' + version
         message = '''gnulib-tool (%s %s)%s\n%s\n%s\n\nWritten by %s.''' \
-            % (info.package(), info.date(), info.version(), info.copyright(),
+            % (info.package(), info.date(), version, info.copyright(),
                info.license(), info.authors())
         print(message)
         sys.exit(0)
index 7170268b0ed8a3e06053b11890bc33978da58fc8..de3a90dc371aea20693ba11a02df570079d9d2f7 100644 (file)
@@ -40,7 +40,6 @@ Implement the options:
   -S | --more-symlinks
   -H | --more-hardlinks
   --help (same output)
-  --version
 
 --------------------------------------------------------------------------------
 
index 34b38db7eb504faa5b8073ad39ccf24b013993fe..5e386e7c342941cb64326fc59b3ea346258c3a0f 100644 (file)
@@ -65,9 +65,7 @@ class GLInfo(object):
         The special __author__ variable is used (type is list).'''
         result = ''
         for item in __author__:
-            if item == __author__[-2]:
-                result += '%s ' % item
-            elif item == __author__[-1]:
+            if item == __author__[-1]:
                 result += 'and %s' % item
             else:
                 result += '%s, ' % item
@@ -75,38 +73,58 @@ class GLInfo(object):
 
     def license(self):
         '''Return formatted string which contains license and its description.'''
-        result = 'License GPLv3+: GNU GPL version 3 or later'
-        result += ' <https://gnu.org/licenses/gpl.html>\n'
-        result += 'This is free software: you are free'
-        result += ' to change and redistribute it.\n'
+        result = 'License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>\n'
+        result += 'This is free software: you are free to change and redistribute it.\n'
         result += 'There is NO WARRANTY, to the extent permitted by law.'
         return result
 
     def copyright(self):
         '''Return formatted string which contains copyright.
         The special __copyright__ variable is used (type is str).'''
-        result = 'Copyright (C) %s' % __copyright__
+        copyright = __copyright__
+        # Per the GNU Coding Standards, show only the last year.
+        copyright = re.compile('^[0-9]*-').sub('', copyright)
+        result = 'Copyright (C) %s' % copyright
         return result
 
     def date(self):
         '''Return formatted string which contains date and time in GMT format.'''
         if isdir(DIRS['git']):
-            counter = int()  # Create counter
-            result = ''  # Create string
-            args = ['git', 'log']
-            result = sp.check_output(args).decode("UTF-8")
-            # Get date as "Fri Mar 21 07:16:51 2008 -0600" from string
-            pattern = re.compile('Date:[\t ]*(.*?)$', re.S | re.M)
-            result = pattern.findall(result)[0]
-            # Turn "Fri Mar 21 07:16:51 2008 -0600" into "Mar 21 2008 07:16:51 -0600"
-            pattern = re.compile('^[^ ]* ([^ ]*) ([0-9]*) ([0-9:]*) ([0-9]*) ')
-            result = pattern.sub('\\1 \\2 \\4 \\3 ', result)
-            # Use GNU date to compute the time in GMT
-            args = ['date', '-d', result, '-u', '+%Y-%m-%d %H:%M:%S']
-            proc = sp.check_output(args)
-            result = str(proc, "UTF-8")
-            result = result.rstrip(os.linesep)
-            return result
+            have_git = None
+            try:
+                sp.check_call(['git', '--version'], stdout=sp.DEVNULL)
+                have_git = True
+            except:
+                have_git = False
+            if have_git:
+                have_GNU_date = None
+                try:
+                    sp.check_call(['date', '--version'], stdout=sp.DEVNULL)
+                    have_GNU_date = True
+                except:
+                    have_GNU_date = False
+                if have_GNU_date:
+                    args = ['git', 'log', '-n', '1', 'ChangeLog']
+                    result = sp.check_output(args, cwd=DIRS['root']).decode("UTF-8")
+                    # Get date as "Fri Mar 21 07:16:51 2008 -0600" from string
+                    pattern = re.compile('^Date:[\t ]*(.*?)$', re.M)
+                    result = pattern.findall(result)[0]
+                    # Turn "Fri Mar 21 07:16:51 2008 -0600" into "Mar 21 2008 07:16:51 -0600"
+                    pattern = re.compile('^[^ ]* ([^ ]*) ([0-9]*) ([0-9:]*) ([0-9]*) ')
+                    result = pattern.sub('\\1 \\2 \\4 \\3 ', result)
+                    # Use GNU date to compute the time in GMT
+                    args = ['date', '-d', result, '-u', '+%Y-%m-%d %H:%M:%S']
+                    proc = sp.check_output(args)
+                    result = str(proc, "UTF-8")
+                    result = result.rstrip(os.linesep)
+                    return result
+        # gnulib copy without versioning information.
+        first_changelog_line = None
+        with codecs.open(os.path.join(DIRS['root'], 'ChangeLog'), 'rb', 'UTF-8') as file:
+            line = file.readline()
+            first_changelog_line = line.rstrip()
+        result = re.compile(' .*').sub('', first_changelog_line)
+        return result
 
     def usage(self):
         '''Show help message.'''
@@ -289,10 +307,20 @@ Report bugs to <bug-gnulib@gnu.org>.'''
     def version(self):
         '''Return formatted string which contains git version.'''
         if isdir(DIRS['git']):
-            version_gen = joinpath(DIRS['build-aux'], 'git-version-gen')
-            args = [version_gen, DIRS['root']]
-            result = sp.check_output(args).decode("UTF-8")
-            result = result.strip()
-            if result == 'UNKNOWN':
-                result = ''
-            return result
+            have_git = None
+            try:
+                sp.check_call(['git', '--version'], stdout=sp.DEVNULL)
+                have_git = True
+            except:
+                have_git = False
+            if have_git:
+                version_gen = joinpath(DIRS['build-aux'], 'git-version-gen')
+                args = [version_gen, '/dev/null']
+                result = sp.check_output(args, cwd=DIRS['root']).decode("UTF-8")
+                result = result.strip()
+                result = result.replace('-dirty', '-modified')
+                if result == 'UNKNOWN':
+                    result = ''
+                return result
+        # gnulib copy without versioning information.
+        return ''
index 4eff6da8bca2a0427492f1fd6f6758d2a9b49b93..ffee05846ecd8bc6878273e7e3c4e94ce4720ca6 100644 (file)
@@ -41,7 +41,7 @@ __author__ = \
         'Dmitriy Selyutin',
     ]
 __license__ = 'GNU GPLv3+'
-__copyright__ = '2002-2017 Free Software Foundation, Inc.'
+__copyright__ = '2002-2022 Free Software Foundation, Inc.'
 
 
 #===============================================================================