Zine

open source content publishing system


source: scripts/regenerate-post-uids @ 1279:088d2f519391

Revision 1279:088d2f519391, 1.7 KB checked in by Georg Brandl <georg@…>, 2 years ago (diff)

Update copyright notices.

  • Property exe set to *
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3"""
4    Regenerate Post.uids.
5    ---------------------
6
7    Regenerates the uids for all postings.
8
9    Use Case:
10      When an ATOM feed is generated, each entry is given
11      a tag URI. The URI for each post entry is taken from
12      Post.uid.
13      The format of Post.uid did not always fit the tag URI
14      spec at http://www.faqs.org/rfcs/rfc4151.html.
15      The problem was fixed in changeset 5937aca4e919.
16      Old postings still contain the old uids though, so
17      they need to be regenerated.
18
19    :copyright: (c) 2010 by the Zine Team, see AUTHORS for more details.
20    :license: BSD, see LICENSE for more details.
21"""
22
23from optparse import OptionParser
24
25from _init_zine import find_instance
26
27
28def regenerate_post_uids(instance):
29    from zine import setup
30    app = setup(instance)
31    del setup
32    from zine.models import Post
33    from zine.database import db
34    from zine.utils.text import build_tag_uri
35
36    for post in Post.query.all():
37        post.uid = build_tag_uri(app, post.pub_date, post.content_type,
38                                 post.slug)
39    db.commit()
40    print "Done regenerating post uids."
41
42
43def main():
44    parser = OptionParser(usage='%prog -I /path/to/instance')
45    parser.add_option('--instance', '-I', dest='instance',
46                      help='Use the given Zine instance.')
47    options, args = parser.parse_args()
48    if args:
49        parser.error('incorrect number of arguments')
50    instance = options.instance or find_instance()
51    if instance is None:
52        parser.error('instance not found. Specify path to instance')
53
54    regenerate_post_uids(instance)
55
56
57if __name__ == '__main__':
58    main()
Note: See TracBrowser for help on using the repository browser.