Skip to content

Commit

Permalink
chore(lint): Enable PyLint rule W0237 (arguments-renamed)
Browse files Browse the repository at this point in the history
Thank you to Manual (@feman323) for this contribution.

Related to #1755 .
---------

Co-authored-by: buhtz <c.buhtz@posteo.jp>
  • Loading branch information
feman323 and buhtz authored Aug 11, 2024
1 parent 7c09317 commit 2f23ec4
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 44 deletions.
10 changes: 4 additions & 6 deletions common/applicationinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
This module holds the ApplicationInstance class, used to handle
the one application instance mechanism.
"""

import os
import fcntl
import logger
Expand Down Expand Up @@ -63,15 +62,14 @@ def __del__(self):

# TODO Rename to is_single_instance() to make the purpose more obvious
def check(self, autoExit=False):
"""
Check if the current application is already running
"""Check if the current application is already running.
Args:
autoExit (bool): automatically call sys.exit if there is another
instance running
autoExit (bool): Automatically call ``sys.exit()`` if there is
another instance running.
Returns:
bool: ``True`` if this is the only application instance
bool: ``True`` if this is the only application instance.
"""
# check if the pidfile exists
if not os.path.isfile(self.pidFile):
Expand Down
68 changes: 34 additions & 34 deletions common/guiapplicationinstance.py
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
# Back In Time
# Copyright (C) 2008-2022 Oprea Dan, Bart de Koning, Richard Bailey, Germar Reitze
# Back In Time
# Copyright (C) 2008-2022 Oprea Dan, Bart de Koning, Richard Bailey,
# Germar Reitze
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import os

import logger
from applicationinstance import ApplicationInstance


class GUIApplicationInstance(ApplicationInstance):
"""Handle one application instance mechanism.
"""
class used to handle one application instance mechanism
"""
def __init__(self, baseControlFile, raiseCmd = ''):
"""
specify the base for control files
"""
def __init__(self, baseControlFile, raiseCmd=''):
"""Specify the base for control files."""
self.raiseFile = baseControlFile + '.raise'
self.raiseCmd = raiseCmd

super(GUIApplicationInstance, self).__init__(baseControlFile + '.pid', False, False)
super(GUIApplicationInstance, self).__init__(
baseControlFile + '.pid', False, False)

#remove raiseFile is already exists
# Remove raiseFile is already exists
if os.path.exists(self.raiseFile):
os.remove(self.raiseFile)

self.check(raiseCmd)
self.check()
self.startApplication()

def check(self, raiseCmd):
"""
check if the current application is already running
"""
def check(self):
"""Check if the current application is already running."""
ret = super(GUIApplicationInstance, self).check(False)
if not ret:
print("The application is already running! (pid: %s)" % self.pid)
#notify raise
print(f'The application is already running. (pid: {self.pid})')

# Notify raise
try:
with open(self.raiseFile, 'wt') as f:
f.write(raiseCmd)
f.write(self.raiseCmd)

except OSError as e:
logger.error('Failed to write raise file %s: [%s] %s' %(e.filename, e.errno, e.strerror))
logger.error(f'Failed to write raise file {e.filename}: '
f'[{e.errno}] {e.strerror}')

# Exit raise an exception so don't put it in a try/except block
exit(0)

exit(0) #exit raise an exception so don't put it in a try/except block
else:
return ret

Expand Down
2 changes: 1 addition & 1 deletion common/test/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ def test_with_pylint(self):
'W4902', # deprecated-method
'W4904', # deprecated-class
'W0614', # unused-wildcard-import
'W0237', # arguments-renamed
'W0123', # eval-used
'W0707', # raise-missing-from

# Enable asap. This list is a selection of existing (not all!)
# problems currently existing in the BIT code base. Quite easy to fix
# because their count is low.
# 'R0801', # duplicate-code
# 'W0237', # arguments-renamed
# 'W0221', # arguments-differ
# 'W0603', # global-statement
# 'W0612', # unused-variable
Expand Down
10 changes: 7 additions & 3 deletions common/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2601,16 +2601,20 @@ def kill(self, signum, frame):


class Daemon:
"""
A generic daemon class.
"""A generic daemon class.
Usage: subclass the Daemon class and override the run() method
Daemon Copyright by Sander Marechal
License CC BY-SA 3.0
http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/
"""
def __init__(self, pidfile = None, stdin='/dev/null', stdout='/dev/stdout', stderr='/dev/null', umask = 0o022):
def __init__(self,
pidfile=None,
stdin='/dev/null',
stdout='/dev/stdout',
stderr='/dev/null',
umask = 0o022):
self.stdin = stdin
self.stdout = stdout
self.stderr = stderr
Expand Down

0 comments on commit 2f23ec4

Please sign in to comment.