def get_metadata_and_check_license(self, result): """Download files to download + license and check it""" logger.debug("Parse download metadata") error_msg = result[self.download_page].error if error_msg: logger.error("An error occurred while downloading {}: {}".format( self.download_page, error_msg)) UI.return_main_screen() url, checksum = (None, None) with StringIO() as license_txt: in_license = False in_download = False for line in result[self.download_page].buffer: line_content = line.decode() if self.expect_license: in_license = self.parse_license(line_content, license_txt, in_license) (download, in_download) = self.parse_download_link( line_content, in_download) if download is not None: (newurl, new_checksum) = download url = newurl if newurl is not None else url checksum = new_checksum if new_checksum is not None else checksum if url is not None: if self.checksum_type and checksum: logger.debug( "Found download link for {}, checksum: {}". format(url, checksum)) break elif not self.checksum_type: logger.debug( "Found download link for {}".format(url)) break if url is None or (self.checksum_type and checksum is None): logger.error( "Download page changed its syntax or is not parsable") UI.return_main_screen() self.download_requests.append( DownloadItem(url, Checksum(self.checksum_type, checksum))) if license_txt.getvalue() != "": logger.debug("Check license agreement.") UI.display( LicenseAgreement( strip_tags(license_txt.getvalue()).strip(), self.start_download_and_install, UI.return_main_screen)) elif self.expect_license: logger.error( "We were expecting to find a license on the download page, we didn't." ) UI.return_main_screen() else: self.start_download_and_install() return
def get_metadata_and_check_license(self, result): """Download files to download + license and check it""" logger.debug("Parse download metadata") error_msg = result[self.download_page].error if error_msg: logger.error("An error occurred while downloading {}: {}".format( self.download_page, error_msg)) UI.return_main_screen(status_code=1) in_download = False sig_url = None for line in result[self.download_page].buffer: line_content = line.decode() (new_sig_url, in_download) = self.parse_download_link(line_content, in_download) if str(new_sig_url) > str(sig_url): # Avoid fetching development snapshots if 'DEVELOPMENT-SNAPSHOT' not in new_sig_url: tmp_release = re.search("ubuntu(.....).tar", new_sig_url).group(1) if tmp_release <= get_current_distro_version(): sig_url = new_sig_url if not sig_url: logger.error("Download page changed its syntax or is not parsable") UI.return_main_screen(status_code=1) if self.dry_run: UI.display(DisplayMessage("Found download URL: " + sig_url)) UI.return_main_screen(status_code=0) DownloadCenter(urls=[ DownloadItem(sig_url, None), DownloadItem(self.asc_url, None) ], on_done=self.check_gpg_and_start_download, download=False)
def remove(self): """Remove current framework if installed Not that we only remove desktop file, launcher icon and dir content, we do not remove packages as they might be in used for other framework""" # check if it's installed and so on. super().remove() UI.display(DisplayMessage("Removing {}".format(self.name))) if self.desktop_filename: with suppress(FileNotFoundError): os.remove(get_launcher_path(self.desktop_filename)) os.remove( os.path.join(self.default_binary_link_path, self.exec_link_name)) if self.icon_filename: with suppress(FileNotFoundError): os.remove(get_icon_path(self.icon_filename)) with suppress(FileNotFoundError): shutil.rmtree(self.install_path) path = os.path.dirname(self.install_path) while path is not DEFAULT_INSTALL_TOOLS_PATH: if os.listdir(path) == []: logger.debug( "Empty folder, cleaning recursively: {}".format(path)) os.rmdir(path) path = os.path.dirname(path) else: break remove_framework_envs_from_user(self.name) self.remove_from_config() UI.delayed_display(DisplayMessage("Suppression done")) UI.return_main_screen()
def check_data_and_start_download(self, url=None, checksum=None, license_txt=StringIO()): if url is None: logger.error( "Download page changed its syntax or is not parsable (url missing)" ) UI.return_main_screen(status_code=1) if (self.checksum_type and checksum is None): logger.error( "Download page changed its syntax or is not parsable (checksum missing)" ) logger.error("URL is: {}".format(url)) UI.return_main_screen(status_code=1) self.download_requests.append( DownloadItem(url, Checksum(self.checksum_type, checksum))) if license_txt.getvalue() != "": logger.debug("Check license agreement.") UI.display( LicenseAgreement( strip_tags(license_txt.getvalue()).strip(), self.start_download_and_install, UI.return_main_screen)) elif self.expect_license and not self.auto_accept_license: logger.error( "We were expecting to find a license on the download page, we didn't." ) UI.return_main_screen(status_code=1) else: self.start_download_and_install()
def post_install(self): """Add necessary environment variables""" # add a few fall-back variables that might be used by some tools add_env_to_user( self.name, { "NDK_ROOT": { "value": self.install_path, "keep": False }, "ANDROID_NDK": { "value": self.install_path, "keep": False }, "ANDROID_NDK_HOME": { "value": self.install_path, "keep": False } }) # print wiki page message UI.display( DisplayMessage( "NDK installed in {}. More information on how to use it on {}". format( self.install_path, "https://developer.android.com/tools/sdk/ndk/index.html#GetStarted" )))
def confirm_path(self, path_dir=""): """Confirm path dir""" if not path_dir: logger.debug("No installation path provided. Requesting one.") UI.display(InputText("Choose installation path:", self.confirm_path, self.install_path)) return logger.debug("Installation path provided. Checking if exists.") with suppress(FileNotFoundError): if os.listdir(path_dir): # we already told we were ok to overwrite as it was the previous install path if path_dir not in self._paths_to_clean: if path_dir == "/": logger.error("This doesn't seem wise. We won't let you shoot in your feet.") self.confirm_path() return self.install_path = path_dir # we don't set it before to not repropose / as installation path UI.display(YesNo("{} isn't an empty directory, do you want to remove its content and install " "there?".format(path_dir), self.set_installdir_to_clean, UI.return_main_screen)) return self.install_path = path_dir if self.desktop_filename: self.exec_path = os.path.join(self.install_path, self.required_files_path[0]) # if self.exec_rel_path: # self.exec_path = os.path.join(self.install_path, self.exec_rel_path) self.download_provider_page()
def check_external_license(self, result): """Check external license which is in a separate page (can be factorized in BaseInstaller)""" logger.debug("Parse license page") error_msg = result[self.license_url].error if error_msg: logger.error("An error occurred while downloading {}: {}".format(self.license_url, error_msg)) UI.return_main_screen(status_code=1) with StringIO() as license_txt: in_license = False for line in result[self.license_url].buffer: line = line.decode() if ('SOFTWARE LICENSE TERMS' in line): in_license = True if in_license and "<strong>* * *</strong>" in line: in_license = False continue if in_license: license_txt.write(line.strip() + "\n") if license_txt.getvalue() != "": logger.debug("Check license agreement.") UI.display(LicenseAgreement(strip_tags(license_txt.getvalue()).strip(), self.start_download_and_install, UI.return_main_screen)) else: logger.error("We were expecting to find a license, we didn't.") UI.return_main_screen(status_code=1)
def remove(self): """Remove current framework if installed Not that we only remove desktop file, launcher icon and dir content, we do not remove packages as they might be in used for other framework""" # check if it's installed and so on. super().remove() UI.display(DisplayMessage("Removing {}".format(self.name))) if self.desktop_filename: with suppress(FileNotFoundError): os.remove(get_launcher_path(self.desktop_filename)) os.remove( os.path.join(self.default_binary_link_path, self.exec_link_name)) if self.icon_filename: with suppress(FileNotFoundError): os.remove(get_icon_path(self.icon_filename)) with suppress(FileNotFoundError): shutil.rmtree(self.install_path) remove_framework_envs_from_user(self.name) self.remove_from_config() UI.delayed_display(DisplayMessage("Suppression done")) UI.return_main_screen()
def decompress_and_install(self, fds): UI.display(DisplayMessage("Installing {}".format(self.name))) # empty destination directory if reinstall for dir_to_remove in self._paths_to_clean: with suppress(FileNotFoundError): shutil.rmtree(dir_to_remove) # marked them as cleaned self._paths_to_clean = [] os.makedirs(self.install_path, exist_ok=True) decompress_fds = {} for fd in fds: direct_copy = False for ext in self.DIRECT_COPY_EXT: if fd.name.endswith(ext): direct_copy = True break if direct_copy: shutil.copy2( fd.name, os.path.join(self.install_path, os.path.basename(fd.name))) else: decompress_fds[fd] = Decompressor.DecompressOrder( dir=self.dir_to_decompress_in_tarball, dest=self.install_path) Decompressor(decompress_fds, self.decompress_and_install_done) UI.display(UnknownProgress(self.iterate_until_install_done))
def confirm_path(self, path_dir=""): """Confirm path dir""" if not path_dir: logger.debug("No installation path provided. Requesting one.") UI.display( InputText("Choose installation path:", self.confirm_path, self.install_path)) return logger.debug("Installation path provided. Checking if exists.") with suppress(FileNotFoundError): if os.listdir(path_dir): # we already told we were ok to overwrite as it was the previous install path if path_dir not in self._paths_to_clean: if path_dir == "/": logger.error( "This doesn't seem wise. We won't let you shoot in your feet." ) self.confirm_path() return self.install_path = path_dir # we don't set it before to not repropose / as installation path UI.display( YesNo( "{} isn't an empty directory, do you want to remove its content and install " "there?".format(path_dir), self.set_installdir_to_clean, UI.return_main_screen)) return self.install_path = path_dir self.download_provider_page()
def language_select_callback(self, url): url = url.replace("&", "&") logger.debug("Found download link for {}".format(url)) if self.dry_run: UI.display(DisplayMessage("Found download URL: " + url)) UI.return_main_screen(status_code=0) self.download_requests.append(DownloadItem(url, None)) self.start_download_and_install()
def post_install(self): """Add necessary environment variables""" add_env_to_user(self.name, {"NDK_ROOT": {"value": self.install_path, "keep": False}}) # print wiki page message UI.display(DisplayMessage("NDK installed in {}. More information on how to use it on {}".format( self.install_path, "https://developer.android.com/tools/sdk/ndk/index.html#GetStarted")))
def post_install(self): """Print wiki page message""" UI.display( DisplayMessage( "NDK installed in {}. More information on how to use it on {}". format( self.install_path, "https://developer.android.com/tools/sdk/ndk/index.html#GetStarted" )))
def decompress_and_install(self, fd): UI.display(DisplayMessage("Installing {}".format(self.name))) # empty destination directory if reinstall for dir_to_remove in self._paths_to_clean: with suppress(FileNotFoundError): shutil.rmtree(dir_to_remove) Decompressor({fd: Decompressor.DecompressOrder(dir=self.dir_to_decompress_in_tarball, dest=self.install_path)}, self.decompress_and_install_done) UI.display(UnknownProgress(self.iterate_until_install_done))
def test_call_display(self, mocksys): """We call the display method from the UIPlug""" UI.display(self.contentType) self.start_glib_mainloop() self.wait_for_mainloop_shutdown() self.assertTrue(self.mockUIPlug._display.called) self.assertIsNotNone(self.mainloop_thread) self.assertIsNotNone(self.display_thread) self.assertEqual(self.mainloop_thread, self.display_thread)
def setup(self, arg_install_path=None): self.arg_install_path = arg_install_path super().setup() # first step, check if installed if self.is_installed: UI.display(YesNo("{} is already installed on your system, do you want to reinstall " "it anyway?".format(self.name), self.reinstall, UI.return_main_screen)) else: self.confirm_path(arg_install_path)
def setup(self, install_path=None, auto_accept_license=False): self.arg_install_path = install_path self.auto_accept_license = auto_accept_license super().setup() # first step, check if installed if self.is_installed: UI.display(YesNo("{} is already installed on your system, do you want to reinstall " "it anyway?".format(self.name), self.reinstall, UI.return_main_screen)) else: self.confirm_path(self.arg_install_path)
def decompress_and_install(self, fd): UI.display(DisplayMessage("Installing {}".format(self.name))) shutil.copyfile(fd.name, self.install_path + '/drjava.jar') self.post_install() # Mark as installation done in configuration self.mark_in_config() UI.delayed_display(DisplayMessage("Installation done")) UI.return_main_screen()
def get_metadata_and_check_license(self, result): """Download files to download + license and check it""" logger.debug("Parse download metadata") error_msg = result[self.download_page].error if error_msg: logger.error("An error occurred while downloading {}: {}".format(self.download_page, error_msg)) UI.return_main_screen(status_code=1) url, checksum = (None, None) with StringIO() as license_txt: in_license = False in_download = False for line in result[self.download_page].buffer: line_content = line.decode() if self.expect_license and not self.auto_accept_license: in_license = self.parse_license(line_content, license_txt, in_license) # always take the first valid (url, checksum) if not match_last_link is set to True: download = None if url is None or (self.checksum_type and not checksum) or self.match_last_link: (download, in_download) = self.parse_download_link(line_content, in_download) if download is not None: (newurl, new_checksum) = download url = newurl if newurl is not None else url checksum = new_checksum if new_checksum is not None else checksum if url is not None: if self.checksum_type and checksum: logger.debug("Found download link for {}, checksum: {}".format(url, checksum)) elif not self.checksum_type: logger.debug("Found download link for {}".format(url)) if url is None: logger.error("Download page changed its syntax or is not parsable (url missing)") UI.return_main_screen(status_code=1) if (self.checksum_type and checksum is None): logger.error("Download page changed its syntax or is not parsable (checksum missing)") logger.error("URL is: {}".format(url)) UI.return_main_screen(status_code=1) self.download_requests.append(DownloadItem(url, Checksum(self.checksum_type, checksum))) if license_txt.getvalue() != "": logger.debug("Check license agreement.") UI.display(LicenseAgreement(strip_tags(license_txt.getvalue()).strip(), self.start_download_and_install, UI.return_main_screen)) elif self.expect_license and not self.auto_accept_license: logger.error("We were expecting to find a license on the download page, we didn't.") UI.return_main_screen(status_code=1) else: self.start_download_and_install()
def start_download_and_install(self): self.last_progress_download = None self.last_progress_requirement = None self.balance_requirement_download = None self.pkg_size_download = 0 self.result_requirement = None self.result_download = None self._download_done_callback_called = False UI.display(DisplayMessage("Downloading and installing requirements")) self.pbar = ProgressBar().start() self.pkg_to_install = RequirementsHandler().install_bucket(self.packages_requirements, self.get_progress_requirement, self.requirement_done) DownloadCenter(urls=self.download_requests, on_done=self.download_done, report=self.get_progress_download)
def post_install(self): """Add necessary environment variables""" add_env_to_user( self.name, {"ANDROID_NDK": { "value": self.install_path, "keep": False }}) """Print wiki page message""" UI.display( DisplayMessage( "NDK installed in {}. More information on how to use it on {}". format( self.install_path, "https://developer.android.com/tools/sdk/ndk/index.html#GetStarted" )))
def check_data_and_start_download(self, url=None, checksum=None, license_txt=StringIO()): if url is None: logger.error("Download page changed its syntax or is not parsable (url missing)") UI.return_main_screen(status_code=1) if (self.checksum_type and checksum is None): logger.error("Download page changed its syntax or is not parsable (checksum missing)") logger.error("URL is: {}".format(url)) UI.return_main_screen(status_code=1) self.download_requests.append(DownloadItem(url, Checksum(self.checksum_type, checksum))) if license_txt.getvalue() != "": logger.debug("Check license agreement.") UI.display(LicenseAgreement(strip_tags(license_txt.getvalue()).strip(), self.start_download_and_install, UI.return_main_screen)) elif self.expect_license and not self.auto_accept_license: logger.error("We were expecting to find a license on the download page, we didn't.") UI.return_main_screen(status_code=1) else: self.start_download_and_install()
def remove(self): """Remove current framework if installed Not that we only remove desktop file, launcher icon and dir content, we do not remove packages as they might be in used for other framework""" # check if it's installed and so on. super().remove() UI.display(DisplayMessage("Removing {}".format(self.name))) if self.desktop_filename: with suppress(FileNotFoundError): os.remove(get_launcher_path(self.desktop_filename)) if self.icon_filename: with suppress(FileNotFoundError): os.remove(get_icon_path(self.icon_filename)) with suppress(FileNotFoundError): shutil.rmtree(self.install_path) remove_framework_envs_from_user(self.name) self.remove_from_config() UI.delayed_display(DisplayMessage("Suppression done")) UI.return_main_screen()
def decompress_and_install(self, fds): UI.display(DisplayMessage("Installing {}".format(self.name))) # empty destination directory if reinstall for dir_to_remove in self._paths_to_clean: with suppress(FileNotFoundError): shutil.rmtree(dir_to_remove) # marked them as cleaned self._paths_to_clean = [] os.makedirs(self.install_path, exist_ok=True) decompress_fds = {} for fd in fds: direct_copy = False for ext in self.DIRECT_COPY_EXT: if fd.name.endswith(ext): direct_copy = True break if direct_copy: shutil.copy2(fd.name, os.path.join(self.install_path, os.path.basename(fd.name))) else: decompress_fds[fd] = Decompressor.DecompressOrder(dir=self.dir_to_decompress_in_tarball, dest=self.install_path) Decompressor(decompress_fds, self.decompress_and_install_done) UI.display(UnknownProgress(self.iterate_until_install_done))
def run_display(future): self.function_thread = threading.current_thread().ident UI.display(self.contentType)
def post_install(self): """Print wiki page message""" UI.display(DisplayMessage("NDK installed in {}. More information on how to use it on {}".format( self.install_path, "https://developer.android.com/tools/sdk/ndk/index.html#GetStarted")))