Ticket #7241: 7241-trac-admin-wiki-export-r7376.diff
| File 7241-trac-admin-wiki-export-r7376.diff, 15.2 KB (added by cboos, 4 months ago) |
|---|
-
trac/admin/console.py
37 37 from trac.util.html import html 38 38 from trac.util.text import to_unicode, wrap, unicode_quote, unicode_unquote, \ 39 39 print_table, console_print 40 from trac.util.translation import _ 40 from trac.util.translation import _, ngettext 41 41 from trac.wiki import WikiPage 42 42 from trac.wiki.api import WikiSystem 43 43 from trac.wiki.macros import WikiMacroBase 44 44 45 45 TRAC_VERSION = pkg_resources.get_distribution('Trac').version 46 46 47 def printout(*args): 48 console_print(sys.stdout, *args) 49 47 50 def copytree(src, dst, symlinks=False, skip=[]): 48 51 """Recursively copy a directory tree using copy2() (from shutil.copytree.) 49 52 … … 124 127 125 128 def run(self): 126 129 self.interactive = True 127 print """Welcome to trac-admin %(version)s130 printout(_("""Welcome to trac-admin %(version)s 128 131 Interactive Trac administration console. 129 132 Copyright (c) 2003-2008 Edgewall Software 130 133 131 134 Type: '?' or 'help' for help on commands. 132 """ % {'version': TRAC_VERSION}135 """, version=TRAC_VERSION)) 133 136 self.cmdloop() 134 137 135 138 ## … … 285 288 console_print(sys.stderr, "No documentation found for '%s'" % 286 289 arg[0]) 287 290 else: 288 print 'trac-admin - The Trac Administration Console %s' \289 % TRAC_VERSION291 printout(_("trac-admin - The Trac Administration Console " 292 "%(version)s", version=TRAC_VERSION)) 290 293 if not self.interactive: 291 294 print 292 print "Usage: trac-admin </path/to/projenv> [command [subcommand] [option ...]]\n" 293 print "Invoking trac-admin without command starts "\ 294 "interactive mode." 295 printout(_("Usage: trac-admin </path/to/projenv> " 296 "[command [subcommand] [option ...]]\n") 297 ) 298 printout(_("Invoking trac-admin without command starts " 299 "interactive mode.")) 295 300 self.print_doc(self.all_docs()) 296 301 297 302 … … 427 432 rows.sort() 428 433 print_table(rows, ['User', 'Action']) 429 434 print 430 print 'Available actions:'435 printout(_("Available actions:")) 431 436 actions = self._permsys.get_actions() 432 437 actions.sort() 433 438 text = ', '.join(actions) 434 print wrap(text, initial_indent=' ', subsequent_indent=' ',435 linesep='\n')439 printout(wrap(text, initial_indent=' ', subsequent_indent=' ', 440 linesep='\n')) 436 441 print 437 442 438 443 def _do_permission_add(self, user, action): 439 444 if not self._permsys: 440 445 self._permsys = PermissionSystem(self.env_open()) 441 446 if not action.islower() and not action.isupper(): 442 print 'Group names must be in lower case and actions in upper case' 447 printout(_("Group names must be in lower case and actions in " 448 "upper case")) 443 449 return 444 450 self._permsys.grant_permission(user, action) 445 451 … … 471 477 472 478 def get_initenv_args(self): 473 479 returnvals = [] 474 print 'Creating a new Trac environment at %s' % self.envname 475 print 476 print 'Trac will first ask a few questions about your environment ' 477 print 'in order to initalize and prepare the project database.' 478 print 479 print " Please enter the name of your project." 480 print " This name will be used in page titles and descriptions." 481 print 480 printout(_("Creating a new Trac environment at %(envname)s", 481 envname=self.envname)) 482 printout(_(""" 483 Trac will first ask a few questions about your environment 484 in order to initialize and prepare the project database. 485 486 Please enter the name of your project. 487 This name will be used in page titles and descriptions. 488 """)) 482 489 dp = 'My Project' 483 returnvals.append(raw_input('Project Name [%s]> ' % dp).strip() or dp) 484 print 485 print ' Please specify the connection string for the database to use.' 486 print ' By default, a local SQLite database is created in the environment ' 487 print ' directory. It is also possible to use an already existing ' 488 print ' PostgreSQL database (check the Trac documentation for the exact ' 489 print ' connection string syntax).' 490 print 490 returnvals.append(raw_input(_("Project Name [%(default)s]> ", 491 default=dp)).strip() or dp) 492 printout(_(""" 493 Please specify the connection string for the database to use. 494 By default, a local SQLite database is created in the environment 495 directory. It is also possible to use an already existing 496 PostgreSQL database (check the Trac documentation for the exact 497 connection string syntax). 498 499 """)) 491 500 ddb = 'sqlite:db/trac.db' 492 prompt = 'Database connection string [%s]> ' % ddb501 prompt = _("Database connection string [%(default)s]> ", default=ddb) 493 502 returnvals.append(raw_input(prompt).strip() or ddb) 494 print 495 print ' Please specify the type of version control system,' 496 print ' By default, it will be svn.' 497 print 498 print ' If you don\'t want to use Trac with version control integration, ' 499 print ' choose the default here and don\'t specify a repository directory. ' 500 print ' in the next question.' 501 print 503 printout(_(""" 504 Please specify the type of version control system, 505 By default, it will be svn. 506 507 If you don't want to use Trac with version control integration, 508 choose the default here and don\'t specify a repository directory. 509 in the next question. 510 511 """)) 502 512 drpt = 'svn' 503 prompt = 'Repository type [%s]> ' % drpt513 prompt = _("Repository type [%(default)s]> ", default=drpt) 504 514 returnvals.append(raw_input(prompt).strip() or drpt) 505 print 506 print ' Please specify the absolute path to the version control ' 507 print ' repository, or leave it blank to use Trac without a repository.' 508 print ' You can also set the repository location later.' 509 print 510 prompt = 'Path to repository [/path/to/repos]> ' 515 printout(_(""" 516 Please specify the absolute path to the version control 517 repository, or leave it blank to use Trac without a repository. 518 You can also set the repository location later. 519 520 """)) 521 prompt = _("Path to repository [/path/to/repos]> ") 511 522 returnvals.append(raw_input(prompt).strip()) 512 523 print 513 524 return returnvals … … 543 554 project_name, db_str, repository_type, repository_dir = arg[:4] 544 555 545 556 try: 546 print 'Creating and Initializing Project'557 printout(_("Creating and Initializing Project")) 547 558 options = [ 548 559 ('trac', 'database', db_str), 549 560 ('trac', 'repository_type', repository_type), … … 562 573 sys.exit(1) 563 574 564 575 # Add a few default wiki pages 565 print ' Installing default wiki pages'576 printout(_(" Installing default wiki pages")) 566 577 cnx = self.__env.get_db_cnx() 567 578 cursor = cnx.cursor() 568 579 pages_dir = pkg_resources.resource_filename('trac.wiki', … … 574 585 try: 575 586 repos = self.__env.get_repository() 576 587 if repos: 577 print ' Indexing repository'588 printout(_(" Indexing repository")) 578 589 repos.sync(self._resync_feedback) 579 590 except TracError, e: 580 591 console_print(sys.stderr, "\nWarning:\n") … … 590 601 traceback.print_exc() 591 602 return 2 592 603 593 print """604 printout(_(""" 594 605 --------------------------------------------------------------------- 595 606 Project environment for '%(project_name)s' created. 596 607 … … 614 625 http://trac.edgewall.org/ 615 626 616 627 Congratulations! 617 """ % dict(project_name=project_name, project_path=self.envname,628 """, project_name=project_name, project_path=self.envname, 618 629 project_dir=os.path.basename(self.envname), 619 config_path=os.path.join(self.envname, 'conf', 'trac.ini')) 630 config_path=os.path.join(self.envname, 'conf', 'trac.ini'))) 620 631 621 632 _help_resync = [('resync', 'Re-synchronize trac with the repository'), 622 633 ('resync <rev>', 'Re-synchronize only the given <rev>')] … … 633 644 rev = argv[0] 634 645 if rev: 635 646 env.get_repository().sync_changeset(rev) 636 print '%s resynced.' % rev647 printout(_("%(rev)s resynced.", rev=rev)) 637 648 return 638 649 from trac.versioncontrol.cache import CACHE_METADATA_KEYS 639 print 'Resyncing repository history... '650 printout(_("Resyncing repository history... ")) 640 651 cnx = self.db_open() 641 652 cursor = cnx.cursor() 642 653 cursor.execute("DELETE FROM revision") … … 649 660 repos = env.get_repository().sync(self._resync_feedback) 650 661 cursor.execute("SELECT count(rev) FROM revision") 651 662 for cnt, in cursor: 652 print cnt, 'revisions cached.', 653 print 'Done.' 663 printout(ngettext("%(num)s revision cached.", 664 "%(num)s revisions cached.", cnt, num=cnt)) 665 printout(_("Done.")) 654 666 655 667 ## Wiki 656 668 _help_wiki = [('wiki list', 'List wiki pages'), … … 749 761 params=(title,)) 750 762 old = list(rows) 751 763 if old and title in create_only: 752 console_print(sys.stdout,' %s already exists.' % title)764 printout(' %s already exists.' % title) 753 765 return False 754 766 if old and data == old[0][0]: 755 console_print(sys.stdout,' %s already up to date.' % title)767 printout(' %s already up to date.' % title) 756 768 return False 757 769 f.close() 758 770 … … 768 780 "ORDER BY version DESC LIMIT 1", params=[page]) 769 781 text = data.next()[0] 770 782 if not filename: 771 print text783 printout(text) 772 784 else: 773 785 if os.path.isfile(filename): 774 786 raise Exception("File '%s' exists" % filename) … … 785 797 raise TracError("%s is not a directory" % dir) 786 798 for p in pages: 787 799 dst = os.path.join(dir, unicode_quote(p, '')) 788 console_print(sys.stdout, " %s => %s" % (p,dst))800 printout(_(" %(src)s => %(dst)s", src=p, dst=dst)) 789 801 self._do_wiki_export(p, dst) 790 802 791 803 def _do_wiki_load(self, dir, cursor=None, ignore=[], create_only=[]): … … 797 809 page = unicode_unquote(page.encode('utf-8')) 798 810 if os.path.isfile(filename): 799 811 if self._do_wiki_import(filename, page, cursor, create_only): 800 print (" %s imported from %s" %801 (filename, page)).encode(cons_charset)812 printout(_(" %(page)s imported from %(filename)s", 813 filename=filename, page=page)) 802 814 803 815 ## Ticket 804 816 _help_ticket = [('ticket remove <number>', 'Remove ticket')] … … 825 837 else: 826 838 self.do_help ('ticket') 827 839 828 def _do_ticket_remove(self, num ber):829 ticket = Ticket(self.env_open(), num ber)840 def _do_ticket_remove(self, num): 841 ticket = Ticket(self.env_open(), num) 830 842 ticket.delete() 831 print "Ticket %d and all associated data removed." % number843 printout(_("Ticket %(num)s and all associated data removed.", num=num)) 832 844 833 845 834 846 ## (Ticket) Type … … 1121 1133 self.db_open() 1122 1134 1123 1135 if not self.__env.needs_upgrade(): 1124 print "Database is up to date, no upgrade necessary."1136 printout(_("Database is up to date, no upgrade necessary.")) 1125 1137 return 1126 1138 1127 1139 try: … … 1133 1145 "upgrade without doing a backup." % msg) 1134 1146 else: 1135 1147 raise 1136 print 'Upgrade done.'1148 printout(_("Upgrade done.")) 1137 1149 1138 1150 _help_hotcopy = [('hotcopy <backupdir>', 1139 1151 'Make a hot backup copy of an environment')] … … 1155 1167 cursor.execute("UPDATE system SET name=NULL WHERE name IS NULL") 1156 1168 1157 1169 try: 1158 print 'Hotcopying %s to %s ...' % (self.__env.path, dest), 1170 printout(_('Hotcopying %(src)s to %(dst)s ...', 1171 src=self.__env.path, dst=dest)) 1159 1172 db_str = self.__env.config.get('trac', 'database') 1160 1173 prefix, db_path = db_str.split(':', 1) 1161 1174 if prefix == 'sqlite': … … 1169 1182 # Unlock database 1170 1183 cnx.rollback() 1171 1184 1172 print 'Hotcopy done.'1185 printout(_("Hotcopy done.")) 1173 1186 1174 1187 _help_deploy = [('deploy <directory>', 1175 1188 'Extract static resources from Trac and all plugins.')] … … 1190 1203 os.makedirs(target) 1191 1204 os.makedirs(chrome_target) 1192 1205 from trac.web.chrome import Chrome 1193 print 'Copying resources from:'1206 printout(_("Copying resources from:")) 1194 1207 for provider in Chrome(self.env_open()).template_providers: 1195 1208 paths = list(provider.get_htdocs_dirs()) 1196 1209 if not len(paths): 1197 1210 continue 1198 print ' %s.%s' % (provider.__module__, provider.__class__.__name__) 1211 printout(' %s.%s' % (provider.__module__, 1212 provider.__class__.__name__)) 1199 1213 for key, root in paths: 1200 1214 source = os.path.normpath(root) 1201 print ' ', source1215 printout(' ', source) 1202 1216 if os.path.exists(source): 1203 1217 dest = os.path.join(chrome_target, key) 1204 1218 copytree(source, dest) 1205 1219 1206 1220 # Create and copy scripts 1207 1221 os.makedirs(script_target) 1208 print 'Creating scripts.'1222 printout(_("Creating scripts.")) 1209 1223 data = {'env': self.env_open(), 'executable': sys.executable} 1210 1224 for script in ('cgi', 'fcgi', 'wsgi'): 1211 1225 dest = os.path.join(script_target, 'trac.'+script) … … 1260 1274 if args[0] in ('-h', '--help', 'help'): 1261 1275 return admin.onecmd('help') 1262 1276 elif args[0] in ('-v','--version'): 1263 print '%s %s' %(os.path.basename(sys.argv[0]), TRAC_VERSION)1277 printout(os.path.basename(sys.argv[0]), TRAC_VERSION) 1264 1278 else: 1265 1279 env_path = os.path.abspath(args[0]) 1266 1280 try: -
trac/util/text.py
112 112 113 113 def console_print(out, *args): 114 114 cons_charset = getattr(out, 'encoding', None) or 'utf-8' 115 out.write(' '.join([to_unicode(a).encode(cons_charset ) for a in args])+116 '\n')115 out.write(' '.join([to_unicode(a).encode(cons_charset, 'replace') 116 for a in args])+ '\n') 117 117 118 118 # -- Plain text formatting 119 119
