Commit 8878da32 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Add the script fix_harvesters_collections.py.

parent d1f24520
# -*- coding: utf-8 -*-
""" NAME
fix_harvesters_collections
SYNOPSIS
fix_harvesters_collections [options]
DESCRIPTION
Up to version 0.9.6.5, the field collections can contains a list
of collection separated by a comma. This rule is in conflict when
defining a collection using author name since author name can contain
also comma.
In version 0.9.6.6, it has been decided that the collection field
contains the definition for only one collection.
This script allow to migrate from 0.9.6.5 to 0.9.6.6 approach.
OPTIONS
EXAMPLE
> cd ...limbra/scripts
> run -S test_limbra script fix_harvesters_collections.py
> run loop fix_harvesters_collections.py
> ...
AUTHOR
R. Le Gac -- Oct 2017
"""
if __name__ == "__main__":
import sys
# scan the harvesters table
for row in db(db.harvesters).iterselect():
collections = row.collections
if row.host == "cds.cern.ch" and "," in collections:
print "\n\tsplit:", collections
data = row.as_dict()
del data["id"]
# insert new harvesters
for elt in collections.split(","):
print "\t\tinsert →", elt.strip()
data["collections"] = elt.strip()
db.harvesters.insert(**data)
# delete old harvesters
print "\t\tdelete →", row.id
del db.harvesters[row.id]
# commit change
rep = raw_input("Commit database changes [y/N]: ")
if rep == 'y':
db.commit()
# exit gently
sys.exit(0)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment