Zine

open source content publishing system


Changeset 1316:764968e27341


Ignore:
Timestamp:
07/14/09 17:03:12 (3 years ago)
Author:
s0undt3ch
Branch:
default
Message:

Corrected copyright for zine.plugins.eric_the_fish.databse.
More explicit indentation for zine.upgrades.versions.001_split_tables.
Moved the migrations log formatters and handlers to their own module zine.upgrades.loggers.

Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • external-plugins/eric_the_fish/database.py

    r1314 r1316  
    11# -*- coding: utf-8 -*- 
    2 # vim: sw=4 ts=4 fenc=utf-8 et 
    3 # ============================================================================== 
    4 # Copyright © 2009 UfSoft.org - Pedro Algarvio <ufs@ufsoft.org> 
    5 # 
    6 # License: BSD - Please view the LICENSE file for additional information. 
    7 # ============================================================================== 
     2""" 
     3    zine.plugins.eric_the_fish.databse 
     4    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     5 
     6    Database tables and objects for the "Annoying fish for the admin panel". 
     7 
     8    :copyright: (c) 2009 by the Zine Team, see AUTHORS for more details. 
     9    :license: BSD, see LICENSE for more details. 
     10""" 
    811 
    912from zine.database import db, metadata 
  • zine/upgrades/__init__.py

    r1315 r1316  
    1212import re 
    1313import sys 
    14 import types 
    1514import logging 
    1615from os.path import dirname, expanduser, join 
     
    2019from migrate.versioning.util import construct_engine 
    2120from zine import __version__ as VERSION, setup 
    22 from zine.upgrades import customisation 
     21from zine.upgrades import customisation, loggers 
    2322 
    2423REPOSITORY_PATH = dirname(__file__) 
    25  
    26  
    27 class LogFormatter(logging.Formatter): 
    28     def format(self, record): 
    29         """ 
    30         Format the specified record as text. 
    31  
    32         The record's attribute dictionary is used as the operand to a 
    33         string formatting operation which yields the returned string. 
    34         Before formatting the dictionary, a couple of preparatory steps 
    35         are carried out. The message attribute of the record is computed 
    36         using LogRecord.getMessage(). If the formatting string contains 
    37         "%(asctime)", formatTime() is called to format the event time. 
    38         If there is exception information, it is formatted using 
    39         formatException() and appended to the message. 
    40         """ 
    41         record.message = record.getMessage() 
    42 #        if string.find(self._fmt,"%(asctime)") >= 0: 
    43 #            record.asctime = self.formatTime(record, self.datefmt) 
    44         s = self._fmt % record.__dict__ 
    45         if record.exc_info: 
    46             # Cache the traceback text to avoid converting it multiple times 
    47             # (it's constant anyway) 
    48             if not record.exc_text: 
    49                 record.exc_text = self.formatException(record.exc_info) 
    50         if record.exc_text: 
    51 #            if s[-1:] != "\n": 
    52 #                s = s + "\n" 
    53             s = s + record.exc_text 
    54         from zine.utils.zeml import parse_html 
    55         trailing_new_line = s and s.endswith('\n') or False 
    56         s = parse_html(s).to_text(simple=True) 
    57         if s and s.endswith('\n') and not trailing_new_line: 
    58             s = s.rstrip('\n') 
    59         return s 
    60  
    61 class LogHandler(logging.StreamHandler): 
    62     def emit(self, record): 
    63         """ 
    64         Emit a record. 
    65  
    66         If a formatter is specified, it is used to format the record. 
    67         The record is then written to the stream with a trailing newline 
    68         [N.B. this may be removed depending on feedback]. If exception 
    69         information is present, it is formatted using 
    70         traceback.print_exception and appended to the stream. 
    71         """ 
    72         try: 
    73             msg = self.format(record) 
    74 #            fs = "%s\n" 
    75             fs = '%s' 
    76             if not hasattr(types, "UnicodeType"): #if no unicode support... 
    77                 self.stream.write(fs % msg) 
    78             else: 
    79                 try: 
    80                     self.stream.write(fs % msg) 
    81                 except UnicodeError: 
    82                     self.stream.write(fs % msg.encode("UTF-8")) 
    83             self.flush() 
    84         except (KeyboardInterrupt, SystemExit): 
    85             raise 
    86         except: 
    87             self.handleError(record) 
    88  
     24log = logging.getLogger(__name__) 
    8925 
    9026class CommandLineInterface(object): 
     
    12258        root_logger = logging.getLogger() 
    12359        root_logger.setLevel(logging.DEBUG) 
    124         handler = LogHandler(sys.stdout) 
    125         handler.setFormatter(LogFormatter("%(message)s")) 
     60        handler = loggers.LogHandler(sys.stdout) 
     61        handler.setFormatter(loggers.LogFormatter("%(message)s")) 
    12662        root_logger.addHandler(handler) 
    12763 
  • zine/upgrades/versions/001_split_tables.py

    r1315 r1316  
    292292 
    293293    log.info('<ul>') 
    294     log.info(' <li>Auto-loading needed extra tables</li>\n') 
     294    log.info('  <li>Auto-loading needed extra tables</li>\n') 
    295295    post_links = db.Table('post_links', metadata2, autoload=True) 
    296296    post_categories = db.Table('post_categories', metadata2, autoload=True) 
    297297    post_tags = db.Table('post_tags', metadata2, autoload=True) 
    298298 
    299     log.info(' <li>Dropping old posts table indexes</li>\n') 
     299    log.info('  <li>Dropping old posts table indexes</li>\n') 
    300300    for index in posts_old.indexes: 
    301301        try: 
     
    304304            # Index is on table definition but not on the database!? Weird 
    305305            pass 
    306     log.info(' <li>Dropping existing posts sequence if it exists</li>\n') 
     306    log.info('  <li>Dropping existing posts sequence if it exists</li>\n') 
    307307    try: 
    308308        posts_new_seq.drop(migrate_engine) 
     
    311311 
    312312 
    313     log.info(' <li>Dropping existing comments sequence if it exists</li>\n') 
     313    log.info('  <li>Dropping existing comments sequence if it exists</li>\n') 
    314314    try: 
    315315        new_comments_seq.drop(migrate_engine) 
     
    317317        pass 
    318318 
    319     log.info(' <li>Querying for old posts from database</li>\n') 
    320     log.info(' <li>Got %d posts</li>\n', session.query(PostOld).count()) 
     319    log.info('  <li>Querying for old posts from database</li>\n') 
     320    log.info('  <li>Got %d posts</li>\n', session.query(PostOld).count()) 
    321321    session.close() 
    322322 
    323     log.info(' <li>Create texts table</li>\n') 
     323    log.info('  <li>Create texts table</li>\n') 
    324324    texts.create(migrate_engine) 
    325325 
    326     log.info(' <li>Renaming old posts table</li>\n') 
     326    log.info('  <li>Renaming old posts table</li>\n') 
    327327    posts_old.rename('posts_upgrade') 
    328328 
    329     log.info(' <li>Create new posts table</li>\n') 
     329    log.info('  <li>Create new posts table</li>\n') 
    330330    posts_new.create(migrate_engine) 
    331331 
    332     log.info(' <li>Renaming old comments table</li>\n') 
     332    log.info('  <li>Renaming old comments table</li>\n') 
    333333    comments_old.rename('comments_upgrade') 
    334334 
    335     log.info(' <li>Create new comments table</li>\n') 
     335    log.info('  <li>Create new comments table</li>\n') 
    336336    comments_new.create(migrate_engine) 
    337337 
    338338 
    339     log.info(' <li>Migrate old posts into new table:</li>\n') 
     339    log.info('  <li>Migrate old posts into new table:</li>\n') 
    340340    log.info('<ul>') 
    341341    for post in session.query(PostOld).all(): 
    342         log.info('\n  <li>%s</li>\n', post.title) 
     342        log.info('    <li>%s</li>\n', post.title) 
    343343        log.info('<ul>') 
    344344        new_post = PostNew(post.pub_date, 
     
    353353                           post.content_type, 
    354354                           post.status) 
    355         log.info('   <li>Create new text entry</li>\n') 
     355        log.info('      <li>Create new text entry</li>\n') 
    356356        new_post.t = Text(post.text, post.parser_data, post.extra) 
    357357        session.add(new_post) 
     
    359359        comments_count = len(post.comments) 
    360360        n = (comments_count >= 100 and comments_count or 0) 
    361         log.info('   <li>Migrating %d comments <span class="progress">', 
     361        log.info('      <li>Migrating %d comments <span class="progress">', 
    362362                 comments_count) 
    363363        for comment in post.comments: 
    364364            if n >= 100: 
    365365                n = 0 
    366                 log.info('<br/>\n   ') 
     366                log.info('<br/>\n      ') 
    367367            parent_comment_new = None 
    368368            if comment.parent_id: 
     
    396396            n += 1 
    397397        log.info('</span></li>\n') 
    398         log.info('   <li>Update linked tables <tt>post_categories</tt>, ' 
     398        log.info('      <li>Update linked tables <tt>post_categories</tt>, ' 
    399399                 '<tt>post_links</tt> and <tt>post_tags</tt> for new ' 
    400400                 '<tt>post_id</tt></li>\n') 
     
    412412    log.info('</ul>') 
    413413 
    414     log.info(' <li>Drop old comments table</li>\n') 
     414    log.info('  <li>Drop old comments table</li>\n') 
    415415    drop_table(comments_old, migrate_engine) 
    416416 
    417     log.info(' <li>Drop old posts table</li>\n') 
     417    log.info('  <li>Drop old posts table</li>\n') 
    418418    drop_table(posts_old, migrate_engine) 
    419419 
     
    439439 
    440440    log.info('<ul>') 
    441     log.info(' <li>Auto-loading needed extra tables</li>\n') 
     441    log.info('  <li>Auto-loading needed extra tables</li>\n') 
    442442    post_links = db.Table('post_links', metadata2, autoload=True) 
    443443    post_categories = db.Table('post_categories', metadata2, autoload=True) 
    444444    post_tags = db.Table('post_tags', metadata2, autoload=True) 
    445445 
    446     log.info(' <li>Dropping new posts table indexes</li>\n') 
     446    log.info('  <li>Dropping new posts table indexes</li>\n') 
    447447    for index in posts_new.indexes: 
    448448        try: 
     
    452452            pass 
    453453 
    454     log.info(' <li>Querying new posts from database</li>\n') 
    455     log.info(' <li>Got %d posts</li>\n', session.query(PostNew).count()) 
     454    log.info('  <li>Querying new posts from database</li>\n') 
     455    log.info('  <li>Got %d posts</li>\n', session.query(PostNew).count()) 
    456456    session.close() 
    457457 
    458     log.info(' <li>Renaming new posts table</li>\n') 
     458    log.info('  <li>Renaming new posts table</li>\n') 
    459459    posts_new.rename('posts_downgrade') 
    460460 
    461     log.info(' <li>Create old posts table</li>\n') 
     461    log.info('  <li>Create old posts table</li>\n') 
    462462    posts_old.create(migrate_engine) 
    463463 
    464     log.info(' <li>Renaming new comments table</li>\n') 
     464    log.info('  <li>Renaming new comments table</li>\n') 
    465465    comments_new.rename('comments_downgrade') 
    466466 
    467     log.info(' <li>Create old comments table</li>\n') 
     467    log.info('  <li>Create old comments table</li>\n') 
    468468    comments_old.create(migrate_engine) 
    469469 
    470     log.info(' <li>Migrate new posts into old table</li>\n') 
     470    log.info('  <li>Migrate new posts into old table:</li>\n') 
    471471    log.info('<ul>') 
    472472    for post in session.query(PostNew).all(): 
    473         log.info('\n  <li>%s</li>\n') % post.title 
     473        log.info('    <li>%s</li>\n') % post.title 
    474474        log.info('<ul>') 
    475475        old_post = PostOld(post.pub_date, 
     
    490490        comments_count = len(post.comments) 
    491491        n = comments_count >= 100 and comments_count or 0 
    492         log.info('   <li>Migrating %d comments <span class="progress">', 
     492        log.info('      <li>Migrating %d comments <span class="progress">', 
    493493                 comments_count) 
    494494        for comment in post.comments: 
    495495            if n >= 100: 
    496496                n = 0 
    497                 log.info('<br/>\n   ') 
     497                log.info('<br/>\n      ') 
    498498            parent_comment_old = None 
    499499            if comment.parent_id: 
     
    527527        log.info('</span></li>\n') 
    528528 
    529         log.info('   <li>Update linked tables <tt>post_categories</tt>, ' 
     529        log.info('      <li>Update linked tables <tt>post_categories</tt>, ' 
    530530                 '<tt>post_links</tt> and <tt>post_tags</tt> for old ' 
    531531                 '<tt>post_id</tt></li>\n') 
     
    542542        log.info('</ul>') 
    543543    log.info('</ul>') 
    544     log.info(' <li>Drop new posts table</li>\n') 
     544    log.info('  <li>Drop new posts table</li>\n') 
    545545    drop_table(posts_new, migrate_engine) 
    546546 
    547     log.info(' <li>Drop new comments table</li>\n') 
     547    log.info('  <li>Drop new comments table</li>\n') 
    548548    drop_table(comments_new, migrate_engine) 
    549549 
    550     log.info(' <li>Drop texts table</li>\n') 
     550    log.info('  <li>Drop texts table</li>\n') 
    551551    drop_table(texts, migrate_engine) 
    552552 
  • zine/upgrades/versions/002_notification_subscriptions.py

    r1315 r1316  
    3131    # named 'migrate_engine' imported from migrate. 
    3232    log.info('<ul>') 
    33     log.info(' <li>Create the notification subscriptions table</li>\n') 
     33    log.info('  <li>Create the notification subscriptions table</li>\n') 
    3434    log.info('</ul>') 
    3535    notification_subscriptions.create(migrate_engine) 
     
    3939    # Operations to reverse the above upgrade go here. 
    4040    log.info('<ul>') 
    41     log.info(' <li>Drop the notification subscriptions table</li>\n') 
     41    log.info('  <li>Drop the notification subscriptions table</li>\n') 
    4242    log.info('</ul>') 
    4343    notification_subscriptions.drop(migrate_engine) 
Note: See TracChangeset for help on using the changeset viewer.