Conditions | 3 |
Total Lines | 31 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import os |
||
18 | def handle(self, *args, **options): |
||
19 | # get the file list from the filesystem |
||
20 | data_source_dir = os.path.join( |
||
21 | settings.PROTECTED_MEDIA_ROOT, |
||
22 | Submission.upload_dir) |
||
23 | |||
24 | data_source_files = os.listdir(data_source_dir) |
||
25 | |||
26 | # prepend DataSource.upload_dir to file list |
||
27 | data_source_files = [ |
||
28 | os.path.join( |
||
29 | Submission.upload_dir, |
||
30 | uploaded_file) |
||
31 | for uploaded_file in data_source_files] |
||
32 | |||
33 | # get the file list from the db |
||
34 | queryset = Submission.objects.all() |
||
35 | database_files = [ |
||
36 | str(datasource.uploaded_file) for datasource in queryset] |
||
37 | |||
38 | for datasource_file in data_source_files: |
||
39 | if datasource_file not in database_files: |
||
40 | to_remove = os.path.join( |
||
41 | settings.PROTECTED_MEDIA_ROOT, |
||
42 | datasource_file) |
||
43 | |||
44 | # debug |
||
45 | print("Removing %s" % (to_remove)) |
||
46 | os.remove(to_remove) |
||
47 | |||
48 | call_command('mycheck') |
||
49 |