Skip to content

Commit 5bac6fe

Browse files
committed
format using ruff
1 parent 36f09a3 commit 5bac6fe

File tree

24 files changed

+1838
-1725
lines changed

24 files changed

+1838
-1725
lines changed

safeeyes/__main__.py

Lines changed: 69 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616

1717
# You should have received a copy of the GNU General Public License
1818
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
"""Safe Eyes is a utility to remind you to take break frequently to protect
20+
your eyes from eye strain.
1921
"""
20-
Safe Eyes is a utility to remind you to take break frequently to protect your eyes from eye strain.
21-
"""
22+
2223
import argparse
2324
import gettext
2425
import locale
@@ -33,13 +34,11 @@
3334
from safeeyes.safeeyes import SAFE_EYES_VERSION
3435
from safeeyes.rpc import RPCClient
3536

36-
gettext.install('safeeyes', utility.LOCALE_PATH)
37+
gettext.install("safeeyes", utility.LOCALE_PATH)
3738

3839

3940
def __running():
40-
"""
41-
Check if SafeEyes is already running.
42-
"""
41+
"""Check if SafeEyes is already running."""
4342
process_count = 0
4443
for proc in psutil.process_iter():
4544
if not proc.cmdline:
@@ -52,7 +51,9 @@ def __running():
5251
else:
5352
# In older versions cmdline was a list object
5453
cmd_line = proc.cmdline
55-
if ('python3' in cmd_line[0] or 'python' in cmd_line[0]) and ('safeeyes' in cmd_line[1] or 'safeeyes' in cmd_line):
54+
if ("python3" in cmd_line[0] or "python" in cmd_line[0]) and (
55+
"safeeyes" in cmd_line[1] or "safeeyes" in cmd_line
56+
):
5657
process_count += 1
5758
if process_count > 1:
5859
return True
@@ -64,29 +65,63 @@ def __running():
6465

6566

6667
def main():
67-
"""
68-
Start the Safe Eyes.
69-
"""
70-
system_locale = gettext.translation('safeeyes', localedir=utility.LOCALE_PATH, languages=[utility.system_locale(), 'en_US'], fallback=True)
68+
"""Start the Safe Eyes."""
69+
system_locale = gettext.translation(
70+
"safeeyes",
71+
localedir=utility.LOCALE_PATH,
72+
languages=[utility.system_locale(), "en_US"],
73+
fallback=True,
74+
)
7175
system_locale.install()
7276
try:
7377
# locale.bindtextdomain is required for Glade files
74-
locale.bindtextdomain('safeeyes', utility.LOCALE_PATH)
78+
locale.bindtextdomain("safeeyes", utility.LOCALE_PATH)
7579
except AttributeError:
76-
logging.warning('installed python\'s gettext module does not support locale.bindtextdomain. locale.bindtextdomain is required for Glade files')
77-
80+
logging.warning(
81+
"installed python's gettext module does not support locale.bindtextdomain."
82+
" locale.bindtextdomain is required for Glade files"
83+
)
7884

79-
parser = argparse.ArgumentParser(prog='safeeyes')
85+
parser = argparse.ArgumentParser(prog="safeeyes")
8086
group = parser.add_mutually_exclusive_group()
81-
group.add_argument('-a', '--about', help=_('show the about dialog'), action='store_true')
82-
group.add_argument('-d', '--disable', help=_('disable the currently running safeeyes instance'), action='store_true')
83-
group.add_argument('-e', '--enable', help=_('enable the currently running safeeyes instance'), action='store_true')
84-
group.add_argument('-q', '--quit', help=_('quit the running safeeyes instance and exit'), action='store_true')
85-
group.add_argument('-s', '--settings', help=_('show the settings dialog'), action='store_true')
86-
group.add_argument('-t', '--take-break', help=_('Take a break now').lower(), action='store_true')
87-
parser.add_argument('--debug', help=_('start safeeyes in debug mode'), action='store_true')
88-
parser.add_argument('--status', help=_('print the status of running safeeyes instance and exit'), action='store_true')
89-
parser.add_argument('--version', action='version', version='%(prog)s ' + SAFE_EYES_VERSION)
87+
group.add_argument(
88+
"-a", "--about", help=_("show the about dialog"), action="store_true"
89+
)
90+
group.add_argument(
91+
"-d",
92+
"--disable",
93+
help=_("disable the currently running safeeyes instance"),
94+
action="store_true",
95+
)
96+
group.add_argument(
97+
"-e",
98+
"--enable",
99+
help=_("enable the currently running safeeyes instance"),
100+
action="store_true",
101+
)
102+
group.add_argument(
103+
"-q",
104+
"--quit",
105+
help=_("quit the running safeeyes instance and exit"),
106+
action="store_true",
107+
)
108+
group.add_argument(
109+
"-s", "--settings", help=_("show the settings dialog"), action="store_true"
110+
)
111+
group.add_argument(
112+
"-t", "--take-break", help=_("Take a break now").lower(), action="store_true"
113+
)
114+
parser.add_argument(
115+
"--debug", help=_("start safeeyes in debug mode"), action="store_true"
116+
)
117+
parser.add_argument(
118+
"--status",
119+
help=_("print the status of running safeeyes instance and exit"),
120+
action="store_true",
121+
)
122+
parser.add_argument(
123+
"--version", action="version", version="%(prog)s " + SAFE_EYES_VERSION
124+
)
90125
args = parser.parse_args()
91126

92127
# Initialize the logging
@@ -99,10 +134,15 @@ def main():
99134
logging.info("Safe Eyes is already running")
100135
if not config.get("use_rpc_server", True):
101136
# RPC sever is disabled
102-
print(_('Safe Eyes is running without an RPC server. Turn it on to use command-line arguments.'))
137+
print(
138+
_(
139+
"Safe Eyes is running without an RPC server. Turn it on to use"
140+
" command-line arguments."
141+
)
142+
)
103143
sys.exit(0)
104144
return
105-
rpc_client = RPCClient(config.get('rpc_port'))
145+
rpc_client = RPCClient(config.get("rpc_port"))
106146
if args.about:
107147
rpc_client.show_about()
108148
elif args.disable:
@@ -123,14 +163,14 @@ def main():
123163
sys.exit(0)
124164
else:
125165
if args.status:
126-
print(_('Safe Eyes is not running'))
166+
print(_("Safe Eyes is not running"))
127167
sys.exit(0)
128168
elif not args.quit:
129169
logging.info("Starting Safe Eyes")
130170
safe_eyes = SafeEyes(system_locale, config, args)
131171
safe_eyes.start()
132172

133173

134-
if __name__ == '__main__':
135-
signal.signal(signal.SIGINT, signal.SIG_DFL) # Handle Ctrl + C
174+
if __name__ == "__main__":
175+
signal.signal(signal.SIGINT, signal.SIG_DFL) # Handle Ctrl + C
136176
main()

0 commit comments

Comments
 (0)