fix basic

This commit is contained in:
k3nny 2024-11-29 00:32:39 +01:00
parent 274e1e2e59
commit 8479c378ee
3 changed files with 26 additions and 19 deletions

View File

@ -3,4 +3,8 @@ line-length = 140
[tool.ruff] [tool.ruff]
# Allow lines to be as long as 120. # Allow lines to be as long as 120.
line-length = 140 line-length = 140
indent-width = 4
[tool.ruff.lint]
ignore = ["F401","F403","F405","E402"]

View File

@ -29,6 +29,7 @@ sys.path.insert(0,os.path.join(tisbackup_root_dir,'libtisbackup'))
import errno import errno
import logging import logging
import os.path import os.path
from optparse import OptionParser from optparse import OptionParser
from iniparse import ConfigParser, ini from iniparse import ConfigParser, ini
@ -191,7 +192,7 @@ class tis_backup:
finally: finally:
self.logger.debug('worst nagios status :"%i"',worst_nagiosstatus) self.logger.debug('worst nagios status :"%i"',worst_nagiosstatus)
print('%s (tisbackup V%s)' %(nagiosoutput,version)) 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) sys.exit(worst_nagiosstatus)
def process_backup(self,sections=[]): def process_backup(self,sections=[]):
@ -285,7 +286,6 @@ class tis_backup:
def cleanup_backup_section(self,sections = []): def cleanup_backup_section(self,sections = []):
log = ''
processed = False processed = False
if not sections: if not sections:
sections = [backup_item.backup_name for backup_item in self.backup_list] 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) (nagiosstatus,log) = backup_item.checknagios(maxage_hours=maxage_hours)
globallog.append('[%s] %s' % (backup_item.backup_name,log)) globallog.append('[%s] %s' % (backup_item.backup_name,log))
self.logger.debug('[%s] nagios:"%i" log: %s',backup_item.backup_name,nagiosstatus,log) self.logger.debug('[%s] nagios:"%i" log: %s',backup_item.backup_name,nagiosstatus,log)
processed = True #processed = True
if nagiosstatus >= worst_nagiosstatus: # if nagiosstatus >= worst_nagiosstatus:
worst_nagiosstatus = nagiosstatus # worst_nagiosstatus = nagiosstatus
def main(): def main():
@ -398,7 +398,7 @@ def main():
backup_sections = all_sections backup_sections = all_sections
else: else:
for b in backup_sections: 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) raise Exception('Section %s is not defined in config file' % b)
if dry_run: if dry_run:

View File

@ -72,7 +72,7 @@ tasks_db = os.path.join(tisbackup_root_dir,"tasks.sqlite")
def read_all_configs(base_dir): def read_all_configs(base_dir):
raw_configs = [] raw_configs = []
list_config = [] list_config = []
config_base_dir = base_dir #config_base_dir = base_dir
for file in os.listdir(base_dir): for file in os.listdir(base_dir):
if isfile(join(base_dir,file)): if isfile(join(base_dir,file)):
@ -112,11 +112,12 @@ def read_all_configs(base_dir):
backup_sections = all_sections backup_sections = all_sections
else: else:
for b in backup_sections: 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) raise Exception('Section %s is not defined in config file' % b)
if not backup_sections: # never used..
sections = [backup_item.backup_name for backup_item in backup.backup_list] # if not backup_sections:
# sections = [backup_item.backup_name for backup_item in backup.backup_list]
for backup_item in backup.backup_list: for backup_item in backup.backup_list:
if backup_item.backup_name in backup_sections: if backup_item.backup_name in backup_sections:
@ -190,12 +191,14 @@ def read_config():
backup_sections = all_sections backup_sections = all_sections
else: else:
for b in backup_sections: 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) raise Exception('Section %s is not defined in config file' % b)
result = [] 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: for backup_item in backup.backup_list:
if backup_item.backup_name in backup_sections: if backup_item.backup_name in backup_sections:
@ -261,7 +264,7 @@ def backup_all():
@app.route('/config_number/') @app.route('/config_number/')
@app.route('/config_number/<int:id>') @app.route('/config_number/<int:id>')
def set_config_number(id=None): 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 global config_number
config_number=id config_number=id
read_config() read_config()
@ -350,7 +353,7 @@ def run_command(cmd, info=""):
result ="" result =""
try: try:
result = check_output(cmd, stderr=subprocess.STDOUT,shell=True) result = check_output(cmd, stderr=subprocess.STDOUT,shell=True)
except CalledProcessError as e: except CalledProcessError:
raise_error(result,info) raise_error(result,info)
return result return result
@ -376,7 +379,7 @@ def export_backup_status():
exports = dbstat.query('select * from stats where TYPE="EXPORT" and backup_start>="%s"' % mindate) exports = dbstat.query('select * from stats where TYPE="EXPORT" and backup_start>="%s"' % mindate)
error = "" error = ""
finish=not runnings_backups() finish=not runnings_backups()
if get_task() != None and finish: if get_task() is not None and finish:
status = get_task().get() status = get_task().get()
if status != "ok": if status != "ok":
error = "Export failing with error: "+status error = "Export failing with error: "+status
@ -386,8 +389,8 @@ def export_backup_status():
def runnings_backups(): def runnings_backups():
task = get_task() task = get_task()
is_runnig = (task != None) is_runnig = (task is not None)
finish = ( is_runnig and task.get() != None) finish = ( is_runnig and task.get() is not None)
return is_runnig and not finish return is_runnig and not finish