From: Marcin Koziej Date: Tue, 11 Dec 2012 12:01:44 +0000 (+0100) Subject: Fix something script X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/877f24b0b26f4f2473f8d6dfe2946a213bd286c0?ds=sidebyside Fix something script --- diff --git a/scripts/fix_something.py b/scripts/fix_something.py new file mode 100755 index 00000000..59781308 --- /dev/null +++ b/scripts/fix_something.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# +import sys +sys.path.append('.') +sys.path.append('./apps') +sys.path.append('./lib') + +from django.core.management import setup_environ +from redakcja import settings + +setup_environ(settings) + +from catalogue.models import Book, Chunk +import re + +fixed = {} + +tag_with_name = r"<([^>]+)name=\"([^>]+)>" + +def fix(book, author, dry_run=True): + if len(book) == 0: + print "%s does not contain chunks" % book.slug + return + fc = book[0] + txt = fc.materialize() + + newtxt, cnt = re.subn(tag_with_name, r'<\1nazwa="\2>', txt) + if cnt == 0: + print "%s nothing changed" % book + return + + if not dry_run: + print "%s changing" % book + fc.commit(newtxt, author=author, description=u"Automatyczna zmiana atrybutu name na nazwa") + + +import sys +import getopt +from django.contrib.auth.models import User +opts, oth_ = getopt.getopt(sys.argv[1:], + [], + [ "seriously"]) +dry_run = not (("--seriously",'') in opts) +me = User.objects.get(username='marcinkoziej') +if dry_run: + print "This is a dry run, to really change dates, run with --seriously" +for b in Book.objects.all(): + fix(b, me, dry_run) + + +