Created
August 24, 2015 01:42
-
-
Save lmacken/4ea39791146a0e027408 to your computer and use it in GitHub Desktop.
A script to fix the update submitters bug with the bodhi1 -> bodhi2 migration.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import __main__ | |
__requires__ = __main__.__requires__ = 'WebOb>=1.4.1' | |
import pkg_resources | |
# This program is free software; you can redistribute it and/or | |
# modify it under the terms of the GNU General Public License | |
# as published by the Free Software Foundation; either version 2 | |
# of the License, or (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, | |
# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
# GNU General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program; if not, write to the Free Software | |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
""" | |
A script to fix the update submitters bug with the bodhi1 -> bodhi2 migration. | |
https://github.com/fedora-infra/bodhi/issues/241 | |
""" | |
__requires__ = 'bodhi' | |
import sys | |
import cPickle as pickle | |
from pyramid.paster import setup_logging | |
setup_logging('/etc/bodhi/production.ini') | |
from bodhi.util import get_db_from_config | |
def fix_submitters(): | |
print "\nLoading pickled database %s" % sys.argv[1] | |
db = file(sys.argv[1], 'r') | |
data = pickle.load(db) | |
import transaction | |
from bodhi.models import Update, User | |
from sqlalchemy.orm.exc import NoResultFound | |
db = get_db_from_config() | |
transaction.begin() | |
total = 0 | |
num_busted = 0 | |
for u in data['updates']: | |
total += 1 | |
try: | |
update = db.query(Update).filter_by(title=u['title']).one() | |
if update.user.name != u['submitter']: | |
print('Invalid submitter %s submitted %s, not %s' % | |
(u['submitter'], u['title'], update.user.name)) | |
num_busted += 1 | |
user = User.get(u['submitter'], db) | |
if not user: | |
print('Creating new user: %s' % u['submitter']) | |
user = User(name=u['submitter']) | |
db.add(user) | |
db.flush() | |
update.user = user | |
except NoResultFound: | |
continue | |
print('total updates = %d' % total) | |
print('num busted = %d' % num_busted) | |
transaction.commit() | |
def main(): | |
fix_submitters() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome!