Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
214 changes: 0 additions & 214 deletions src/murfey/server/api/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand Down Expand Up @@ -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]*<span data-view-component="true" class="f1 text-bold d-inline mr-3"><a href="/microsoft/terminal/releases/tag/([\w\.]+)" data-view-component="true" class="Link--primary Link">[\w\s\.\-]+</a></span>'
r"[\s]*<span>"
r'[\s]*<span data-view-component="true" class="Label Label--warning Label--large v-align-text-bottom d-none d-md-inline-block">Pre-release</span>'
)
# Older packages in the repo are named "Color Tools"; omit them
colortool_pattern = r'<span data-view-component="true" class="f1 text-bold d-inline mr-3"><a href="/microsoft/terminal/releases/tag/([\w\.]+)" data-view-component="true" class="Link--primary Link">Color Tool[\w\s]+</a></span>'

# 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(
(
"<!DOCTYPE html>",
"<html>",
"<head>",
" <title>Links to Windows Terminal Versions</title>",
"</head>",
"<body>",
" <h1>Links to Windows Terminal Versions</h1>",
)
)
# 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'<a href="{base_url}/{path}/{quote(version, safe="")}">{quote(version, safe="")}</a><br />'
link_list.append(hyperlink)
hyperlinks = "\n".join(link_list)

html_tail = "\n".join(
(
"</body>",
"</html>",
)
)

# 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(
(
"<!DOCTYPE html>",
"<html>",
"<head>",
f' <title>Links to Windows Terminal {quote(version, safe="")} Assets</title>',
"</head>",
"<body>",
f' <h1>Links to Windows Terminal {quote(version, safe="")} Assets</h1>',
)
)
# 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'<a href="{base_url}/{path}/{quote(asset, safe="")}">{quote(asset, safe="")}</a><br />'
link_list.append(hyperlink)
hyperlinks = "\n".join(link_list)

html_tail = "\n".join(
(
"</body>",
"</html>",
)
)

# 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
Expand Down
1 change: 0 additions & 1 deletion src/murfey/server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
74 changes: 0 additions & 74 deletions src/murfey/templates/bootstrap.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,80 +63,6 @@ <h3>Installing MSYS2</h3>
$ pacman -S mingw-w64-x86_64-rust --disable-download-timeout
</pre>

<h3>Installing Windows Terminal</h3>
<p>
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
<a href="https://github.com/microsoft/terminal">Windows Terminal</a> as a
wrapper for MSYS2.
</p>
<p>
The latest release of Windows Terminal can be downloaded directly from
<a href="https://github.com/microsoft/terminal/releases">GitHub</a>, or
through this <a href="/microsoft/terminal/releases">mirror</a>. This will
download a ZIP file, which can be extracted to a directory of your choosing
and used out of the box.
</p>
<p>
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:
</p>
<ol start="1">
<li>Open Windows Terminal.</li>
<li>
Click on the dropdown arrow to the right of the "new tab" button on the
title bar.
</li>
<li>
Click "Settings" (alternatively, use the "Ctrl + ," keyboard shortcut).
</li>
<li>
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.
</li>
<li>Under "profiles" > "list", Add this dictionary entry for UCRT64:</li>
</ol>
<pre style="font-family: monospace">
"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"
},
<span style="color: red; font-family: monospace">{
"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"
}</span>
]
},
</pre>
<ol start="6">
<li>
Additionally, if you want Windows Terminal to always start using UCRT64, you
can replace the "defaultProfile" key with the "guid" value of UCRT64.
</li>
<li>Save your changes and close.</li>
</ol>
<p>
With these changes, you should now be able to run UCRT64 in the Windows
Terminal.
</p>

<h2>Setting Up Python</h2>
<p>
Once Python and pip are installed in the terminal, you have the option to
Expand Down
Loading