Add progress bar to zipgrep
This commit is contained in:
@@ -44,10 +44,29 @@ async function pollTask(poll_url, disableTimeout) {
|
||||
|
||||
if (res && res.status) {
|
||||
let status = res.status.toLowerCase();
|
||||
if (status === "pending") {
|
||||
status = "pending or unknown";
|
||||
|
||||
const progress = document.getElementById("progress");
|
||||
|
||||
if (status === "progress") {
|
||||
progress.classList.remove("d-none");
|
||||
const bar = progress.children[0];
|
||||
|
||||
const {current, total, running} = res.result;
|
||||
const perc = Math.min( Math.max(100 * current / total, 0), 100);
|
||||
bar.style.width = `${perc}%`;
|
||||
bar.setAttribute("aria-valuenow", current);
|
||||
bar.setAttribute("aria-valuemax", total);
|
||||
|
||||
const packages = running.map(x => `${x.author}/${x.name}`).join(", ");
|
||||
document.getElementById("status").textContent = `Status: in progress (${current} / ${total})\n\n${packages}`;
|
||||
} else {
|
||||
progress.classList.add("d-none");
|
||||
|
||||
if (status === "pending") {
|
||||
status = "pending or unknown";
|
||||
}
|
||||
document.getElementById("status").textContent = `Status: ${status}`;
|
||||
}
|
||||
document.getElementById("status").textContent = `Status: ${status}`;
|
||||
}
|
||||
|
||||
if (res && res.status === "SUCCESS") {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
from subprocess import Popen, PIPE
|
||||
from typing import Optional
|
||||
|
||||
@@ -22,12 +23,15 @@ from app.models import Package, PackageState, PackageRelease
|
||||
from app.tasks import celery
|
||||
|
||||
|
||||
@celery.task()
|
||||
def search_in_releases(query: str, file_filter: str):
|
||||
@celery.task(bind=True)
|
||||
def search_in_releases(self, query: str, file_filter: str):
|
||||
packages = list(Package.query.filter(Package.state == PackageState.APPROVED).all())
|
||||
running = []
|
||||
results = []
|
||||
|
||||
total = len(packages)
|
||||
self.update_state(state="PROGRESS", meta={"current": 0, "total": total})
|
||||
|
||||
while len(packages) > 0 or len(running) > 0:
|
||||
# Check running
|
||||
for i in range(len(running) - 1, -1, -1):
|
||||
@@ -37,10 +41,13 @@ def search_in_releases(query: str, file_filter: str):
|
||||
if exit_code is None:
|
||||
continue
|
||||
elif exit_code == 0:
|
||||
print(f"[Zipgrep] Success for {package.name}", file=sys.stderr)
|
||||
results.append({
|
||||
"package": package.as_key_dict(),
|
||||
"lines": handle.stdout.read(),
|
||||
})
|
||||
else:
|
||||
print(f"[Zipgrep] Error for {package.name}", file=sys.stderr)
|
||||
|
||||
del running[i]
|
||||
|
||||
@@ -49,9 +56,17 @@ def search_in_releases(query: str, file_filter: str):
|
||||
package = packages.pop()
|
||||
release: Optional[PackageRelease] = package.get_download_release()
|
||||
if release:
|
||||
print(f"[Zipgrep] Starting {package.name}", file=sys.stderr)
|
||||
handle = Popen(["zipgrep", query, release.file_path, file_filter], stdout=PIPE, encoding="UTF-8")
|
||||
running.append([package, handle])
|
||||
|
||||
remaining = len(packages) + len(running)
|
||||
self.update_state(state="PROGRESS", meta={
|
||||
"current": total - remaining,
|
||||
"total": total,
|
||||
"running": [x[0].as_key_dict() for x in running],
|
||||
})
|
||||
|
||||
if len(running) > 0:
|
||||
running[0][1].wait()
|
||||
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
{% block content %}
|
||||
<h1>{{ self.title() }}</h1>
|
||||
<p id="status"></p>
|
||||
<div id="progress" class="progress d-none">
|
||||
<div class="progress-bar bg-info" role="progressbar" style="width: 50%;" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100"></div>
|
||||
</div>
|
||||
|
||||
{% if "error" in info or info.status == "FAILURE" or info.status == "REVOKED" %}
|
||||
<pre style="white-space: pre-wrap; word-wrap: break-word;">{{ info.error }}</pre>
|
||||
|
||||
Reference in New Issue
Block a user