Merge branch 'master' of github.com:warpc/rosa-build
This commit is contained in:
commit
1a62895fd5
|
@ -12,13 +12,13 @@ class PersonalRepositoriesController < ApplicationController
|
|||
|
||||
#TODO: Add git repo move into private repos path.
|
||||
def change_visibility
|
||||
@repository.change_visibility
|
||||
@repository.platform.change_visibility
|
||||
|
||||
redirect_to settings_personal_repository_path(@repository)
|
||||
end
|
||||
|
||||
def settings
|
||||
if @repository.hidden?
|
||||
if @repository.platform.hidden?
|
||||
@urmpi_command = "urpmi -add http://login@password:#{ request.host }/privates/#{ @repository.platform.name }/main/"
|
||||
else
|
||||
@urmpi_command = "urpmi -add http://#{ request.host }/downloads/#{ @repository.platform.name }/main/"
|
||||
|
|
|
@ -13,13 +13,13 @@ module PersonalRepository
|
|||
pl.unixname = "#{self.uname}_personal"
|
||||
pl.platform_type = 'personal'
|
||||
pl.distrib_type = 'mandriva2011'
|
||||
pl.visibility = 'open'
|
||||
pl.save
|
||||
|
||||
rep = pl.repositories.build
|
||||
rep.owner = pl.owner
|
||||
rep.name = 'main'
|
||||
rep.unixname = 'main'
|
||||
rep.visibility = 'open'
|
||||
rep.save
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#require 'lib/build_server.rb'
|
||||
class Platform < ActiveRecord::Base
|
||||
DOWNLOADS_PATH = RAILS_ROOT + '/public/downloads'
|
||||
VISIBILITIES = ['open', 'hidden']
|
||||
|
||||
relationable :as => :target
|
||||
|
||||
belongs_to :parent, :class_name => 'Platform', :foreign_key => 'parent_platform_id'
|
||||
|
@ -31,10 +33,18 @@ class Platform < ActiveRecord::Base
|
|||
|
||||
#attr_accessible :visibility
|
||||
|
||||
after_create lambda {
|
||||
add_downloads_symlink unless self.hidden?
|
||||
}
|
||||
|
||||
def path
|
||||
build_path(unixname)
|
||||
end
|
||||
|
||||
def hidden?
|
||||
self.visibility == 'hidden'
|
||||
end
|
||||
|
||||
def clone(new_name, new_unixname)
|
||||
p = Platform.new
|
||||
p.name = new_name
|
||||
|
@ -62,6 +72,16 @@ class Platform < ActiveRecord::Base
|
|||
rel.save
|
||||
end
|
||||
end
|
||||
|
||||
def change_visibility
|
||||
if !self.hidden?
|
||||
self.update_attribute(:visibility, 'hidden')
|
||||
remove_downloads_symlink
|
||||
else
|
||||
self.update_attribute(:visibility, 'open')
|
||||
add_downloads_symlink
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
|
@ -131,4 +151,21 @@ class Platform < ActiveRecord::Base
|
|||
BuildServer.freeze_platform self.unixname
|
||||
end
|
||||
end
|
||||
|
||||
def symlink_downloads_path
|
||||
"#{ DOWNLOADS_PATH }/#{ self.unixname }"
|
||||
end
|
||||
|
||||
def add_downloads_symlink
|
||||
#raise "Personal platform path #{ symlink_downloads_path } already exists!" if File.exists?(symlink_downloads_path) && File.directory?(symlink_downloads_path)
|
||||
return true if File.exists?(symlink_downloads_path) && File.directory?(symlink_downloads_path)
|
||||
FileUtils.symlink path, symlink_downloads_path
|
||||
end
|
||||
|
||||
def remove_downloads_symlink
|
||||
#raise "Personal platform path #{ symlink_downloads_path } does not exists!" if !(File.exists?(symlink_downloads_path) && File.directory?(symlink_downloads_path))
|
||||
return true if !(File.exists?(symlink_downloads_path) && File.directory?(symlink_downloads_path))
|
||||
FileUtils.rm_rf symlink_downloads_path
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -20,7 +20,7 @@ class Project < ActiveRecord::Base
|
|||
validates :owner, :presence => true
|
||||
validate {errors.add(:base, I18n.t('flash.project.save_warning_ssh_key')) if owner.ssh_key.blank?}
|
||||
|
||||
attr_accessible :category_id, :name, :unixname, :description, :visibility
|
||||
#attr_accessible :category_id, :name, :unixname, :description, :visibility
|
||||
attr_readonly :unixname
|
||||
|
||||
scope :recent, order("name ASC")
|
||||
|
@ -28,11 +28,12 @@ class Project < ActiveRecord::Base
|
|||
scope :by_visibilities, lambda {|v| {:conditions => ['visibility in (?)', v.join(',')]}}
|
||||
scope :addable_to_repository, lambda { |repository_id| where("projects.id NOT IN (SELECT project_to_repositories.project_id FROM project_to_repositories WHERE (project_to_repositories.repository_id != #{ repository_id }))") }
|
||||
|
||||
before_create :create_git_repo, :make_owner_rel
|
||||
before_update :update_git_repo
|
||||
before_destroy :destroy_git_repo
|
||||
before_create :make_owner_rel
|
||||
before_create :xml_rpc_create
|
||||
before_destroy :xml_rpc_destroy
|
||||
before_create :create_git_repo
|
||||
before_update :update_git_repo
|
||||
before_destroy :destroy_git_repo
|
||||
after_create :attach_to_personal_repository
|
||||
|
||||
def project_versions
|
||||
|
@ -72,7 +73,7 @@ class Project < ActiveRecord::Base
|
|||
if result == BuildServer::SUCCESS
|
||||
return true
|
||||
else
|
||||
raise "Failed to add project #{name} to repo #{repo.name} of platform #{platf.name}."
|
||||
raise "Failed to add project #{name} to repo #{repo.name} of platform #{platf.name} with code #{result}."
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -85,7 +86,7 @@ class Project < ActiveRecord::Base
|
|||
if result == BuildServer::SUCCESS
|
||||
return true
|
||||
else
|
||||
raise "Failed to create project #{name} (repo #{repository.name}) inside platform #{repository.platform.name}."
|
||||
raise "Failed to create project #{name} (repo #{repository.name}) inside platform #{repository.platform.name} with code #{result}."
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -132,12 +133,21 @@ class Project < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def xml_rpc_destroy
|
||||
result = BuildServer.delete_project unixname, repository.platform.unixname
|
||||
def xml_rpc_create
|
||||
result = BuildServer.create_project unixname, "#{owner.uname}_personal", 'main', path
|
||||
if result == BuildServer::SUCCESS
|
||||
return true
|
||||
else
|
||||
raise "Failed to delete repository #{name} (repo #{repository.name}) inside platform #{repository.platform.name}."
|
||||
raise "Failed to create project #{name} (repo main) inside platform #{owner.uname}_personal with code #{result}."
|
||||
end
|
||||
end
|
||||
|
||||
def xml_rpc_destroy
|
||||
result = BuildServer.delete_project unixname, "#{owner.uname}_personal"
|
||||
if result == BuildServer::SUCCESS
|
||||
return true
|
||||
else
|
||||
raise "Failed to delete repository #{name} (repo main) inside platform #{owner.uname}_personal with code #{result}."
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,36 +1,60 @@
|
|||
class ProjectToRepository < ActiveRecord::Base
|
||||
belongs_to :project
|
||||
belongs_to :repository
|
||||
|
||||
delegate :path, :to => :project
|
||||
|
||||
before_save :create_link
|
||||
after_destroy :remove_link
|
||||
#before_save :create_link
|
||||
#before_save :add_compability_link
|
||||
#after_destroy :remove_link
|
||||
#after_destroy :remove_compability_link
|
||||
|
||||
after_create lambda {
|
||||
project.xml_rpc_create
|
||||
}
|
||||
|
||||
def path
|
||||
build_path(project.unixname)
|
||||
#def path
|
||||
# build_path(project.unixname)
|
||||
#end
|
||||
|
||||
# This is symbolink to /git_projects/<owner.uname>/<unixname>.git
|
||||
def sym_path
|
||||
"#{ repository.platform.path }/projects/#{ project.unixname }.git"
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def build_path(dir)
|
||||
File.join(repository.path, dir)
|
||||
end
|
||||
#def build_path(dir)
|
||||
# File.join(repository.path, dir)
|
||||
#end
|
||||
|
||||
def create_link
|
||||
exists = File.exists?(path) && File.directory?(path)
|
||||
raise "Symlink #{path} already exists" if exists
|
||||
#def create_link
|
||||
# exists = File.exists?(path) && File.directory?(path)
|
||||
# raise "Symlink #{path} already exists" if exists
|
||||
# if new_record?
|
||||
# FileUtils.ln_s(project.path, path)
|
||||
# end
|
||||
#end
|
||||
#
|
||||
#def remove_link
|
||||
# exists = File.exists?(path) && File.directory?(path)
|
||||
# raise "Directory #{path} didn't exists" unless exists
|
||||
# FileUtils.rm_rf(path)
|
||||
#end
|
||||
|
||||
def add_compability_link
|
||||
exists = File.exists?(sym_path) && File.directory?(sym_path)
|
||||
return false if exists
|
||||
if new_record?
|
||||
FileUtils.ln_s(project.path, path)
|
||||
#FileUtils.ln_s(path, sym_path)
|
||||
system("sudo ln -s #{ path } #{ sym_path }")
|
||||
end
|
||||
end
|
||||
|
||||
def remove_link
|
||||
exists = File.exists?(path) && File.directory?(path)
|
||||
raise "Directory #{path} didn't exists" unless exists
|
||||
FileUtils.rm_rf(path)
|
||||
def remove_compability_link
|
||||
exists = File.exists?(sym_path) && File.directory?(sym_path)
|
||||
return false unless exists
|
||||
#FileUtils.rm_rf(sym_path)
|
||||
system("sudo rm -rf #{ sym_path }")
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
class Repository < ActiveRecord::Base
|
||||
|
||||
DOWNLOADS_PATH = RAILS_ROOT + '/public/downloads'
|
||||
|
||||
VISIBILITIES = ['open', 'hidden']
|
||||
relationable :as => :target
|
||||
|
||||
|
@ -29,19 +27,11 @@ class Repository < ActiveRecord::Base
|
|||
before_create :xml_rpc_create
|
||||
before_destroy :xml_rpc_destroy
|
||||
|
||||
after_create lambda {
|
||||
add_downloads_symlink unless self.hidden?
|
||||
}
|
||||
|
||||
attr_accessible :visibility, :name, :unixname, :platform_id
|
||||
|
||||
def path
|
||||
build_path(unixname)
|
||||
end
|
||||
|
||||
def hidden?
|
||||
self.visibility == 'hidden'
|
||||
end
|
||||
# def path
|
||||
# build_path(unixname)
|
||||
# end
|
||||
|
||||
def clone
|
||||
r = Repository.new
|
||||
|
@ -50,16 +40,6 @@ class Repository < ActiveRecord::Base
|
|||
r.projects = projects.map(&:clone)
|
||||
return r
|
||||
end
|
||||
|
||||
def change_visibility
|
||||
if !self.hidden?
|
||||
self.update_attribute(:visibility, 'hidden')
|
||||
remove_downloads_symlink
|
||||
else
|
||||
self.update_attribute(:visibility, 'open')
|
||||
add_downloads_symlink
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
|
@ -70,26 +50,26 @@ class Repository < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def build_path(dir)
|
||||
File.join(platform.path, dir)
|
||||
end
|
||||
|
||||
def create_directory
|
||||
exists = File.exists?(path) && File.directory?(path)
|
||||
raise "Directory #{path} already exists" if exists
|
||||
if new_record?
|
||||
FileUtils.mkdir_p(path)
|
||||
%w(release updates).each { |subrep| FileUtils.mkdir_p(path + subrep) }
|
||||
elsif unixname_changed?
|
||||
FileUtils.mv(build_path(unixname_was), buildpath(unixname))
|
||||
end
|
||||
end
|
||||
|
||||
def remove_directory
|
||||
exists = File.exists?(path) && File.directory?(path)
|
||||
raise "Directory #{path} didn't exists" unless exists
|
||||
FileUtils.rm_rf(path)
|
||||
end
|
||||
# def build_path(dir)
|
||||
# File.join(platform.path, dir)
|
||||
# end
|
||||
#
|
||||
# def create_directory
|
||||
# exists = File.exists?(path) && File.directory?(path)
|
||||
# raise "Directory #{path} already exists" if exists
|
||||
# if new_record?
|
||||
# FileUtils.mkdir_p(path)
|
||||
# %w(release updates).each { |subrep| FileUtils.mkdir_p(path + subrep) }
|
||||
# elsif unixname_changed?
|
||||
# FileUtils.mv(build_path(unixname_was), buildpath(unixname))
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# def remove_directory
|
||||
# exists = File.exists?(path) && File.directory?(path)
|
||||
# raise "Directory #{path} didn't exists" unless exists
|
||||
# FileUtils.rm_rf(path)
|
||||
# end
|
||||
|
||||
def xml_rpc_create
|
||||
result = BuildServer.create_repo unixname, platform.unixname
|
||||
|
@ -108,21 +88,5 @@ class Repository < ActiveRecord::Base
|
|||
raise "Failed to delete repository #{name} inside platform #{platform.name}."
|
||||
end
|
||||
end
|
||||
|
||||
def symlink_downloads_path
|
||||
"#{ DOWNLOADS_PATH }/#{ self.platform.unixname }"
|
||||
end
|
||||
|
||||
def add_downloads_symlink
|
||||
#raise "Personal platform path #{ symlink_downloads_path } already exists!" if File.exists?(symlink_downloads_path) && File.directory?(symlink_downloads_path)
|
||||
return true if File.exists?(symlink_downloads_path) && File.directory?(symlink_downloads_path)
|
||||
FileUtils.symlink platform.path, symlink_downloads_path
|
||||
end
|
||||
|
||||
def remove_downloads_symlink
|
||||
#raise "Personal platform path #{ symlink_downloads_path } does not exists!" if !(File.exists?(symlink_downloads_path) && File.directory?(symlink_downloads_path))
|
||||
return true if !(File.exists?(symlink_downloads_path) && File.directory?(symlink_downloads_path))
|
||||
FileUtils.rm_rf symlink_downloads_path
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -9,9 +9,9 @@
|
|||
.group
|
||||
%span= t("activerecord.attributes.repository.visibility") + ":"
|
||||
%span
|
||||
%i= t("activerecord.attributes.repository.visibility_types.#{ @repository.visibility }")
|
||||
%i= t("activerecord.attributes.repository.visibility_types.#{ @repository.platform.visibility }")
|
||||
.group
|
||||
= link_to t("layout.personal_repositories.change_visibility_from_#{ @repository.visibility }"), change_visibility_personal_repository_path(@repository)
|
||||
= link_to t("layout.personal_repositories.change_visibility_from_#{ @repository.platform.visibility }"), change_visibility_personal_repository_path(@repository)
|
||||
|
||||
%br
|
||||
.group
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
class RemoveVisibilityFromRepositories < ActiveRecord::Migration
|
||||
def self.up
|
||||
remove_column :repositories, :visibility
|
||||
end
|
||||
|
||||
def self.down
|
||||
add_column :repositories, :visibility, :string, :default => "open"
|
||||
end
|
||||
end
|
13
db/schema.rb
13
db/schema.rb
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20111027230610) do
|
||||
ActiveRecord::Schema.define(:version => 20111028070604) do
|
||||
|
||||
create_table "arches", :force => true do |t|
|
||||
t.string "name", :null => false
|
||||
|
@ -208,20 +208,18 @@ ActiveRecord::Schema.define(:version => 20111027230610) do
|
|||
t.string "object_type"
|
||||
t.integer "target_id"
|
||||
t.string "target_type"
|
||||
t.integer "role_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "repositories", :force => true do |t|
|
||||
t.string "name", :null => false
|
||||
t.integer "platform_id", :null => false
|
||||
t.string "name", :null => false
|
||||
t.integer "platform_id", :null => false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "unixname", :null => false
|
||||
t.string "unixname", :null => false
|
||||
t.integer "owner_id"
|
||||
t.string "owner_type"
|
||||
t.string "visibility", :default => "open"
|
||||
end
|
||||
|
||||
create_table "rights", :force => true do |t|
|
||||
|
@ -271,9 +269,8 @@ ActiveRecord::Schema.define(:version => 20111027230610) do
|
|||
t.datetime "remember_created_at"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "uname"
|
||||
t.text "ssh_key"
|
||||
t.integer "role_id"
|
||||
t.string "uname"
|
||||
t.integer "global_role_id"
|
||||
end
|
||||
|
||||
|
|
|
@ -56,8 +56,8 @@ class BuildServer
|
|||
self.client.call('delete_container', container_id)
|
||||
end
|
||||
|
||||
def self.create_project name, platform_name, repo_name
|
||||
self.client.call('create_project', name, repo_name, platform_name)
|
||||
def self.create_project name, platform_name, repo_name, git_project_path
|
||||
self.client.call('create_project', name, repo_name, platform_name, git_project_path)
|
||||
end
|
||||
|
||||
def self.delete_project name, platform_name
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
/var/rosa/platforms/test2_personal
|
Loading…
Reference in New Issue