mirror of
https://github.com/ItsDrike/dotfiles.git
synced 2025-04-28 05:02:26 +00:00
OOP: Installation Checks
This commit is contained in:
parent
61c44e1a76
commit
bab2696bac
3 changed files with 100 additions and 4 deletions
|
@ -1,15 +1,102 @@
|
||||||
from util import Path, Print
|
from util import Path, Print, Install
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
|
class InstallationChecks:
|
||||||
|
@staticmethod
|
||||||
|
def installation_error(package):
|
||||||
|
Print.err(f'Dotfiles installation cancelled - {package} not installed')
|
||||||
|
raise Install.InstallationError(f'{package} not installed')
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_installation_path(standard_paths):
|
||||||
|
dir_exists, path = Path.check_dir_exists(standard_paths)
|
||||||
|
path = path.replace('~', '$HOME')
|
||||||
|
|
||||||
|
return dir_exists, path
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def install_package(package, standard_paths, status, use_aur=False):
|
||||||
|
if not Install.package(
|
||||||
|
package,
|
||||||
|
f'default + (This is {status} for dotfiles to work)',
|
||||||
|
aur=use_aur):
|
||||||
|
return False, None
|
||||||
|
else:
|
||||||
|
installation_path = InstallationChecks.get_installation_path(
|
||||||
|
standard_paths)
|
||||||
|
|
||||||
|
if not installation_path: # Package was not found in standard paths after installation
|
||||||
|
Print.err(
|
||||||
|
f'Installation location of {package} has changed, please contact the developer'
|
||||||
|
)
|
||||||
|
return False, None
|
||||||
|
else:
|
||||||
|
return True, installation_path
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def check_zsh():
|
||||||
|
if Install.check_not_installed('zsh'):
|
||||||
|
if not Install.package(
|
||||||
|
'zsh',
|
||||||
|
'default + (This is REQUIRED shell for dotfiles to work)'):
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def check_oh_my_zsh():
|
||||||
|
standard_paths = [
|
||||||
|
'~/.oh-my-zsh', '~/oh-my-zsh', '~/ohmyzsh', '~/.config/oh-my-zsh',
|
||||||
|
'/usr/share/oh-my-zsh'
|
||||||
|
]
|
||||||
|
oh_my_zsh_path = InstallationChecks.get_installation_path(
|
||||||
|
standard_paths)
|
||||||
|
|
||||||
|
if oh_my_zsh_path: # Check if package was found in standard paths
|
||||||
|
return True, oh_my_zsh_path
|
||||||
|
else: # Package wasn't found, try to install it
|
||||||
|
return InstallationChecks.install_package('oh-my-zsh',
|
||||||
|
standard_paths,
|
||||||
|
'REQUIRED zsh package',
|
||||||
|
use_aur=True)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def check_zsh_highlight():
|
||||||
|
standard_paths = [
|
||||||
|
'/usr/share/zsh/plugins/zsh-syntax-highlighting',
|
||||||
|
'/usr/share/zsh/zsh-syntax-highlighting',
|
||||||
|
'/usr/share/zsh-syntax-highlighting'
|
||||||
|
]
|
||||||
|
zsh_highlight_path = InstallationChecks.get_installation_path(
|
||||||
|
standard_paths)
|
||||||
|
|
||||||
|
if zsh_highlight_path: # Check if package was found in standard paths
|
||||||
|
return True, zsh_highlight_path
|
||||||
|
else: # Package wasn't found, try to install it
|
||||||
|
return InstallationChecks.install_package(
|
||||||
|
'zsh-syntax-highlighting', standard_paths,
|
||||||
|
'RECOMMENDED zsh extension')
|
||||||
|
|
||||||
|
|
||||||
class Dotfiles:
|
class Dotfiles:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.backup_location = Path.join(Path.WORKING_FLODER, 'Backups')
|
self.backup_location = Path.join(Path.WORKING_FLODER, 'Backups')
|
||||||
self.dotfiles_location = Path.join(Path.WORKING_FLODER, 'files')
|
self.dotfiles_location = Path.join(Path.WORKING_FLODER, 'files')
|
||||||
|
|
||||||
|
def start(self):
|
||||||
self.initial_checks()
|
self.initial_checks()
|
||||||
|
|
||||||
def initial_checks(self):
|
def initial_checks(self):
|
||||||
pass
|
if not InstallationChecks.check_zsh():
|
||||||
|
InstallationChecks.installation_error('zsh')
|
||||||
|
|
||||||
|
self.oh_my_zsh_installed, self.oh_my_zsh_path = InstallationChecks.check_oh_my_zsh(
|
||||||
|
)
|
||||||
|
if not self.oh_my_zsh_installed:
|
||||||
|
InstallationChecks.installation_error('oh-my-zsh')
|
||||||
|
|
||||||
|
self.zsh_syntax_highlighting_installed, self.zsh_syntax_highlighting_path = InstallationChecks.check_zsh_highlight(
|
||||||
|
)
|
||||||
|
|
||||||
def make_backup(self):
|
def make_backup(self):
|
||||||
Print.action('Creating current dotfiles backup')
|
Print.action('Creating current dotfiles backup')
|
||||||
|
@ -36,3 +123,8 @@ class Dotfiles:
|
||||||
|
|
||||||
def personalized_changes(self, file):
|
def personalized_changes(self, file):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
dotfiles = Dotfiles()
|
||||||
|
dotfiles.start()
|
||||||
|
|
|
@ -5,6 +5,10 @@ import shutil
|
||||||
from util import Command, Input, Print, Path
|
from util import Command, Input, Print, Path
|
||||||
|
|
||||||
|
|
||||||
|
class InstallationError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def _generate_install_text(install_text, package_name, yay=False, git=False):
|
def _generate_install_text(install_text, package_name, yay=False, git=False):
|
||||||
if install_text == 'default':
|
if install_text == 'default':
|
||||||
install_text = f'Do you wish to install {package_name}?'
|
install_text = f'Do you wish to install {package_name}?'
|
||||||
|
|
|
@ -22,10 +22,10 @@ def check_dir_exists(paths):
|
||||||
for dir_path in paths:
|
for dir_path in paths:
|
||||||
dir_path = os.path.expanduser(dir_path)
|
dir_path = os.path.expanduser(dir_path)
|
||||||
if os.path.isdir(dir_path):
|
if os.path.isdir(dir_path):
|
||||||
return True
|
return True, dir_path
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
return False
|
return False, None
|
||||||
|
|
||||||
|
|
||||||
def check_file_exists(paths):
|
def check_file_exists(paths):
|
||||||
|
|
Loading…
Add table
Reference in a new issue