Class: Projects

Inherits:
Hash
  • Object
show all
Defined in:
lib/base/projects.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Hash

#execute, #to_html

Constructor Details

#initialize(env = nil) ⇒ Projects

Returns a new instance of Projects.



13
14
15
16
17
# File 'lib/base/projects.rb', line 13

def initialize env=nil
	@env=env if env.kind_of?(Environment)
	@env=Environment.new if @env.nil?
	open
end

Instance Attribute Details

#envObject

Returns the value of attribute env.



11
12
13
# File 'lib/base/projects.rb', line 11

def env
  @env
end

Class Method Details

.currentObject



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/base/projects.rb', line 202

def self.current
	project=nil
	url=Git.remote_origin
	url=Svn.url if url.length==0
	if(Rake.application.original_dir.include?('/wrk/') &&
		   url.length > 0)
		project=Project.new(url)
		fullname=Rake.application.original_dir.gsub("#{Environment.dev_root}/wrk/",'')
		project[:fullname] = name if(name.length>0 && !name.include?(Environment.dev_root))
		if(defined?(PROJECTS))
			PROJECTS[name]=project if(!PROJECTS.has_key?(name))
			project.each{|k,v|PROJECTS[name][k]=v}
			PROJECTS.save
		else
			project[:fullname]=name
		end
	end			
	project
end

.user_projects_filenameObject



197
198
199
200
# File 'lib/base/projects.rb', line 197

def self.user_projects_filename
	FileUtils.mkdir_p("#{Environment.dev_root}/data") if(!File.exists?("#{Environment.dev_root}/data"))
	"#{Environment.dev_root}/data/PROJECTS.json"
end

Instance Method Details

#add(args) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/base/projects.rb', line 72

def add args
	url=args[0]
	project=Project.new(url)
	project[:fullname]=args[1] if args.length > 1
	project.set_timeout args[2] if args.length > 2
	if(!self.has_key?(project[:fullname]) && project[:fullname].length > 0)
		@env.out "adding #{project.fullname}\n"
		self[project.fullname]=project
		self.save
	end
end

#clobber(args) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/base/projects.rb', line 164

def clobber args
		projects=get_projects args
		puts "clobbering #{projects.length} projects..." if @env.debug?
		projects.each{|project|
			begin
   project.clobber
   #Dir.remove_empty @env.wrk_dir
  rescue => error
  	puts "error raised during clobber #{project.fullname}"
  	puts "--------------------------------------------"
  	puts error
  	puts "--------------------------------------------"
  end
		}
end

#currentObject



23
24
25
26
27
28
29
30
# File 'lib/base/projects.rb', line 23

def current
  fullname=Rake.application.original_dir.gsub("#{Environment.default.wrk_dir}/",'')
  if(self.has_key? fullname)
    self[fullname]
  else
    nil
  end
end

#filenameObject



19
20
21
# File 'lib/base/projects.rb', line 19

def filename
	"#{@env.root_dir}/data/Projects.json"
end

#get_projects(value = '') ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/base/projects.rb', line 50

def get_projects value=''
	puts "get_projects #{value.to_s}" if @env.debug?
	puts "get_project total project count #{self.length}" if @env.debug?
	projects=Array.new
	filter=''
	filter=value.to_s if !value.nil? && value.kind_of?(String)
	filter=value[0].to_s if !value.nil? && value.kind_of?(Array) && !value[0].to_s.include?('=')

    puts "get_project filter '#{filter}'" if @env.debug?
	self.each{|k,v|
		puts " checking project #{k}" if @env.debug?
		puts " v.class #{v.class}" if @env.debug?
		if(filter.length==0 || k.include?(filter))
			if(v.kind_of?(Project))
			   projects << v
			   v.env=@env
			end
		end
	}
	projects
end

#help(args) ⇒ Object



97
98
# File 'lib/base/projects.rb', line 97

def help args
end

#import(pattern = '') ⇒ Object



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/base/projects.rb', line 229

