Skip to content

Commit

Permalink
Feature/add update test (#27)
Browse files Browse the repository at this point in the history
* added update test

* added debug mode

* fix update opensuse

* minor refactoring
  • Loading branch information
l8556 authored Apr 3, 2024
1 parent 08a4dc4 commit 1bb874e
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 110 deletions.
21 changes: 10 additions & 11 deletions frameworks/desktop/desktop_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ def __init__(self, data: Data):
self.log_file = join(self.tmp_dir, "desktop.log")
self.create_log_file()
self.debug_command = '--ascdesktop-support-debug-info'
self.log_out_command = f'--ascdesktop-log-file={"stdout" if HostInfo().os != "windows" else self.log_file}'
self.log_out_cmd = f'--ascdesktop-log-file={"stdout" if HostInfo().os != "windows" else self.log_file}'

def open(self, file_path: str = None, debug_mode: bool = False, log_out_mode: bool = False) -> Popen:
command = (
f"{self._generate_running_command()}"
f"{(' ' + self.log_out_command) if log_out_mode else ''}"
f"{(' ' + self.log_out_cmd) if log_out_mode else ''}"
f"{(' ' + self.debug_command) if debug_mode else ''}"
f"{(' ' + file_path) if file_path else ''}".strip()
)
return Popen(command, stdout=PIPE, stderr=PIPE, shell=True)

@staticmethod
def wait_until_open(
self,
stdout_process: Popen,
wait_msg: str = '[DesktopEditors]: start page loaded',
timeout: int = 30
Expand All @@ -43,7 +43,7 @@ def wait_until_open(
with console.status('green]|INFO| Wait until desktop editor opens') as status:
while (time.time() - start_time) < timeout:
status.update(f'[green]|INFO| Waiting for {wait_msg}: {timeout-(time.time() - start_time):.02f} sec.')
output = stdout_process.stdout.readline().decode().strip()
output = self._read_log(wait_msg, stdout_process)
if output:
console.print(f"[cyan]|INFO| {output}")
if wait_msg in output:
Expand All @@ -53,24 +53,23 @@ def wait_until_open(
f"[red]|ERROR| The waiting time {timeout} seconds for the editor to open has expired."
)

def version(self) -> "str | None":
def get_version(self) -> "str | None":
version = re.findall(
r"\d+\.\d+\.\d+\.\d+",
FileUtils.output_cmd(f'{self._generate_running_command()} --version')
)
return version[0] if version else None

def close(self):
# Todo
# call('killall DesktopEditors', shell=True) -> segmentation fault in stdout
...
def _read_log(self, wait_msg: str, stdout_process: Popen) -> str:
if 'stdout' in self.log_out_cmd:
return stdout_process.stdout.readline().decode().strip()

def read_log(self, wait_msg: str):
for line in FileUtils.file_reader(self.log_file).split('\n'):
print(line) if line else ...
if wait_msg == line.strip():
self.create_log_file()
return
return line.strip()


def create_log_file(self):
FileUtils.create_dir(dirname(self.log_file), stdout=False)
Expand Down
28 changes: 18 additions & 10 deletions frameworks/desktop/package/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ def __init__(self, data: Data):
self.path: str = join(self.download_dir, self.name)
FileUtils.create_dir(self.download_dir, stdout=False)

def get(self) -> "None":
def get(self) -> None:
headers = FileUtils.get_headers(self.url)
if self.exists(headers):
print(f"[green]|INFO| Package {self.name} already exists. Path: {self.path}")
else:
self.download() if headers else print(f"[red]|WARNING| Package does not exist on aws")
self.install()

@highlighter(color='green')
def download(self) -> None:
Expand All @@ -37,23 +36,32 @@ def download(self) -> None:
def exists(self, headers: "dict | None" = None) -> bool:
if headers and isfile(self.path):
return int(getsize(self.path)) == int(headers['Content-Length'])
elif isfile(self.path):
return True
return False
return isfile(self.path)

def install(self) -> None:
def install(
self,
yum_installer: bool = False,
apt_get_installer: bool = False,
custom_installer: str = None
) -> None:
print(f"[green]|INFO| Installing Desktop version: {self.version}\nPackage: {self.name}")
if isfile(self.path):
call(self._get_install_command(), shell=True)
call(self._get_install_command(yum_installer, apt_get_installer, custom_installer), shell=True)
else:
raise PackageException(f"[red]|ERROR| Package not exists.")

def _get_install_command(self) -> str:
def _get_install_command(self, yum_installer: bool, apt_get_installer: bool, custom_installer: str = None) -> str:
if custom_installer:
return f"sudo {custom_installer} {self.path}"
if self.path.lower().endswith('.deb'):
self._unlock_dpkg()
return f'sudo dpkg -i {self.path}'
if apt_get_installer:
return f"sudo apt-get install -y {self.path}"
return f"sudo dpkg -i {self.path}"
elif self.path.lower().endswith('.rpm'):
return f'sudo rpm -i {self.path}'
if yum_installer:
return f"sudo yum install -y {self.path}"
return f"sudo rpm -i {self.path}"
else:
raise PackageException(
f"[red]|ERROR| Unable to generate a command to install the desktop package.\n"
Expand Down
48 changes: 25 additions & 23 deletions frameworks/host_control/host_info/HostInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,35 @@
@singleton
class HostInfo:
def __init__(self):
self.os = system().lower()
self.__arch = machine().lower()

def name(self, pretty: bool = False) -> "str | None":
if self.os == 'windows':
return self.os
return Unix().pretty_name if pretty else Unix().id

@property
def version(self) -> "str | None":
return version() if self.os == 'windows' else Unix().version
self.__os = None
self.__arch = None
self.__version = None

@property
def os(self):
def os(self) -> str:
if self.__os is None:
self.__os = system().lower()
if self.__os not in ['linux', 'darwin', 'windows']:
print(f"[bold red]|ERROR| Error defining os: {self.__os}")
self.__os = ''
return self.__os

@property
def arch(self):
def arch(self) -> str:
if self.__arch is None:
self.__arch = machine().lower()
return self.__arch

@os.setter
def os(self, value):
if value == 'linux':
self.__os = 'linux'
elif value == 'darwin':
self.__os = 'mac'
elif value == 'windows':
self.__os = 'windows'
else:
print(f"[bold red]|WARNING| Error defining os: {value}")
def name(self, pretty: bool = False) -> str:
if self.os == 'windows':
return self.os
return Unix().pretty_name if pretty else Unix().id

@property
def version(self) -> str:
if self.__version is None:
if self.os == 'windows':
self.__version = version()
else:
self.__version = Unix().version
return self.__version
55 changes: 15 additions & 40 deletions frameworks/host_control/host_info/Unix.py
Original file line number Diff line number Diff line change
@@ -1,61 +1,36 @@
# -*- coding: utf-8 -*-
import platform
from distro import name, version, id

from frameworks.decorators import singleton
import distro

@singleton
class Unix:
def __init__(self):
self._name = distro.name()
self._version = distro.version()
self._id = distro.id()
self._pretty_name = distro.name(pretty=True)
self._name = None
self._version = None
self._id = None
self._pretty_name = None

@property
def pretty_name(self):
def pretty_name(self) -> str:
if self._pretty_name is None:
self._pretty_name = name(pretty=True)
return self._pretty_name

@pretty_name.setter
def pretty_name(self, value):
if value:
self._pretty_name = value
else:
raise print(f"[bold red]|ERROR| Can't get pretty name")

@property
def id(self):
def id(self) -> str:
if self._id is None:
self._id = id()
return self._id

@id.setter
def id(self, value):
if value:
self._id = value
else:
raise print(f"[bold red]|ERROR| Can't get distribution id")

@property
def name(self) -> str:
if self._name is None:
self._name = name()
return self._name

@property
def version(self) -> str:
if self._version is None:
self._version = version()
return self._version

@version.setter
def version(self, value: str):
if value:
self._version = value
else:
raise print(f"[bold red]|ERROR| Can't get distribution version")

@name.setter
def name(self, value: str):
if value:
self._name = value
else:
raise print(f"[bold red]|ERROR| Can't get distribution name")

@staticmethod
def get_distro_info() -> dict:
return platform.freedesktop_os_release()
15 changes: 9 additions & 6 deletions tasks.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
# -*- coding: utf-8 -*-
from invoke import task

from tests.desktop_test import DesktopTest
from tests.desktop_tests import DesktopTests


@task
def open_test(c, version=None, display=False, config=None, telegram=False, license=None):
DesktopTest(
def open_test(c, version=None, update_from=None, display=False, config=None, telegram=False, license=None):
DesktopTests(
version=version,
update_from=update_from,
virtual_display=display,
custom_config=config if config else None,
telegram=telegram,
license_file_path=license
).run()
).open_test()


@task
def install_desktop(c, version=None, config=None, license=None):
test = DesktopTest(
test = DesktopTests(
version=version,
virtual_display=False,
debug_mode=True,
custom_config=config if config else None,
license_file_path=license
)
test.install_package()
test.install_package(test.version, test.desktop)
test.check_installed()
test.check_correct_version()
test.desktop.set_license()
Expand Down
Loading

0 comments on commit 1bb874e

Please sign in to comment.