@@ -0,0 +1,1594 @@
+%22%22%22.. Ignore pydocstyle D400.%0A%0A====================%0AClean test directory%0A====================%0A%0ACommand to run on local machine::%0A%0A    ./manage.py clean_test_dir%0A%0A%22%22%22%0Aimport os%0Aimport re%0Aimport shutil%0A%0Afrom django.core.management.base import BaseCommand%0A%0Afrom resolwe.flow.managers.protocol import ExecutorFiles%0Afrom resolwe.test.testcases.setting_overrides import FLOW_EXECUTOR_SETTINGS%0A%0ATEST_DIR_REGEX = r'%5Etest_%5Cd+$'%0A%0A%0Aclass Command(BaseCommand):%0A    %22%22%22Cleanup files created during testing.%22%22%22%0A%0A    help = %22Cleanup files created during testing.%22%0A%0A    def handle(self, *args, **kwargs):%0A        %22%22%22Cleanup files created during testing.%22%22%22%0A        for name in %5B'DATA_DIR', 'UPLOAD_DIR', 'RUNTIME_DIR'%5D:%0A            directory = os.path.abspath(FLOW_EXECUTOR_SETTINGS%5Bname%5D)%0A%0A            for basename in os.listdir(directory):%0A%0A                fname = os.path.abspath(os.path.join(directory, basename))%0A%0A                if not os.path.isdir(fname):%0A                    continue%0A                if not re.match(TEST_DIR_REGEX, basename):%0A                    continue%0A%0A                def handle_error(func, path, exc_info):%0A                    %22%22%22Handle permission errors while removing secrets directory.%22%22%22%0A                    if isinstance(exc_info%5B1%5D, PermissionError):%0A                        # Verify that such woraround can only be applied to secrets dir.%0A                        assert os.path.basename(path) == ExecutorFiles.SECRETS_DIR%0A                        os.chmod(path, 0o700)%0A                        shutil.rmtree(path)%0A%0A                shutil.rmtree(fname, onerror=handle_error)%0A

Add clean_test_dir management command