public inbox for cygwin-apps-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jon TURNEY <jturney@sourceware.org>
To: cygwin-apps-cvs@sourceware.org
Subject: [calm - Cygwin server-side packaging maintenance script] branch master, updated. 20200401-9-gdef453c
Date: Mon, 13 Apr 2020 15:49:18 +0000 (GMT)	[thread overview]
Message-ID: <20200413154918.7A9603887000@sourceware.org> (raw)




https://sourceware.org/git/gitweb.cgi?p=cygwin-apps/calm.git;h=def453ca2dbcf4b392ed001d0924abbe9c42efb4

commit def453ca2dbcf4b392ed001d0924abbe9c42efb4
Author: Jon Turney <jon.turney@dronecode.org.uk>
Date:   Mon Apr 13 16:46:27 2020 +0100

    Add a tool for demonstrating version sort

https://sourceware.org/git/gitweb.cgi?p=cygwin-apps/calm.git;h=296e9c5ef1d4a3cf16389a464a17d7ef537fd78f

commit 296e9c5ef1d4a3cf16389a464a17d7ef537fd78f
Author: Jon Turney <jon.turney@dronecode.org.uk>
Date:   Mon Apr 13 15:51:36 2020 +0100

    Enhance homepage fixing to handle
    
    * Trivial terminal '/' redirects
    * 308 Permanent Redirect as well as 301 Moved Permanently

https://sourceware.org/git/gitweb.cgi?p=cygwin-apps/calm.git;h=22252b665bad46eeaa95abf66bc6332c691cfbf9

commit 22252b665bad46eeaa95abf66bc6332c691cfbf9
Author: Jon Turney <jon.turney@dronecode.org.uk>
Date:   Mon Apr 13 15:01:29 2020 +0100

    Enhance homepage hint fixer so it can be run on specified packages


Diff:
---
 calm/fix-missing-src-hint-info.py | 13 +++++++++--
 calm/fixes.py                     |  9 +++++--
 calm/sort-versions.py             | 49 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 67 insertions(+), 4 deletions(-)

diff --git a/calm/fix-missing-src-hint-info.py b/calm/fix-missing-src-hint-info.py
index 31342ae..cb461b0 100644
--- a/calm/fix-missing-src-hint-info.py
+++ b/calm/fix-missing-src-hint-info.py
@@ -32,8 +32,16 @@ from . import common_constants
 from . import fixes
 
 
-def fix_hints(relarea):
+def fix_hints(relarea, packages):
     for (dirpath, _subdirs, files) in os.walk(relarea):
+
+        # only apply to listed packages, if specified
+        if packages:
+            relpath = os.path.relpath(dirpath, relarea)
+            relpath = relpath.split(os.path.sep)
+            if (len(relpath) < 3) or (relpath[2] not in packages):
+                continue
+
         for f in files:
             match = re.match(r'^(.*)-src\.tar\.(bz2|gz|lzma|xz)$', f)
             if match:
@@ -53,6 +61,7 @@ def main():
     relarea_default = common_constants.FTP
 
     parser = argparse.ArgumentParser(description='src hint improver')
+    parser.add_argument('package', nargs='*', metavar='PACKAGE')
     parser.add_argument('-v', '--verbose', action='count', dest='verbose', help='verbose output', default=0)
     parser.add_argument('--releasearea', action='store', metavar='DIR', help="release directory (default: " + relarea_default + ")", default=relarea_default, dest='relarea')
     (args) = parser.parse_args()
@@ -62,7 +71,7 @@ def main():
 
     logging.basicConfig(format=os.path.basename(sys.argv[0]) + ': %(message)s')
 
-    fix_hints(args.relarea)
+    fix_hints(args.relarea, args.package)
 
 
 #
diff --git a/calm/fixes.py b/calm/fixes.py
index b07dccc..b42c575 100644
--- a/calm/fixes.py
+++ b/calm/fixes.py
@@ -73,7 +73,7 @@ def follow_redirect(homepage):
     opener = urllib.request.build_opener(NoRedirection)
     try:
         response = opener.open(homepage)
-        if response.code == 301:
+        if response.code in [301, 308]:
             return response.headers['Location']
     except (ConnectionResetError, ValueError, urllib.error.URLError) as e:
         logging.warning('error %s checking homepage:%s' % (e, homepage))
@@ -118,8 +118,13 @@ def fix_homepage_src_hint(dirpath, hf, tf):
 
         logging.info('adding homepage:%s to hints for srcpkg %s' % (homepage, tf))
 
-    # check for http -> https redirects
     redirect_homepage = follow_redirect(homepage)
+
+    # trivial URL transformations aren't interesting
+    if redirect_homepage.endswith('/') and not homepage.endswith('/'):
+        homepage = homepage + '/'
+
+    # check for http -> https redirects
     if redirect_homepage != homepage:
         if redirect_homepage == homepage.replace('http://', 'https://'):
             logging.warning('homepage:%s permanently redirects to %s, fixing' % (homepage, redirect_homepage))
diff --git a/calm/sort-versions.py b/calm/sort-versions.py
new file mode 100644
index 0000000..fbe6a6e
--- /dev/null
+++ b/calm/sort-versions.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python3
+#
+# Copyright (c) 2020 Jon Turney
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#
+
+import argparse
+import sys
+
+from . import version
+
+
+def main():
+    parser = argparse.ArgumentParser(description='version sort')
+    parser.add_argument('version', nargs='*', metavar='VERSION')
+    (args) = parser.parse_args()
+
+    versions = sorted([version.SetupVersion(v) for v in args.version])
+
+    prev = None
+    for v in versions:
+        if prev:
+            if prev != v:
+                print()
+            else:
+                print(' ', end='')
+        print(v._version_string, end='')
+        prev = v
+
+
+if __name__ == "__main__":
+    sys.exit(main())



                 reply	other threads:[~2020-04-13 15:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200413154918.7A9603887000@sourceware.org \
    --to=jturney@sourceware.org \
    --cc=cygwin-apps-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).