Commit b12d9aab authored by Christian Trenkwalder's avatar Christian Trenkwalder Committed by Sébastien Helleu

i3lock_away.py 0.2: make script compatible with Python 3

parent 589eab1c
......@@ -17,17 +17,22 @@
#
# Set away status if i3lock is running
# This script a copy the slock_away.py script, by Peter A. Shevtsov.
# The only change is the detection of the i3lock process instead of the slock one.
# The only change is the detection of the i3lock process instead of the slock
# one.
#
# History:
# 2019-12-23, Christian Trenkwalder <[email protected]>:
# version 0.2: updated to work with python3
#
# 2017-06-07, Bertrand Ciroux <[email protected]>:
# version 0.1: initial release
#
from __future__ import print_function
SCRIPT_NAME = "i3lock_away"
SCRIPT_AUTHOR = "Bertrand Ciroux <[email protected]>"
SCRIPT_VERSION = "0.1"
SCRIPT_VERSION = "0.2"
SCRIPT_LICENSE = "GPL3"
SCRIPT_DESC = "Set away status if i3lock is running"
......@@ -38,14 +43,14 @@ import_ok = True
try:
import weechat
except ImportError:
print "This script must be run under WeeChat."
print "Get WeeChat now at: http://www.weechat.org/"
print("This script must be run under WeeChat.")
print("Get WeeChat now at: http://www.weechat.org/")
import_ok = False
try:
import subprocess
except ImportError:
print "Missing package(s) for %s: %s" % (SCRIPT_NAME, message)
except ImportError as message:
print("Missing package(s) for %s: %s" % (SCRIPT_NAME, message))
import_ok = False
TIMER = None
......@@ -81,8 +86,9 @@ def set_away(message, overridable_messages=[]):
"""Sets away status, but respectfully
(so it doesn't change already set statuses"""
if (weechat.config_get_plugin('away') == '1'):
return # No need to go away again
# (this prevents some repeated messages)
# No need to go away again
# (this prevents some repeated messages)
return
serverlist = weechat.infolist_get('irc_server', '', '')
if serverlist:
buffers = []
......@@ -103,8 +109,8 @@ def set_away(message, overridable_messages=[]):
def i3lock_away_cb(data, buffer, args):
"""Callback for /i3lock_away command"""
response = {
'msg': lambda status:
weechat.config_set_plugin('away_message', status)
'msg': lambda status: weechat.config_set_plugin(
'away_message', status)
}
if args:
words = args.strip().partition(' ')
......@@ -112,9 +118,9 @@ def i3lock_away_cb(data, buffer, args):
response[words[0]](words[2])
else:
weechat.prnt('', "i3lock_away error: %s not a recognized command. "
"Try /help i3lock_away" % words[0])
"Try /help i3lock_away" % words[0])
weechat.prnt('', "i3lock_away: away message: \"%s\"" %
weechat.config_get_plugin('away_message'))
weechat.config_get_plugin('away_message'))
return weechat.WEECHAT_RC_OK
......@@ -127,7 +133,7 @@ def auto_check(data, remaining_calls):
def check():
"""Check for existance of process and set away if it isn't there"""
pidof = subprocess.Popen("pidof i3lock",
shell=True, stdout=subprocess.PIPE)
shell=True, stdout=subprocess.PIPE)
pidof.wait()
if pidof.returncode == 0:
set_away(weechat.config_get_plugin('away_message'), [])
......@@ -145,10 +151,11 @@ def check_timer():
int(weechat.config_get_plugin('interval')) * 1000,
0, 0, "auto_check", "")
if __name__ == "__main__" and import_ok:
if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION,
SCRIPT_LICENSE, SCRIPT_DESC, "", ""):
for option, default_value in settings.iteritems():
SCRIPT_LICENSE, SCRIPT_DESC, "", ""):
for option, default_value in settings.items():
if not weechat.config_is_set_plugin(option):
weechat.config_set_plugin(option, default_value)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment