[diffoscope] 05/05: Add a --status-fd argument to output machine-readable status to the specified file descriptor.

Chris Lamb chris at chris-lamb.co.uk
Mon Sep 26 18:58:03 CEST 2016


This is an automated email from the git hooks/post-receive script.

lamby pushed a commit to branch master
in repository diffoscope.

commit b346c29263c69e405a25249431e7690ef8d924f2
Author: Chris Lamb <lamby at debian.org>
Date:   Mon Sep 26 18:55:38 2016 +0200

    Add a --status-fd argument to output machine-readable status to the specified file descriptor.
    
    Signed-off-by: Chris Lamb <lamby at debian.org>
---
 diffoscope/main.py     |  2 ++
 diffoscope/progress.py | 15 ++++++++++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/diffoscope/main.py b/diffoscope/main.py
index 723d09f..357d821 100644
--- a/diffoscope/main.py
+++ b/diffoscope/main.py
@@ -125,6 +125,8 @@ def create_parser():
                         400, 20)
     parser.add_argument('--new-file', dest='new_file', action='store_true',
                         help='treat absent files as empty')
+    parser.add_argument('--status-fd', dest='status_fd', metavar='N', type=int,
+                        help='Send machine-readable status to file descriptor N')
     parser.add_argument('--css', metavar='url', dest='css_url',
                         help='link to an extra CSS for the HTML report')
     parser.add_argument('--jquery', metavar='url', dest='jquery_url',
diff --git a/diffoscope/progress.py b/diffoscope/progress.py
index bb123ce..9882a6d 100644
--- a/diffoscope/progress.py
+++ b/diffoscope/progress.py
@@ -17,6 +17,8 @@
 # You should have received a copy of the GNU General Public License
 # along with diffoscope.  If not, see <http://www.gnu.org/licenses/>.
 
+import os
+
 class ProgressManager(object):
     _singleton = {}
 
@@ -29,7 +31,8 @@ class ProgressManager(object):
             self.observers = []
 
     def setup(self, parsed_args):
-        pass
+        if parsed_args.status_fd:
+            self.register(StatusFD(parsed_args.status_fd))
 
     ##
 
@@ -74,3 +77,13 @@ class Progress(object):
 
         self.current += delta
         ProgressManager().step(delta)
+
+class StatusFD(object):
+    def __init__(self, fileno):
+        self.fileobj = os.fdopen(fileno, 'w')
+
+    def notify(self, current, total):
+        print('{}\t{}'.format(current, total, file=self.fileobj))
+
+    def finish(self):
+        pass

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list