We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Traceback with migration pootle_fs.0002_convert_localfs
I hit this traceback when running the new migrations in my local DB, specifically `pootle_fs.0002_convert_localfs`:


```pytb
Running migrations:
  Applying pootle_fs.0002_convert_localfs...Traceback (most recent call last):
  File "manage.py", line 24, in <module>
    execute_from_command_line()
  File "/home/leo/.virtualenvs/ptl/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/home/leo/.virtualenvs/ptl/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/leo/.virtualenvs/ptl/local/lib/python2.7/site-packages/django/core/management/base.py", line 294, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/leo/.virtualenvs/ptl/local/lib/python2.7/site-packages/django/core/management/base.py", line 345, in execute
    output = self.handle(*args, **options)
  File "/home/leo/.virtualenvs/ptl/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 204, in handle
    fake_initial=fake_initial,
  File "/home/leo/.virtualenvs/ptl/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 115, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/home/leo/.virtualenvs/ptl/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 145, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/home/leo/.virtualenvs/ptl/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/home/leo/.virtualenvs/ptl/local/lib/python2.7/site-packages/django/db/migrations/migration.py", line 126, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/home/leo/.virtualenvs/ptl/local/lib/python2.7/site-packages/django/db/migrations/operations/special.py", line 189, in database_forwards
    self.code(from_state.apps, schema_editor)
  File "/home/leo/Escritorio/core_pootle/pootle/apps/pootle_fs/migrations/0002_convert_localfs.py", line 118, in convert_to_localfs
    filepath = store.file.path[len(proj_trans_path):]
  File "/home/leo/.virtualenvs/ptl/local/lib/python2.7/site-packages/django/db/models/fields/files.py", line 63, in _get_path
    self._require_file()
  File "/home/leo/.virtualenvs/ptl/local/lib/python2.7/site-packages/django/db/models/fields/files.py", line 46, in _require_file
    raise ValueError("The '%s' attribute has no file associated with it." % self.field.name)
ValueError: The 'file' attribute has no file associated with it.
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pootle/apps/pootle_store/migrations/0033_remove_store_file.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 # Generated by Django 1.10.7 on 2017-08-26 14:01
3 from __future__ import unicode_literals
4 
5 from django.db import migrations
6 
7 
8 class Migration(migrations.Migration):
9 
10     dependencies = [
11         ('pootle_store', '0032_fix_empty_wordcounts'),
12     ]
13 
14     operations = [
15         migrations.RemoveField(
16             model_name='store',
17             name='file',
18         ),
19     ]
20
```

