~sirn/fanboi2

7789db5cdfdad45cdee835212cfd2c1b07e3089a — Kridsada Thanabulpong 4 years ago 6713af3
Add utility for syncing topic bumped at.
5 files changed, 48 insertions(+), 12 deletions(-)

M README.rst
R fanboi2/scripts/{create_board.py => board_create.py}
R fanboi2/scripts/{update_board.py => board_update.py}
A fanboi2/scripts/topic_sync.py
M setup.py
M README.rst => README.rst +3 -3
@@ 66,12 66,12 @@ Management Scripts

After you've setup the environment, the first thing you want to do is to create a new board::

    $ fb2_create_board development.ini --title Lounge --slug lounge
    $ fb2_create_board development.ini --title Demo --slug demo
    $ fb2_board_create development.ini --title Lounge --slug lounge
    $ fb2_board_create development.ini --title Demo --slug demo

Above commands will create a board named "Lounge" and "Demo" at ``/lounge`` and ``/demo`` respectively. Now if you want to update something such as description, you can now do::

    $ fb2_update_board development.ini -s lounge -f description
    $ fb2_board_update development.ini -s lounge -f description

Slug is used here to identify which board to edit. All database fields in board are editable this way. Some field, such as ``settings`` must be a **valid JSON**. Both commands also accepts ``--help`` which will display some available options. Apart from the above two scripts, there are many other commands you might be interested in, such as:


R fanboi2/scripts/create_board.py => fanboi2/scripts/board_create.py +8 -4
@@ 11,13 11,17 @@ USAGE = "Usage: %prog config arguments"


def main(argv=sys.argv):
    config_uri = argv[1]
    argv = argv[2:]

    parser = optparse.OptionParser(usage=USAGE, description=DESCRIPTION)
    parser.add_option('-t', '--title', dest='title', type='string')
    parser.add_option('-s', '--slug', dest='slug', type='string')

    if not argv or len(argv) < 2:
        parser.print_help()
        sys.exit(1)

    config_uri = argv[1]
    argv = argv[2:]

    options, args = parser.parse_args(argv)
    if options.title is None:
        parser.error('You must provide at least --title')


@@ 35,4 39,4 @@ def main(argv=sys.argv):
        DBSession.add(board)
        DBSession.flush()
        print(("Successfully added %s (slug: %s)" %
               (board.title, board.slug)))
\ No newline at end of file
               (board.title, board.slug)))

R fanboi2/scripts/update_board.py => fanboi2/scripts/board_update.py +7 -3
@@ 17,13 17,17 @@ USAGE = "Usage: %prog config arguments"


def main(argv=sys.argv):
    config_uri = argv[1]
    argv = argv[2:]

    parser = optparse.OptionParser(usage=USAGE, description=DESCRIPTION)
    parser.add_option('-f', '--field', dest='field', type='string')
    parser.add_option('-s', '--slug', dest='slug', type='string')

    if not argv or len(argv) < 2:
        parser.print_help()
        sys.exit(1)

    config_uri = argv[1]
    argv = argv[2:]

    options, args = parser.parse_args(argv)
    if options.field is None:
        parser.error('You must provide --field')

A fanboi2/scripts/topic_sync.py => fanboi2/scripts/topic_sync.py +27 -0
@@ 0,0 1,27 @@
import os
import sys
import sqlalchemy as sa
from fanboi2.models import DBSession, TopicMeta, Post
from pyramid.paster import bootstrap


def main(argv=sys.argv):
    if not len(argv) >= 2:
        sys.stderr.write("Usage: %s config\n" % os.path.basename(argv[0]))
        sys.stderr.write("Configuration file not present.\n")
        sys.exit(1)

    bootstrap(argv[1])

    query = TopicMeta.__table__.update().\
            values(bumped_at=sa.select([Post.created_at]).\
                   where(Post.topic_id == TopicMeta.topic_id).\
                   where(Post.bumped).\
                   order_by(sa.desc(Post.created_at)).\
                   limit(1)).\
                returning(TopicMeta.topic_id,
                          TopicMeta.bumped_at)
    res = DBSession.execute(query)

    for topic_id, bumped_at in res:
        print("Topic %s set bumped_at to %s" % (topic_id, bumped_at))

M setup.py => setup.py +3 -2
@@ 65,8 65,9 @@ setup(name='fanboi2',
      entry_points={
          "paste.app_factory": ["main = fanboi2:main"],
          "console_scripts": [
              "fb2_create_board = fanboi2.scripts.create_board:main",
              "fb2_update_board = fanboi2.scripts.update_board:main",
              "fb2_board_create = fanboi2.scripts.board_create:main",
              "fb2_board_update = fanboi2.scripts.board_update:main",
              "fb2_topic_sync = fanboi2.scripts.topic_sync:main",
              "fb2_celery = fanboi2.scripts.celery:main",
          ]
      })