diff --git a/jupyter_remote_desktop_proxy/__init__.py b/jupyter_remote_desktop_proxy/__init__.py index f97b95dd..0429867f 100644 --- a/jupyter_remote_desktop_proxy/__init__.py +++ b/jupyter_remote_desktop_proxy/__init__.py @@ -11,21 +11,7 @@ def setup_desktop(): # This is only readable, writeable & searchable by our uid sockets_dir = tempfile.mkdtemp() sockets_path = os.path.join(sockets_dir, 'vnc-socket') - - # Try to find a local install of vncserver script. - # If installed with jupyter-remote-desktop-proxy.install, - # it will by default in of two location based on the tigervnc version: - # - bundled_bin: tigervnc < 1.11.0 - # - bundled_exec: tigervnc > 1.11.0 - # If no vncserver is found in the default bundled path, which will - # look in the user's PATH. If which return None, vncserver was not found - # and an exception is raised. - bundled_bin = os.path.join(HERE, 'share/tigervnc/bin') - bundled_libexec = os.path.join(HERE, 'share/tigervnc/libexec') - vncserver = which( - cmd='vncserver', - path=f"{bundled_bin}:{bundled_libexec}:{os.environ.get('PATH', os.defpath)}" - ) + vncserver = which('vncserver') if vncserver is None: raise FileNotFoundError('jupyter-remote-desktop-proxy: could not find vncserver') diff --git a/jupyter_remote_desktop_proxy/install.py b/jupyter_remote_desktop_proxy/install.py deleted file mode 100644 index e929b4b2..00000000 --- a/jupyter_remote_desktop_proxy/install.py +++ /dev/null @@ -1,152 +0,0 @@ -import argparse -import hashlib -import os -import platform -import shutil -import tarfile -import textwrap -from urllib.request import HTTPError, urlopen, urlretrieve - -from xml.etree import ElementTree - -HERE = os.path.dirname(os.path.abspath(__file__)) - -def checksum_file(path): - """Compute the md5 checksum of a path""" - hasher = hashlib.md5() - with open(path, "rb") as f: - for chunk in iter(lambda: f.read(4096), b""): - hasher.update(chunk) - return hasher.hexdigest() - -def fetch_release_info(tigervnc_archive, tigervnc_version): - """Fetch the download url and md5 checksum from tigervnc release rss""" - url = ( - "https://sourceforge.net/projects/tigervnc/rss" - f"?path=/stable/{tigervnc_version}" - ) - release_title = f'/stable/{tigervnc_version}/{tigervnc_archive}' - print(f"Fetching md5 and download url from {url}") - - with urlopen(url) as f: - tree = ElementTree.parse(f) - root = tree.getroot() - channel = root.find('channel') - for item in channel.iterfind('item'): - title = item.find('title') - if title.text == release_title: - media = item.find('{http://video.search.yahoo.com/mrss/}content') - url = media.get('url') - md5 = media.find('{http://video.search.yahoo.com/mrss/}hash').text - break - else: - raise Exception(f"Could not find a tarball \"{tigervnc_archive}\" on sourceforge.net") - return url, md5 - - -def install_tigervnc(prefix, plat, tigervnc_version): - tigervnc_path = os.path.join(prefix, "bin", "vncconfig") - if os.path.exists(tigervnc_path): - print(f"Tigervnc already exists at {tigervnc_path}. Remove it to re-install.") - print("--- Done ---") - return - - tigervnc_archive = f"tigervnc-{tigervnc_version}.{plat}.tar.gz" - tigervnc_archive_path = os.path.join(prefix, tigervnc_archive) - try: - tigervnc_url, tigervnc_md5 = fetch_release_info(tigervnc_archive, tigervnc_version) - except HTTPError as e: - print(f"Failed to retrieve md5 and download url: {e}") - return - except Exception as e: - print(f"Failed to retrieve md5 and download url: {e}") - return - - print(f"Downloading tigervnc {tigervnc_version} from {tigervnc_url}...") - urlretrieve(tigervnc_url, tigervnc_archive_path) - - md5 = checksum_file(tigervnc_archive_path) - if md5 != tigervnc_md5: - raise OSError(f"Checksum failed {md5} != {tigervnc_md5}") - - print("Extracting the archive...") - with tarfile.open(tigervnc_archive_path, "r") as tar_ref: - tar_ref.extractall(prefix) - - shutil.copytree( - src=f"{prefix}/tigervnc-{tigervnc_version}.{plat}/usr", - dst=prefix, - dirs_exist_ok=True, - ) - - print(f"Installed tigervnc {tigervnc_version}") - shutil.rmtree(f"{prefix}/tigervnc-{tigervnc_version}.{plat}") - os.unlink(tigervnc_archive_path) - print("--- Done ---") - - -def main(): - # extract supported and default versions from urls - parser = argparse.ArgumentParser( - description="Dependency installer helper", - formatter_class=argparse.RawTextHelpFormatter, - ) - - parser.add_argument( - "--output", - dest="installation_dir", - default=f"{HERE}/share/tigervnc", - help=textwrap.dedent( - """\ - The installation directory (absolute or relative path). - If it doesn't exist, it will be created. - If no directory is provided, it defaults to: - --- %(default)s --- - """ - ), - ) - - machine = platform.machine() - parser.add_argument( - "--platform", - dest="plat", - default=machine, - help=textwrap.dedent( - """\ - The platform to download for. - If no platform is provided, it defaults to: - --- %(default)s --- - """ - ), - ) - - parser.add_argument( - "--tigervnc-version", - dest="tigervnc_version", - default="1.10.1", - choices=["1.10.1", "1.10.0", "1.9.0"], - help=textwrap.dedent( - """\ - The version of tigervnc to download. - If no version is provided, it defaults to: - --- %(default)s --- - """ - ), - ) - - args = parser.parse_args() - deps_dir = args.installation_dir - plat = args.plat - tigervnc_version = args.tigervnc_version.lstrip("v") - - if os.path.exists(deps_dir): - print(f"Using existing output directory {deps_dir}...") - else: - print(f"Creating output directory {deps_dir}...") - os.makedirs(deps_dir) - - install_tigervnc(deps_dir, plat, tigervnc_version) - - -if __name__ == "__main__": - main() \ No newline at end of file