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
276 changes: 271 additions & 5 deletions app/nullius/judge/store.py

Large diffs are not rendered by default.

18 changes: 17 additions & 1 deletion app/nullius/runs/uid.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,20 @@ def of(job_dir: str, cfg: dict, res: dict) -> tuple:
f = facts(job_dir, cfg, res)
if f is None:
return "", "pending"
return str(uuid.uuid5(NS_JOB, json.dumps(f, sort_keys=True, separators=(",", ":")))), "derived"
return _derived(f), "derived"


def _derived(f: dict) -> str:
return str(uuid.uuid5(NS_JOB, json.dumps(f, sort_keys=True, separators=(",", ":"))))


#: the folder a derived identity took, before #793, from a job folder spelt ``pair/``, ``pair/.`` or ``pair/..``
EARLIER_FOLDERS = ("", ".", "..")


def earlier(job_dir: str) -> set:
"""The identities the job's files derived before #793 under each spelling of `EARLIER_FOLDERS`,
read strictly (`strict`): none for a declared or pending one. Several jobs can share one."""
cfg, res = _strict_json(os.path.join(job_dir, "config.json")), _strict_json(os.path.join(job_dir, "result.json"))
f = None if _declared(cfg) else facts(job_dir, cfg, res)
return set() if f is None else {_derived(dict(f, folder=n)) for n in EARLIER_FOLDERS}
14 changes: 10 additions & 4 deletions app/nullius/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ def list_all(home_dir: str) -> list:

def every(home_dir: str) -> list:
"""Every workspace under *home_dir*, for a reader that must miss none: OSError while one
there cannot be read (another version, damaged), since what it holds is unknown."""
there cannot be read (another version, damaged, denied, roots that are no list of paths),
since what it holds is unknown."""
try:
names = sorted(os.listdir(home_dir))
except FileNotFoundError:
Expand All @@ -324,10 +325,15 @@ def every(home_dir: str) -> list:
for name in names:
try:
ws = load(home_dir, name)
except (TypeError, ValueError) as error:
if ws is None and _NAME.fullmatch(name):
os.lstat(_path(home_dir, name)) # there, or not to be told: unread
raise ValueError("unread")
if ws and not all(isinstance(rs, list) and all(isinstance(r, str) for r in rs) for rs in (ws.roots, ws.job_roots)):
raise ValueError("invalid roots")
except (FileNotFoundError, NotADirectoryError):
continue
except (OSError, TypeError, ValueError) as error:
raise OSError(f"workspace {name} cannot be read") from error
if ws is None and _NAME.fullmatch(name) and os.path.lexists(_path(home_dir, name)):
raise OSError(f"workspace {name} cannot be read")
found += [ws] if ws else []
return found

Expand Down
7 changes: 4 additions & 3 deletions app/static/judgements-move.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

async function ask({later = false} = {}) {
const got = await nulliusFetch(URL_, {headers: {Accept: 'application/json'}}).then(r => r.ok ? r.json() : {workspaces: []}).catch(() => ({workspaces: []}));
if (!got.workspaces.length) { if (later) remember(); return; } // nothing to move: not asked again here
if (!got.workspaces.length) { if (later) remember(); else notify('Nothing to move.'); return; } // not asked again here
// a native modal, as the welcome: it keeps the focus, makes the page behind it inert and closes on Escape
const d = document.createElement('dialog');
d.className = 'onb-dialog';
Expand All @@ -31,7 +31,8 @@
d.returnValue = 'move'; d.close();
if (j.ok) {
notify('Judgements moved.');
document.querySelectorAll('[data-move-judgements-row]').forEach(x => x.remove());
// the count is gone; the button stays, as the page would show it now
document.querySelectorAll('[data-move-judgements-row] .st-value').forEach(x => { if (x.firstChild?.nodeType === Node.TEXT_NODE) x.firstChild.remove(); });
} else notify(j.error || 'The judgements could not be moved.', {error: true});
});
// Escape, like Not now
Expand All @@ -44,7 +45,7 @@
document.addEventListener('click', e => { if (e.target.closest('[data-move-judgements]')) ask(); });

// shortcut: this first-load dialog is temporary migration UI, against "a notice is a toast"; remove it after a few versions.
if (window.parent !== window) return;
if (window.parent !== window || !me.hasAttribute('data-prompt')) return;
let seen = true;
try { seen = !!localStorage.getItem(KEY) || !(JSON.parse(localStorage.getItem('nullius-onboarding')) || {}).asked; } catch {}
if (!seen && !document.querySelector('dialog[open]')) ask({later: true});
Expand Down
2 changes: 1 addition & 1 deletion app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@
</script>
{% endif %}
<script src="{{ url_for('static', filename='controls.js') }}"></script>
{% if judgements_unmoved() %}<script src="{{ url_for('static', filename='judgements-move.js') }}" data-url="{{ url_for('judgements_move') }}" data-csrf="{{ csrf_token() }}"></script>{% endif %}
{% set judgements_prompt = judgements_unmoved() %}{% if judgements_prompt or old_judgements %}<script src="{{ url_for('static', filename='judgements-move.js') }}" data-url="{{ url_for('judgements_move') }}" data-csrf="{{ csrf_token() }}"{% if judgements_prompt %} data-prompt{% endif %}></script>{% endif %}
{% if not embedded %}
{% include "workspaces/_create.html" %}
<script src="{{ url_for('static', filename='workspaces/create.js') }}"></script>
Expand Down
2 changes: 1 addition & 1 deletion app/templates/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ <h2 id="judge-h">Judges</h2>
{% if old_judgements and writable %}
<div class="st-card" data-move-judgements-row>
<div class="st-row"><span class="st-row-label">In workspaces</span>
<span class="st-row-value st-value">{{ old_judgements|sum(attribute=1) }} judgement{{ '' if old_judgements|sum(attribute=1) == 1 else 's' }}<button type="button" class="btn sm" data-move-judgements>Move judgements</button></span></div>
{% set n = old_judgements|sum(attribute=1) %}<span class="st-row-value st-value">{% if n %}{{ n }} judgement{{ '' if n == 1 else 's' }}{% endif %}<button type="button" class="btn sm" data-move-judgements>Move judgements</button></span></div>
</div>
{% endif %}
</section>
Expand Down
Loading
Loading