hello!

don't know if I invented something new or if perhaps there is better way (I
couldn't find it)..  

That's why I'd like to hear your comments.

the goal is to have multiple trac environments / projects, like this:
/var/trac/project_a
/var/trac/project_b
/var/trac/project_c
...

The server would then be started with something like:
tracd -p 3800 --auth=*,/var/trac/digest,trac /var/trac/project_a
/var/trac/project_b ....

What's the problem with this? The logins are specified in digest file and
shared among the projects, but permissions and user settings (including an
important one - EMAIL), are in sqlite databases for each project.

I wrote a ruby script that creates a new trac environment and copies the
permissions and user settings from the reference project.

It also processes the new project's trac.conf file -> it adds the reference
to the global file (that has just the smtp settings) and removes that
section from the project's trac.conf (so it doesn't override the global
settings, of course).

So this scheme looks pretty maintenable for a while.. If some permission or
email needs to change, then you just change it in the reference project and
run the part of the script that copies permissions from the trac.db.

Please post your comments!

Here is the entire script:
------------------------

require 'rubygems'
require 'sqlite3'

puts "New trac environment directory (example: myproject): "
new_env = gets.chomp
puts "Subversion sub-path (example: projects/something): "
repo_sub_path = gets.chomp

base_path = "/var/trac"
#new_env = ARGV[0]
new_env_path = base_path + "/" + new_env
#repo_sub_path = ARGV[1]

repo_path = "/home/svn/main/" + repo_sub_path

# create new environment
result = system("trac-admin #{new_env_path} initenv #{new_env}
sqlite:db/trac.db svn #{repo_path}")

if(!result)
  puts "\n\nHave you run init_trac with SUDO ?"
  exit
end

# set permissions
puts "setting permissions on /db /attachments /conf ..."
dirs = []
dirs << new_env_path + "/db"
dirs << new_env_path + "/attachments"
dirs << new_env_path + "/conf"

# this is not secure - will have to find out what's the best here
dirs.each do |dir|
  system("chmod -R og+w #{dir}")
end

puts "copying permissions and user settings (name & email) from the main
repo..."

# set source and target databases
db_source = SQLite3::Database.new(base_path + "/projecta/db/trac.db")
db_target = SQLite3::Database.new(new_env_path + "/db/trac.db")

# delete permissions and emails from the target database
db_target.execute("delete from permission");
db_target.execute("delete from session_attribute where name = 'email'");

# copy permissions
db_source.execute("select * from permission") do |row|
  db_target.execute("insert into permission values ( ?, ? )", *row)
end
 
# copy emails
db_source.execute("select * from session_attribute where name = 'email' or
name = 'name'") do |row|
  db_target.execute("insert into session_attribute values ( ?, ?, ?, ? )",
*row)
end

# add reference to global ini file
puts "adding reference to /var/trac/global_trac.inf to the trac.ini"

fout = File.open(new_env_path + "/conf/trac_new.ini", "w")

fout.puts "[inherit]"
fout.puts "file = /var/trac/global_trac.ini"
fout.puts

skip = false

File.open(new_env_path + "/conf/trac.ini").each { |line|
  if line.include?("[notification]")
    skip = true
  elsif line =~ /^[.*?]/ # stop skipping lines when we reach another
[something] directive
    skip = false
  end
    
  fout.puts line.gsub("http://example.org";, "http://dev.my_site.com";) unless
skip
}

fout.close

system("rm #{new_env_path}/conf/trac.ini")
system("mv #{new_env_path}/conf/trac_new.ini #{new_env_path}/conf/trac.ini")



-- 
View this message in context: 
http://www.nabble.com/my-solution-for-multiple-projects..-opinions-tp15135673p15135673.html
Sent from the Trac Users mailing list archive at Nabble.com.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Trac 
Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/trac-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to