diff --git a/src/murfey/server/api/bootstrap.py b/src/murfey/server/api/bootstrap.py index 5b89d00b1..3b8e5edfb 100644 --- a/src/murfey/server/api/bootstrap.py +++ b/src/murfey/server/api/bootstrap.py @@ -43,7 +43,6 @@ bootstrap = APIRouter(prefix="/bootstrap", tags=["bootstrap"]) cygwin = APIRouter(prefix="/cygwin", tags=["bootstrap"]) msys2 = APIRouter(prefix="/msys2", tags=["bootstrap"]) -windows_terminal = APIRouter(prefix="/microsoft/terminal", tags=["bootstrap"]) pypi = APIRouter(prefix="/pypi", tags=["bootstrap"]) plugins = APIRouter(prefix="/plugins", tags=["bootstrap"]) @@ -565,219 +564,6 @@ def get_msys2_package_file( raise HTTPException(status_code=package_file.status_code) -""" -======================================================================================= -WINDOWS TERMINAL-RELATED FUNCTIONS AND ENDPOINTS -======================================================================================= -""" - -windows_terminal_url = "https://github.com/microsoft/terminal/releases" - - -def get_number_of_github_pages(url) -> int: - """ - Parses the main GitHub releases page to find the number of pages present in the - repository. - """ - - response = requests.get(url) - headers = response.headers - if not headers["content-type"].startswith("text/html"): - raise HTTPException("Unable to parse non-HTML page for page numbers") - - # Find the number of pages present in this release - text = response.text - pattern = r'aria-label="Page ([0-9]+)"' - matches = re.findall(pattern, text) - if len(matches) == 0: - raise HTTPException("No page numbers found") - pages = [int(item) for item in matches] - pages.sort(reverse=True) - return pages[0] - - -@windows_terminal.get("/releases", response_class=Response) -def get_windows_terminal_releases(request: Request): - """ - Returns a list of stable Windows Terminal releases from the GitHub repository. - """ - - num_pages = get_number_of_github_pages(windows_terminal_url) - - # Get list of release versions - versions: list[str] = [] - - # RegEx patterns to parse HTML file with - # https://github.com/{owner}/{repo}/releases/expanded_assets/{version} leads to a - # HTML page with the assets for that particular version - release_pattern = ( - r'src="' + f"{windows_terminal_url}" + r'/expanded_assets/([v0-9\.]+)"' - ) - # Pre-release label follows after link to version tag - prerelease_pattern = ( - r'[\s]*[\w\s\.\-]+' - r"[\s]*" - r'[\s]*Pre-release' - ) - # Older packages in the repo are named "Color Tools"; omit them - colortool_pattern = r'Color Tool[\w\s]+' - - # Iterate through repository pages - for p in range(num_pages): - url = f"{windows_terminal_url}?page={p + 1}" - response = requests.get(url) - headers = response.headers - if not headers["content-type"].startswith("text/html"): - raise HTTPException("Unable to parse non-HTML page for package versions") - text = response.text - - # Collect only stable releases - releases = re.findall(release_pattern, text) - prereleases = re.findall(prerelease_pattern, text) - colortool = re.findall(colortool_pattern, text) - stable = set(releases) - (set(prereleases) | set(colortool)) - versions.extend(stable) - - # Construct HTML document for available versions - html_head = "\n".join( - ( - "", - "", - "", - " Links to Windows Terminal Versions", - "", - "", - "

Links to Windows Terminal Versions

", - ) - ) - # Construct hyperlinks - link_list = [] - base_url = str(request.base_url).strip("/") # Remove trailing '/' - path = request.url.path.strip("/") # Remove leading '/' - - for v in range(len(versions)): - version = versions[v] - hyperlink = f'{quote(version, safe="")}
' - link_list.append(hyperlink) - hyperlinks = "\n".join(link_list) - - html_tail = "\n".join( - ( - "", - "", - ) - ) - - # Combine - content = "\n".join((html_head, hyperlinks, html_tail)) - - # Return FastAPI response - return Response( - content=content.encode("utf-8"), - status_code=response.status_code, - media_type="text/html", - ) - - -@windows_terminal.get("/releases/{version}", response_class=Response) -def get_windows_terminal_version_assets( - version: str, - request: Request, -): - """ - Returns a list of packages for the selected version of Windows Terminal. - """ - - # Validate inputs - if bool(re.match(r"^[\w\-\.]+$", version)) is False: - raise HTTPException("Invalid version format") - - # https://github.com/{owner}/{repo}/releases/expanded_assets/{version} - url = f'{windows_terminal_url}/expanded_assets/{quote(version, safe="")}' - - response = requests.get(url) - headers = response.headers - if not headers["content-type"].startswith("text/html"): - raise HTTPException("Unable to parse non-HTML page for page numbers") - text = response.text - - # Find hyperlinks - pattern = ( - r'href="[/\w\.]+/releases/download/' - + f'{quote(version, safe="")}' - + r'/([\w\.\-]+)"' - ) - assets = re.findall(pattern, text) - - # Construct HTML document for available assets - html_head = "\n".join( - ( - "", - "", - "", - f' Links to Windows Terminal {quote(version, safe="")} Assets', - "", - "", - f'

Links to Windows Terminal {quote(version, safe="")} Assets

', - ) - ) - # Construct hyperlinks - link_list = [] - base_url = str(request.base_url).strip("/") # Remove trailing '/' - path = request.url.path.strip("/") # Remove leading '/' - - for a in range(len(assets)): - asset = assets[a] - hyperlink = f'{quote(asset, safe="")}
' - link_list.append(hyperlink) - hyperlinks = "\n".join(link_list) - - html_tail = "\n".join( - ( - "", - "", - ) - ) - - # Combine - content = "\n".join((html_head, hyperlinks, html_tail)) - - # Return FastAPI response - return Response( - content=content.encode("utf-8"), - status_code=response.status_code, - media_type="text/html", - ) - - -@windows_terminal.get("/releases/{version}/{file_name}", response_class=Response) -def get_windows_terminal_package_file( - version: str, - file_name: str, -): - """ - Returns a package from the GitHub repository. - """ - - # Validate version and file names - if bool(re.match(r"^[\w\.\-]+$", version)) is False: - raise HTTPException("Invalid version format") - if bool(re.match(r"^[\w\.\-]+$", file_name)) is False: - raise HTTPException("Invalid file name") - - # https://github.com/{owner}/{repo}/releases/download/{version}/{file_name} - url = f'{windows_terminal_url}/download/{quote(version, safe="")}/{quote(file_name, safe="")}' - response = requests.get(url) - if response.status_code == 200: - return Response( - content=response.content, - status_code=response.status_code, - headers=response.headers, - ) - else: - raise HTTPException(status_code=response.status_code) - - """ ======================================================================================= PYPI-RELATED FUNCTIONS AND ENDPOINTS diff --git a/src/murfey/server/main.py b/src/murfey/server/main.py index 61ab08201..96533fd7d 100644 --- a/src/murfey/server/main.py +++ b/src/murfey/server/main.py @@ -65,7 +65,6 @@ class Settings(BaseSettings): app.include_router(murfey.server.api.bootstrap.bootstrap) app.include_router(murfey.server.api.bootstrap.cygwin) app.include_router(murfey.server.api.bootstrap.msys2) -app.include_router(murfey.server.api.bootstrap.windows_terminal) app.include_router(murfey.server.api.bootstrap.pypi) app.include_router(murfey.server.api.bootstrap.plugins) app.include_router(murfey.server.api.clem.router) diff --git a/src/murfey/templates/bootstrap.html b/src/murfey/templates/bootstrap.html index abc83e4bf..deb83f6ba 100644 --- a/src/murfey/templates/bootstrap.html +++ b/src/murfey/templates/bootstrap.html @@ -63,80 +63,6 @@

Installing MSYS2

$ pacman -S mingw-w64-x86_64-rust --disable-download-timeout -

Installing Windows Terminal

-

- There is currently a bug with MSYS2 terminals on Windows 10 that prevents its - user interface from working properly. Our current solution is to use - Microsoft's - Windows Terminal as a - wrapper for MSYS2. -

-

- The latest release of Windows Terminal can be downloaded directly from - GitHub, or - through this mirror. This will - download a ZIP file, which can be extracted to a directory of your choosing - and used out of the box. -

-

- In order to run the UCRT64 environment in Windows Terminal, Windows Terminal - will need to be directed to it by adding a dictionary entry in its settings - JSON file. To do so: -

-
    -
  1. Open Windows Terminal.
  2. -
  3. - Click on the dropdown arrow to the right of the "new tab" button on the - title bar. -
  4. -
  5. - Click "Settings" (alternatively, use the "Ctrl + ," keyboard shortcut). -
  6. -
  7. - On the bottom left corner of the window, click on the "Open JSON file" - option. This will bring up the JSON file managing Windows Terminal's - settings in your default code editor. -
  8. -
  9. Under "profiles" > "list", Add this dictionary entry for UCRT64:
  10. -
-
-      "profiles":
-      {
-          "defaults": {},
-          "list":
-          [
-              {
-                  "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
-                  "hidden": false,
-                  "name": "Windows PowerShell"
-              },
-              {
-                  "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
-                  "hidden": false,
-                  "name": "Command Prompt"
-              },
-              {
-                  "guid": "{17da3cac-b318-431e-8a3e-7fcdefe6d114}",
-                  "name": "UCRT64 / MSYS2",
-                  "commandline": "C:/msys64/msys2_shell.cmd -defterm -here -no-start -ucrt64",
-                  "startingDirectory": "C:/msys64/home/%USERNAME%",
-                  "icon": "C:/msys64/ucrt64.ico"
-              }
-          ]
-      },
-
-
    -
  1. - Additionally, if you want Windows Terminal to always start using UCRT64, you - can replace the "defaultProfile" key with the "guid" value of UCRT64. -
  2. -
  3. Save your changes and close.
  4. -
-

- With these changes, you should now be able to run UCRT64 in the Windows - Terminal. -

-

Setting Up Python

Once Python and pip are installed in the terminal, you have the option to