Skip to content

Commit

Permalink
Added monitor app for deps publication (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr3zee authored Jan 31, 2025
1 parent 3f6aeba commit 4d40922
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ detekt/reports/**

local.properties
scan-journal.log

monitor/.venv
monitor/.idea
148 changes: 148 additions & 0 deletions monitor/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import asyncio
import os
import sys
from typing import List

import httpx

from textual.app import App, ComposeResult
from textual.binding import Binding
from textual.containers import VerticalScroll, Container, HorizontalGroup
from textual.widget import Widget
from textual.widgets import Header, ProgressBar, Static, Footer

REPO_URL = "https://repo.maven.apache.org/maven2"


def read_publications(version, path):
files = [[x[0], list(filter(lambda file: file.endswith(".pom"), x[2]))[0]] for x in os.walk(path) if
version in x[0]]
paths = list(map(lambda tpl: Path(f"{tpl[0].removeprefix(path)}/{tpl[1]}"), files))
return paths


class Path:
def __init__(self, path) -> None:
self.full = path
self.base = os.path.basename(path)
self.calculated_id = str(self.base.replace(".", "_"))


class Dependency(HorizontalGroup):
def __init__(self, path: Path, *children: Widget) -> None:
self.path = path
super().__init__(*children, name=self.path.base)

def compose(self) -> ComposeResult:
yield Static(self.path.base, id=self.path.calculated_id)


class MonitoringApp(App):
CSS = """
Screen {
align: center middle;
}
Header {
text-align: center;
}
.progress-container {
width: 80%;
height: 3;
margin: 1 0;
}
VerticalScroll {
width: 95%;
height: 80%;
border: solid white;
}
.found {
color: green;
}
.hidden {
display: none;
}
"""

BINDINGS = [
Binding(key="q", action="quit", description="Quit the app"),
Binding(key="h", action="hide", description="Hide/Show Uploaded"),
]

def __init__(self, paths: List[Path], version, *children, **kwargs):
super().__init__(*children, **kwargs)
self.paths = paths
self.version = version

def compose(self) -> ComposeResult:
yield Header(show_clock=True, name="Monitoring")
yield Container(
ProgressBar(
total=len(self.paths),
show_percentage=True,
id="progress-bar",
show_eta=False,
),
classes="progress-container",
)

deps = [Dependency(i) for i in self.paths]
yield VerticalScroll(*deps)
yield Footer()

hidden = True

def action_hide(self):
if self.hidden:
self.query(".found").remove_class("hidden")
else:
self.query(".found").add_class("hidden")

self.hidden = not self.hidden

def on_mount(self):
self.title = "Monitoring Dependencies"
self.sub_title = f"Version {self.version}"

def on_load(self) -> None:
self.run_worker(self.gather(), exclusive=True)

async def gather(self):
await asyncio.gather(*[self.update_weather(path) for path in _paths])

lock = asyncio.Lock()
progress = 0

async def update_weather(self, path: Path) -> None:
url = f"{REPO_URL}/{path.full}"
async with httpx.AsyncClient() as client:
response = await client.get(url)
if response.status_code == 200:
weather_widget = self.query_one(f"#{path.calculated_id}", Static)
weather_widget.add_class("found")
if self.hidden:
weather_widget.add_class("hidden")
weather_widget.update(f"{path.base} - UPLOADED")
await self.lock.acquire()
self.progress += 1
self.query_one("#progress-bar", ProgressBar).update(progress=self.progress)
self.lock.release()
else:
await asyncio.sleep(1)
await self.update_weather(path)


if __name__ == "__main__":
if not os.path.exists("../build/repo/"):
print("use ./publishLocal.sh from the repository root")
elif len(sys.argv) != 2:
print("Usage: python main.py <version>")
else:
_version = sys.argv[1]
_paths = read_publications(_version, "../build/repo/")
app = MonitoringApp(_paths, _version)
app.run()
34 changes: 34 additions & 0 deletions monitor/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
aiohappyeyeballs==2.4.4
aiohttp==3.11.11
aiohttp-jinja2==1.6
aiosignal==1.3.2
anyio==4.8.0
async-timeout==5.0.1
attrs==25.1.0
certifi==2024.12.14
click==8.1.8
exceptiongroup==1.2.2
frozenlist==1.5.0
h11==0.14.0
httpcore==1.0.7
httpx==0.28.1
idna==3.10
Jinja2==3.1.5
linkify-it-py==2.0.3
markdown-it-py==3.0.0
MarkupSafe==3.0.2
mdit-py-plugins==0.4.2
mdurl==0.1.2
msgpack==1.1.0
multidict==6.1.0
platformdirs==4.3.6
propcache==0.2.1
Pygments==2.19.1
rich==13.9.4
sniffio==1.3.1
textual==1.0.0
textual-dev==1.7.0
textual-serve==1.1.1
typing_extensions==4.12.2
uc-micro-py==1.0.3
yarl==1.18.3

0 comments on commit 4d40922

Please sign in to comment.