mirror of
https://github.com/iio612/DEFENDER.git
synced 2026-02-13 19:24:23 +00:00
remove logging library
This commit is contained in:
@@ -2,7 +2,7 @@ from dataclasses import dataclass
|
||||
from subprocess import check_call, run, CalledProcessError, PIPE
|
||||
from platform import python_version, python_version_tuple
|
||||
from sys import exit
|
||||
import os, logging
|
||||
import os
|
||||
|
||||
class Install:
|
||||
|
||||
@@ -36,7 +36,7 @@ class Install:
|
||||
if self.skip_install:
|
||||
return None
|
||||
|
||||
self.Logs.debug(f'Configuration loaded : {self.config}')
|
||||
print(f'Configuration loaded : {self.config}')
|
||||
|
||||
# Sinon tester les dependances python et les installer avec pip
|
||||
if self.do_install():
|
||||
@@ -86,27 +86,13 @@ class Install:
|
||||
if self.is_root():
|
||||
self.skip_install = True
|
||||
|
||||
def init_log_system(self) -> None:
|
||||
|
||||
# Init logs object
|
||||
self.Logs = logging
|
||||
self.Logs.basicConfig(level=logging.DEBUG,
|
||||
filename=self.config.install_log_file,
|
||||
encoding='UTF-8',
|
||||
format='%(asctime)s - %(levelname)s - %(filename)s - %(lineno)d - %(funcName)s - %(message)s')
|
||||
|
||||
self.Logs.debug('#################### STARTING INSTALLATION ####################')
|
||||
|
||||
return None
|
||||
|
||||
def is_root(self) -> bool:
|
||||
|
||||
if os.geteuid() != 0:
|
||||
self.Logs.debug('User without privileges ==> PASS')
|
||||
print('User without privileges ==> PASS')
|
||||
return False
|
||||
elif os.geteuid() == 0:
|
||||
print('/!\\ Do not use root to install Defender /!\\')
|
||||
self.Logs.critical('/!\\ Do not use root to install Defender /!\\')
|
||||
exit("Do not use root to install Defender")
|
||||
return True
|
||||
|
||||
@@ -116,29 +102,23 @@ class Install:
|
||||
|
||||
if not os.path.exists(full_service_file_path):
|
||||
print(f'/!\\ Service file does not exist /!\\')
|
||||
self.Logs.debug('/!\\ Service file does not exist ==> PASS /!\\')
|
||||
return True
|
||||
|
||||
# Check if virtual env exist
|
||||
if not os.path.exists(f'{os.path.join(self.config.defender_install_folder, self.config.venv_folder)}'):
|
||||
self.run_subprocess(self.config.venv_cmd_installation)
|
||||
print(f'/!\\ Virtual env does not exist run the install /!\\')
|
||||
self.Logs.debug('/!\\ Virtual env does not exist run the install ==> PASS /!\\')
|
||||
return True
|
||||
|
||||
def run_subprocess(self, command:list) -> None:
|
||||
|
||||
print(command)
|
||||
self.Logs.debug(f"> {command}")
|
||||
print(f'> {command}')
|
||||
try:
|
||||
check_call(command)
|
||||
print("The command completed successfully.")
|
||||
self.Logs.debug("The command completed successfully.")
|
||||
except CalledProcessError as e:
|
||||
print(f"The command failed with the return code: {e.returncode}")
|
||||
print(f"Try to install dependencies ...")
|
||||
self.Logs.critical(f"The command failed with the return code: {e.returncode}")
|
||||
self.Logs.critical("Try to install dependencies manually ...")
|
||||
exit(5)
|
||||
|
||||
def check_python_version(self) -> bool:
|
||||
@@ -156,16 +136,13 @@ class Install:
|
||||
|
||||
if int(sys_major) < int(min_major):
|
||||
print(f"## Your python version must be greather than or equal to {self.config.python_current_version} ##")
|
||||
self.Logs.critical(f'## Your python version must be greather than or equal to {self.config.python_current_version} ##')
|
||||
return False
|
||||
|
||||
elif (int(sys_major) <= int(min_major)) and (int(sys_minor) < int(min_minor)):
|
||||
print(f"## Your python version must be greather than or equal to {self.config.python_current_version} ##")
|
||||
self.Logs.critical(f'## Your python version must be greather than or equal to {self.config.python_current_version} ##')
|
||||
return False
|
||||
|
||||
print(f"===> Version of python : {self.config.python_current_version} ==> OK")
|
||||
self.Logs.debug(f'===> Version of python : {self.config.python_current_version} ==> OK')
|
||||
print(f"> Version of python : {self.config.python_current_version} ==> OK")
|
||||
|
||||
return True
|
||||
|
||||
@@ -176,7 +153,7 @@ class Install:
|
||||
run([self.config.venv_python_executable, '-c', f'import {package_name}'], check=True, stdout=PIPE, stderr=PIPE)
|
||||
return True
|
||||
except CalledProcessError as cpe:
|
||||
self.Logs.error(cpe)
|
||||
print(cpe)
|
||||
return False
|
||||
|
||||
def install_dependencies(self) -> None:
|
||||
@@ -223,7 +200,6 @@ class Install:
|
||||
|
||||
if os.path.exists(full_service_file_path):
|
||||
print(f'/!\\ Service file already exist /!\\')
|
||||
self.Logs.debug(f'The file {full_service_file_path} exist ==> PASS')
|
||||
return None
|
||||
|
||||
contain = f'''[Unit]
|
||||
|
||||
Reference in New Issue
Block a user