forked from smallcloudai/refact
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add refact-build-info file to give passport for build * add tab version * tab about * fix ui * cleanup
- Loading branch information
Showing
7 changed files
with
121 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div class="pane"> | ||
<h2>Version</h2> | ||
<div class="mt-3 mb-3" id="refact-version"></div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
export function tab_about_version_get() { | ||
fetch("/tab-about-version-get") | ||
.then(function(response) { | ||
return response.json(); | ||
}) | ||
.then(function(data) { | ||
const tab_version = document.getElementById("refact-version") | ||
var version_table_data = `<tr><th>Package</th><th>Version</th><th>Commit Hash</th></tr>`; | ||
data["version_table"].forEach(function(row) { | ||
version_table_data += ` | ||
<tr> | ||
<td><label class="refact-item-name">${row[0]}</label></td> | ||
<td><label class="refact-item-version">${row[1]}</label></td> | ||
<td><label class="refact-item-hash">${row[2]}</label></td> | ||
</tr>`; | ||
}); | ||
tab_version.innerHTML = ` | ||
<div><table class="table table-stripped align-left"> | ||
${version_table_data} | ||
</table></div>`; | ||
}); | ||
} | ||
|
||
|
||
export async function init() { | ||
let req = await fetch('/tab-about.html'); | ||
document.querySelector('#about').innerHTML = await req.text(); | ||
} | ||
|
||
|
||
export function tab_switched_here() { | ||
tab_about_version_get(); | ||
} | ||
|
||
|
||
export function tab_switched_away() { | ||
} | ||
|
||
|
||
export function tab_update_each_couple_of_seconds() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import asyncio | ||
import os.path | ||
|
||
from fastapi import APIRouter | ||
from fastapi.responses import JSONResponse | ||
|
||
from self_hosting_machinery.webgui.selfhost_webutils import log | ||
|
||
from typing import List, Tuple | ||
|
||
|
||
__all__ = ["TabAboutRouter"] | ||
|
||
|
||
class TabAboutRouter(APIRouter): | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self._version_table = None | ||
self.add_api_route("/tab-about-version-get", self._tab_about_version_get, methods=["GET"]) | ||
|
||
async def _get_pip_module_version(self, module_name: str): | ||
try: | ||
process = await asyncio.create_subprocess_exec( | ||
"pip", "show", module_name, | ||
stdout=asyncio.subprocess.PIPE) | ||
stdout, stderr = await process.communicate() | ||
for line in stdout.decode().splitlines(): | ||
if line.startswith("Version:"): | ||
return line.split()[-1] | ||
except Exception as e: | ||
log(f"Error while getting '{module_name}' version: {e}") | ||
return "N/A" | ||
|
||
async def _get_lsp_version(self): | ||
try: | ||
process = await asyncio.create_subprocess_exec( | ||
"refact-lsp", "--version", | ||
stdout=asyncio.subprocess.PIPE) | ||
stdout, stderr = await process.communicate() | ||
for line in stdout.decode().splitlines(): | ||
return line.split()[-1] | ||
except Exception as e: | ||
log(f"Error while getting 'refact-lsp' version: {e}") | ||
return "N/A" | ||
|
||
def _get_build_info(self): | ||
build_info_filename = "/refact-build-info.txt" | ||
build_info = dict() | ||
if os.path.exists(build_info_filename): | ||
with open(build_info_filename, "r") as f: | ||
build_info = dict(line.split() for line in f.readlines()) | ||
return build_info | ||
|
||
async def _init_version_table(self) -> List[Tuple[str, str, str]]: | ||
build_info = self._get_build_info() | ||
refact_version = await self._get_pip_module_version("refact-self-hosting") | ||
lsp_version = await self._get_lsp_version() | ||
return [ | ||
("refact", refact_version, build_info.get("refact", "N/A")), | ||
("refact-lsp", lsp_version, build_info.get("refact-lsp", "N/A")), | ||
] | ||
|
||
async def _tab_about_version_get(self): | ||
if not self._version_table: | ||
self._version_table = await self._init_version_table() | ||
return JSONResponse({"version_table": self._version_table}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters