Project

General

Profile

Patch #5035 » migrate_from_trac_v1.patch

Mike Stupalov, 2010-03-10 14:40

View differences:

lib/tasks/migrate_from_trac.rake (working copy)
241 241
          if name_attr = TracSessionAttribute.find_by_sid_and_name(username, 'name')
242 242
            name = name_attr.value
243 243
          end
244
          name =~ (/(.*)(\s+\w+)?/)
244
          name =~ (/(.+?)(?:[\ \t]+(.+)?|[\ \t]+|)$/)
245 245
          fn = $1.strip
246 246
          ln = ($2 || '-').strip
247 247

  
......
271 271

  
272 272
      # Basic wiki syntax conversion
273 273
      def self.convert_wiki_text(text)
274
        # Titles
275
        text = text.gsub(/^(\=+)\s(.+)\s(\=+)/) {|s| "\nh#{$1.length}. #{$2}\n"}
276
        # External Links
277
        text = text.gsub(/\[(http[^\s]+)\s+([^\]]+)\]/) {|s| "\"#{$2}\":#{$1}"}
274
        # New line
275
        text = text.gsub(/\[\[BR\]\]/, "\n") # This has to go before the rules below
276
        # Titles (only h1. to h6.)
277
        text = text.gsub(/(?:^|^\ +)(\={1,6})\ (.+)\ (\={1,6})/) {|s| "\nh#{$1.length}. #{$2}\n"}
278
        # External Links:
279
        #      [http://example.com/]
280
        text = text.gsub(/\[((?:https?|ftp)\:\S+)\]/, '\1')
281
        #      [http://example.com/ Example],[http://example.com/ "Example"]
