Completed
Push — master ( 389083...305338 )
by
unknown
01:39
created

update_symbols_urls()   A

Complexity

Conditions 4

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 4
c 2
b 0
f 0
dl 0
loc 16
rs 9.2
1
# -*- coding: utf-8 -*-
2
# Generated by Django 1.9.6 on 2017-03-04 06:19
3
from __future__ import unicode_literals
4
import os
5
6
from django.db import migrations
7
from django.conf import settings
8
9
10
def update_symbols_urls(apps, schema_editor):
11
    if settings.DEFAULT_FILE_STORAGE == 'omaha_server.s3utils.S3Storage':
12
        Symbols = apps.get_model("crash", "Symbols")
13
        symbols = Symbols.objects.filter(debug_file__contains=' ').iterator()
14
        for symbol in symbols:
15
            old_name = symbol.file.name
16
            if symbol.file.storage.exists(old_name):
17
                head, tail = os.path.split(old_name)
18
                new_name = os.path.join(head, '%s.sym' % symbol.debug_file)
19
                storage = symbol.file.storage
20
                file_obj = storage._open(old_name)
21
                symbol.file.save(new_name, file_obj)
22
                file_obj.close()
23
                storage.delete(old_name)
24
            else:
25
                print "File %s was not found" % old_name
26
27
28
class Migration(migrations.Migration):
29
30
    dependencies = [
31
        ('crash', '0026_auto_20170304_0601'),
32
    ]
33
34
    operations = [
35
        migrations.RunPython(
36
            update_symbols_urls,
37
            reverse_code=migrations.RunPython.noop
38
        ),
39
    ]