cuju-render 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cuju/render/__init__.py +759 -0
- cuju/render/__main__.py +1065 -0
- cuju/render/_export/__init__.py +3 -0
- cuju/render/_export/feed.py +542 -0
- cuju/render/_export/sizes.py +157 -0
- cuju/render/_export/video.py +1618 -0
- cuju/render/_export/video_jobs.py +408 -0
- cuju/render/_format/__init__.py +3 -0
- cuju/render/_format/annotations.py +235 -0
- cuju/render/_format/codec.py +307 -0
- cuju/render/_format/keep.py +121 -0
- cuju/render/_format/recording.py +860 -0
- cuju/render/_format/writer.py +54 -0
- cuju/render/_guide/__init__.py +3 -0
- cuju/render/_guide/doctor.py +523 -0
- cuju/render/_guide/help.py +62 -0
- cuju/render/_guide/tutorial.py +254 -0
- cuju/render/_http/__init__.py +3 -0
- cuju/render/_http/commands.py +57 -0
- cuju/render/_http/headers.py +103 -0
- cuju/render/_http/launch.py +500 -0
- cuju/render/_http/launchers.py +408 -0
- cuju/render/_http/pwa.py +128 -0
- cuju/render/_http/server.py +2105 -0
- cuju/render/_http/window.py +360 -0
- cuju/render/_moments/__init__.py +3 -0
- cuju/render/_moments/captions.py +284 -0
- cuju/render/_moments/events.py +1123 -0
- cuju/render/_moments/search.py +694 -0
- cuju/render/_packages/__init__.py +3 -0
- cuju/render/_packages/glsl.py +746 -0
- cuju/render/_packages/loudness.py +334 -0
- cuju/render/_packages/pack.py +1959 -0
- cuju/render/_packages/presentation.py +1376 -0
- cuju/render/_packages/vocabulary.py +609 -0
- cuju/render/_playing/__init__.py +3 -0
- cuju/render/_playing/achievements.py +463 -0
- cuju/render/_playing/bench.py +609 -0
- cuju/render/_playing/challenges.py +1813 -0
- cuju/render/_playing/demo.py +323 -0
- cuju/render/_playing/draw.py +211 -0
- cuju/render/_playing/errors.py +20 -0
- cuju/render/_playing/game.py +645 -0
- cuju/render/_playing/limits.py +339 -0
- cuju/render/_playing/play.py +926 -0
- cuju/render/_playing/policy_worker.py +250 -0
- cuju/render/_playing/strict.py +810 -0
- cuju/render/_registry/__init__.py +3 -0
- cuju/render/_registry/clips.py +394 -0
- cuju/render/_registry/joints.py +108 -0
- cuju/render/_registry/teams.py +2058 -0
- cuju/render/_store/__init__.py +3 -0
- cuju/render/_store/home.py +70 -0
- cuju/render/_store/library.py +604 -0
- cuju/render/_store/samples.py +163 -0
- cuju/render/_text/__init__.py +3 -0
- cuju/render/_text/languages.py +637 -0
- cuju/render/_text/messages.py +1396 -0
- cuju/render/_tournaments/__init__.py +3 -0
- cuju/render/_tournaments/results.py +547 -0
- cuju/render/_tournaments/tournament.py +2742 -0
- cuju/render/_tournaments/tournament_cli.py +587 -0
- cuju/render/_tournaments/tournament_runner.py +1975 -0
- cuju/render/_version.py +6 -0
- cuju/render/_watch/__init__.py +3 -0
- cuju/render/_watch/grid.py +265 -0
- cuju/render/_watch/live.py +664 -0
- cuju/render/_watch/notebook.py +79 -0
- cuju/render/_watch/show.py +171 -0
- cuju/render/samples/sample-11v11.cjr +0 -0
- cuju/render/samples/sample-5v5.cjr +0 -0
- cuju/render/samples/teams/starter/main.py +33 -0
- cuju/render/scenarios/benchmark_full_game_11_vs_11_easy.py +46 -0
- cuju/render/scenarios/benchmark_full_game_11_vs_11_hard.py +46 -0
- cuju/render/scenarios/benchmark_full_game_11_vs_11_medium.py +46 -0
- cuju/render/scenarios/benchmark_full_game_5_vs_5_easy.py +34 -0
- cuju/render/scenarios/benchmark_full_game_5_vs_5_hard.py +34 -0
- cuju/render/scenarios/benchmark_full_game_5_vs_5_medium.py +34 -0
- cuju/render/web/assets/adboard_polygon.webp +0 -0
- cuju/render/web/assets/adboard_your_ad_here.webp +0 -0
- cuju/render/web/assets/animations/kaykit-rig-medium-combatmelee.glb +0 -0
- cuju/render/web/assets/animations/kaykit-rig-medium-general.glb +0 -0
- cuju/render/web/assets/animations/kaykit-rig-medium-movementadvanced.glb +0 -0
- cuju/render/web/assets/animations/kaykit-rig-medium-movementbasic.glb +0 -0
- cuju/render/web/assets/animations/kaykit-rig-medium-simulation.glb +0 -0
- cuju/render/web/assets/animations/kaykit-rig-medium-special.glb +0 -0
- cuju/render/web/assets/ball.glb +0 -0
- cuju/render/web/assets/challenges/3_vs_1_with_keeper.mp4 +0 -0
- cuju/render/web/assets/challenges/3_vs_1_with_keeper.webp +0 -0
- cuju/render/web/assets/challenges/corner.mp4 +0 -0
- cuju/render/web/assets/challenges/corner.webp +0 -0
- cuju/render/web/assets/challenges/counterattack_easy.mp4 +0 -0
- cuju/render/web/assets/challenges/counterattack_easy.webp +0 -0
- cuju/render/web/assets/challenges/counterattack_hard.mp4 +0 -0
- cuju/render/web/assets/challenges/counterattack_hard.webp +0 -0
- cuju/render/web/assets/challenges/empty_goal.mp4 +0 -0
- cuju/render/web/assets/challenges/empty_goal.webp +0 -0
- cuju/render/web/assets/challenges/empty_goal_close.mp4 +0 -0
- cuju/render/web/assets/challenges/empty_goal_close.webp +0 -0
- cuju/render/web/assets/challenges/manifest.json +375 -0
- cuju/render/web/assets/challenges/one_on_one.mp4 +0 -0
- cuju/render/web/assets/challenges/one_on_one.webp +0 -0
- cuju/render/web/assets/challenges/one_on_one_hard.mp4 +0 -0
- cuju/render/web/assets/challenges/one_on_one_hard.webp +0 -0
- cuju/render/web/assets/challenges/pass_and_shoot_with_keeper.mp4 +0 -0
- cuju/render/web/assets/challenges/pass_and_shoot_with_keeper.webp +0 -0
- cuju/render/web/assets/challenges/run_pass_and_shoot_with_keeper.mp4 +0 -0
- cuju/render/web/assets/challenges/run_pass_and_shoot_with_keeper.webp +0 -0
- cuju/render/web/assets/challenges/run_to_score.mp4 +0 -0
- cuju/render/web/assets/challenges/run_to_score.webp +0 -0
- cuju/render/web/assets/challenges/run_to_score_with_keeper.mp4 +0 -0
- cuju/render/web/assets/challenges/run_to_score_with_keeper.webp +0 -0
- cuju/render/web/assets/challenges/single_goal_versus_lazy.mp4 +0 -0
- cuju/render/web/assets/challenges/single_goal_versus_lazy.webp +0 -0
- cuju/render/web/assets/crowd.webp +0 -0
- cuju/render/web/assets/crowd_normal.webp +0 -0
- cuju/render/web/assets/cuju-logo-384.png +0 -0
- cuju/render/web/assets/cuju-logo.png +0 -0
- cuju/render/web/assets/cuju-logo.svg +46 -0
- cuju/render/web/assets/cuju-mark-light.svg +33 -0
- cuju/render/web/assets/cuju-mark.svg +33 -0
- cuju/render/web/assets/goal.glb +0 -0
- cuju/render/web/assets/grass.webp +0 -0
- cuju/render/web/assets/hair_black.png +0 -0
- cuju/render/web/assets/hair_blonde.png +0 -0
- cuju/render/web/assets/hair_brown.png +0 -0
- cuju/render/web/assets/hair_darkblonde.png +0 -0
- cuju/render/web/assets/hair_long01.glb +0 -0
- cuju/render/web/assets/hair_long02.glb +0 -0
- cuju/render/web/assets/hair_medium01.glb +0 -0
- cuju/render/web/assets/hair_red.png +0 -0
- cuju/render/web/assets/hair_short01.glb +0 -0
- cuju/render/web/assets/hair_short02.glb +0 -0
- cuju/render/web/assets/icons/cuju-192.png +0 -0
- cuju/render/web/assets/icons/cuju-512.png +0 -0
- cuju/render/web/assets/icons/cuju-maskable-512.png +0 -0
- cuju/render/web/assets/kit_goalkeeper.webp +0 -0
- cuju/render/web/assets/kit_mask.png +0 -0
- cuju/render/web/assets/kit_normal.webp +0 -0
- cuju/render/web/assets/manifest.json +601 -0
- cuju/render/web/assets/models/kaykit-barbarian.glb +0 -0
- cuju/render/web/assets/models/kaykit-barbarian.json +23 -0
- cuju/render/web/assets/models/kaykit-knight.glb +0 -0
- cuju/render/web/assets/models/kaykit-knight.json +23 -0
- cuju/render/web/assets/models/kaykit-mage.glb +0 -0
- cuju/render/web/assets/models/kaykit-mage.json +23 -0
- cuju/render/web/assets/models/kaykit-mannequin-medium.glb +0 -0
- cuju/render/web/assets/models/kaykit-mannequin-medium.json +23 -0
- cuju/render/web/assets/models/kaykit-ranger.glb +0 -0
- cuju/render/web/assets/models/kaykit-ranger.json +23 -0
- cuju/render/web/assets/models/kaykit-rogue-hooded.glb +0 -0
- cuju/render/web/assets/models/kaykit-rogue-hooded.json +23 -0
- cuju/render/web/assets/models/kaykit-rogue.glb +0 -0
- cuju/render/web/assets/models/kaykit-rogue.json +23 -0
- cuju/render/web/assets/models/kaykit-skeleton-mage.glb +0 -0
- cuju/render/web/assets/models/kaykit-skeleton-mage.json +23 -0
- cuju/render/web/assets/models/kaykit-skeleton-minion.glb +0 -0
- cuju/render/web/assets/models/kaykit-skeleton-minion.json +23 -0
- cuju/render/web/assets/models/kaykit-skeleton-rogue.glb +0 -0
- cuju/render/web/assets/models/kaykit-skeleton-rogue.json +23 -0
- cuju/render/web/assets/models/kaykit-skeleton-warrior.glb +0 -0
- cuju/render/web/assets/models/kaykit-skeleton-warrior.json +23 -0
- cuju/render/web/assets/pitch.webp +0 -0
- cuju/render/web/assets/pitch_normal.webp +0 -0
- cuju/render/web/assets/player.glb +0 -0
- cuju/render/web/assets/shoe.webp +0 -0
- cuju/render/web/assets/shoe_sole.png +0 -0
- cuju/render/web/assets/skin_01.png +0 -0
- cuju/render/web/assets/skin_02.png +0 -0
- cuju/render/web/assets/skin_03.png +0 -0
- cuju/render/web/assets/skin_04.png +0 -0
- cuju/render/web/assets/sounds/applause.ogg +0 -0
- cuju/render/web/assets/sounds/beach-wave-1.ogg +0 -0
- cuju/render/web/assets/sounds/beach-wave-2.ogg +0 -0
- cuju/render/web/assets/sounds/beach-wave-3.ogg +0 -0
- cuju/render/web/assets/sounds/beach-wave-4.ogg +0 -0
- cuju/render/web/assets/sounds/city-horn.ogg +0 -0
- cuju/render/web/assets/sounds/city-loop.ogg +0 -0
- cuju/render/web/assets/sounds/city-siren.ogg +0 -0
- cuju/render/web/assets/sounds/crowd-cheer.ogg +0 -0
- cuju/render/web/assets/sounds/crowd-loop.ogg +0 -0
- cuju/render/web/assets/sounds/crowd-ooh.ogg +0 -0
- cuju/render/web/assets/sounds/gulls.ogg +0 -0
- cuju/render/web/assets/sounds/neon-sting.ogg +0 -0
- cuju/render/web/assets/sounds/rain-loop.ogg +0 -0
- cuju/render/web/assets/sounds/sounds.json +46 -0
- cuju/render/web/assets/sounds/space-beep.ogg +0 -0
- cuju/render/web/assets/sounds/space-hum.ogg +0 -0
- cuju/render/web/assets/sounds/space-radio.ogg +0 -0
- cuju/render/web/assets/sounds/whistle-long.ogg +0 -0
- cuju/render/web/assets/sounds/whistle-short.ogg +0 -0
- cuju/render/web/assets/sounds/wind-loop.ogg +0 -0
- cuju/render/web/easy.css +357 -0
- cuju/render/web/export.html +23 -0
- cuju/render/web/feed.css +262 -0
- cuju/render/web/feed.html +28 -0
- cuju/render/web/flat.css +120 -0
- cuju/render/web/home.css +837 -0
- cuju/render/web/index.html +373 -0
- cuju/render/web/js/boot.js +50 -0
- cuju/render/web/js/broadcast/audio.js +2141 -0
- cuju/render/web/js/broadcast/celebrate.js +1238 -0
- cuju/render/web/js/broadcast/decisions.js +609 -0
- cuju/render/web/js/broadcast/hud.js +352 -0
- cuju/render/web/js/broadcast/show.js +3614 -0
- cuju/render/web/js/broadcast/transition.js +2231 -0
- cuju/render/web/js/broadcast/voices.js +153 -0
- cuju/render/web/js/capture.js +101 -0
- cuju/render/web/js/core/accessibility.js +90 -0
- cuju/render/web/js/core/api.js +429 -0
- cuju/render/web/js/core/comfort.js +135 -0
- cuju/render/web/js/core/i18n.js +705 -0
- cuju/render/web/js/core/icons.js +167 -0
- cuju/render/web/js/core/input-settings.js +156 -0
- cuju/render/web/js/core/keys.js +277 -0
- cuju/render/web/js/core/language-ui.js +125 -0
- cuju/render/web/js/core/menu.js +853 -0
- cuju/render/web/js/core/names.js +113 -0
- cuju/render/web/js/core/page-structure.js +110 -0
- cuju/render/web/js/core/scenarios.js +109 -0
- cuju/render/web/js/core/spoilers.js +236 -0
- cuju/render/web/js/core/typeahead.js +38 -0
- cuju/render/web/js/export/dom-picture.js +330 -0
- cuju/render/web/js/export/export-host.js +97 -0
- cuju/render/web/js/export/feed-dialog.js +191 -0
- cuju/render/web/js/export/feed-params.js +266 -0
- cuju/render/web/js/export/feed.js +363 -0
- cuju/render/web/js/export/mp4-mux.js +295 -0
- cuju/render/web/js/export/photo-core.js +313 -0
- cuju/render/web/js/export/photo.js +1314 -0
- cuju/render/web/js/export/safe-frame.js +59 -0
- cuju/render/web/js/export/size-fields.js +103 -0
- cuju/render/web/js/export/sizes.js +178 -0
- cuju/render/web/js/export/video-boot.js +55 -0
- cuju/render/web/js/export/video-browser.js +325 -0
- cuju/render/web/js/export/video-export.js +417 -0
- cuju/render/web/js/export/video-plan.js +207 -0
- cuju/render/web/js/export/video-range.js +185 -0
- cuju/render/web/js/export/webm-mux.js +198 -0
- cuju/render/web/js/feed-boot.js +151 -0
- cuju/render/web/js/feed-frame.js +101 -0
- cuju/render/web/js/help/doctor.js +488 -0
- cuju/render/web/js/help/firstrun.js +379 -0
- cuju/render/web/js/help/help-center.js +438 -0
- cuju/render/web/js/help/install-offer.js +164 -0
- cuju/render/web/js/help/install-state.js +104 -0
- cuju/render/web/js/help/lessons-core.js +207 -0
- cuju/render/web/js/help/lessons.js +463 -0
- cuju/render/web/js/help/palette.js +584 -0
- cuju/render/web/js/help/pwa.js +257 -0
- cuju/render/web/js/help/tour-core.js +241 -0
- cuju/render/web/js/help/tour.js +461 -0
- cuju/render/web/js/main.js +2513 -0
- cuju/render/web/js/pages/draw.js +188 -0
- cuju/render/web/js/pages/fieldpage.js +530 -0
- cuju/render/web/js/pages/home.js +521 -0
- cuju/render/web/js/pages/matches.js +779 -0
- cuju/render/web/js/pages/moments-ui.js +359 -0
- cuju/render/web/js/pages/queue-filters.js +63 -0
- cuju/render/web/js/pages/recording-groups.js +80 -0
- cuju/render/web/js/pages/recordings.js +1069 -0
- cuju/render/web/js/play/bench.js +347 -0
- cuju/render/web/js/play/challenges.js +1302 -0
- cuju/render/web/js/play/medals.js +127 -0
- cuju/render/web/js/play/play.js +1953 -0
- cuju/render/web/js/play/teasers.js +196 -0
- cuju/render/web/js/play/touch.js +350 -0
- cuju/render/web/js/play/tournament-layout.js +487 -0
- cuju/render/web/js/play/tournament-results.js +441 -0
- cuju/render/web/js/play/tournament-strict.js +560 -0
- cuju/render/web/js/play/tournament.js +2585 -0
- cuju/render/web/js/players/animate.js +972 -0
- cuju/render/web/js/players/clips.js +224 -0
- cuju/render/web/js/players/kaykit.js +162 -0
- cuju/render/web/js/players/kits.js +676 -0
- cuju/render/web/js/players/number-patch.js +82 -0
- cuju/render/web/js/players/players.js +2694 -0
- cuju/render/web/js/players/recolor.js +893 -0
- cuju/render/web/js/players/retarget.js +325 -0
- cuju/render/web/js/players/rig-numbers.js +174 -0
- cuju/render/web/js/presentation/animator.js +231 -0
- cuju/render/web/js/presentation/assign.js +85 -0
- cuju/render/web/js/presentation/behaviors.js +440 -0
- cuju/render/web/js/presentation/budget.js +209 -0
- cuju/render/web/js/presentation/catalog.js +1674 -0
- cuju/render/web/js/presentation/clocks.js +72 -0
- cuju/render/web/js/presentation/commands.js +301 -0
- cuju/render/web/js/presentation/contract.js +240 -0
- cuju/render/web/js/presentation/effects.js +904 -0
- cuju/render/web/js/presentation/flash.js +605 -0
- cuju/render/web/js/presentation/freeze-worklet.js +22 -0
- cuju/render/web/js/presentation/glsl.js +464 -0
- cuju/render/web/js/presentation/host.js +323 -0
- cuju/render/web/js/presentation/index.js +2066 -0
- cuju/render/web/js/presentation/loudness-worklet.js +235 -0
- cuju/render/web/js/presentation/loudness.js +740 -0
- cuju/render/web/js/presentation/moments.js +536 -0
- cuju/render/web/js/presentation/post.js +327 -0
- cuju/render/web/js/presentation/preview.js +180 -0
- cuju/render/web/js/presentation/protocol.js +174 -0
- cuju/render/web/js/presentation/reach.js +158 -0
- cuju/render/web/js/presentation/rigging.js +130 -0
- cuju/render/web/js/presentation/sandbox.js +157 -0
- cuju/render/web/js/presentation/shaders.js +235 -0
- cuju/render/web/js/presentation/stage.js +402 -0
- cuju/render/web/js/presentation/teamaudio.js +722 -0
- cuju/render/web/js/presentation/tracks.js +197 -0
- cuju/render/web/js/presentation/values.js +81 -0
- cuju/render/web/js/recording/annotation-data.js +203 -0
- cuju/render/web/js/recording/captions.js +491 -0
- cuju/render/web/js/recording/codec.js +185 -0
- cuju/render/web/js/recording/decode-worker.js +70 -0
- cuju/render/web/js/recording/decode.js +94 -0
- cuju/render/web/js/recording/episodes.js +46 -0
- cuju/render/web/js/recording/format.js +461 -0
- cuju/render/web/js/recording/live.js +348 -0
- cuju/render/web/js/recording/moments-query.js +59 -0
- cuju/render/web/js/recording/moments.js +149 -0
- cuju/render/web/js/recording/pose.js +86 -0
- cuju/render/web/js/recording/timeline.js +275 -0
- cuju/render/web/js/teams/art.js +50 -0
- cuju/render/web/js/teams/clip-editor.js +293 -0
- cuju/render/web/js/teams/editor.js +1979 -0
- cuju/render/web/js/teams/library.js +344 -0
- cuju/render/web/js/teams/painter.js +633 -0
- cuju/render/web/js/teams/surprise-ui.js +195 -0
- cuju/render/web/js/teams/surprise.js +497 -0
- cuju/render/web/js/teams/team-check.js +127 -0
- cuju/render/web/js/watch/annotations.js +270 -0
- cuju/render/web/js/watch/flat.js +366 -0
- cuju/render/web/js/watch/grid.js +436 -0
- cuju/render/web/js/watch/pitch2d.js +289 -0
- cuju/render/web/js/watch/player-tools.js +192 -0
- cuju/render/web/js/watch/presets.js +201 -0
- cuju/render/web/js/world/arenas.js +997 -0
- cuju/render/web/js/world/ball.js +204 -0
- cuju/render/web/js/world/cameras.js +982 -0
- cuju/render/web/js/world/crowd.js +376 -0
- cuju/render/web/js/world/field.js +227 -0
- cuju/render/web/js/world/framing.js +145 -0
- cuju/render/web/js/world/occlusion.js +48 -0
- cuju/render/web/js/world/pitch.js +703 -0
- cuju/render/web/js/world/scene.js +395 -0
- cuju/render/web/js/world/sky.js +325 -0
- cuju/render/web/js/world/stadium.js +1262 -0
- cuju/render/web/js/world/vendor-sky.js +367 -0
- cuju/render/web/js/world/weather.js +264 -0
- cuju/render/web/languages/en.json +4750 -0
- cuju/render/web/lessons.json +137 -0
- cuju/render/web/manifest.webmanifest +23 -0
- cuju/render/web/style.css +8399 -0
- cuju/render/web/sw.js +235 -0
- cuju/render/web/vendor/fabric/LICENSE +16 -0
- cuju/render/web/vendor/fabric/fabric.min.mjs +1 -0
- cuju/render/web/vendor/lucide/LICENSE +43 -0
- cuju/render/web/vendor/lucide/icons.js +141 -0
- cuju/render/web/vendor/three/LICENSE +21 -0
- cuju/render/web/vendor/three/build/three.core.js +60586 -0
- cuju/render/web/vendor/three/build/three.module.js +19719 -0
- cuju/render/web/vendor/three/examples/jsm/loaders/GLTFLoader.js +4925 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/EffectComposer.js +365 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/MaskPass.js +195 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/OutputPass.js +148 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/Pass.js +191 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/RenderPass.js +193 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/ShaderPass.js +135 -0
- cuju/render/web/vendor/three/examples/jsm/postprocessing/UnrealBloomPass.js +541 -0
- cuju/render/web/vendor/three/examples/jsm/shaders/CopyShader.js +52 -0
- cuju/render/web/vendor/three/examples/jsm/shaders/LuminosityHighPassShader.js +68 -0
- cuju/render/web/vendor/three/examples/jsm/shaders/OutputShader.js +103 -0
- cuju/render/web/vendor/three/examples/jsm/utils/BufferGeometryUtils.js +1501 -0
- cuju/render/web/vendor/three/examples/jsm/utils/SkeletonUtils.js +496 -0
- cuju_render-0.1.0.dist-info/METADATA +116 -0
- cuju_render-0.1.0.dist-info/RECORD +382 -0
- cuju_render-0.1.0.dist-info/WHEEL +4 -0
- cuju_render-0.1.0.dist-info/licenses/LICENSE +202 -0
- cuju_render-0.1.0.dist-info/licenses/LICENSES/CC-BY-4.0.txt +396 -0
- cuju_render-0.1.0.dist-info/licenses/LICENSES/CC0-1.0.txt +127 -0
- cuju_render-0.1.0.dist-info/licenses/LICENSES/ISC.txt +16 -0
- cuju_render-0.1.0.dist-info/licenses/LICENSES/MIT.txt +24 -0
- cuju_render-0.1.0.dist-info/licenses/LICENSES/Unlicense.txt +13 -0
- cuju_render-0.1.0.dist-info/licenses/NOTICE +35 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Copyright 2026 The cuju Authors
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
"""The hidden folder of the renderer, which holds saved matches, teams and live sources."""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import os
|
|
9
|
+
import re
|
|
10
|
+
import secrets
|
|
11
|
+
import sys
|
|
12
|
+
import time
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
|
|
15
|
+
# The variable that moves the folder, read on every call so that a test can set it.
|
|
16
|
+
HOME_VARIABLE = 'CUJU_RENDER_HOME'
|
|
17
|
+
|
|
18
|
+
_IDENTIFIER = re.compile(r'[a-z0-9][a-z0-9_-]{0,63}')
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def home() -> Path:
|
|
22
|
+
"""Returns the folder of the renderer, `~/.cuju/render` or the one `CUJU_RENDER_HOME` names."""
|
|
23
|
+
folder = os.environ.get(HOME_VARIABLE)
|
|
24
|
+
return Path(folder).expanduser().resolve() if folder else Path.home() / '.cuju' / 'render'
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def folder(kind: str) -> Path:
|
|
28
|
+
"""Returns the subfolder `matches`, `teams`, `live` or `requests`, created when missing."""
|
|
29
|
+
path = home() / kind
|
|
30
|
+
path.mkdir(parents=True, exist_ok=True)
|
|
31
|
+
return path
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def python_command() -> list[str]:
|
|
35
|
+
"""Returns the start of the command of a Python process that the renderer starts.
|
|
36
|
+
|
|
37
|
+
Python 3.11 brought `-P`, which keeps the working folder off the path of modules, so no folder
|
|
38
|
+
of the home, such as `teams` or `requests`, imports as a package in the process.
|
|
39
|
+
"""
|
|
40
|
+
return [sys.executable, '-P'] if sys.version_info >= (3, 11) else [sys.executable]
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def process_environment() -> dict[str, str]:
|
|
44
|
+
"""Returns the environment of a Python process that the renderer starts.
|
|
45
|
+
|
|
46
|
+
The process reads and writes its pipes in UTF-8, the encoding the renderer reads and writes
|
|
47
|
+
them in, whatever the code page of the system.
|
|
48
|
+
"""
|
|
49
|
+
return {**os.environ, 'PYTHONIOENCODING': 'utf-8'}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def process_folder() -> Path:
|
|
53
|
+
"""Returns the working folder of a Python process that the renderer starts, made when missing.
|
|
54
|
+
|
|
55
|
+
That is the home folder, which `-P` keeps off the path of modules. Python 3.10 has no `-P`,
|
|
56
|
+
so there the process starts in the folder `run` of the home, which the renderer keeps empty.
|
|
57
|
+
"""
|
|
58
|
+
folder = home() if sys.version_info >= (3, 11) else home() / 'run'
|
|
59
|
+
folder.mkdir(parents=True, exist_ok=True)
|
|
60
|
+
return folder
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def new_identifier(prefix: str) -> str:
|
|
64
|
+
"""Returns an identifier that sorts by creation time, such as `m-20261106-101500-3fa9`."""
|
|
65
|
+
return f'{prefix}-{time.strftime("%Y%m%d-%H%M%S")}-{secrets.token_hex(2)}'
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def valid_identifier(identifier: str) -> bool:
|
|
69
|
+
"""Returns whether `identifier` is safe as a file name, so no request can leave the folder."""
|
|
70
|
+
return bool(_IDENTIFIER.fullmatch(identifier))
|
|
@@ -0,0 +1,604 @@
|
|
|
1
|
+
# Copyright 2026 The cuju Authors
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
"""The library of saved matches, each a `.cjr` file with a small summary beside it.
|
|
5
|
+
|
|
6
|
+
The files lie side by side in one folder, and each summary names the folder of the page's explorer
|
|
7
|
+
that its match sits in, a path such as `League/Week 1`, so moving a match rewrites one small file.
|
|
8
|
+
The summary also keeps the favorite mark, tags and notes of the page, and the time a recording
|
|
9
|
+
went to the Trash, so marking, tagging and trashing never rewrite the frames.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import contextlib
|
|
15
|
+
import json
|
|
16
|
+
import os
|
|
17
|
+
import shutil
|
|
18
|
+
import struct
|
|
19
|
+
import time
|
|
20
|
+
from collections.abc import Callable
|
|
21
|
+
from functools import wraps
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
from threading import RLock
|
|
24
|
+
from typing import Any, TypeVar
|
|
25
|
+
|
|
26
|
+
from .._format import recording as _recording
|
|
27
|
+
from .._text import languages as _languages
|
|
28
|
+
from .._text import messages as _messages
|
|
29
|
+
from .._text.messages import MessageError
|
|
30
|
+
from . import home as _home
|
|
31
|
+
|
|
32
|
+
_SCORE = struct.Struct('<2i')
|
|
33
|
+
# The sample matches that ship with the package, which the library receives once each.
|
|
34
|
+
_SAMPLES = Path(__file__).parents[1] / 'samples'
|
|
35
|
+
# The file of the home folder that names the samples the library has received.
|
|
36
|
+
_SEEDED = 'samples.json'
|
|
37
|
+
# The title that each sample ships with and its message, which the page shows in its language
|
|
38
|
+
# while the sample keeps that title.
|
|
39
|
+
_SAMPLE_TITLES = {
|
|
40
|
+
'sample-5v5': 'server.names.sample_5v5',
|
|
41
|
+
'sample-11v11': 'server.names.sample_11v11',
|
|
42
|
+
}
|
|
43
|
+
# The limits of the details that the page edits.
|
|
44
|
+
_TAGS, _TAG_LENGTH, _NOTES_LENGTH = 20, 40, 10000
|
|
45
|
+
# The seconds that a recording and its summary stand unchanged before a summary made again is kept.
|
|
46
|
+
_SETTLED_SECONDS = 60
|
|
47
|
+
# One server thread at a time reads and writes the summaries, so no change undoes another.
|
|
48
|
+
_LOCK = RLock()
|
|
49
|
+
_Function = TypeVar('_Function', bound=Callable[..., Any])
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _locked(function: _Function) -> _Function:
|
|
53
|
+
"""Runs `function` with the lock of the library held."""
|
|
54
|
+
|
|
55
|
+
@wraps(function)
|
|
56
|
+
def call(*arguments: Any, **options: Any) -> Any:
|
|
57
|
+
with _LOCK:
|
|
58
|
+
return function(*arguments, **options)
|
|
59
|
+
|
|
60
|
+
return call # type: ignore[return-value]
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _summary(path: Path) -> dict[str, Any]:
|
|
64
|
+
"""Returns the summary of a recording, with every field the page reads in its expected type.
|
|
65
|
+
|
|
66
|
+
A missing or unreadable summary is made again from the header, and a field of the wrong type,
|
|
67
|
+
from a hand edit or another version, falls back to its default. A summary that is missing,
|
|
68
|
+
empty or cut short, as a hard stop during a save leaves it, is made once and kept, once the
|
|
69
|
+
recording and its summary have stood unchanged for a minute, so no save is still writing them.
|
|
70
|
+
"""
|
|
71
|
+
try:
|
|
72
|
+
entry = json.loads(path.with_suffix('.json').read_text(encoding='utf-8'))
|
|
73
|
+
if not isinstance(entry, dict):
|
|
74
|
+
raise ValueError('expected a summary object')
|
|
75
|
+
except (OSError, ValueError) as error:
|
|
76
|
+
entry = _summarize(path)
|
|
77
|
+
if isinstance(error, FileNotFoundError | ValueError) and _settled(path):
|
|
78
|
+
with contextlib.suppress(OSError):
|
|
79
|
+
_store(path, entry)
|
|
80
|
+
for key, kind, default in (
|
|
81
|
+
('folder', str, ''),
|
|
82
|
+
('provenance', dict, {}),
|
|
83
|
+
('favorite', bool, False),
|
|
84
|
+
('tags', list, []),
|
|
85
|
+
('notes', str, ''),
|
|
86
|
+
):
|
|
87
|
+
if not isinstance(entry.get(key), kind):
|
|
88
|
+
entry[key] = default
|
|
89
|
+
entry['tags'] = [tag for tag in entry['tags'] if isinstance(tag, str)]
|
|
90
|
+
# A summary of an older install may hold a title, scenario or team name of another type.
|
|
91
|
+
if not isinstance(entry.get('title'), str):
|
|
92
|
+
entry['title'] = path.stem
|
|
93
|
+
entry.pop('title_id', None)
|
|
94
|
+
for key, default in (('scenario', ''), ('created', '')):
|
|
95
|
+
if not isinstance(entry.get(key), str):
|
|
96
|
+
entry[key] = default
|
|
97
|
+
teams = entry.get('teams')
|
|
98
|
+
entry['teams'] = [
|
|
99
|
+
name if name is None or isinstance(name, str) else ''
|
|
100
|
+
for name in (teams if isinstance(teams, list) else ['', ''])
|
|
101
|
+
]
|
|
102
|
+
if not isinstance(entry.get('deleted_at'), str):
|
|
103
|
+
entry.pop('deleted_at', None)
|
|
104
|
+
group = _group_of(entry.get('group'))
|
|
105
|
+
if group is None:
|
|
106
|
+
entry.pop('group', None)
|
|
107
|
+
else:
|
|
108
|
+
entry['group'] = group
|
|
109
|
+
return _labelled(entry)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
# The fields of a group beside its identifier and labels, each with the types it may hold.
|
|
113
|
+
_GROUP_FIELDS: tuple[tuple[str, tuple[type, ...]], ...] = (
|
|
114
|
+
('kind', (str,)),
|
|
115
|
+
('challenge', (str,)),
|
|
116
|
+
('state', (str,)),
|
|
117
|
+
('attempt', (int,)),
|
|
118
|
+
('attempts', (int,)),
|
|
119
|
+
('value', (int, float, type(None))),
|
|
120
|
+
('seconds', (int, float, type(None))),
|
|
121
|
+
('medal', (str, type(None))),
|
|
122
|
+
('practice', (bool,)),
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _group_of(value: Any) -> dict[str, Any] | None:
|
|
127
|
+
"""Returns the group of a summary in its expected form, or `None` for one that does not fit.
|
|
128
|
+
|
|
129
|
+
A group gathers the recordings of one run of a challenge. It holds its identifier, its title,
|
|
130
|
+
competitor and result as labels or text, the attempt of the recording and the run's details,
|
|
131
|
+
and a field of the wrong type, from a hand edit or another version, is left out.
|
|
132
|
+
"""
|
|
133
|
+
if not isinstance(value, dict) or not isinstance(value.get('id'), str):
|
|
134
|
+
return None
|
|
135
|
+
if not _home.valid_identifier(value['id']):
|
|
136
|
+
return None
|
|
137
|
+
group: dict[str, Any] = {'id': value['id']}
|
|
138
|
+
labels = {}
|
|
139
|
+
for field, default in (('title', value['id']), ('competitor', ''), ('result', '')):
|
|
140
|
+
found = _recording.label_of(value, field)
|
|
141
|
+
labels[field] = found if isinstance(found, (str, dict)) else default
|
|
142
|
+
# A person's run under a default name, of any language, shows the default of the page's own.
|
|
143
|
+
competitor = labels['competitor']
|
|
144
|
+
if isinstance(competitor, str) and competitor in _languages.default_names():
|
|
145
|
+
person = _messages.label('server.names.default_person')
|
|
146
|
+
labels['competitor'] = person
|
|
147
|
+
title = labels['title']
|
|
148
|
+
if isinstance(title, dict) and title.get('id') == 'server.names.challenge_run':
|
|
149
|
+
values = {**(title.get('values') or {}), 'competitor': person}
|
|
150
|
+
labels['title'] = _messages.label('server.names.challenge_run', **values)
|
|
151
|
+
for field, found in labels.items():
|
|
152
|
+
group.update(_messages.named(field, found))
|
|
153
|
+
for field, kinds in _GROUP_FIELDS:
|
|
154
|
+
found = value.get(field)
|
|
155
|
+
whole = isinstance(found, bool) == (kinds == (bool,))
|
|
156
|
+
if field in value and isinstance(found, kinds) and whole:
|
|
157
|
+
group[field] = found
|
|
158
|
+
return group
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def _labelled(entry: dict[str, Any]) -> dict[str, Any]:
|
|
162
|
+
"""Returns a summary whose names that cuju made carry their messages, the rest as text.
|
|
163
|
+
|
|
164
|
+
A title keeps `title_id` and `title_values` while they are valid, and a shipped sample whose
|
|
165
|
+
title is still the one it ships with takes its message. `team_labels` holds the label of each
|
|
166
|
+
team that has one and `None` beside a name that a person gave.
|
|
167
|
+
"""
|
|
168
|
+
title = _recording.label_of(entry, 'title')
|
|
169
|
+
message = _SAMPLE_TITLES.get(str(entry.get('id')))
|
|
170
|
+
if not isinstance(title, dict) and message and entry.get('title') == _messages.text(message):
|
|
171
|
+
title = _messages.label(message)
|
|
172
|
+
entry = {key: value for key, value in entry.items() if key not in ('title_id', 'title_values')}
|
|
173
|
+
entry.update(_messages.named('title', title))
|
|
174
|
+
labels = entry.get('team_labels')
|
|
175
|
+
if not (
|
|
176
|
+
isinstance(labels, list)
|
|
177
|
+
and len(labels) == len(entry.get('teams') or ())
|
|
178
|
+
and all(label is None or _messages.valid_label(label) for label in labels)
|
|
179
|
+
):
|
|
180
|
+
entry.pop('team_labels', None)
|
|
181
|
+
return entry
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def _teams_of(document: dict[str, Any]) -> list[dict[str, Any]]:
|
|
185
|
+
"""Returns the teams of a header that `_recording.validate_header` checked, two by default."""
|
|
186
|
+
return document.get('teams') or [{}, {}]
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def _team_labels(document: dict[str, Any]) -> list[dict[str, Any] | None]:
|
|
190
|
+
"""Returns the label of each team of a header, `None` for a name that a person gave."""
|
|
191
|
+
labels = []
|
|
192
|
+
for team in _teams_of(document):
|
|
193
|
+
found = _recording.label_of(team, 'name')
|
|
194
|
+
labels.append(found if isinstance(found, dict) else None)
|
|
195
|
+
return labels
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def _settled(path: Path) -> bool:
|
|
199
|
+
"""Returns whether a recording and its summary, if any, stood unchanged for a minute."""
|
|
200
|
+
times = []
|
|
201
|
+
for item in (path, path.with_suffix('.json')):
|
|
202
|
+
with contextlib.suppress(FileNotFoundError):
|
|
203
|
+
times.append(item.stat().st_mtime)
|
|
204
|
+
return bool(times) and time.time() - max(times) > _SETTLED_SECONDS
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def _store(path: Path, summary: dict[str, Any]) -> None:
|
|
208
|
+
"""Writes the summary of the recording at `path` through a temporary file."""
|
|
209
|
+
target = path.with_suffix('.json')
|
|
210
|
+
temporary = target.with_name(target.name + '.part')
|
|
211
|
+
temporary.write_text(json.dumps(summary), encoding='utf-8')
|
|
212
|
+
temporary.replace(target)
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def save(
|
|
216
|
+
head: bytes,
|
|
217
|
+
frames: list[bytes],
|
|
218
|
+
identifier: str | None = None,
|
|
219
|
+
version: int = _recording.VERSION,
|
|
220
|
+
annotations: list[dict[str, Any]] | None = None,
|
|
221
|
+
) -> Path:
|
|
222
|
+
"""Writes a recording and its summary into the library and returns the recording's path.
|
|
223
|
+
|
|
224
|
+
Args:
|
|
225
|
+
head: The magic, length and header, as `_recording.header` returns them.
|
|
226
|
+
frames: The frames.
|
|
227
|
+
identifier: The name of the files, by default a new one that no recording holds.
|
|
228
|
+
version: The version of the recording file.
|
|
229
|
+
annotations: The records of the annotations, which version 2 keeps.
|
|
230
|
+
"""
|
|
231
|
+
if identifier is None:
|
|
232
|
+
path = reserve()
|
|
233
|
+
else:
|
|
234
|
+
path = _home.folder('matches') / f'{identifier}.cjr'
|
|
235
|
+
try:
|
|
236
|
+
_recording.write(path, head, frames, version, annotations)
|
|
237
|
+
document = json.loads(head[len(_recording.MAGIC) + 4 :])
|
|
238
|
+
_write_summary(path, document, frames[-1] if frames else None, len(frames))
|
|
239
|
+
except BaseException:
|
|
240
|
+
if identifier is None:
|
|
241
|
+
path.with_suffix('.json').unlink(missing_ok=True)
|
|
242
|
+
raise
|
|
243
|
+
return path
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
def reserve() -> Path:
|
|
247
|
+
"""Returns the path of a new recording under an identifier that no other recording holds.
|
|
248
|
+
|
|
249
|
+
Identifiers sort by the second they are made in, so recorders of several processes that save
|
|
250
|
+
in the same second differ by their random end alone. The summary's file is created at once,
|
|
251
|
+
which only one saver can do, and a draw that is taken is drawn again.
|
|
252
|
+
"""
|
|
253
|
+
folder = _home.folder('matches')
|
|
254
|
+
while True:
|
|
255
|
+
path = folder / f'{_home.new_identifier("m")}.cjr'
|
|
256
|
+
if path.exists():
|
|
257
|
+
continue
|
|
258
|
+
try:
|
|
259
|
+
with path.with_suffix('.json').open('x', encoding='utf-8'):
|
|
260
|
+
pass
|
|
261
|
+
except FileExistsError:
|
|
262
|
+
continue
|
|
263
|
+
return path
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def _write_summary(
|
|
267
|
+
path: Path, document: dict[str, Any], last: bytes | None, steps: int
|
|
268
|
+
) -> dict[str, Any]:
|
|
269
|
+
"""Writes the summary of the recording at `path` beside it and returns the summary.
|
|
270
|
+
|
|
271
|
+
The header is one that `_recording.validate_header` checked, and a field that it leaves out
|
|
272
|
+
takes its default, the identifier for the title and the empty text for the scenario.
|
|
273
|
+
"""
|
|
274
|
+
title = _recording.label_of(document, 'title')
|
|
275
|
+
summary = {
|
|
276
|
+
'id': path.stem,
|
|
277
|
+
**_messages.named('title', path.stem if title is None else title),
|
|
278
|
+
'scenario': document.get('scenario') or '',
|
|
279
|
+
'teams': [team.get('name') for team in _teams_of(document)],
|
|
280
|
+
'team_labels': _team_labels(document),
|
|
281
|
+
'score': list(_SCORE.unpack_from(last, 8)) if last else [0, 0],
|
|
282
|
+
'steps': steps,
|
|
283
|
+
'created': time.strftime('%Y-%m-%dT%H:%M:%S'),
|
|
284
|
+
'bytes': path.stat().st_size,
|
|
285
|
+
'folder': '',
|
|
286
|
+
# A recording made before provenance, such as a shipped sample, has none to carry.
|
|
287
|
+
'provenance': document.get('provenance')
|
|
288
|
+
if isinstance(document.get('provenance'), dict)
|
|
289
|
+
else {},
|
|
290
|
+
}
|
|
291
|
+
_store(path, summary)
|
|
292
|
+
return _labelled(summary)
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
def samples() -> list[str]:
|
|
296
|
+
"""Returns the names of the sample matches that ship with the package, such as `sample-5v5`."""
|
|
297
|
+
# Five a side lists before eleven a side, as the page offers them.
|
|
298
|
+
names = (path.stem for path in _SAMPLES.glob('*.cjr'))
|
|
299
|
+
return sorted(names, key=lambda name: (len(name), name))
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
def _seeded() -> set[str]:
|
|
303
|
+
"""Returns the names of the samples that the library has received."""
|
|
304
|
+
try:
|
|
305
|
+
return set(json.loads((_home.home() / _SEEDED).read_text(encoding='utf-8'))['seeded'])
|
|
306
|
+
except (OSError, ValueError, KeyError, TypeError):
|
|
307
|
+
return set()
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
def _add_sample(name: str) -> Path | None:
|
|
311
|
+
"""Copies a sample into the library and returns its path, or `None` when the name is taken.
|
|
312
|
+
|
|
313
|
+
The library keeps the sample as it keeps any recording, and a recording or summary of the same
|
|
314
|
+
name stays as it is.
|
|
315
|
+
"""
|
|
316
|
+
path = _home.folder('matches') / f'{name}.cjr'
|
|
317
|
+
if path.exists() or path.with_suffix('.json').exists():
|
|
318
|
+
return None
|
|
319
|
+
temporary = path.with_name(path.name + '.part')
|
|
320
|
+
shutil.copyfile(_SAMPLES / f'{name}.cjr', temporary)
|
|
321
|
+
temporary.replace(path)
|
|
322
|
+
document = _recording.read_header(path)
|
|
323
|
+
# A file of version 2 decodes its last frame from the keyframe before it.
|
|
324
|
+
last = None
|
|
325
|
+
for frame in _recording.frames(path, start=max(0, document['frame_count'] - 1)):
|
|
326
|
+
last = frame
|
|
327
|
+
summary = _write_summary(path, document, last, document['frame_count'])
|
|
328
|
+
# A sample dates from its shipped file, so the user's own recordings list above it.
|
|
329
|
+
shipped = (_SAMPLES / f'{name}.cjr').stat().st_mtime
|
|
330
|
+
summary['created'] = time.strftime('%Y-%m-%dT%H:%M:%S', time.localtime(shipped))
|
|
331
|
+
_store(path, summary)
|
|
332
|
+
return path
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
def add_samples(names: list[str] | None = None, again: bool = True) -> list[Path]:
|
|
336
|
+
"""Copies sample matches into the library and returns the paths of those added.
|
|
337
|
+
|
|
338
|
+
Each sample is marked as received in the home folder, so a deleted sample stays deleted until
|
|
339
|
+
it is requested again. A request brings a sample in the Trash back with its details, as
|
|
340
|
+
Restore does, and counts it among those added.
|
|
341
|
+
|
|
342
|
+
Args:
|
|
343
|
+
names: The samples, by default every one.
|
|
344
|
+
again: Whether to add samples that the library has received before, as a request does,
|
|
345
|
+
or only new ones, as the first start of the server does, which leaves the Trash as it
|
|
346
|
+
is.
|
|
347
|
+
|
|
348
|
+
Raises:
|
|
349
|
+
ArgumentError: If a name is not a shipped sample.
|
|
350
|
+
"""
|
|
351
|
+
shipped = samples()
|
|
352
|
+
names = shipped if names is None else names
|
|
353
|
+
unknown = [name for name in names if name not in shipped]
|
|
354
|
+
if unknown:
|
|
355
|
+
raise MessageError('server.library.samples', shipped=shipped, unknown=unknown)
|
|
356
|
+
seeded = _seeded()
|
|
357
|
+
wanted = [name for name in names if again or name not in seeded]
|
|
358
|
+
if not wanted:
|
|
359
|
+
return []
|
|
360
|
+
added = [path for path in map(_add_sample, wanted) if path is not None]
|
|
361
|
+
if again:
|
|
362
|
+
added += [path_of(name) for name in wanted if trash(name, restore=True)]
|
|
363
|
+
marker = _home.home() / _SEEDED
|
|
364
|
+
temporary = marker.with_name(marker.name + '.part')
|
|
365
|
+
temporary.write_text(json.dumps({'seeded': sorted(seeded | set(wanted))}), encoding='utf-8')
|
|
366
|
+
temporary.replace(marker)
|
|
367
|
+
return added
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
@_locked
|
|
371
|
+
def matches(trash: bool = False, group: str | None = None) -> list[dict[str, Any]]:
|
|
372
|
+
"""Returns the summary of every recording of the library, or of the Trash, newest first.
|
|
373
|
+
|
|
374
|
+
With `group`, it returns the recordings of that group alone, in the order of their attempts.
|
|
375
|
+
"""
|
|
376
|
+
entries = []
|
|
377
|
+
for path in _home.folder('matches').glob('*.cjr'):
|
|
378
|
+
entry = _summary(path)
|
|
379
|
+
if ('deleted_at' in entry) != trash:
|
|
380
|
+
continue
|
|
381
|
+
if group is None or (entry.get('group') or {}).get('id') == group:
|
|
382
|
+
entries.append(entry)
|
|
383
|
+
entries.sort(key=lambda entry: str(entry.get('created') or ''), reverse=True)
|
|
384
|
+
if group is not None:
|
|
385
|
+
entries.sort(key=lambda entry: entry['group'].get('attempt', 0))
|
|
386
|
+
return entries
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
@_locked
|
|
390
|
+
def set_group(group: dict[str, Any], members: dict[str, int]) -> None:
|
|
391
|
+
"""Writes a group into the summary of each of its recordings, with the attempt of each.
|
|
392
|
+
|
|
393
|
+
Args:
|
|
394
|
+
group: The group, its identifier and the fields that `_group_of` keeps.
|
|
395
|
+
members: The attempt of each recording of the group, by recording identifier.
|
|
396
|
+
"""
|
|
397
|
+
for identifier, attempt in members.items():
|
|
398
|
+
path = path_of(identifier, include_trash=True)
|
|
399
|
+
if path is None:
|
|
400
|
+
continue
|
|
401
|
+
summary = _summary(path)
|
|
402
|
+
summary['group'] = {**group, 'attempt': attempt}
|
|
403
|
+
_store(path, summary)
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
@_locked
|
|
407
|
+
def trash_group(group: str, restore: bool = False) -> list[str]:
|
|
408
|
+
"""Moves every recording of a group to the Trash at once, or restores them all.
|
|
409
|
+
|
|
410
|
+
Returns:
|
|
411
|
+
The identifiers of the recordings moved, empty for a group without any to move.
|
|
412
|
+
"""
|
|
413
|
+
if not isinstance(group, str):
|
|
414
|
+
return []
|
|
415
|
+
return [entry['id'] for entry in matches(restore, group) if trash(entry['id'], restore)]
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
def _summarize(path: Path) -> dict[str, Any]:
|
|
419
|
+
"""Returns the summary of a recording that has none, such as one copied into the folder."""
|
|
420
|
+
provenance: Any = {}
|
|
421
|
+
labels: list[dict[str, Any] | None] = [None, None]
|
|
422
|
+
try:
|
|
423
|
+
# The header comes checked, so each field holds its type or is left out.
|
|
424
|
+
document = _recording.read_header(path)
|
|
425
|
+
teams = [team.get('name') for team in _teams_of(document)]
|
|
426
|
+
title = _recording.label_of(document, 'title') or path.stem
|
|
427
|
+
scenario = document.get('scenario') or ''
|
|
428
|
+
labels = _team_labels(document)
|
|
429
|
+
provenance = document.get('provenance') or {}
|
|
430
|
+
except Exception:
|
|
431
|
+
teams, title, scenario = ['', ''], path.stem, ''
|
|
432
|
+
created = time.strftime('%Y-%m-%dT%H:%M:%S', time.localtime(path.stat().st_mtime))
|
|
433
|
+
return {
|
|
434
|
+
'id': path.stem,
|
|
435
|
+
**_messages.named('title', title),
|
|
436
|
+
'scenario': scenario,
|
|
437
|
+
'teams': teams,
|
|
438
|
+
'team_labels': labels,
|
|
439
|
+
'score': None,
|
|
440
|
+
'steps': None,
|
|
441
|
+
'created': created,
|
|
442
|
+
'bytes': path.stat().st_size,
|
|
443
|
+
'provenance': provenance if isinstance(provenance, dict) else {},
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
def _folder_path(folder: Any) -> str:
|
|
448
|
+
"""Returns a folder of the explorer in canonical form, or raises `ArgumentError`."""
|
|
449
|
+
if not isinstance(folder, str):
|
|
450
|
+
raise MessageError('server.library.folder_text', folder=repr(folder))
|
|
451
|
+
parts = [part.strip() for part in folder.replace('\\', '/').split('/') if part.strip()]
|
|
452
|
+
if any(part in ('.', '..') or len(part) > 64 for part in parts) or len(parts) > 8:
|
|
453
|
+
raise MessageError('server.library.folder_size', folder=repr(folder))
|
|
454
|
+
return '/'.join(parts)
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
@_locked
|
|
458
|
+
def update(
|
|
459
|
+
identifier: str,
|
|
460
|
+
title: str | None = None,
|
|
461
|
+
folder: str | None = None,
|
|
462
|
+
favorite: bool | None = None,
|
|
463
|
+
tags: list[str] | None = None,
|
|
464
|
+
notes: str | None = None,
|
|
465
|
+
) -> dict[str, Any]:
|
|
466
|
+
"""Renames a recording, moves it to a folder or edits its details, and returns its summary.
|
|
467
|
+
|
|
468
|
+
Every change is checked before any is kept, so a refused change leaves the summary as it was.
|
|
469
|
+
|
|
470
|
+
Args:
|
|
471
|
+
identifier: The recording.
|
|
472
|
+
title: The new title, or `None` to keep it.
|
|
473
|
+
folder: The folder, such as `League/Week 1`, the empty text for the top, or `None`.
|
|
474
|
+
favorite: Whether the recording is a favorite, or `None` to keep the mark.
|
|
475
|
+
tags: Up to twenty tags of at most forty characters, or `None` to keep them. Repeated
|
|
476
|
+
tags are kept once.
|
|
477
|
+
notes: Notes of at most ten thousand characters, or `None` to keep them.
|
|
478
|
+
|
|
479
|
+
Raises:
|
|
480
|
+
ArgumentError: If the recording is unknown or in the Trash, or a change is invalid.
|
|
481
|
+
"""
|
|
482
|
+
path = path_of(identifier)
|
|
483
|
+
if path is None:
|
|
484
|
+
raise MessageError('server.library.unknown', identifier=repr(identifier))
|
|
485
|
+
summary = _summary(path)
|
|
486
|
+
if favorite is not None:
|
|
487
|
+
if not isinstance(favorite, bool):
|
|
488
|
+
raise MessageError('server.library.favorite', favorite=repr(favorite))
|
|
489
|
+
summary['favorite'] = favorite
|
|
490
|
+
if tags is not None:
|
|
491
|
+
if (
|
|
492
|
+
not isinstance(tags, list)
|
|
493
|
+
or len(tags) > _TAGS
|
|
494
|
+
or not all(isinstance(tag, str) and 0 < len(tag.strip()) <= _TAG_LENGTH for tag in tags)
|
|
495
|
+
):
|
|
496
|
+
raise MessageError('server.library.tags')
|
|
497
|
+
summary['tags'] = list(dict.fromkeys(tag.strip() for tag in tags))
|
|
498
|
+
if notes is not None:
|
|
499
|
+
if not isinstance(notes, str) or len(notes) > _NOTES_LENGTH:
|
|
500
|
+
raise MessageError('server.library.notes')
|
|
501
|
+
summary['notes'] = notes
|
|
502
|
+
if title is not None:
|
|
503
|
+
title = str(title).strip()[:120]
|
|
504
|
+
if not title:
|
|
505
|
+
raise MessageError('server.library.title')
|
|
506
|
+
# A title that a person gives is text, which the page shows as given.
|
|
507
|
+
summary.pop('title_id', None)
|
|
508
|
+
summary.pop('title_values', None)
|
|
509
|
+
summary['title'] = title
|
|
510
|
+
if folder is not None:
|
|
511
|
+
summary['folder'] = _folder_path(folder)
|
|
512
|
+
_store(path, summary)
|
|
513
|
+
return summary
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
@_locked
|
|
517
|
+
def path_of(identifier: str, include_trash: bool = False) -> Path | None:
|
|
518
|
+
"""Returns the path of a recording, or `None` for an unknown or unsafe identifier.
|
|
519
|
+
|
|
520
|
+
The identifier must be a plain file name, so no request reaches outside the library's folder.
|
|
521
|
+
A recording in the Trash counts as unknown unless `include_trash` is true.
|
|
522
|
+
"""
|
|
523
|
+
if not isinstance(identifier, str) or not _home.valid_identifier(identifier):
|
|
524
|
+
return None
|
|
525
|
+
path = _home.folder('matches') / f'{identifier}.cjr'
|
|
526
|
+
if not path.is_file() or (not include_trash and 'deleted_at' in _summary(path)):
|
|
527
|
+
return None
|
|
528
|
+
return path
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
@_locked
|
|
532
|
+
def details(identifier: str) -> dict[str, Any]:
|
|
533
|
+
"""Returns the summary of a recording of the library, with its details and provenance.
|
|
534
|
+
|
|
535
|
+
Raises:
|
|
536
|
+
ArgumentError: If the recording is unknown or in the Trash.
|
|
537
|
+
"""
|
|
538
|
+
path = path_of(identifier)
|
|
539
|
+
if path is None:
|
|
540
|
+
raise MessageError('server.library.unknown', identifier=repr(identifier))
|
|
541
|
+
return _summary(path)
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
@_locked
|
|
545
|
+
def trash(identifier: str, restore: bool = False) -> bool:
|
|
546
|
+
"""Moves a recording to the Trash, or restores it, and returns whether it existed.
|
|
547
|
+
|
|
548
|
+
Only the summary changes, so a restored recording keeps its frames, folder and details.
|
|
549
|
+
"""
|
|
550
|
+
path = path_of(identifier, include_trash=True)
|
|
551
|
+
if path is None:
|
|
552
|
+
return False
|
|
553
|
+
summary = _summary(path)
|
|
554
|
+
if restore:
|
|
555
|
+
if 'deleted_at' not in summary:
|
|
556
|
+
return False
|
|
557
|
+
del summary['deleted_at']
|
|
558
|
+
else:
|
|
559
|
+
if 'deleted_at' in summary:
|
|
560
|
+
return False
|
|
561
|
+
summary['deleted_at'] = time.strftime('%Y-%m-%dT%H:%M:%S')
|
|
562
|
+
_store(path, summary)
|
|
563
|
+
return True
|
|
564
|
+
|
|
565
|
+
|
|
566
|
+
@_locked
|
|
567
|
+
def purge(identifier: str) -> bool:
|
|
568
|
+
"""Deletes a recording of the Trash for good, and returns whether there was one to delete.
|
|
569
|
+
|
|
570
|
+
A recording outside the Trash stays, so a permanent deletion always passes through the Trash.
|
|
571
|
+
"""
|
|
572
|
+
path = path_of(identifier, include_trash=True)
|
|
573
|
+
if path is None or 'deleted_at' not in _summary(path):
|
|
574
|
+
return False
|
|
575
|
+
_unlink(path)
|
|
576
|
+
path.with_suffix('.json').unlink(missing_ok=True)
|
|
577
|
+
return True
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
def _unlink(path: Path) -> None:
|
|
581
|
+
"""Deletes a file, trying again for a moment while Windows says another program holds it.
|
|
582
|
+
|
|
583
|
+
A virus scanner or a search indexer may hold a file it has only just been written, for a
|
|
584
|
+
fraction of a second, and a deletion then fails with a sharing violation that passes.
|
|
585
|
+
"""
|
|
586
|
+
for attempt in range(20):
|
|
587
|
+
try:
|
|
588
|
+
path.unlink()
|
|
589
|
+
return
|
|
590
|
+
except PermissionError:
|
|
591
|
+
if os.name != 'nt' or attempt == 19:
|
|
592
|
+
raise
|
|
593
|
+
time.sleep(0.1)
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
@_locked
|
|
597
|
+
def remove(identifier: str) -> bool:
|
|
598
|
+
"""Deletes a recording and its summary at once, in the Trash or not, and says if it existed."""
|
|
599
|
+
path = path_of(identifier, include_trash=True)
|
|
600
|
+
if path is None:
|
|
601
|
+
return False
|
|
602
|
+
_unlink(path)
|
|
603
|
+
path.with_suffix('.json').unlink(missing_ok=True)
|
|
604
|
+
return True
|