[dput-ng-maint] Bug#880461: [PATCH] dput: default to uploading the most recent changes file

Michael Stapelberg stapelberg at debian.org
Tue Oct 31 20:26:37 UTC 2017


Package: dput-ng
Version: 1.15
Severity: normal

The current default behavior of displaying an error message is not very useful.

I’d wager that the vast majority of dput invocations just upload the most
recently created changes file. The attached patch makes that the default.

Please consider merging the attached patch. Thanks!

-- System Information:
Debian Release: buster/sid
  APT prefers testing
  APT policy: (990, 'testing'), (500, 'unstable-debug'), (500, 'testing-debug'), (500, 'unstable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386, armel, mipsel, arm64

Kernel: Linux 4.13.0-1-amd64 (SMP w/12 CPU cores)
Locale: LANG=de_DE.UTF-8, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8), LANGUAGE=de_DE.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages dput-ng depends on:
ii  python       2.7.13-2
ii  python-dput  1.15

Versions of packages dput-ng recommends:
ii  bash-completion  1:2.1-4.3
ii  python-paramiko  2.0.0-1

dput-ng suggests no packages.

-- no debconf information
-------------- next part --------------
>From 4c369deb9564484b93012ececdb880901c7a6d5f Mon Sep 17 00:00:00 2001
From: Michael Stapelberg <stapelberg at debian.org>
Date: Tue, 31 Oct 2017 21:18:47 +0100
Subject: [PATCH 1/2] dput: default to uploading the most recent changes file

The user is first prompted for confirmation to prevent accidental uploads by
people who are unaware of the new behavior.
---
 bin/dput        | 20 +++++++++++++++++++-
 dput/command.py | 15 ++++++++-------
 dput/util.py    | 16 ++++++++++++----
 3 files changed, 39 insertions(+), 12 deletions(-)

diff --git a/bin/dput b/bin/dput
index db98e62..e116fa8 100755
--- a/bin/dput
+++ b/bin/dput
@@ -22,15 +22,19 @@
 import sys
 import argparse
 
+import glob
+
 # A little temporary hack for those of us not using virtualenv
 import os
 sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
 
 import dput.core
 import dput.changes
+import dput.util
 import dput.exceptions
 from dput import upload_package
 from dput.profile import parse_overrides
+from dput.interface import BUTTON_OK
 
 parser = argparse.ArgumentParser(description='Debian package upload tool')
 parser.add_argument('-d', '--debug', action='count', default=False,
@@ -73,7 +77,7 @@ parser.add_argument('-V', '--check-version', action='store_true',
 parser.add_argument('host', metavar="HOST", action='store', default=None,
                     help="Target host to upload a package", nargs="?")
 parser.add_argument('changes', metavar="CHANGES-FILE", action='store',
-                    default=None, nargs='+', help="A Debian .changes file")
+                    default=None, nargs='*', help="A Debian .changes file")
 args = parser.parse_args()
 
 
@@ -98,6 +102,20 @@ try:
             overrides.append(arg)
     args.override = parse_overrides(overrides)
 
+    if not args.changes:
+        changes_files = glob.glob('*.changes')
+        most_recent_changes_file = max(changes_files, key=os.path.getctime)
+        profile = dput.profile.load_profile(args.host)
+        with dput.util.get_interface(profile) as interface:
+            if interface.boolean(
+                    'dput',
+                    ('No CHANGES-FILE specified. '
+                     'Upload most recent changes file %s?' % (
+                         most_recent_changes_file)),
+                    question_type=[BUTTON_OK],
+                    default=BUTTON_OK):
+                args.changes.append(most_recent_changes_file)
+
     for changes in args.changes:
         changes = dput.changes.parse_changes_file(
             changes,
diff --git a/dput/command.py b/dput/command.py
index 55b427e..8509bfa 100644
--- a/dput/command.py
+++ b/dput/command.py
@@ -78,13 +78,14 @@ def load_commands(profile):
     for command in profile['valid_commands']:
         logger.debug("importing command: %s" % (command))
         try:
-            # XXX: Stubbed the profile for now. That ignores any user choice
-            #      on the profile.
-            #      Reason being that the profile and the argument parser is a
-            #      transitive circular dependency. That should be fixed at some
-            #      point.
-            with get_obj_by_name('commands', command, {}) as(obj, interface):
-                commands.append(obj(interface))
+            with get_obj_by_name('commands', command) as obj:
+                # XXX: Stubbed the profile for now. That ignores any user choice
+                #      on the profile.
+                #      Reason being that the profile and the argument parser is a
+                #      transitive circular dependency. That should be fixed at some
+                #      point.
+                with get_interface({}) as interface:
+                    commands.append(obj(interface))
         except NoSuchConfigError:
             raise DputConfigurationError("No such command: `%s'" % (command))
 
diff --git a/dput/util.py b/dput/util.py
index ddbb438..6275a5b 100644
--- a/dput/util.py
+++ b/dput/util.py
@@ -323,7 +323,7 @@ def obj_docs(cls, ostr):
 
 
 @contextmanager
-def get_obj_by_name(cls, name, profile):
+def get_obj_by_name(cls, name):
     """
     Run a function, defined by ``name``, filed in class ``cls``
     """
@@ -333,7 +333,14 @@ def get_obj_by_name(cls, name, profile):
         raise DputConfigurationError("No such obj: `%s'" % (
             name
         ))
+    try:
+        yield obj
+    finally:
+        pass
 
+
+ at contextmanager
+def get_interface(profile):
     interface = 'cli'
     if 'interface' in profile:
         interface = profile['interface']
@@ -347,7 +354,7 @@ def get_obj_by_name(cls, name, profile):
     interface.initialize()
 
     try:
-        yield (obj, interface)
+        yield interface
     finally:
         pass
 
@@ -362,5 +369,6 @@ def run_func_by_name(cls, name, changes, profile):
 
     This is used to run the hooks, internally.
     """
-    with get_obj_by_name(cls, name, profile) as(obj, interface):
-        obj(changes, profile, interface)
+    with get_obj_by_name(cls, name) as obj:
+        with get_interface(profile) as interface:
+            obj(changes, profile, interface)
-- 
2.14.2



More information about the dput-ng-maint mailing list