From 8479c378ee9721dec4d2959e443b737c5ef19857 Mon Sep 17 00:00:00 2001 From: k3nny Date: Fri, 29 Nov 2024 00:32:39 +0100 Subject: [PATCH] fix basic --- pyproject.toml | 6 +++++- tisbackup.py | 12 ++++++------ tisbackup_gui.py | 27 +++++++++++++++------------ 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 9f2e9f4..d838849 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,4 +3,8 @@ line-length = 140 [tool.ruff] # Allow lines to be as long as 120. -line-length = 140 \ No newline at end of file +line-length = 140 +indent-width = 4 + +[tool.ruff.lint] +ignore = ["F401","F403","F405","E402"] \ No newline at end of file diff --git a/tisbackup.py b/tisbackup.py index c78ad2b..2788dc8 100755 --- a/tisbackup.py +++ b/tisbackup.py @@ -29,6 +29,7 @@ sys.path.insert(0,os.path.join(tisbackup_root_dir,'libtisbackup')) import errno import logging import os.path + from optparse import OptionParser from iniparse import ConfigParser, ini @@ -191,7 +192,7 @@ class tis_backup: finally: self.logger.debug('worst nagios status :"%i"',worst_nagiosstatus) print('%s (tisbackup V%s)' %(nagiosoutput,version)) - print('\n'.join(["[%s]:%s" % (l[0],l[1]) for l in globallog])) + print('\n'.join(["[%s]:%s" % (log_elem[0],log_elem[1]) for log_elem in globallog])) sys.exit(worst_nagiosstatus) def process_backup(self,sections=[]): @@ -285,7 +286,6 @@ class tis_backup: def cleanup_backup_section(self,sections = []): - log = '' processed = False if not sections: sections = [backup_item.backup_name for backup_item in self.backup_list] @@ -321,9 +321,9 @@ class tis_backup: (nagiosstatus,log) = backup_item.checknagios(maxage_hours=maxage_hours) globallog.append('[%s] %s' % (backup_item.backup_name,log)) self.logger.debug('[%s] nagios:"%i" log: %s',backup_item.backup_name,nagiosstatus,log) - processed = True - if nagiosstatus >= worst_nagiosstatus: - worst_nagiosstatus = nagiosstatus + #processed = True + # if nagiosstatus >= worst_nagiosstatus: + # worst_nagiosstatus = nagiosstatus def main(): @@ -398,7 +398,7 @@ def main(): backup_sections = all_sections else: for b in backup_sections: - if not b in all_sections: + if b not in all_sections: raise Exception('Section %s is not defined in config file' % b) if dry_run: diff --git a/tisbackup_gui.py b/tisbackup_gui.py index 57a1102..ea99d99 100755 --- a/tisbackup_gui.py +++ b/tisbackup_gui.py @@ -72,7 +72,7 @@ tasks_db = os.path.join(tisbackup_root_dir,"tasks.sqlite") def read_all_configs(base_dir): raw_configs = [] list_config = [] - config_base_dir = base_dir + #config_base_dir = base_dir for file in os.listdir(base_dir): if isfile(join(base_dir,file)): @@ -112,11 +112,12 @@ def read_all_configs(base_dir): backup_sections = all_sections else: for b in backup_sections: - if not b in all_sections: + if b not in all_sections: raise Exception('Section %s is not defined in config file' % b) - if not backup_sections: - sections = [backup_item.backup_name for backup_item in backup.backup_list] + # never used.. + # if not backup_sections: + # sections = [backup_item.backup_name for backup_item in backup.backup_list] for backup_item in backup.backup_list: if backup_item.backup_name in backup_sections: @@ -190,12 +191,14 @@ def read_config(): backup_sections = all_sections else: for b in backup_sections: - if not b in all_sections: + if b not in all_sections: raise Exception('Section %s is not defined in config file' % b) result = [] - if not backup_sections: - sections = [backup_item.backup_name for backup_item in backup.backup_list] + + # not used ... + # if not backup_sections: + # sections = [backup_item.backup_name for backup_item in backup.backup_list] for backup_item in backup.backup_list: if backup_item.backup_name in backup_sections: @@ -261,7 +264,7 @@ def backup_all(): @app.route('/config_number/') @app.route('/config_number/') def set_config_number(id=None): - if id != None and len(CONFIG) > id: + if id is not None and len(CONFIG) > id: global config_number config_number=id read_config() @@ -350,7 +353,7 @@ def run_command(cmd, info=""): result ="" try: result = check_output(cmd, stderr=subprocess.STDOUT,shell=True) - except CalledProcessError as e: + except CalledProcessError: raise_error(result,info) return result @@ -376,7 +379,7 @@ def export_backup_status(): exports = dbstat.query('select * from stats where TYPE="EXPORT" and backup_start>="%s"' % mindate) error = "" finish=not runnings_backups() - if get_task() != None and finish: + if get_task() is not None and finish: status = get_task().get() if status != "ok": error = "Export failing with error: "+status @@ -386,8 +389,8 @@ def export_backup_status(): def runnings_backups(): task = get_task() - is_runnig = (task != None) - finish = ( is_runnig and task.get() != None) + is_runnig = (task is not None) + finish = ( is_runnig and task.get() is not None) return is_runnig and not finish