From 5a3c1c20eb7b6889f7746be587903b4cae0868cc Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Tue, 9 Jun 2020 21:58:32 +0200 Subject: [PATCH 1/2] Switch from http to https by default --- grml-paste | 2 +- grml-paste.1.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/grml-paste b/grml-paste index 33cfd29..2f57d96 100755 --- a/grml-paste +++ b/grml-paste @@ -12,7 +12,7 @@ import inspect import getpass # program defaults -DEFAULT_SERVER = "http://paste.grml.org/server.pl" +DEFAULT_SERVER = "https://paste.grml.org/server.pl" class ActionFailedException(Exception): diff --git a/grml-paste.1.txt b/grml-paste.1.txt index 9026164..c9bd9ff 100644 --- a/grml-paste.1.txt +++ b/grml-paste.1.txt @@ -12,7 +12,7 @@ grml-paste [options] ACTION Description ----------- -grml-paste is a command line interface for uploading plain text to http://paste.grml.org/ +grml-paste is a command line interface for uploading plain text to https://paste.grml.org/ Options ------- @@ -93,7 +93,7 @@ Upload error and warning messages of X.org log as hidden entry. Bugs ---- -Please report feedback, link:http://grml.org/bugs/[bugreports] and wishes link:http://grml.org/contact/[to the grml team]. +Please report feedback, link:https://grml.org/bugs/[bugreports] and wishes link:https://grml.org/contact/[to the grml team]. Authors ------- From c0acd324c28506c5c110bf6dcee87238267a8a6d Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Tue, 9 Jun 2020 21:58:56 +0200 Subject: [PATCH 2/2] chore: run black + isort to unify coding style While at it fix some typos: * ActionFailedException -> ActionFailedException * "Time at wich" -> "Time at which" --- grml-paste | 65 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 19 deletions(-) diff --git a/grml-paste b/grml-paste index 2f57d96..b89a200 100755 --- a/grml-paste +++ b/grml-paste @@ -5,11 +5,11 @@ # License: This file is licensed under the GPL v2. ################################################################################ +import getpass +import inspect +import optparse import sys from xmlrpc.client import ServerProxy -import optparse -import inspect -import getpass # program defaults DEFAULT_SERVER = "https://paste.grml.org/server.pl" @@ -32,11 +32,11 @@ class ActionFailedException(Exception): def _paste(opts): """Get paste proxy object""" - return (ServerProxy(opts.server, verbose=False).paste) + return ServerProxy(opts.server, verbose=False).paste def _check_success(return_data): - """Check if call was successful, raise AcitonFailedException otherwise""" + """Check if call was successful, raise ActionFailedException otherwise""" if return_data["rc"] != 0: raise ActionFailedException(return_data["statusmessage"], return_data) return return_data @@ -52,7 +52,11 @@ def action_add_paste(opts, code): if len(code) == 0: code = [line.rstrip() for line in sys.stdin.readlines()] code = "\n".join(code) - result = _check_success(_paste(opts).addPaste(code, opts.name, opts.expire * 3600, opts.lang, opts.private)) + result = _check_success( + _paste(opts).addPaste( + code, opts.name, opts.expire * 3600, opts.lang, opts.private + ) + ) return result["statusmessage"], result @@ -125,7 +129,10 @@ def action_help(opts, args): if alias in actions: function_name = actions[alias] print(inspect.getdoc(globals()[function_name])) - print("\naliases: " + " ".join([i for i in actions_r[function_name] if i != alias])) + print( + "\naliases: " + + " ".join([i for i in actions_r[function_name] if i != alias]) + ) else: print("Error: No such command - %s" % (alias)) OPT_PARSER.print_usage() @@ -155,7 +162,7 @@ if __name__ == "__main__": "action_add_short_url addurl", "action_get_short_url geturl", "action_get_short_url_clicks getclicks", - "action_help help" + "action_help help", ] for action_spec in action_specs: aliases = action_spec.split() @@ -165,20 +172,40 @@ if __name__ == "__main__": for i in v: actions[i] = action_name - usage = "usage: %prog [options] ACTION \n\n" +\ - "actions:\n" +\ - "\n".join(["%12s\t%s" % (v[0], inspect.getdoc(globals()[action_name]).splitlines()[0]) - for (action_name, v) in actions_r.items()]) + usage = ( + "usage: %prog [options] ACTION \n\n" + + "actions:\n" + + "\n".join( + [ + "%12s\t%s" + % (v[0], inspect.getdoc(globals()[action_name]).splitlines()[0]) + for (action_name, v) in actions_r.items() + ] + ) + ) running_user = getpass.getuser() parser = optparse.OptionParser(usage=usage) parser.add_option("-n", "--name", default=running_user, help="Name of poster") - parser.add_option("-e", "--expire", type=int, default=72, metavar="HOURS", - help="Time at wich paste should expire") - parser.add_option("-l", "--lang", default="Plain", help="Type of language to highlight") - parser.add_option("-p", "--private", action="count", dest="private", default=0, - help="Create hidden paste"), - parser.add_option("-s", "--server", default=DEFAULT_SERVER, - help="Paste server") + parser.add_option( + "-e", + "--expire", + type=int, + default=72, + metavar="HOURS", + help="Time at which paste should expire", + ) + parser.add_option( + "-l", "--lang", default="Plain", help="Type of language to highlight" + ) + parser.add_option( + "-p", + "--private", + action="count", + dest="private", + default=0, + help="Create hidden paste", + ), + parser.add_option("-s", "--server", default=DEFAULT_SERVER, help="Paste server") parser.add_option("-v", "--verbose", action="count", default=0, help="More output") (opts, args) = parser.parse_args() OPT_PARSER = parser