Path: `pootle/apps/pootle_fs/migrations/0002_convert_localfs.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 # Generated by Django 1.10.7 on 2017-08-17 09:16
3 from __future__ import unicode_literals
4 
5 import logging
6 import os
7 from functools import partial
8 
9 import dirsync
10 
11 from django.conf import settings
12 from django.db import migrations
13 
14 from translate.lang.data import langcode_re
15 
16 
17 def _file_belongs_to_project(project, filename):
18     ext = os.path.splitext(filename)[1][1:]
19     filetype_extensions = list(
20         project.filetypes.values_list(
21             "extension__name", flat=True))
22     template_extensions = list(
23         project.filetypes.values_list(
24             "template_extension__name", flat=True))
25     return (
26         ext in filetype_extensions
27         or (ext in template_extensions))
28 
29 
30 def _detect_treestyle_and_path(project, proj_trans_path):
31     dirlisting = os.walk(proj_trans_path)
32     dirpath_, dirnames, filenames = dirlisting.next()
33 
34     if not dirnames:
35         # No subdirectories
36         if filter(partial(_file_belongs_to_project, project), filenames):
37             # Translation files found, assume gnu
38             return "gnu", ""
39 
40     # There are subdirectories
41     has_subdirs = filter(
42         (lambda dirname: dirname == 'templates'
43          or langcode_re.match(dirname)),
44         dirnames)
45     if has_subdirs:
46         return "nongnu", None
47 
48     # No language subdirs found, look for any translation file
49     # in subdirs
50     for dirpath_, dirnames, filenames in os.walk(proj_trans_path):
51         if filter(partial(_file_belongs_to_project, project), filenames):
52             return "gnu", dirpath_.replace(proj_trans_path, "")
53     # Unsure
54     return "nongnu", None
55 
56 
57 def _get_translation_mapping(project):
58     old_translation_path = settings.POOTLE_TRANSLATION_DIRECTORY
59     proj_trans_path = os.path.join(old_translation_path, project.code)
60     old_treestyle, old_path = (
61         _detect_treestyle_and_path(project, proj_trans_path)
62         if project.treestyle == "auto"
63         else (project.treestyle, None))
64     project.treestyle = "pootle_fs"
65     if old_treestyle == "nongnu":
66         return "/<language_code>/<dir_path>/<filename>.<ext>"
67     else:
68         return "%s/<language_code>.<ext>" % (old_path)
69 
70 
71 def _set_project_config(Config, project_ct, project):
72     old_translation_path = settings.POOTLE_TRANSLATION_DIRECTORY
73     proj_trans_path = os.path.join(old_translation_path, project.code)
74     configs = Config.objects.filter(
75         content_type=project_ct,
76         object_pk=project.pk)
77     configs.delete()
78     Config.objects.update_or_create(
79         content_type=project_ct,
80         object_pk=project.pk,
81         key="pootle_fs.fs_url",
82         defaults=dict(
83             value=proj_trans_path))
84     Config.objects.update_or_create(
85         content_type=project_ct,
86         object_pk=project.pk,
87         key="pootle_fs.fs_type",
88         defaults=dict(
89             value="localfs"))
90     Config.objects.update_or_create(
91         content_type=project_ct,
92         object_pk=project.pk,
93         key="pootle_fs.translation_mappings",
94         defaults=dict(
95             value=dict(default=_get_translation_mapping(project))))
96 
97 
98 def convert_to_localfs(apps, schema_editor):
99     Project = apps.get_model("pootle_project.Project")
100     Store = apps.get_model("pootle_store.Store")
101     StoreFS = apps.get_model("pootle_fs.StoreFS")
102     Config = apps.get_model("pootle_config.Config")
103     ContentType = apps.get_model("contenttypes.ContentType")
104     project_ct = ContentType.objects.get_for_model(Project)
105     old_translation_path = settings.POOTLE_TRANSLATION_DIRECTORY
106 
107     for project in Project.objects.exclude(treestyle="pootle_fs"):
108         proj_trans_path = os.path.join(old_translation_path, project.code)
109         proj_stores = Store.objects.filter(
110             translation_project__project=project)
111         _set_project_config(Config, project_ct, project)
112         project.treestyle = "pootle_fs"
113         project.save()
114         store_fs = StoreFS.objects.filter(
115             store__translation_project__project=project)
116         store_fs.delete()
117         for store in proj_stores:
118             filepath = store.file.path[len(proj_trans_path):]
119             StoreFS.objects.update_or_create(
120                 project=project,
121                 store=store,
122                 defaults=dict(
123                     path=filepath,
124                     pootle_path=store.pootle_path,
125                     last_sync_revision=store.last_sync_revision,
126                     last_sync_mtime=store.file_mtime))
127         fs_temp = os.path.join(
128             settings.POOTLE_FS_WORKING_PATH, project.code)
129         dirsync.sync(
130             proj_trans_path,
131             fs_temp,
132             "sync",
133             create=True,
134             purge=True,
135             logger=logging.getLogger(dirsync.__name__))
136 
137 
138 class Migration(migrations.Migration):
139 
140     dependencies = [
141         ('contenttypes', '0002_remove_content_type_name'),
142         ('pootle_fs', '0001_initial'),
143         ('pootle_format', '0003_remove_extra_indeces'),
144         ('pootle_config', '0001_initial'),
145         ('pootle_store', '0013_set_store_filetype_again'),
146         ('pootle_project', '0016_change_treestyle_choices_label'),
147     ]
148 
149     operations = [
150         migrations.RunPython(convert_to_localfs),
151     ]
152
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pootle/apps/pootle_fs/migrations/0002_convert_localfs.py b/pootle/apps/pootle_fs/migrations/0002_convert_localfs.py
--- a/pootle/apps/pootle_fs/migrations/0002_convert_localfs.py
+++ b/pootle/apps/pootle_fs/migrations/0002_convert_localfs.py
@@ -107,7 +107,7 @@
     for project in Project.objects.exclude(treestyle="pootle_fs"):
         proj_trans_path = os.path.join(old_translation_path, project.code)
         proj_stores = Store.objects.filter(
-            translation_project__project=project)
+            translation_project__project=project).exclude(file="")
         _set_project_config(Config, project_ct, project)
         project.treestyle = "pootle_fs"
         project.save()
diff --git a/pootle/apps/pootle_store/migrations/0033_remove_store_file.py b/pootle/apps/pootle_store/migrations/0033_remove_store_file.py
--- a/pootle/apps/pootle_store/migrations/0033_remove_store_file.py
+++ b/pootle/apps/pootle_store/migrations/0033_remove_store_file.py
@@ -8,6 +8,7 @@
 class Migration(migrations.Migration):
 
     dependencies = [
+        ('pootle_fs', '0002_convert_localfs'),
         ('pootle_store', '0032_fix_empty_wordcounts'),
     ]

{"golden_diff": "diff --git a/pootle/apps/pootle_fs/migrations/0002_convert_localfs.py b/pootle/apps/pootle_fs/migrations/0002_convert_localfs.py\n--- a/pootle/apps/pootle_fs/migrations/0002_convert_localfs.py\n+++ b/pootle/apps/pootle_fs/migrations/0002_convert_localfs.py\n@@ -107,7 +107,7 @@\n     for project in Project.objects.exclude(treestyle=\"pootle_fs\"):\n         proj_trans_path = os.path.join(old_translation_path, project.code)\n         proj_stores = Store.objects.filter(\n-            translation_project__project=project)\n+            translation_project__project=project).exclude(file=\"\")\n         _set_project_config(Config, project_ct, project)\n         project.treestyle = \"pootle_fs\"\n         project.save()\ndiff --git a/pootle/apps/pootle_store/migrations/0033_remove_store_file.py b/pootle/apps/pootle_store/migrations/0033_remove_store_file.py\n--- a/pootle/apps/pootle_store/migrations/0033_remove_store_file.py\n+++ b/pootle/apps/pootle_store/migrations/0033_remove_store_file.py\n@@ -8,6 +8,7 @@\n class Migration(migrations.Migration):\n \n     dependencies = [\n+        ('pootle_fs', '0002_convert_localfs'),\n         ('pootle_store', '0032_fix_empty_wordcounts'),\n     ]\n", "issue": "Traceback with migration pootle_fs.0002_convert_localfs\nI hit this traceback when running the new migrations in my local DB, specifically `pootle_fs.0002_convert_localfs`:\r\n\r\n\r\n```pytb\r\nRunning migrations:\r\n  Applying pootle_fs.0002_convert_localfs...Traceback (most recent call last):\r\n  File \"manage.py\", line 24, in <module>\r\n    execute_from_command_line()\r\n  File \"/home/leo/.virtualenvs/ptl/local/lib/python2.7/site-packages/django/core/management/__init__.py\", line 367, in execute_from_command_line\r\n    utility.execute()\r\n  File \"/home/leo/.virtualenvs/ptl/local/lib/python2.7/site-packages/django/core/management/__init__.py\", line 359, in execute\r\n    self.fetch_command(subcommand).run_from_argv(self.argv)\r\n  File \"/home/leo/.virtualenvs/ptl/local/lib/python2.7/site-packages/django/core/management/base.py\", line 294, in run_from_argv\r\n    self.execute(*args, **cmd_options)\r\n  File \"/home/leo/.virtualenvs/ptl/local/lib/python2.7/site-packages/django/core/management/base.py\", line 345, in execute\r\n    output = self.handle(*args, **options)\r\n  File \"/home/leo/.virtualenvs/ptl/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py\", line 204, in handle\r\n    fake_initial=fake_initial,\r\n  File \"/home/leo/.virtualenvs/ptl/local/lib/python2.7/site-packages/django/db/migrations/executor.py\", line 115, in migrate\r\n    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)\r\n  File \"/home/leo/.virtualenvs/ptl/local/lib/python2.7/site-packages/django/db/migrations/executor.py\", line 145, in _migrate_all_forwards\r\n    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)\r\n  File \"/home/leo/.virtualenvs/ptl/local/lib/python2.7/site-packages/django/db/migrations/executor.py\", line 244, in apply_migration\r\n    state = migration.apply(state, schema_editor)\r\n  File \"/home/leo/.virtualenvs/ptl/local/lib/python2.7/site-packages/django/db/migrations/migration.py\", line 126, in apply\r\n    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)\r\n  File \"/home/leo/.virtualenvs/ptl/local/lib/python2.7/site-packages/django/db/migrations/operations/special.py\", line 189, in database_forwards\r\n    self.code(from_state.apps, schema_editor)\r\n  File \"/home/leo/Escritorio/core_pootle/pootle/apps/pootle_fs/migrations/0002_convert_localfs.py\", line 118, in convert_to_localfs\r\n    filepath = store.file.path[len(proj_trans_path):]\r\n  File \"/home/leo/.virtualenvs/ptl/local/lib/python2.7/site-packages/django/db/models/fields/files.py\", line 63, in _get_path\r\n    self._require_file()\r\n  File \"/home/leo/.virtualenvs/ptl/local/lib/python2.7/site-packages/django/db/models/fields/files.py\", line 46, in _require_file\r\n    raise ValueError(\"The '%s' attribute has no file associated with it.\" % self.field.name)\r\nValueError: The 'file' attribute has no file associated with it.\r\n```\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n# Generated by Django 1.10.7 on 2017-08-26 14:01\nfrom __future__ import unicode_literals\n\nfrom django.db import migrations\n\n\nclass Migration(migrations.Migration):\n\n    dependencies = [\n        ('pootle_store', '0032_fix_empty_wordcounts'),\n    ]\n\n    operations = [\n        migrations.RemoveField(\n            model_name='store',\n            name='file',\n        ),\n    ]\n", "path": "pootle/apps/pootle_store/migrations/0033_remove_store_file.py"}, {"content": "# -*- coding: utf-8 -*-\n# Generated by Django 1.10.7 on 2017-08-17 09:16\nfrom __future__ import unicode_literals\n\nimport logging\nimport os\nfrom functools import partial\n\nimport dirsync\n\nfrom django.conf import settings\nfrom django.db import migrations\n\nfrom translate.lang.data import langcode_re\n\n\ndef _file_belongs_to_project(project, filename):\n    ext = os.path.splitext(filename)[1][1:]\n    filetype_extensions = list(\n        project.filetypes.values_list(\n            \"extension__name\", flat=True))\n    template_extensions = list(\n        project.filetypes.values_list(\n            \"template_extension__name\", flat=True))\n    return (\n        ext in filetype_extensions\n        or (ext in template_extensions))\n\n\ndef _detect_treestyle_and_path(project, proj_trans_path):\n    dirlisting = os.walk(proj_trans_path)\n    dirpath_, dirnames, filenames = dirlisting.next()\n\n    if not dirnames:\n        # No subdirectories\n        if filter(partial(_file_belongs_to_project, project), filenames):\n            # Translation files found, assume gnu\n            return \"gnu\", \"\"\n\n    # There are subdirectories\n    has_subdirs = filter(\n        (lambda dirname: dirname == 'templates'\n         or langcode_re.match(dirname)),\n        dirnames)\n    if has_subdirs:\n        return \"nongnu\", None\n\n    # No language subdirs found, look for any translation file\n    # in subdirs\n    for dirpath_, dirnames, filenames in os.walk(proj_trans_path):\n        if filter(partial(_file_belongs_to_project, project), filenames):\n            return \"gnu\", dirpath_.replace(proj_trans_path, \"\")\n    # Unsure\n    return \"nongnu\", None\n\n\ndef _get_translation_mapping(project):\n    old_translation_path = settings.POOTLE_TRANSLATION_DIRECTORY\n    proj_trans_path = os.path.join(old_translation_path, project.code)\n    old_treestyle, old_path = (\n        _detect_treestyle_and_path(project, proj_trans_path)\n        if project.treestyle == \"auto\"\n        else (project.treestyle, None))\n    project.treestyle = \"pootle_fs\"\n    if old_treestyle == \"nongnu\":\n        return \"/<language_code>/<dir_path>/<filename>.<ext>\"\n    else:\n        return \"%s/<language_code>.<ext>\" % (old_path)\n\n\ndef _set_project_config(Config, project_ct, project):\n    old_translation_path = settings.POOTLE_TRANSLATION_DIRECTORY\n    proj_trans_path = os.path.join(old_translation_path, project.code)\n    configs = Config.objects.filter(\n        content_type=project_ct,\n        object_pk=project.pk)\n    configs.delete()\n    Config.objects.update_or_create(\n        content_type=project_ct,\n        object_pk=project.pk,\n        key=\"pootle_fs.fs_url\",\n        defaults=dict(\n            value=proj_trans_path))\n    Config.objects.update_or_create(\n        content_type=project_ct,\n        object_pk=project.pk,\n        key=\"pootle_fs.fs_type\",\n        defaults=dict(\n            value=\"localfs\"))\n    Config.objects.update_or_create(\n        content_type=project_ct,\n        object_pk=project.pk,\n        key=\"pootle_fs.translation_mappings\",\n        defaults=dict(\n            value=dict(default=_get_translation_mapping(project))))\n\n\ndef convert_to_localfs(apps, schema_editor):\n    Project = apps.get_model(\"pootle_project.Project\")\n    Store = apps.get_model(\"pootle_store.Store\")\n    StoreFS = apps.get_model(\"pootle_fs.StoreFS\")\n    Config = apps.get_model(\"pootle_config.Config\")\n    ContentType = apps.get_model(\"contenttypes.ContentType\")\n    project_ct = ContentType.objects.get_for_model(Project)\n    old_translation_path = settings.POOTLE_TRANSLATION_DIRECTORY\n\n    for project in Project.objects.exclude(treestyle=\"pootle_fs\"):\n        proj_trans_path = os.path.join(old_translation_path, project.code)\n        proj_stores = Store.objects.filter(\n            translation_project__project=project)\n        _set_project_config(Config, project_ct, project)\n        project.treestyle = \"pootle_fs\"\n        project.save()\n        store_fs = StoreFS.objects.filter(\n            store__translation_project__project=project)\n        store_fs.delete()\n        for store in proj_stores:\n            filepath = store.file.path[len(proj_trans_path):]\n            StoreFS.objects.update_or_create(\n                project=project,\n                store=store,\n                defaults=dict(\n                    path=filepath,\n                    pootle_path=store.pootle_path,\n                    last_sync_revision=store.last_sync_revision,\n                    last_sync_mtime=store.file_mtime))\n        fs_temp = os.path.join(\n            settings.POOTLE_FS_WORKING_PATH, project.code)\n        dirsync.sync(\n            proj_trans_path,\n            fs_temp,\n            \"sync\",\n            create=True,\n            purge=True,\n            logger=logging.getLogger(dirsync.__name__))\n\n\nclass Migration(migrations.Migration):\n\n    dependencies = [\n        ('contenttypes', '0002_remove_content_type_name'),\n        ('pootle_fs', '0001_initial'),\n        ('pootle_format', '0003_remove_extra_indeces'),\n        ('pootle_config', '0001_initial'),\n        ('pootle_store', '0013_set_store_filetype_again'),\n        ('pootle_project', '0016_change_treestyle_choices_label'),\n    ]\n\n    operations = [\n        migrations.RunPython(convert_to_localfs),\n    ]\n", "path": "pootle/apps/pootle_fs/migrations/0002_convert_localfs.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n# Generated by Django 1.10.7 on 2017-08-26 14:01\nfrom __future__ import unicode_literals\n\nfrom django.db import migrations\n\n\nclass Migration(migrations.Migration):\n\n    dependencies = [\n        ('pootle_fs', '0002_convert_localfs'),\n        ('pootle_store', '0032_fix_empty_wordcounts'),\n    ]\n\n    operations = [\n        migrations.RemoveField(\n            model_name='store',\n            name='file',\n        ),\n    ]\n", "path": "pootle/apps/pootle_store/migrations/0033_remove_store_file.py"}, {"content": "# -*- coding: utf-8 -*-\n# Generated by Django 1.10.7 on 2017-08-17 09:16\nfrom __future__ import unicode_literals\n\nimport logging\nimport os\nfrom functools import partial\n\nimport dirsync\n\nfrom django.conf import settings\nfrom django.db import migrations\n\nfrom translate.lang.data import langcode_re\n\n\ndef _file_belongs_to_project(project, filename):\n    ext = os.path.splitext(filename)[1][1:]\n    filetype_extensions = list(\n        project.filetypes.values_list(\n            \"extension__name\", flat=True))\n    template_extensions = list(\n        project.filetypes.values_list(\n            \"template_extension__name\", flat=True))\n    return (\n        ext in filetype_extensions\n        or (ext in template_extensions))\n\n\ndef _detect_treestyle_and_path(project, proj_trans_path):\n    dirlisting = os.walk(proj_trans_path)\n    dirpath_, dirnames, filenames = dirlisting.next()\n\n    if not dirnames:\n        # No subdirectories\n        if filter(partial(_file_belongs_to_project, project), filenames):\n            # Translation files found, assume gnu\n            return \"gnu\", \"\"\n\n    # There are subdirectories\n    has_subdirs = filter(\n        (lambda dirname: dirname == 'templates'\n         or langcode_re.match(dirname)),\n        dirnames)\n    if has_subdirs:\n        return \"nongnu\", None\n\n    # No language subdirs found, look for any translation file\n    # in subdirs\n    for dirpath_, dirnames, filenames in os.walk(proj_trans_path):\n        if filter(partial(_file_belongs_to_project, project), filenames):\n            return \"gnu\", dirpath_.replace(proj_trans_path, \"\")\n    # Unsure\n    return \"nongnu\", None\n\n\ndef _get_translation_mapping(project):\n    old_translation_path = settings.POOTLE_TRANSLATION_DIRECTORY\n    proj_trans_path = os.path.join(old_translation_path, project.code)\n    old_treestyle, old_path = (\n        _detect_treestyle_and_path(project, proj_trans_path)\n        if project.treestyle == \"auto\"\n        else (project.treestyle, None))\n    project.treestyle = \"pootle_fs\"\n    if old_treestyle == \"nongnu\":\n        return \"/<language_code>/<dir_path>/<filename>.<ext>\"\n    else:\n        return \"%s/<language_code>.<ext>\" % (old_path)\n\n\ndef _set_project_config(Config, project_ct, project):\n    old_translation_path = settings.POOTLE_TRANSLATION_DIRECTORY\n    proj_trans_path = os.path.join(old_translation_path, project.code)\n    configs = Config.objects.filter(\n        content_type=project_ct,\n        object_pk=project.pk)\n    configs.delete()\n    Config.objects.update_or_create(\n        content_type=project_ct,\n        object_pk=project.pk,\n        key=\"pootle_fs.fs_url\",\n        defaults=dict(\n            value=proj_trans_path))\n    Config.objects.update_or_create(\n        content_type=project_ct,\n        object_pk=project.pk,\n        key=\"pootle_fs.fs_type\",\n        defaults=dict(\n            value=\"localfs\"))\n    Config.objects.update_or_create(\n        content_type=project_ct,\n        object_pk=project.pk,\n        key=\"pootle_fs.translation_mappings\",\n        defaults=dict(\n            value=dict(default=_get_translation_mapping(project))))\n\n\ndef convert_to_localfs(apps, schema_editor):\n    Project = apps.get_model(\"pootle_project.Project\")\n    Store = apps.get_model(\"pootle_store.Store\")\n    StoreFS = apps.get_model(\"pootle_fs.StoreFS\")\n    Config = apps.get_model(\"pootle_config.Config\")\n    ContentType = apps.get_model(\"contenttypes.ContentType\")\n    project_ct = ContentType.objects.get_for_model(Project)\n    old_translation_path = settings.POOTLE_TRANSLATION_DIRECTORY\n\n    for project in Project.objects.exclude(treestyle=\"pootle_fs\"):\n        proj_trans_path = os.path.join(old_translation_path, project.code)\n        proj_stores = Store.objects.filter(\n            translation_project__project=project).exclude(file=\"\")\n        _set_project_config(Config, project_ct, project)\n        project.treestyle = \"pootle_fs\"\n        project.save()\n        store_fs = StoreFS.objects.filter(\n            store__translation_project__project=project)\n        store_fs.delete()\n        for store in proj_stores:\n            filepath = store.file.path[len(proj_trans_path):]\n            StoreFS.objects.update_or_create(\n                project=project,\n                store=store,\n                defaults=dict(\n                    path=filepath,\n                    pootle_path=store.pootle_path,\n                    last_sync_revision=store.last_sync_revision,\n                    last_sync_mtime=store.file_mtime))\n        fs_temp = os.path.join(\n            settings.POOTLE_FS_WORKING_PATH, project.code)\n        dirsync.sync(\n            proj_trans_path,\n            fs_temp,\n            \"sync\",\n            create=True,\n            purge=True,\n            logger=logging.getLogger(dirsync.__name__))\n\n\nclass Migration(migrations.Migration):\n\n    dependencies = [\n        ('contenttypes', '0002_remove_content_type_name'),\n        ('pootle_fs', '0001_initial'),\n        ('pootle_format', '0003_remove_extra_indeces'),\n        ('pootle_config', '0001_initial'),\n        ('pootle_store', '0013_set_store_filetype_again'),\n        ('pootle_project', '0016_change_treestyle_choices_label'),\n    ]\n\n    operations = [\n        migrations.RunPython(convert_to_localfs),\n    ]\n", "path": "pootle/apps/pootle_fs/migrations/0002_convert_localfs.py"}]}