1- import os
2- import os . path
1+ from concurrent . futures import ProcessPoolExecutor
2+ from pathlib import Path
33
44from django .core .management .base import BaseCommand
55
66from oioioi .filetracker .client import get_client
77
88
9+ def upload_sandbox (file ):
10+ filetracker = get_client ()
11+ filetracker .put_file ("/sandboxes/" + file .name , str (file ))
12+
13+
914class Command (BaseCommand ):
1015 def add_arguments (self , parser ):
1116 parser .add_argument (
@@ -19,17 +24,12 @@ def add_arguments(self, parser):
1924
2025 help = "Upload sandboxes to the Filetracker."
2126
22- def handle (self , * args , ** options ):
23- filetracker = get_client ()
2427
28+ def handle (self , * args , ** options ):
2529 print ("--- Saving sandboxes to the Filetracker ..." , file = self .stdout )
2630
27- sandboxes_dir = os .fsencode (options ["sandboxes_dir" ])
28- for file in os .listdir (sandboxes_dir ):
29- filename = os .fsdecode (file )
30- if not filename .endswith (".tar.gz" ):
31- continue
32-
33- filetracker .put_file ("/sandboxes/" + filename , os .path .join (options ["sandboxes_dir" ], filename ))
31+ sandboxes_dir = Path (options ["sandboxes_dir" ])
32+ with ProcessPoolExecutor () as executor :
33+ executor .map (upload_sandbox , sandboxes_dir .glob ('*.tar.gz' ))
3434
3535 print ("--- Done." , file = self .stdout )
0 commit comments