-
Notifications
You must be signed in to change notification settings - Fork 1
/
submitproject
executable file
·220 lines (202 loc) · 6.12 KB
/
submitproject
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/usr/bin/env ruby
require 'optparse'
require 'ostruct'
require 'yaml'
require 'tmpdir'
#global variables:
# $logfile
# $osccmd
# $debug_project
def log(message)
unless $logfile
return
end
open($logfile, 'a') { |f|
f.puts message
}
end
# create a submit request
def create_sr(package,from,to)
puts "Creating submit request for package #{package} from #{from} to #{to}"
if $debug_project
to = $debug_project
puts "Creating submit request for package #{package} from #{from} to #{to}"
end
log "Creating submit request for package #{package} from #{from} to #{to}"
if system("#{$osccmd} sr #{from} #{package} #{to}")
request = `#{$osccmd} request list #{to} #{package} |grep "State:\\(new\\|review\\)" |head -n 1 |cut -d\\ -f2`
log "Created request id #{request}"
end
end
#ask a Yes/No question
def ask(question)
puts question
begin
system "stty raw -echo"
out = STDIN.getc.chr.downcase
ensure
system "stty -raw echo"
end
if out == 'c'
exit
elsif out == 'y'
return true
elsif out == 'n'
return false
end
return ask(question)
end
#ask whether to submit a package or not, submit if requested
def ask_submit(package, from, to, question)
ret = false;
if ask question
create_sr(package, from, to)
ret = true
else
puts "Skipping package #{package}"
end
ret
end
# print diff of a specific file; return true if files differ
def file_diff(package, from, to, file)
ret = true;
Dir.mktmpdir {|tmpdir|
files_found = system("cd #{tmpdir} && #{$osccmd} co #{from} #{package} #{file} && mv #{file} #{file}.new && #{$osccmd} co #{to} #{package} #{file} >/dev/null 2>&1")
unless files_found
puts "=== Cannot check out file #{file} from package #{package}"
ret = true
else
ret = ! system("cd #{tmpdir} && diff #{file} #{file}.new")
end
}
ret
end
def changelog_diff(package, from, to)
unless file_diff(package, from, to, "#{package}.changes")
puts "=== Changelog has not changed..."
return false
end
return true
end
def find_package_in_prjlist(package, prjlist)
found=nil
prjlist.each do |project|
if system "#{$osccmd} ls #{project} #{package} >/dev/null 2>/dev/null"
found=project;
break
end
end
found;
end
def find_package(package,projects)
found=nil
projects.each do |prjlist|
project_found = find_package_in_prjlist(package, prjlist)
if project_found != nil
found=[prjlist[0], project_found]
break
end
end
found;
end
def submit_project(project, options)
$logfile = options.logfile
$debug_project = options.debug_project
$osccmd = options.api_url ? "osc -A #{options.api_url} " : "osc "
prjconf = options.prjconf ? options.prjconf : "~/.oscsubmit"
projects = YAML.load_file(File.expand_path(prjconf, __FILE__))
# filter out generated packages
pkglist = `#{$osccmd} ls #{project} |grep -v _product:`
pkglist.split.each do |package|
puts "=== Analyzing package #{package}..."
(target_project, project_found) = find_package(package,projects[project])
if target_project == nil
target_project = projects[project][0][0];
end
package_found = project_found != nil
if package_found
puts "=== Package #{package} found in project #{project_found}"
if (package == "_product")
changed = false;
`#{$osccmd} ls #{project} #{package} |grep '\\(product\\|group\\|spec\\)$'`.split.each do |file|
changed = file_diff(package, project, project_found, file) || changed;
end
if (changed)
ask_submit(package, project, target_project, "=== Submit package #{package} to #{target_project}? (y/n/c)")
else
puts "Package #{package} not changed, skipping..."
end
else
changed = false
if changelog_diff(package, project, project_found)
changed = true
else
diff = `#{$osccmd} rdiff #{project_found} #{package} #{project}`
puts diff
changed = diff != ""
end
if changed
submitted = ask_submit(package, project, target_project, "=== Submit package #{package} to #{target_project}? (y/n/c)")
unless submitted || target_project == projects[project][0][0]
target_project = projects[project][0][0];
ask_submit(package, project, target_project, "=== Submit package #{package} to #{target_project}? (y/n/c)")
end
else
puts "Package #{package} not changed, skipping..."
end
end
else
ask_submit(package, project, target_project, "=== Pakcage #{package} is new. Submit to #{target_project}? (y/n/c)")
end
end
end
def go
options = {}
help = ''
create_opts = OpenStruct.new
parser = OptionParser.new do |opts|
opts.banner = ("Usage: submitproject PROJECT_ID [options]")
opts.separator ""
opts.on("-A", "--apiurl API_URL", String,
"URL of the Open Build Service API") do |api_url|
create_opts.api_url = api_url
end
opts.on("-p", "--prjconf PROJECT_CONFIG", String,
"Configuration of sumit target projects") do |prjconf|
create_opts.prjconf = prjconf
end
opts.on("-l", "--log LOGDILE", String,
"Store information to notify the AutoBuild team") do |logfile|
create_opts.logfile = logfile
end
opts.on("-d", "--debug_project PROJECT", String,
"Create all submit request to different project; for debugging purposes") do |debug_project|
create_opts.debug_project = debug_project
end
opts.on_tail("-h", "--help", "Show this help and exit") do |v|
options[:help] = v
puts opts.to_s
exit 0
end
help = opts.to_s
end.parse!
if ARGV.empty?
$stderr.puts help
exit 1
elsif ARGV.one?
if create_opts.logfile
open(create_opts.logfile, 'w') { |f|
f.puts "Submitting project #{ARGV[0]}"
}
end
submit_project(ARGV[0], create_opts)
else
raise(OptionParser::ParseError,
"Got too many arguments. See --help for usage.")
end
rescue OptionParser::ParseError
$stderr.puts("Could not process command line arguments. "+
"#{$!} #{ARGV.join(' ')}")
exit 1
end
go