def get_metadata_and_check_license(self, result): logger.debug("Fetched download page, parsing.") page = result[self.download_page] error_msg = 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) try: assets = json.loads(page.buffer.read().decode())["assets"] download_url = None for asset in assets: if ".tar.gz" in asset["browser_download_url"]: download_url = asset["browser_download_url"] if not download_url: raise IndexError except (json.JSONDecodeError, IndexError): logger.error( "Can't parse the download URL from the download page.") UI.return_main_screen(status_code=1) logger.debug("Found download URL: " + download_url) self.download_requests.append(DownloadItem(download_url, None)) self.start_download_and_install()
def get_metadata_and_check_license(self, result): """Get latest version and append files to download""" logger.debug("Set 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) version = '' version_re = r'Dart SDK (.*) api docs' for line in result[self.download_page].buffer: p = re.search(version_re, line.decode()) with suppress(AttributeError): version = p.group(1) break else: logger.error("Download page changed its syntax or is not parsable") UI.return_main_screen(status_code=1) tag_machine = 'x64' if platform.machine() == 'i686': tag_machine = 'ia32' url = "https://storage.googleapis.com/dart-archive/channels/stable/release/{}/sdk/dartsdk-linux-{}-release.zip"\ .format(version, tag_machine) logger.debug("Found download link for {}".format(url)) self.download_requests.append(DownloadItem(url, None)) self.start_download_and_install()
def get_metadata_and_check_license(self, result): logger.debug("Fetched download page, parsing.") page = result[self.download_page] error_msg = page.error if error_msg: logger.error("An error occurred while downloading {}: {}".format(self.download_page_url, error_msg)) UI.return_main_screen() soup = BeautifulSoup(page.buffer) link = soup.find('a', text="HTTPS") if link is None: logger.error("Can't parse the download URL from the download page.") UI.return_main_screen() download_url = link.attrs['href'] checksum_url = download_url + '.sha256' logger.debug("Found download URL: " + download_url) logger.debug("Downloading checksum first, from " + checksum_url) def checksum_downloaded(results): checksum_result = next(iter(results.values())) # Just get the first. if checksum_result.error: logger.error(checksum_result.error) UI.return_main_screen() checksum = checksum_result.buffer.getvalue().decode('utf-8').split()[0] logger.info('Obtained SHA256 checksum: ' + checksum) self.download_requests.append(DownloadItem(download_url, checksum=Checksum(ChecksumType.sha256, checksum), ignore_encoding=True)) self.start_download_and_install() DownloadCenter([DownloadItem(checksum_url)], on_done=checksum_downloaded, download=False)
def get_metadata_and_check_license(self, result): """Get the latest version and trigger the download of the download_page file. :param result: the file downloaded by DownloadCenter, contains a web page """ # Processing the string to obtain metadata (version) try: url_version_str = result[self.download_page].buffer.read().decode('utf-8') except AttributeError: # The file could not be parsed or there is no network connection logger.error("The download page changed its syntax or is not parsable") UI.return_main_screen(status_code=1) preg = re.compile(".*/images_www/v6/download/.*") for line in url_version_str.split("\n"): if preg.match(line): line = line.replace("var PAGE_ARTIFACTS_LOCATION = \"/images" "_www/v6/download/", "").replace("/\";", "").replace('/final', '') self.version = line.strip() if not self.version: # Fallback logger.error("Could not determine latest version") UI.return_main_screen(status_code=1) self.version_download_page = "https://netbeans.org/images_www/v6/download/" \ "{}/final/js/files.js".format(self.version) DownloadCenter([DownloadItem(self.version_download_page)], self.parse_download_page_callback, download=False)
def complete_download_url(self, result): """Parse the download page and get the SHASUMS256.txt page""" version = None logger.debug("Set the version in the download url") 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) for line in result[self.download_page].buffer: line_content = line.decode() with suppress(AttributeError): if self.lts and "most_recent_lts" in line_content: version = re.search(r': (.*),', line_content).group(1) elif not self.lts and "most_recent_feature_release" in line_content: version = re.search(r': (.*),', line_content).group(1) if not result: logger.error("Download page changed its syntax or is not parsable") UI.return_main_screen(status_code=1) self.download_page = "https://api.adoptopenjdk.net/v3/assets/latest/{}/".format(version) + \ "{}?release=latest&".format(self.jvm_impl) + \ "jvm_impl={}".format(self.jvm_impl) + \ "&vendor=adoptopenjdk&=" DownloadCenter([DownloadItem(self.download_page)], self.get_metadata_and_check_license, download=False)
def download_and_requirements_done(self): # wait for both side to be done if self._download_done_callback_called or ( not self.result_download or not self.result_requirement): return self._download_done_callback_called = True self.pbar.finish() # display eventual errors error_detected = False if self.result_requirement.error: logger.error("Package requirements can't be met: {}".format( self.result_requirement.error)) error_detected = True # check for any errors and collect fds fds = [] for url in self.result_download: if self.result_download[url].error: logger.error(self.result_download[url].error) error_detected = True fds.append(self.result_download[url].fd) if error_detected: UI.return_main_screen(status_code=1) # now decompress self.decompress_and_install(fds)
def get_metadata_and_check_license(self, result): logger.debug("Fetched download page, parsing.") page = result[self.download_page] error_msg = page.error if error_msg: logger.error("An error occurred while downloading {}: {}".format(self.download_page_url, error_msg)) UI.return_main_screen(status_code=1) soup = BeautifulSoup(page.buffer) link = soup.find('a', text="HTTPS") if link is None: logger.error("Can't parse the download URL from the download page.") UI.return_main_screen(status_code=1) download_url = link.attrs['href'] checksum_url = download_url + '.sha256' logger.debug("Found download URL: " + download_url) logger.debug("Downloading checksum first, from " + checksum_url) def checksum_downloaded(results): checksum_result = next(iter(results.values())) # Just get the first. if checksum_result.error: logger.error(checksum_result.error) UI.return_main_screen(status_code=1) checksum = checksum_result.buffer.getvalue().decode('utf-8').split()[0] logger.info('Obtained SHA256 checksum: ' + checksum) self.download_requests.append(DownloadItem(download_url, checksum=Checksum(ChecksumType.sha256, checksum), ignore_encoding=True)) self.start_download_and_install() DownloadCenter([DownloadItem(checksum_url)], on_done=checksum_downloaded, 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) remove_framework_envs_from_user(self.name) self.remove_from_config() UI.delayed_display(DisplayMessage("Suppression done")) UI.return_main_screen()
def get_metadata(self, result): """Download files to download + and download license 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) arch = platform.machine() download_re = r'\'linux64\': \'([^\']+)\'' if arch == 'i686': download_re = r'\'linux32\': \'([^\']+)\'' url = None for line in result[self.download_page].buffer: line = line.decode() p = re.search(download_re, line) with suppress(AttributeError): url = p.group(1) logger.debug("Found download link for {}".format(url)) if url is None: logger.error("Download page changed its syntax or is not parsable") UI.return_main_screen(status_code=1) self.download_requests.append(DownloadItem(url, Checksum(self.checksum_type, None), headers=self.headers)) if not self.auto_accept_license: logger.debug("Downloading License page") DownloadCenter([DownloadItem(self.license_url, headers=self.headers)], self.check_external_license, download=False) else: self.start_download_and_install()
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 get_metadata_and_check_license(self, result): logger.debug("Fetched download page, parsing.") page = result[self.download_page] error_msg = 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) try: key, content = json.loads(page.buffer.read().decode()).popitem() download_url = content[0]['downloads']['linux']['link'] checksum_url = content[0]['downloads']['linux']['checksumLink'] except (json.JSONDecodeError, IndexError): logger.error("Can't parse the download URL from the download page.") UI.return_main_screen(status_code=1) logger.debug("Found download URL: " + download_url) logger.debug("Downloading checksum first, from " + checksum_url) def checksum_downloaded(results): checksum_result = next(iter(results.values())) # Just get the first. if checksum_result.error: logger.error(checksum_result.error) UI.return_main_screen(status_code=1) checksum = checksum_result.buffer.getvalue().decode('utf-8').split()[0] logger.info('Obtained SHA256 checksum: ' + checksum) self.download_requests.append(DownloadItem(download_url, checksum=Checksum(ChecksumType.sha256, checksum), ignore_encoding=True)) self.start_download_and_install() DownloadCenter([DownloadItem(checksum_url)], on_done=checksum_downloaded, download=False)
def get_metadata_and_check_license(self, result): """Get the latest version and trigger the download of the download_page file. :param result: the file downloaded by DownloadCenter, contains a web page """ # Processing the string to obtain metadata (version) try: url_version_str = result[self.download_page].buffer.read().decode('utf-8') except AttributeError: # The file could not be parsed or there is no network connection logger.error("The download page changed its syntax or is not parsable") UI.return_main_screen(status_code=1) preg = re.compile(".*/images_www/v6/download/.*") for line in url_version_str.split("\n"): if preg.match(line): line = line.replace("var PAGE_ARTIFACTS_LOCATION = \"/images" "_www/v6/download/", "").replace("/\";", "") self.version = line.strip() if not self.version: # Fallback logger.error("Could not determine latest version") UI.return_main_screen(status_code=1) self.version_download_page = "https://netbeans.org/images_www/v6/download/" \ "{}/js/files.js".format(self.version) DownloadCenter([DownloadItem(self.version_download_page)], self.parse_download_page_callback, download=False)
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): tmp_release = re.search("ubuntu(.....).tar", new_sig_url).group(1) if tmp_release <= get_current_ubuntu_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) DownloadCenter(urls=[ DownloadItem(sig_url, None), DownloadItem(self.asc_url, None) ], on_done=self.check_gpg_and_start_download, download=False)
def check_gpg_and_start_download(self, download_result): asc_content = download_result.pop( self.asc_url).buffer.getvalue().decode('utf-8') sig_url = list(download_result.keys())[0] res = download_result[sig_url] sig = res.buffer.getvalue().decode('utf-8').split()[0] # When we install new packages, we are executing as root and then dropping # as the user for extracting and such. However, for signature verification, # we use gpg. This one doesn't like priviledge drop (if uid = 0 and # euid = 1000) and asserts if uid != euid. # Importing the key as root as well creates new gnupg files owned as root if # new keys weren't imported first. # Consequently, run gpg as root if we needed root access or as the user # otherwise. We store the gpg public key in a temporary gnupg directory that # will be removed under the same user rights (this directory needs to be owned # by the same user id to not be rejected by gpg).Z if self.need_root_access: with as_root(): with tempfile.TemporaryDirectory() as tmpdirname: self._check_gpg_signature(tmpdirname, asc_content, sig) else: with tempfile.TemporaryDirectory() as tmpdirname: self._check_gpg_signature(tmpdirname, asc_content, sig) # you get and store self.download_url url = re.sub('.sig', '', sig_url) if url is None: logger.error( "Download page changed its syntax or is not parsable (missing url)" ) UI.return_main_screen(status_code=1) logger.debug("Found download link for {}".format(url)) self.download_requests.append(DownloadItem(url, None)) self.start_download_and_install()
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 url_found = False for line in result[self.download_page].buffer: line_content = line.decode() (_url_found, in_download) = self.parse_download_link(line_content, in_download) if not url_found: url_found = _url_found if not url_found: logger.error("Download page changed its syntax or is not parsable") UI.return_main_screen(status_code=1) DownloadCenter(urls=[DownloadItem(self.checksum_url, None)], on_done=self.get_sha_and_start_download, download=False)
def get_metadata(self, result): """Download files to download + and download license 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 = None for line in result[self.download_page].buffer: line = line.decode() p = re.search(r'<a.*href="(.*)">.*for Linux.*', line) with suppress(AttributeError): url = p.group(1) logger.debug("Found download link for {}".format(url)) if url 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, None), headers=self.headers)) logger.debug("Downloading License page") DownloadCenter([DownloadItem(self.license_url, headers=self.headers)], self.check_external_license, 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 download_provider_page(self): # grab initial download link from homepage response = urllib.request.urlopen('https://processing.org/download/?processing') htmlDocument = response.read() soupDocument = BeautifulSoup(htmlDocument, 'html.parser') arch = platform.machine() plat = '' if arch == 'i686': plat = 'linux32' elif arch == 'x86_64': plat = 'linux64' else: logger.error("Unsupported architecture: {}".format(arch)) UI.return_main_screen() downloads = soupDocument.body.find('div', attrs={'class': 'downloads'}) self.version = downloads.find('span', attrs={'class': 'version'}).text dl = downloads.find('ul', attrs={'class': 'current-downloads'}) fileURL = '' for link in dl.find_all('a'): url = link.get('href') if plat in url: fileURL = url break self.download_requests.append(DownloadItem(fileURL)) self.start_download_and_install()
def get_metadata_and_check_license(self, result): logger.debug("Fetched download page, parsing.") page = result[self.download_page] error_msg = 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) try: key, content = json.loads(page.buffer.read().decode()).popitem() download_url = content[0]['downloads']['linux']['link'] checksum_url = content[0]['downloads']['linux']['checksumLink'] except (json.JSONDecodeError, IndexError): logger.error("Can't parse the download URL from the download page.") UI.return_main_screen(status_code=1) logger.debug("Found download URL: " + download_url) logger.debug("Downloading checksum first, from " + checksum_url) def checksum_downloaded(results): checksum_result = next(iter(results.values())) # Just get the first. if checksum_result.error: logger.error(checksum_result.error) UI.return_main_screen(status_code=1) checksum = checksum_result.buffer.getvalue().decode('utf-8').split()[0] logger.info('Obtained SHA256 checksum: ' + checksum) self.download_requests.append(DownloadItem(download_url, checksum=Checksum(ChecksumType.sha256, checksum), ignore_encoding=True)) self.start_download_and_install() DownloadCenter([DownloadItem(checksum_url)], on_done=checksum_downloaded, download=False)
def get_metadata(self, result): """Download files to download + and download license 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) arch = platform.machine() download_re = r'\'linux64\': \'([^\']+)\'' if arch == 'i686': download_re = r'\'linux32\': \'([^\']+)\'' url = None for line in result[self.download_page].buffer: line = line.decode() p = re.search(download_re, line) with suppress(AttributeError): url = p.group(1) logger.debug("Found download link for {}".format(url)) if url is None: logger.error("Download page changed its syntax or is not parsable") UI.return_main_screen(status_code=1) self.download_requests.append(DownloadItem(url, Checksum(self.checksum_type, None), headers=self.headers)) if not self.auto_accept_license: logger.debug("Downloading License page") DownloadCenter([DownloadItem(self.license_url, headers=self.headers)], self.check_external_license, download=False) else: self.start_download_and_install()
def download_and_requirements_done(self): # wait for both side to be done if self._download_done_callback_called or (not self.result_download or not self.result_requirement): return self._download_done_callback_called = True self.pbar.finish() # display eventual errors error_detected = False if self.result_requirement.error: logger.error("Package requirements can't be met: {}".format(self.result_requirement.error)) error_detected = True # check for any errors and collect fds fds = [] for url in self.result_download: if self.result_download[url].error: logger.error(self.result_download[url].error) error_detected = True fds.append(self.result_download[url].fd) if error_detected: UI.return_main_screen(status_code=1) # now decompress self.decompress_and_install(fds)
def check_gpg_and_start_download(self, download_result): asc_content = download_result.pop(self.asc_url).buffer.getvalue().decode('utf-8') sig_url = list(download_result.keys())[0] res = download_result[sig_url] sig = res.buffer.getvalue().decode('utf-8').split()[0] # When we install new packages, we are executing as root and then dropping # as the user for extracting and such. However, for signature verification, # we use gpg. This one doesn't like priviledge drop (if uid = 0 and # euid = 1000) and asserts if uid != euid. # Importing the key as root as well creates new gnupg files owned as root if # new keys weren't imported first. # Consequently, run gpg as root if we needed root access or as the user # otherwise. We store the gpg public key in a temporary gnupg directory that # will be removed under the same user rights (this directory needs to be owned # by the same user id to not be rejected by gpg).Z if self.need_root_access: with as_root(): with tempfile.TemporaryDirectory() as tmpdirname: self._check_gpg_signature(tmpdirname, asc_content, sig) else: with tempfile.TemporaryDirectory() as tmpdirname: self._check_gpg_signature(tmpdirname, asc_content, sig) # you get and store self.download_url url = re.sub('.sig', '', sig_url) if url is None: logger.error("Download page changed its syntax or is not parsable (missing url)") UI.return_main_screen(status_code=1) logger.debug("Found download link for {}".format(url)) self.download_requests.append(DownloadItem(url, None)) self.start_download_and_install()
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 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_ubuntu_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) DownloadCenter(urls=[DownloadItem(sig_url, None), DownloadItem(self.asc_url, None)], on_done=self.check_gpg_and_start_download, download=False)
def remove(self): """Method call to remove the current framework""" if not self.is_installed: logger.error( _("You can't remove {} as it isn't installed".format( self.name))) UI.return_main_screen(status_code=2)
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 run_for(self, args): """Running commands from args namespace""" # try to call default framework if any if not args.framework: if not self.default_framework: message = "A default framework for category {} was requested where there is none".format(self.name) logger.error(message) UI.return_main_screen(status_code=1) self.default_framework.run_for(args) return self.frameworks[args.framework].run_for(args)
def _check_gpg_signature(self, gnupgdir, asc_content, sig): """check gpg signature (temporary stock in dir)""" gpg = gnupg.GPG(gnupghome=gnupgdir) imported_keys = gpg.import_keys(asc_content) if imported_keys.count == 0: logger.error("Keys not valid") UI.return_main_screen(status_code=1) verify = gpg.verify(sig) if verify is False: logger.error("Signature not valid") UI.return_main_screen(status_code=1)
def _check_gpg_signature(self, gnupgdir, asc_content, sig): """check gpg signature (temporary stock in dir)""" gpg = gnupg.GPG(gnupghome=gnupgdir) imported_keys = gpg.import_keys(asc_content) if imported_keys.count == 0: logger.error("Keys not valid") UI.return_main_screen(status_code=1) verify = gpg.verify(sig) if verify is False: logger.error("Signature not valid") UI.return_main_screen(status_code=1)
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 run_for(self, args): """Running commands from args namespace""" # try to call default framework if any if not args.framework: if not self.default_framework: message = _("A default framework for category {} was requested where there is none".format(self.name)) logger.error(message) self.category_parser.print_usage() UI.return_main_screen(status_code=2) self.default_framework.run_for(args) return self.frameworks[args.framework].run_for(args)
def post_install(self): """Create the Unity 3D launcher and setuid chrome sandbox""" with futures.ProcessPoolExecutor(max_workers=1) as executor: # chrome sandbox requires this: https//code.google.com/p/chromium/wiki/LinuxSUIDSandbox f = executor.submit(_chrome_sandbox_setuid, os.path.join(self.install_path, "Editor", "chrome-sandbox")) if not f.result(): UI.return_main_screen(exit_status=1) create_launcher(self.desktop_filename, get_application_desktop_file(name=_("Unity3D Editor"), icon_path=os.path.join(self.install_path, "unity-editor-icon.png"), exec=os.path.join(self.install_path, "Editor", "Unity"), comment=self.description, categories="Development;IDE;"))
def post_install(self): """Create the Unity 3D launcher and setuid chrome sandbox""" with futures.ProcessPoolExecutor(max_workers=1) as executor: # chrome sandbox requires this: https//code.google.com/p/chromium/wiki/LinuxSUIDSandbox f = executor.submit(_chrome_sandbox_setuid, os.path.join(self.install_path, "Editor", "chrome-sandbox")) if not f.result(): UI.return_main_screen(exit_status=1) create_launcher(self.desktop_filename, get_application_desktop_file(name=_("Unity3D Editor"), icon_path=os.path.join(self.install_path, "unity-editor-icon.png"), exec=self.exec_path, comment=self.description, categories="Development;IDE;"))
def checksum_downloaded(results): checksum_result = next(iter(results.values())) # Just get the first. if checksum_result.error: logger.error(checksum_result.error) UI.return_main_screen(status_code=1) checksum = checksum_result.buffer.getvalue().decode('utf-8').split()[0] logger.info('Obtained SHA256 checksum: ' + checksum) self.download_requests.append(DownloadItem(download_url, checksum=Checksum(ChecksumType.sha256, checksum), ignore_encoding=True)) self.start_download_and_install()
def get_url_and_start_download(self, download_result): res = download_result[self.download_url] text = res.buffer.getvalue().decode('utf-8') url = re.search(r'http.*?.sh', text).group(0) if url is None: logger.error("Download page changed its syntax or is not parsable (missing url)") UI.return_main_screen(status_code=1) if self.checksum is None: logger.error("Download page changed its syntax or is not parsable (missing checksum)") UI.return_main_screen(status_code=1) logger.debug("Found download link for {}, checksum: {}".format(url, self.checksum)) self.download_requests.append(DownloadItem(url, Checksum(self.checksum_type, self.checksum))) self.start_download_and_install()
def decompress_and_install(self, fds): # if icon, we grab the icon name to reference it later on for fd in fds: if fd.name.endswith(".svg"): orig_icon_name = os.path.basename(fd.name) break else: logger.error("We couldn't download the Twine icon") UI.return_main_screen(exit_status=1) super().decompress_and_install(fds) # rename the asset logo self.icon_name = "logo.svg" os.rename(os.path.join(self.install_path, orig_icon_name), os.path.join(self.install_path, self.icon_name))
def checksum_downloaded(results): checksum_result = next(iter(results.values())) # Just get the first. if checksum_result.error: logger.error(checksum_result.error) UI.return_main_screen(status_code=1) checksum = checksum_result.buffer.getvalue().decode('utf-8').split()[0] logger.info('Obtained SHA256 checksum: ' + checksum) self.download_requests.append(DownloadItem(download_url, checksum=Checksum(ChecksumType.sha256, checksum), ignore_encoding=True)) self.start_download_and_install()
def decompress_and_install(self, fds): # if icon, we grab the icon name to reference it later on for fd in fds: if fd.name.endswith(".svg"): orig_icon_name = os.path.basename(fd.name) break else: logger.error("We couldn't download the Twine icon") UI.return_main_screen(exit_status=1) super().decompress_and_install(fds) # rename the asset logo self.icon_name = "logo.svg" os.rename(os.path.join(self.install_path, orig_icon_name), os.path.join(self.install_path, self.icon_name))
def get_sha_and_start_download(self, download_result): res = download_result[self.sha1_url] sha1 = res.buffer.getvalue().decode('utf-8').split()[0] url = re.sub('.sha1', '', self.sha1_url) if url is None: logger.error("Download page changed its syntax or is not parsable (missing url)") UI.return_main_screen(status_code=1) if sha1 is None: logger.error("Download page changed its syntax or is not parsable (missing checksum)") UI.return_main_screen(status_code=1) logger.debug("Found download link for {}, checksum: {}".format(url, sha1)) self.download_requests.append(DownloadItem(url, Checksum(ChecksumType.sha1, sha1))) self.start_download_and_install()
def get_sha_and_start_download(self, download_result): res = download_result[self.sha1_url] sha1 = res.buffer.getvalue().decode('utf-8').split()[0] url = re.sub('.sha1', '', self.sha1_url) if url is None: logger.error("Download page changed its syntax or is not parsable (missing url)") UI.return_main_screen(status_code=1) if sha1 is None: logger.error("Download page changed its syntax or is not parsable (missing sha512)") UI.return_main_screen(status_code=1) logger.debug("Found download link for {}, checksum: {}".format(url, sha1)) self.download_requests.append(DownloadItem(url, Checksum(ChecksumType.sha1, sha1))) self.start_download_and_install()
def run_for(self, args): """Running commands from args namespace""" logger.debug("Call run_for on {}".format(self.name)) if args.remove: if args.destdir: message = "You can't specify a destination dir while removing a framework" logger.error(message) UI.return_main_screen() self.remove() else: install_path = None if args.destdir: install_path = os.path.abspath(os.path.expanduser(args.destdir)) self.setup(install_path)
def setup(self): """Method call to setup the Framework""" if not self.is_installable: logger.error(_("You can't install that framework on this machine")) UI.return_main_screen(status_code=1) if self.need_root_access and os.geteuid() != 0: logger.debug("Requesting root access") cmd = ["sudo", "-E", "env", "PATH={}".format(os.getenv("PATH"))] cmd.extend(sys.argv) MainLoop().quit(subprocess.call(cmd)) # be a normal, kind user as we don't want normal files to be written as root switch_to_current_user()
def done(download_result): resIcon = download_result[iconURL] if resIcon.error: logger.error(resIcon.error) UI.return_main_screen() if not os.path.exists(self.install_path): os.makedirs(self.install_path) shutil.copyfile(resIcon.fd.name, self.install_path + '/drjava.jpeg') self.download_requests.append(DownloadItem(jarURL)) self.start_download_and_install()
def setup(self): """Method call to setup the Framework""" if not self.is_installable: logger.error(_("You can't install that framework on this machine")) UI.return_main_screen() if self.need_root_access and os.geteuid() != 0: logger.debug("Requesting root access") cmd = ["sudo", "-E", "env", "PATH={}".format(os.getenv("PATH"))] cmd.extend(sys.argv) MainLoop().quit(subprocess.call(cmd)) # be a normal, kind user as we don't want normal files to be written as root switch_to_current_user()
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 self.dry_run: UI.display(DisplayMessage("Found download URL: " + url)) UI.return_main_screen(status_code=0) 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 prepare_to_download_archive(self, results): """Store the md5 for later and fire off the actual download.""" download_page = results[self.scraped_download_url] checksum_page = results[self.scraped_checksum_url] if download_page.error: logger.error("Error fetching download page: %s", download_page.error) UI.return_main_screen(status_code=1) if checksum_page.error: logger.error("Error fetching checksums: %s", checksum_page.error) UI.return_main_screen(status_code=1) match = re.search( r'^(\S+)\s+arduino-[\d\.\-r]+-linux' + self.bits + '.tar.xz$', checksum_page.buffer.getvalue().decode('ascii'), re.M) if not match: logger.error("Can't find a checksum.") UI.return_main_screen(status_code=1) checksum = match.group(1) soup = BeautifulSoup(download_page.buffer.getvalue(), 'html.parser') btn = soup.find('button', text=re.compile('JUST DOWNLOAD')) if not btn: logger.error("Can't parse download button.") UI.return_main_screen(status_code=1) base_url = download_page.final_url cookies = download_page.cookies final_download_url = parse.urljoin(base_url, btn.parent['href']) logger.info('Final download url: %s, cookies: %s.', final_download_url, cookies) self.download_requests = [ DownloadItem(final_download_url, checksum=Checksum(ChecksumType.md5, checksum), cookies=cookies) ] # add the user to arduino group if not self.was_in_arduino_group: with futures.ProcessPoolExecutor(max_workers=1) as executor: f = executor.submit(_add_to_group, self._current_user, self.ARDUINO_GROUP) if not f.result(): UI.return_main_screen(status_code=1) self.start_download_and_install()
def run_for(self, args): """Running commands from args namespace""" logger.debug("Call run_for on {}".format(self.name)) if args.remove: if args.destdir: message = "You can't specify a destination dir while removing a framework" logger.error(message) UI.return_main_screen() self.remove() else: install_path = None if args.destdir: install_path = os.path.abspath(os.path.expanduser(args.destdir)) self.setup(install_path)
def get_metadata_and_check_license(self, result): """Override this so we can use BS and fetch the checksum separately.""" logger.debug("Fetched download page, parsing.") page = result[self.download_page] error_msg = page.error if error_msg: logger.error("An error occurred while downloading {}: {}".format( self.download_page_url, error_msg)) UI.return_main_screen(status_code=1) soup = BeautifulSoup(page.buffer, 'html.parser') link = (soup.find('div', class_="install").find( 'td', class_="inst-type", text="Linux (.tar.gz)").parent.find( text=self.arch_trans[get_current_arch()]).parent.parent) if link is None: logger.error( "Can't parse the download URL from the download page.") UI.return_main_screen(status_code=1) download_url = link.attrs['href'] checksum_url = download_url + '.sha256' logger.debug("Found download URL: " + download_url) logger.debug("Downloading checksum first, from " + checksum_url) def checksum_downloaded(results): checksum_result = next(iter( results.values())) # Just get the first. if checksum_result.error: logger.error(checksum_result.error) UI.return_main_screen(status_code=1) checksum = checksum_result.buffer.getvalue().decode( 'utf-8').split()[0] logger.info('Obtained SHA256 checksum: ' + checksum) self.download_requests.append( DownloadItem(download_url, checksum=Checksum(ChecksumType.sha256, checksum), ignore_encoding=True)) self.start_download_and_install() DownloadCenter([DownloadItem(checksum_url)], on_done=checksum_downloaded, download=False)
def prepare_to_download_archive(self, results): """Store the md5 for later and fire off the actual download.""" download_page = results[self.scraped_download_url] checksum_page = results[self.scraped_checksum_url] if download_page.error: logger.error("Error fetching download page: %s", download_page.error) UI.return_main_screen(status_code=1) if checksum_page.error: logger.error("Error fetching checksums: %s", checksum_page.error) UI.return_main_screen(status_code=1) match = re.search( r"^(\S+)\s+arduino-[\d\.\-r]+-linux" + self.bits + ".tar.xz$", checksum_page.buffer.getvalue().decode("ascii"), re.M, ) if not match: logger.error("Can't find a checksum.") UI.return_main_screen(status_code=1) checksum = match.group(1) soup = BeautifulSoup(download_page.buffer.getvalue()) btn = soup.find("button", text=re.compile("JUST DOWNLOAD")) if not btn: logger.error("Can't parse download button.") UI.return_main_screen(status_code=1) base_url = download_page.final_url cookies = download_page.cookies final_download_url = parse.urljoin(base_url, btn.parent["href"]) logger.info("Final download url: %s, cookies: %s.", final_download_url, cookies) self.download_requests = [ DownloadItem(final_download_url, checksum=Checksum(ChecksumType.md5, checksum), cookies=cookies) ] # add the user to arduino group if not self.was_in_arduino_group: with futures.ProcessPoolExecutor(max_workers=1) as executor: f = executor.submit(_add_to_group, self._current_user, self.ARDUINO_GROUP) if not f.result(): UI.return_main_screen(status_code=1) self.start_download_and_install()
def run_for(self, args): """Running commands from args namespace""" logger.debug("Call run_for on {}".format(self.name)) if args.remove: if args.destdir: message = "You can't specify a destination dir while removing a framework" logger.error(message) UI.return_main_screen(status_code=2) self.remove() else: install_path = None auto_accept_license = False if args.destdir: install_path = os.path.abspath(os.path.expanduser(args.destdir)) if self.expect_license and args.accept_license: auto_accept_license = True self.setup(install_path=install_path, auto_accept_license=auto_accept_license)
def run_for(self, args): """Running commands from args namespace""" logger.debug("Call run_for on {}".format(self.name)) if args.remove: if args.destdir: message = "You can't specify a destination dir while removing a framework" logger.error(message) UI.return_main_screen(status_code=1) self.remove() else: install_path = None auto_accept_license = False if args.destdir: install_path = os.path.abspath(os.path.expanduser(args.destdir)) if self.expect_license and args.accept_license: auto_accept_license = True self.setup(install_path=install_path, auto_accept_license=auto_accept_license)
def decompress_and_install_done(self, result): self._install_done = True error_detected = False for fd in result: if result[fd].error: logger.error(result[fd].error) error_detected = True fd.close() if error_detected: UI.return_main_screen() self.post_install() # Mark as installation done in configuration self.mark_in_config() UI.delayed_display(DisplayMessage("Installation done")) UI.return_main_screen()
def decompress_and_install_done(self, result): self._install_done = True error_detected = False for fd in result: if result[fd].error: logger.error(result[fd].error) error_detected = True fd.close() if error_detected: UI.return_main_screen(status_code=1) self.post_install() # Mark as installation done in configuration self.mark_in_config() UI.delayed_display(DisplayMessage("Installation done")) UI.return_main_screen()
def done(download_result): res = download_result[md5_url] if res.error: logger.error(res.error) UI.return_main_screen(status_code=1) # Should be ASCII anyway. md5 = res.buffer.getvalue().decode("utf-8").split()[0] logger.debug("Downloaded MD5 is {}".format(md5)) logger.debug("Preparing to download the main archive.") if arch == "i686": download_url = self.DOWNLOAD_URL_PAT.format(arch="", suf="") elif arch == "x86_64": download_url = self.DOWNLOAD_URL_PAT.format(arch="-x86_64", suf="") self.download_requests.append(DownloadItem(download_url, Checksum(ChecksumType.md5, md5))) self.start_download_and_install()
def get_metadata_and_check_license(self, result): """Override this so we can use BS and fetch the checksum separately.""" logger.debug("Fetched download page, parsing.") page = result[self.download_page] error_msg = page.error if error_msg: logger.error("An error occurred while downloading {}: {}".format(self.download_page_url, error_msg)) UI.return_main_screen(status_code=1) soup = BeautifulSoup(page.buffer, 'html.parser') link = (soup.find('div', class_="install") .find('td', class_="inst-type", text="Linux (.tar.gz)") .parent .find(text=self.arch_trans[get_current_arch()]) .parent .parent) if link is None: logger.error("Can't parse the download URL from the download page.") UI.return_main_screen(status_code=1) download_url = link.attrs['href'] checksum_url = download_url + '.sha256' logger.debug("Found download URL: " + download_url) logger.debug("Downloading checksum first, from " + checksum_url) def checksum_downloaded(results): checksum_result = next(iter(results.values())) # Just get the first. if checksum_result.error: logger.error(checksum_result.error) UI.return_main_screen(status_code=1) checksum = checksum_result.buffer.getvalue().decode('utf-8').split()[0] logger.info('Obtained SHA256 checksum: ' + checksum) self.download_requests.append(DownloadItem(download_url, checksum=Checksum(ChecksumType.sha256, checksum), ignore_encoding=True)) self.start_download_and_install() DownloadCenter([DownloadItem(checksum_url)], on_done=checksum_downloaded, download=False)
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 url = False for line in result[self.download_page].buffer: line_content = line.decode() (_url, in_download) = self.parse_download_link(line_content, in_download) if not url: url = _url self.url = url
def post_install(self): """Create the Arduino launcher""" icon_path = join(self.install_path, 'lib', 'arduino_icon.ico') comment = _("The Arduino Software IDE") categories = "Development;IDE;" create_launcher(self.desktop_filename, get_application_desktop_file(name=_("Arduino"), icon_path=icon_path, try_exec=self.exec_path, exec=self.exec_link_name, comment=comment, categories=categories)) # add the user to arduino group if not self.was_in_arduino_group: with futures.ProcessPoolExecutor(max_workers=1) as executor: f = executor.submit(_add_to_group, self._current_user, self.ARDUINO_GROUP) if not f.result(): UI.return_main_screen(status_code=1) UI.delayed_display(DisplayMessage(_("You need to logout and login again for your installation to work")))
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 get_metadata(self, result): """Download files to download""" 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 url_found = False for line in result[self.download_page].buffer: line_content = line.decode() (_url_found, in_download) = self.parse_download_link(line_content, in_download) if not url_found: url_found = _url_found if not url_found: logger.error("Download page changed its syntax or is not parsable") UI.return_main_screen(status_code=1)
def get_metadata_and_check_license(self, result): logger.debug("Fetched download page, parsing.") page = result[self.download_page] error_msg = 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) try: assets = json.loads(page.buffer.read().decode())["assets"] for asset in assets: if "linux-{}".format(self.arch_trans[get_current_arch()]) in asset["browser_download_url"]: download_url = asset["browser_download_url"] except (json.JSONDecodeError, IndexError): logger.error("Can't parse the download URL from the download page.") UI.return_main_screen(status_code=1) logger.debug("Found download URL: " + download_url) self.download_requests.append(DownloadItem(download_url, None)) self.start_download_and_install()