summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Kamat <jaygkamat@gmail.com>2018-03-27 23:43:08 -0400
committerJay Kamat <jaygkamat@gmail.com>2018-03-27 23:43:40 -0400
commitb873cfb18ab8a9ddd1b2e17c5f9043f4b6b9921b (patch)
tree1bcddd8b10627028a42773bc8b8e8289ba011770
parenta1776087e0233009721cf82a9a12c6deb9b0cebe (diff)
downloadqutebrowser-b873cfb18ab8a9ddd1b2e17c5f9043f4b6b9921b.tar.gz
qutebrowser-b873cfb18ab8a9ddd1b2e17c5f9043f4b6b9921b.zip
Fix style issues in qute-keepass
-rwxr-xr-xmisc/userscripts/qute-keepass42
1 files changed, 25 insertions, 17 deletions
diff --git a/misc/userscripts/qute-keepass b/misc/userscripts/qute-keepass
index 55d39e6e4..a21ebc9b3 100755
--- a/misc/userscripts/qute-keepass
+++ b/misc/userscripts/qute-keepass
@@ -17,10 +17,8 @@
# You should have received a copy of the GNU General Public License
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
-# pylint: disable=bad-builtin
-
-USAGE = """This userscript allows for insertion of usernames and passwords from
-keepass databases using pykeepass. Since it is a userscript, it must be run from
+"""This userscript allows for insertion of usernames and passwords from keepass
+databases using pykeepass. Since it is a userscript, it must be run from
qutebrowser.
A sample invocation of this script is:
@@ -34,8 +32,8 @@ And a sample binding
-p or --path is a required argument.
--keyfile-path allows you to specify a keepass keyfile. If you only use a
- keyfile, also add --no-password as well. Specifying --no-password without
- --keyfile-path will lead to an error.
+keyfile, also add --no-password as well. Specifying --no-password without
+--keyfile-path will lead to an error.
login information is inserted using :insert-text and :fake-key <Tab>, which
means you must have a cursor in position before initiating this userscript. If
@@ -53,8 +51,11 @@ WARNING: The login details are viewable as plaintext in qutebrowser's debug log
(qute://log) and could be compromised if you decide to submit a crash report!
********************!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!******************
+
"""
+# pylint: disable=bad-builtin
+
import argparse
import enum
import functools
@@ -68,22 +69,29 @@ from PyQt5.QtWidgets import QApplication, QInputDialog, QLineEdit
try:
import pykeepass
-except ImportError:
- print("pykeepass not found!", file=sys.stderr)
+except ImportError as e:
+ print("pykeepass not found: {}".format(str(e)), file=sys.stderr)
+
+ # Since this is a common error, try to print it to the FIFO if we can.
+ if 'QUTE_FIFO' in os.environ:
+ with open(os.environ['QUTE_FIFO'], 'w') as fifo:
+ fifo.write('message-error "pykeepass failed to be imported."\n')
+ fifo.flush()
sys.exit(100)
argument_parser = argparse.ArgumentParser(
- description=__doc__,
+ description="Fill passwords using keepass.",
formatter_class=argparse.RawDescriptionHelpFormatter,
- epilog=USAGE)
+ epilog=__doc__)
argument_parser.add_argument('url', nargs='?', default=os.getenv('QUTE_URL'))
argument_parser.add_argument('--path', '-p', required=True,
help='Path to the keepass db.')
argument_parser.add_argument('--keyfile-path', '-k', default=None,
help='Path to a keepass keyfile')
-argument_parser.add_argument('--no-password', action='store_true',
- help='True if no password is required.'
- 'Only allowed with --keyfile-path')
+argument_parser.add_argument(
+ '--no-password', action='store_true',
+ help='Supply if no password is required to unlock this database. '
+ 'Only allowed with --keyfile-path')
argument_parser.add_argument(
'--dmenu-invocation', '-d', default='dmenu',
help='Invocation used to execute a dmenu-provider')
@@ -98,9 +106,9 @@ argument_parser.add_argument(
'--io-encoding', '-i', default='UTF-8',
help='Encoding used to communicate with subprocesses')
group = argument_parser.add_mutually_exclusive_group()
-group.add_argument('--username-only', '-e',
+group.add_argument('--username-fill-only', '-e',
action='store_true', help='Only insert username')
-group.add_argument('--password-only', '-w',
+group.add_argument('--password-fill-only', '-w',
action='store_true', help='Only insert password')
CMD_DELAY = 50
@@ -228,9 +236,9 @@ def run(args):
username, password = candidate_to_secret(selection)
insert_mode = ';; enter-mode insert' if args.insert_mode else ''
- if args.username_only:
+ if args.username_fill_only:
qute_command('insert-text {}{}'.format(username, insert_mode))
- elif args.password_only:
+ elif args.password_fill_only:
qute_command('insert-text {}{}'.format(password, insert_mode))
else:
# Enter username and password using insert-key and fake-key <Tab>