~jcsackett/charmworld/bac-tag-constraints

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Copyright 2012, 2013 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

# Escape dots, dollar signs, percent signs in mongo keys

from charmworld.utils import quote_yaml

def upgrade(db):
    """Iterate all charm data and replace all dictionary keys containing
    a '.', '$' or '%' with an escaped variant.
    """
    charm_ids = [charm['_id'] for charm in db.charms.find()]
    for charm_id in charm_ids:
        charm = db.charms.find_one(charm_id)
        quote_yaml(charm)
        db.charms.update({'_id': charm_id}, charm)