<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: trac code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 24 Jul 2008 05:19:48 GMT</pubDate>
    <description>DZone Snippets: trac code</description>
    <item>
      <title>Trac Wiki to GitHub Wiki</title>
      <link>http://snippets.dzone.com/posts/show/5304</link>
      <description>A rough start of a script to help convert the wiki syntax of Trac pages to GitHub-friendly syntax.&lt;br /&gt;&lt;br /&gt;Some TLC is still needed on each output page, but better than doing it all by hand.&lt;br /&gt;&lt;br /&gt;Project lives here: &lt;a href="http://github.com/seven1m/trac_wiki_to_github"&gt;github.com/seven1m/trac_wiki_to_github&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/env ruby&lt;br /&gt; &lt;br /&gt;TRAC_DB_PATH = 'trac.db'&lt;br /&gt;OUT_PATH = 'wiki'&lt;br /&gt;GITHUB_WIKI_URL = '/seven1m/onebody/wikis/'&lt;br /&gt; &lt;br /&gt;require 'sqlite3'&lt;br /&gt; &lt;br /&gt;db = SQLite3::Database.new(TRAC_DB_PATH)&lt;br /&gt;pages = db.execute('select name, text from wiki w2 where version = (select max(version) from wiki where name = w2.name);')&lt;br /&gt; &lt;br /&gt;pages.each do |title, body|&lt;br /&gt;  File.open(File.join(OUT_PATH, title.gsub(/\s/, '')), 'w') do |file|&lt;br /&gt;    body.gsub!(/\{\{\{([^\n]+?)\}\}\}/, '&lt;code&gt;\1&lt;/' + 'code&gt;')&lt;br /&gt;    body.gsub!(/\{\{\{(.+?)\}\}\}/m, '&lt;pre&gt;&lt;code&gt;\1&lt;/' + 'code&gt;&lt;/pre&gt;')&lt;br /&gt;    body.gsub!(/====\s(.+?)\s====/, 'h4. \1')&lt;br /&gt;    body.gsub!(/===\s(.+?)\s===/, 'h3. \1')&lt;br /&gt;    body.gsub!(/==\s(.+?)\s==/, 'h2. \1')&lt;br /&gt;    body.gsub!(/=\s(.+?)\s=[\s\n]*/, '')&lt;br /&gt;    body.gsub!(/\[(http[^\s\[\]]+)\s([^\[\]]+)\]/, '"\2":\1')&lt;br /&gt;    body.gsub!(/\[([^\s]+)\s(.+)\]/, '"\2":' + GITHUB_WIKI_URL + '\1')&lt;br /&gt;    body.gsub!(/([^"\/\!])(([A-Z][a-z0-9]+){2,})/, '\1[[\2]]')&lt;br /&gt;    body.gsub!(/\!(([A-Z][a-z0-9]+){2,})/, '\1')&lt;br /&gt;    body.gsub!(/'''(.+)'''/, '*\1*')&lt;br /&gt;    body.gsub!(/''(.+)''/, '_\1_')&lt;br /&gt;    body.gsub!(/^\s\*/, '*')&lt;br /&gt;    body.gsub!(/^\s\d\./, '#')&lt;br /&gt;    file.write(body)&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 02 Apr 2008 02:05:02 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5304</guid>
      <author>timmorgan (Tim Morgan)</author>
    </item>
    <item>
      <title>Trac Subversion Repository scraper</title>
      <link>http://snippets.dzone.com/posts/show/3376</link>
      <description>Ruby script to pull code from a Trac repo browser.  Useful if you are behind a firewall/proxy and the server has no http access to the subversion repo. (I'm sure its not the prettiest/best/rubiest way to do it, but it worked for me)&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/env ruby&lt;br /&gt;&lt;br /&gt;require 'rubygems'&lt;br /&gt;require 'hpricot'&lt;br /&gt;require 'open-uri'&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#a Trac repo scraper. pass the url to scrape (the root of a repo)&lt;br /&gt;#  and optionally the local path to write to.  defaults to .&lt;br /&gt;&lt;br /&gt;class TracRepoScraper&lt;br /&gt;&lt;br /&gt;  def initialize(trac_url, local_path='.')&lt;br /&gt;    @trac_url = trac_url&lt;br /&gt;&lt;br /&gt;    trac_url =~ /(http:\/\/.*?)\//&lt;br /&gt;    @trac_server = $1&lt;br /&gt;    @local_path =  local_path&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;  def getallfiles(url,cur_localpath)&lt;br /&gt;    if cur_localpath != '.'&lt;br /&gt;      Dir.mkdir(cur_localpath)&lt;br /&gt;    end&lt;br /&gt;    doc = Hpricot(open(url).read)&lt;br /&gt;    doc.search("//tbody//tr//td//a[@class='file']").each do |file_anchor|&lt;br /&gt;      #get the file as curpath+/file_name&lt;br /&gt;&lt;br /&gt;      #following gives us absolute path (excluding domain)&lt;br /&gt;      actual_file_url = @trac_server + file_anchor['href']+'?format=raw'&lt;br /&gt;      #temp&lt;br /&gt;      puts "Saving #{actual_file_url} to #{cur_localpath}/#{file_anchor.inner_html}"&lt;br /&gt;      #read the file and write to a file in the correct directory&lt;br /&gt;      File.open(cur_localpath+"/"+file_anchor.inner_html, 'w') do |f|&lt;br /&gt;        remote_file = open(actual_file_url)&lt;br /&gt;        remote_file.each { |line|&lt;br /&gt;          f.puts(line)&lt;br /&gt;        }&lt;br /&gt;      end&lt;br /&gt;    end&lt;br /&gt;&lt;br /&gt;    doc.search("//tbody//tr//td//a[@class='dir']").each do |dir_anchor|&lt;br /&gt;      #go into the directory&lt;br /&gt;      dir_url = @trac_server + dir_anchor['href']&lt;br /&gt;      puts "*** stepping into #{dir_url}"&lt;br /&gt;      #dir_anchor.inner_html is the name of the subdirectory (relative)&lt;br /&gt;      getallfiles(dir_url, cur_localpath+"/"+dir_anchor.inner_html)&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;  def start&lt;br /&gt;    getallfiles(@trac_url, @local_path)&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#### main&lt;br /&gt;&lt;br /&gt;trac_url = ARGV[0]&lt;br /&gt;localpath = '.'&lt;br /&gt;if ARGV[1]&lt;br /&gt;  if !ARGV[1].strip.empty?&lt;br /&gt;    localpath = ARGV[1].strip&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;TracRepoScraper.new(trac_url, localpath).start&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 27 Jan 2007 02:25:10 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3376</guid>
      <author>deanh (Dean Holdren)</author>
    </item>
    <item>
      <title>Trac installation on its own subdomain</title>
      <link>http://snippets.dzone.com/posts/show/1033</link>
      <description>Most installation documents of Trac show how to install to a directory in the main site's domain. For installation into a subdomain, the Trac data and CGI script should be installed into trac.domain.com/htdocs/trac/, with the following in the Apache config file:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;Directory /path/to/trac.domain.com/htdocs/trac/&gt;&lt;br /&gt;  AllowOverride None&lt;br /&gt;  Options ExecCGI&lt;br /&gt;  AddHandler cgi-script .cgi&lt;br /&gt;  Order allow,deny&lt;br /&gt;  Allow from all&lt;br /&gt;&lt;/Directory&gt;&lt;br /&gt;&lt;br /&gt;&lt;VirtualHost 1.2.3.4&gt;&lt;br /&gt;  ServerName trac.domain.com&lt;br /&gt;  DocumentRoot /path/to/trac.domain.com/htdocs/&lt;br /&gt;&lt;br /&gt;  RewriteEngine On&lt;br /&gt;  RewriteCond %{REQUEST_URI} !^/cgi-bin/&lt;br /&gt;  RewriteCond %{REQUEST_URI} !^/trac/&lt;br /&gt;  RewriteRule ^/(.*) /trac/trac.cgi/$1 [L]&lt;br /&gt;&lt;br /&gt;  &lt;Location /&gt;&lt;br /&gt;    SetEnv TRAC_ENV "/var/lib/trac/projname"&gt;&lt;br /&gt;  &lt;/Location&gt;&lt;br /&gt;&lt;/VirtualHost&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 29 Dec 2005 15:59:04 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1033</guid>
      <author>chipx86 (Christian Hammond)</author>
    </item>
  </channel>
</rss>
