Changeset 1585 for trunk/pylucid/PyLucid/install/update.py
- Timestamp:
- 05/23/08 16:33:49 (22 months ago)
- Files:
-
- 1 modified
-
trunk/pylucid/PyLucid/install/update.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pylucid/PyLucid/install/update.py
r1584 r1585 19 19 20 20 #______________________________________________________________________________ 21 22 import re 23 from PyLucid.tools.Diff import diff_lines as _diff_lines 24 25 PAGE_MSG_RE = re.compile(r"""{% if messages %}.*?{% endif %}(?uims)""") 26 NEW_PAGE_MSG_TAG = "<!-- page_messages -->" 27 BACKUP_NAME_SUFFIX = " auto backup" 28 21 29 class Update2(BaseInstall): 22 30 def view(self): 23 31 self._redirect_execute(self._update_tables) 32 self._redirect_execute(self._update_templates) 24 33 25 34 return self._simple_render( 26 headline="Update PyLucid from v0.8.0 to v0.8. 1"35 headline="Update PyLucid from v0.8.0 to v0.8.5" 27 36 ) 28 37 29 38 def _update_tables(self): 30 print " update database tables:"39 print "*** update database tables:" 31 40 for table_name in ("pagesinternal", "markup"): 32 41 try: … … 40 49 print "OK" 41 50 51 def _update_templates(self): 52 print "\n*** update templates:" 53 templates = Template.objects.all() 54 for template in templates: 55 old_id = template.id 56 57 print "_"*79 58 print "process template '%s':" % template.name 59 60 if BACKUP_NAME_SUFFIX in template.name: 61 #template.delete() 62 print "Skip!" 63 continue 64 65 old_content = template.content 66 new_content = PAGE_MSG_RE.sub(NEW_PAGE_MSG_TAG, old_content) 67 if old_content == new_content: 68 print "Old tag not found or changes applied in the past." 69 continue 70 71 print "result diff:" 72 diff = _diff_lines(old_content, new_content) 73 print diff 74 print "-"*79 75 76 original_name = template.name 77 backup_name = original_name + BACKUP_NAME_SUFFIX 78 print "Create backup template '%s'..." % backup_name, 79 80 try: 81 bak_template = Template.objects.get(name=backup_name) 82 except Template.DoesNotExist: 83 # ok, create backup 84 template.name = backup_name 85 template.id = None 86 template.save() 87 print "OK" 88 else: 89 print "\nError: A template with the name '%s' exists." % ( 90 backup_name 91 ) 92 print "Skip update!" 93 continue 94 95 template.name = original_name 96 template.id = old_id 97 98 print "save new content...", 99 template.content = new_content 100 template.save() 101 print "OK" 42 102 43 103 def update2(request): 44 104 """ 45 1. update from v0.8.0 to v0.8. 1105 1. update from v0.8.0 to v0.8.5 46 106 """ 47 107 return Update2(request).start_view() … … 428 488 "<lucid(Function):(.*?)>(.*?)</lucidFunction>" 429 489 ) 430 PAGE_MSG_TAG = """\431 {% if messages %}432 <fieldset id="page_msg"><legend>page message</legend>433 {% for message in messages %}434 {{ message }}<br />435 {% endfor %}436 </fieldset>437 {% endif %}\438 """439 490 440 491 CHANGE_TAGS = { 441 "page_msg": PAGE_MSG_TAG,492 "page_msg": "<!-- page_messages -->", 442 493 "script_login": "{{ login_link }}", 443 494 "robots": "{{ robots }}",