'Take a changes dict and write them out as migration files.'

def write_migration_files(self, changes):

    directory_created = {}
    for (app_label, app_migrations) in changes.items():
        if (self.verbosity >= 1):
            self.stdout.write((self.style.MIGRATE_HEADING(("Migrations    for    '%s':" % app_label)) + '\n'))
        for migration in app_migrations:
            writer = MigrationWriter(migration)
            if (self.verbosity >= 1):
                try:
                    migration_string = os.path.relpath(writer.path)
                except ValueError:
                    migration_string = writer.path
                if migration_string.startswith('..'):
                    migration_string = writer.path
                self.stdout.write(('        %s\n' % (self.style.MIGRATE_LABEL(migration_string),)))
                for operation in migration.operations:
                    self.stdout.write(('                -    %s\n' % operation.describe()))
            if (not self.dry_run):
                migrations_directory = os.path.dirname(writer.path)
                if (not directory_created.get(app_label)):
                    if (not os.path.isdir(migrations_directory)):
                        os.mkdir(migrations_directory)
                    init_path = os.path.join(migrations_directory, '__init__.py')
                    if (not os.path.isfile(init_path)):
                        open(init_path, 'w').close()
                    directory_created[app_label] = True
                migration_string = writer.as_string()
                with open(writer.path, 'w', encoding='utf-8') as fh:
                    fh.write(migration_string)
            elif (self.verbosity == 3):
                self.stdout.write((self.style.MIGRATE_HEADING(("Full    migrations    file    '%s':" % writer.filename)) + '\n'))
                self.stdout.write(('%s\n' % writer.as_string()))
