Changeset 1316:764968e27341
- Timestamp:
- 07/14/09 17:03:12 (3 years ago)
- Branch:
- default
- Files:
-
- 1 added
- 4 edited
-
external-plugins/eric_the_fish/database.py (modified) (1 diff)
-
zine/upgrades/__init__.py (modified) (3 diffs)
-
zine/upgrades/loggers.py (added)
-
zine/upgrades/versions/001_split_tables.py (modified) (13 diffs)
-
zine/upgrades/versions/002_notification_subscriptions.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
external-plugins/eric_the_fish/database.py
r1314 r1316 1 1 # -*- 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 """ 8 11 9 12 from zine.database import db, metadata -
zine/upgrades/__init__.py
r1315 r1316 12 12 import re 13 13 import sys 14 import types15 14 import logging 16 15 from os.path import dirname, expanduser, join … … 20 19 from migrate.versioning.util import construct_engine 21 20 from zine import __version__ as VERSION, setup 22 from zine.upgrades import customisation 21 from zine.upgrades import customisation, loggers 23 22 24 23 REPOSITORY_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 24 log = logging.getLogger(__name__) 89 25 90 26 class CommandLineInterface(object): … … 122 58 root_logger = logging.getLogger() 123 59 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")) 126 62 root_logger.addHandler(handler) 127 63 -
zine/upgrades/versions/001_split_tables.py
r1315 r1316 292 292 293 293 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') 295 295 post_links = db.Table('post_links', metadata2, autoload=True) 296 296 post_categories = db.Table('post_categories', metadata2, autoload=True) 297 297 post_tags = db.Table('post_tags', metadata2, autoload=True) 298 298 299 log.info(' <li>Dropping old posts table indexes</li>\n')299 log.info(' <li>Dropping old posts table indexes</li>\n') 300 300 for index in posts_old.indexes: 301 301 try: … … 304 304 # Index is on table definition but not on the database!? Weird 305 305 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') 307 307 try: 308 308 posts_new_seq.drop(migrate_engine) … … 311 311 312 312 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') 314 314 try: 315 315 new_comments_seq.drop(migrate_engine) … … 317 317 pass 318 318 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()) 321 321 session.close() 322 322 323 log.info(' <li>Create texts table</li>\n')323 log.info(' <li>Create texts table</li>\n') 324 324 texts.create(migrate_engine) 325 325 326 log.info(' <li>Renaming old posts table</li>\n')326 log.info(' <li>Renaming old posts table</li>\n') 327 327 posts_old.rename('posts_upgrade') 328 328 329 log.info(' <li>Create new posts table</li>\n')329 log.info(' <li>Create new posts table</li>\n') 330 330 posts_new.create(migrate_engine) 331 331 332 log.info(' <li>Renaming old comments table</li>\n')332 log.info(' <li>Renaming old comments table</li>\n') 333 333 comments_old.rename('comments_upgrade') 334 334 335 log.info(' <li>Create new comments table</li>\n')335 log.info(' <li>Create new comments table</li>\n') 336 336 comments_new.create(migrate_engine) 337 337 338 338 339 log.info(' <li>Migrate old posts into new table:</li>\n')339 log.info(' <li>Migrate old posts into new table:</li>\n') 340 340 log.info('<ul>') 341 341 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) 343 343 log.info('<ul>') 344 344 new_post = PostNew(post.pub_date, … … 353 353 post.content_type, 354 354 post.status) 355 log.info(' <li>Create new text entry</li>\n')355 log.info(' <li>Create new text entry</li>\n') 356 356 new_post.t = Text(post.text, post.parser_data, post.extra) 357 357 session.add(new_post) … … 359 359 comments_count = len(post.comments) 360 360 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">', 362 362 comments_count) 363 363 for comment in post.comments: 364 364 if n >= 100: 365 365 n = 0 366 log.info('<br/>\n ')366 log.info('<br/>\n ') 367 367 parent_comment_new = None 368 368 if comment.parent_id: … … 396 396 n += 1 397 397 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>, ' 399 399 '<tt>post_links</tt> and <tt>post_tags</tt> for new ' 400 400 '<tt>post_id</tt></li>\n') … … 412 412 log.info('</ul>') 413 413 414 log.info(' <li>Drop old comments table</li>\n')414 log.info(' <li>Drop old comments table</li>\n') 415 415 drop_table(comments_old, migrate_engine) 416 416 417 log.info(' <li>Drop old posts table</li>\n')417 log.info(' <li>Drop old posts table</li>\n') 418 418 drop_table(posts_old, migrate_engine) 419 419 … … 439 439 440 440 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') 442 442 post_links = db.Table('post_links', metadata2, autoload=True) 443 443 post_categories = db.Table('post_categories', metadata2, autoload=True) 444 444 post_tags = db.Table('post_tags', metadata2, autoload=True) 445 445 446 log.info(' <li>Dropping new posts table indexes</li>\n')446 log.info(' <li>Dropping new posts table indexes</li>\n') 447 447 for index in posts_new.indexes: 448 448 try: … … 452 452 pass 453 453 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()) 456 456 session.close() 457 457 458 log.info(' <li>Renaming new posts table</li>\n')458 log.info(' <li>Renaming new posts table</li>\n') 459 459 posts_new.rename('posts_downgrade') 460 460 461 log.info(' <li>Create old posts table</li>\n')461 log.info(' <li>Create old posts table</li>\n') 462 462 posts_old.create(migrate_engine) 463 463 464 log.info(' <li>Renaming new comments table</li>\n')464 log.info(' <li>Renaming new comments table</li>\n') 465 465 comments_new.rename('comments_downgrade') 466 466 467 log.info(' <li>Create old comments table</li>\n')467 log.info(' <li>Create old comments table</li>\n') 468 468 comments_old.create(migrate_engine) 469 469 470 log.info(' <li>Migrate new posts into old table</li>\n')470 log.info(' <li>Migrate new posts into old table:</li>\n') 471 471 log.info('<ul>') 472 472 for post in session.query(PostNew).all(): 473 log.info(' \n<li>%s</li>\n') % post.title473 log.info(' <li>%s</li>\n') % post.title 474 474 log.info('<ul>') 475 475 old_post = PostOld(post.pub_date, … … 490 490 comments_count = len(post.comments) 491 491 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">', 493 493 comments_count) 494 494 for comment in post.comments: 495 495 if n >= 100: 496 496 n = 0 497 log.info('<br/>\n ')497 log.info('<br/>\n ') 498 498 parent_comment_old = None 499 499 if comment.parent_id: … … 527 527 log.info('</span></li>\n') 528 528 529 log.info(' <li>Update linked tables <tt>post_categories</tt>, '529 log.info(' <li>Update linked tables <tt>post_categories</tt>, ' 530 530 '<tt>post_links</tt> and <tt>post_tags</tt> for old ' 531 531 '<tt>post_id</tt></li>\n') … … 542 542 log.info('</ul>') 543 543 log.info('</ul>') 544 log.info(' <li>Drop new posts table</li>\n')544 log.info(' <li>Drop new posts table</li>\n') 545 545 drop_table(posts_new, migrate_engine) 546 546 547 log.info(' <li>Drop new comments table</li>\n')547 log.info(' <li>Drop new comments table</li>\n') 548 548 drop_table(comments_new, migrate_engine) 549 549 550 log.info(' <li>Drop texts table</li>\n')550 log.info(' <li>Drop texts table</li>\n') 551 551 drop_table(texts, migrate_engine) 552 552 -
zine/upgrades/versions/002_notification_subscriptions.py
r1315 r1316 31 31 # named 'migrate_engine' imported from migrate. 32 32 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') 34 34 log.info('</ul>') 35 35 notification_subscriptions.create(migrate_engine) … … 39 39 # Operations to reverse the above upgrade go here. 40 40 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') 42 42 log.info('</ul>') 43 43 notification_subscriptions.drop(migrate_engine)
Note: See TracChangeset
for help on using the changeset viewer.