282
        text = text.gsub(/\[((?:https?|ftp)\:\S+)[\ \t]+(\")?(.+?)\2?\]/, '"\3":\1')
283
        #      [mailto:some@example.com]
284
        text = text.gsub(/\[mailto\:(\")?(.+?)(\1)?\]/, '\2')
278 285
        # Ticket links:
279
        #      [ticket:234 Text],[ticket:234 This is a test]
280
        text = text.gsub(/\[ticket\:([^\ ]+)\ (.+?)\]/, '"\2":/issues/show/\1')
286
        #      [ticket:234 Text],[ticket:234 This is a test],[ticket:234 "This is a test"]
287
        text = text.gsub(/\[ticket\:([^\ ]+)[\ \t]+(\")?(.+?)\2?\]/, '"\3":/issues/show/\1')
281 288
        #      ticket:1234
282 289
        #      #1 is working cause Redmine uses the same syntax.
283 290
        text = text.gsub(/ticket\:([^\ ]+)/, '#\1')
......
292 299
        #      milestone:0.1.0
293 300
        text = text.gsub(/\[milestone\:([^\ ]+)\]/, 'version:\1')
294 301
        text = text.gsub(/milestone\:([^\ ]+)/, 'version:\1')
295
        # Internal Links
296
        text = text.gsub(/\[\[BR\]\]/, "\n") # This has to go before the rules below
297
        text = text.gsub(/\[\"(.+)\".*\]/) {|s| "[[#{$1.delete(',./?;|:')}]]"}
298
        text = text.gsub(/\[wiki:\"(.+)\".*\]/) {|s| "[[#{$1.delete(',./?;|:')}]]"}
299
        text = text.gsub(/\[wiki:\"(.+)\".*\]/) {|s| "[[#{$1.delete(',./?;|:')}]]"}
300
        text = text.gsub(/\[wiki:([^\s\]]+)\]/) {|s| "[[#{$1.delete(',./?;|:')}]]"}
301
        text = text.gsub(/\[wiki:([^\s\]]+)\s(.*)\]/) {|s| "[[#{$1.delete(',./?;|:')}|#{$2.delete(',./?;|:')}]]"}
302
        # Internal Links:
303
        #      ["Some Link"]
304
        text = text.gsub(/\[\"(.+?)\"\]/) {|s| "[[#{$1.delete(',./?;|:')}]]"}
305
        #      [wiki:"Some Link" "Link description"],[wiki:"Some Link" Link description]
306
        text = text.gsub(/\[wiki\:\"([^\]\"]+)\"[\ \t]+\"?(.+?)\"?\]/) {|s| "[[#{$1.delete(',./?;|:')}|#{$2}]]"}
307
        #      [wiki:"Some Link"]
308
        text = text.gsub(/\[wiki\:\"(.+?)\"\]/) {|s| "[[#{$1.delete(',./?;|:')}]]"}
309
        #text = text.gsub(/\[wiki:\"(.+?)\"\]/) {|s| "[[#{$1.delete(',./?;|:')}]]"} # dublicate??
310
        #      [wiki:SomeLink]
311
        text = text.gsub(/\[wiki\:([^\s\]]+)\]/) {|s| "[[#{$1.delete(',./?;|:')}]]"}
312
        #      [wiki:SomeLink Link description],[wiki:SomeLink "Link description"]
313
        text = text.gsub(/\[wiki\:([^\s\]\"]+)[\ \t]+\"?(.+?)\"?\]/) {|s| "[[#{$1.delete(',./?;|:')}|#{$2}]]"}
302 314

  
303
  # Links to pages UsingJustWikiCaps
304
  text = text.gsub(/([^!]|^)(^| )([A-Z][a-z]+[A-Z][a-zA-Z]+)/, '\\1\\2[[\3]]')
305
  # Normalize things that were supposed to not be links
306
  # like !NotALink
307
  text = text.gsub(/(^| )!([A-Z][A-Za-z]+)/, '\1\2')
315
        # Links to pages UsingJustWikiCaps (not work for unicode)
316
        text = text.gsub(/([^!]|^)(^| )([A-Z][a-z]+[A-Z][a-zA-Z]+)/, '\\1\\2[[\3]]')
317
        # Normalize things that were supposed to not be links
318
        # like !NotALink
319
        text = text.gsub(/(^| )!([A-Z][A-Za-z]+)/, '\1\2')
308 320
        # Revisions links
309 321
        text = text.gsub(/\[(\d+)\]/, 'r\1')
310 322
        # Ticket number re-writing
......
316 328
            s
317 329
          end
318 330
        end
331
        
332
        # Before convert Code highlighting, need procing inline code
333
        # like {{{hello world}}}
334
        text = text.gsub(/\{\{\{(.+?)\}\}\}/, '@\1@')
335
        
319 336
        # We would like to convert the Code highlighting too
320 337
        # This will go into the next line.
321 338
        shebang_line = false
......
357 374
        text = text.gsub(/~~/, '-')
358 375
        text = text.gsub(/`/, '@')
359 376
        text = text.gsub(/,,/, '~')
360
        # Lists
361
        text = text.gsub(/^([ ]+)\* /) {|s| '*' * $1.length + " "}
362

  
377
        # Tables
378
        text = text.gsub(/\|\|/, '|')
379
        # Lists:
380
        #      bullet
381
        text = text.gsub(/^(\ +)\* /) {|s| '*' * $1.length + " "}
382
        #      numbered
383
        text = text.gsub(/^(\ +)\d+\. /) {|s| '#' * $1.length + " "}
384
        # Images (work for only attached in current page [[Image(picture.gif)]])
385
        # need rules for:  * [[Image(wiki:WikiFormatting:picture.gif)]] (referring to attachment on another page)
386
        #                  * [[Image(ticket:1:picture.gif)]] (file attached to a ticket)
387
        #                  * [[Image(htdocs:picture.gif)]] (referring to a file inside project htdocs)
388
        #                  * [[Image(source:/trunk/trac/htdocs/trac_logo_mini.png)]] (a file in repository) 
389
        text = text.gsub(/\[\[image\((.+?)(?:,.+?)?\)\]\]/i, '!\1!')
390
        
363 391
        text
364 392
      end
365 393

  
......
746 774
    DEFAULT_PORTS = {'mysql' => 3306, 'postgresql' => 5432}
747 775

  
748 776
    prompt('Trac directory') {|directory| TracMigrate.set_trac_directory directory.strip}
749
    prompt('Trac database adapter (sqlite, sqlite3, mysql, postgresql)', :default => 'sqlite') {|adapter| TracMigrate.set_trac_adapter adapter}
777
    prompt('Trac database adapter (sqlite, sqlite3, mysql, postgresql)', :default => 'sqlite3') {|adapter| TracMigrate.set_trac_adapter adapter}
750 778
    unless %w(sqlite sqlite3).include?(TracMigrate.trac_adapter)
751 779
      prompt('Trac database host', :default => 'localhost') {|host| TracMigrate.set_trac_db_host host}
752 780
      prompt('Trac database port', :default => DEFAULT_PORTS[TracMigrate.trac_adapter]) {|port| TracMigrate.set_trac_db_port port}
(1-1/7)