def import pattern=''
	wrk=@env.wrk_dir
	if File.exists?(wrk)
	   Dir.chdir(wrk) do
	   	    puts "scanning #{wrk} for imports..."
	   		Dir.glob('**/rakefile.rb').each{|rakefile|
	   			rakedir=File.dirname(rakefile)
	   			url = Project.get_url rakedir
	   			project = Project.new(Project.get_url(rakedir))
	   			project[:fullname]=rakedir.gsub(@env.wrk_dir,'') if(project.fullname.include?(':'))
	   			if(pattern.length==0 || project.fullname.include?(pattern))
	   				if(project.fullname.length > 0 && !self.has_key?(project.fullname))
	   				    puts "importing #{project.fullname}"
	   				    self[project.fullname]=project
	   			    end
	   			end
	   		}
	   end
	   self.save
    end
end

#info(args) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/base/projects.rb', line 118

def info args
	projects=get_projects args
	puts "collecting info for #{projects.length} projects..." if @env.debug?
	exit_code=0
   	projects.each{|project|
   		begin
   		    result=project.info
   		    exit_code=result.exit_code if(result.exit_code!=0)
   		rescue => error
	    	puts "error raised during work #{project.fullname}"
	    	puts "--------------------------------------------"
	    	puts error
	    	puts "--------------------------------------------"
	    end
   	}
   	exit_code
end

#list(args) ⇒ Object



136
137
138
139
140
141
142
143
144
# File 'lib/base/projects.rb', line 136

def list args
   	projects=get_projects args
	puts "listing #{projects.length} projects..." if @env.debug?
   	projects.each{|project|
   		project.list
   		
   	}
   	return 0
end

#make(args) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/base/projects.rb', line 146

def make args
	projects=get_projects args
	puts "making #{projects.length} projects..." if @env.debug?
	exit_code=0
	projects.each{|project|
		begin
		    result=project.make
		    exit_code=result.exit_code if(result.exit_code!=0)
	    rescue => error
	    	puts "error raised during make #{project.fullname}"
	    	puts "--------------------------------------------"
	    	puts error
	    	puts "--------------------------------------------"
	    end
	}
	exit_code
end

#openObject



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/base/projects.rb', line 37

def open
	if File.exists? filename
	  JSON.parse(IO.read(filename)).each{|k,v|
	  	if(v.kind_of?(Project))
	  		self[k]=v
	  	else
	  		self[k]=Project.new(v)
	  	end
	}
	  #update_state
    end
end

#pullObject



222
223
224
# File 'lib/base/projects.rb', line 222

def pull
	self.each{|k,v| v.pull if v.respond_to?("pull".to_sym)}
end

#rakeObject



225
226
227
# File 'lib/base/projects.rb', line 225

def rake
	self.each{|k,v| v.rake if v.respond_to?("rake".to_sym)}
end

#remove(args) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/base/projects.rb', line 84

def remove args
   	projects=get_projects args
	puts "removing #{projects.length} projects..." if @env.debug?
	remove_keys=[]
   	projects.each{|project|
   		project.clobber
   		remove_keys << project.fullname
   	}
   	remove_keys.each{|key|self.delete(key)}
   	self.save
   	return 0
end

#saveObject



32
33
34
35
# File 'lib/base/projects.rb', line 32

def save
	Dir.make File.dirname(filename) if !File.exists? File.dirname(filename)
	File.open(filename,'w'){|f|f.write(JSON.pretty_generate(self))}
end

#update(args) ⇒ Object



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/base/projects.rb', line 180

def update args
	projects=get_projects args
	puts "updating #{projects.length} projects..." if @env.debug?
	projects.each{|project|
	    begin
	    	puts "updating #{project.fullname}" if @env.debug?
   		    result=project.update
   		    exit_code=result.exit_code if(result.exit_code!=0)
   		rescue => error
	    	puts "error raised during update #{project.fullname}"
	    	puts "--------------------------------------------"
	    	puts error
	    	puts "--------------------------------------------"
	    end
	}
end

#work(args) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/base/projects.rb', line 100

def work args
   	projects=get_projects args
	puts "working #{projects.length} projects..." if @env.debug?
	exit_code=0
   	projects.each{|project|
   		begin
   		    result=project.work
   		    exit_code=result.exit_code if(result.exit_code!=0)
   		rescue => error
	    	puts "error raised during work #{project.fullname}"
	    	puts "--------------------------------------------"
	    	puts error
	    	puts "--------------------------------------------"
	    end
   	}
   	exit_code
end