~ubuntu-branches/debian/sid/calligraplan/sid

« back to all changes in this revision

Viewing changes to devtools/release/plan_create_tarball.rb

  • Committer: Package Import Robot
  • Author(s): Pino Toscano
  • Date: 2018-02-01 18:20:19 UTC
  • Revision ID: package-import@ubuntu.com-20180201182019-1qo7qaim5wejm5k9
Tags: upstream-3.1.0
ImportĀ upstreamĀ versionĀ 3.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/ruby
 
2
#
 
3
# Ruby script for generating tarball releases of the Plan repository
 
4
# This script can create signed tarballs with source code and translations.
 
5
# Documentation is not supported atm.
 
6
#
 
7
# (c) 2017 Dag Andersen <danders@get2net.dk>
 
8
# (c) 2016 Dag Andersen <danders@get2net.dk>
 
9
#
 
10
# Parts of this script is from create_tarball_kf5.rb, copyright by:
 
11
# (c) 2005 Mark Kretschmann <markey@web.de>
 
12
# (c) 2006-2008 Tom Albers <tomalbers@kde.nl>
 
13
# (c) 2007 Angelo Naselli <anaselli@linux.it> (command line parameters)
 
14
# Some parts of this code taken from cvs2dist
 
15
#
 
16
# License: GNU General Public License V2
 
17
 
 
18
require 'optparse'
 
19
require 'ostruct'
 
20
require 'find'
 
21
require 'fileutils'
 
22
 
 
23
# check command line parameters
 
24
options = OpenStruct.new
 
25
options.help  = false
 
26
options.sign  = true
 
27
options.program = "gpg2"
 
28
options.translations = true
 
29
options.docs = false
 
30
options.languages = []
 
31
options.branch = "trunk"
 
32
options.tag = "HEAD"
 
33
options.checkversion = true
 
34
#options.version = ""
 
35
options.cstring = ""
 
36
options.infolevel = 0
 
37
 
 
38
opts = OptionParser.new do |opts|
 
39
    opts.on_tail("-h", "--help", "Show this usage statement") do |h|
 
40
        options.help = true
 
41
    end
 
42
    opts.on("-v", "--version <version>", "Package version (Default: no version)") do |v|
 
43
        options.version = v
 
44
    end
 
45
    opts.on("-c", "--cstring <version string>", "Version string to check against version string in CMakeList.txt (Default: use version given in --version option)") do |c|
 
46
        options.cstring = c
 
47
    end
 
48
    opts.on("-n", "--no-check", "Disable version check") do |n|
 
49
        options.checkversion = false;
 
50
    end
 
51
    opts.on("-g", "--gittag <tag>", "Git tag (Default: 'HEAD')") do |g|
 
52
        options.tag = g
 
53
    end
 
54
    opts.on("-t", "--no-translations", "Do not include translations (Default: translations included)") do |t|
 
55
        options.translations = false
 
56
    end
 
57
    opts.on("-b", "--branch", "Translation branch [trunk/stable] (Default: 'trunk')") do |t|
 
58
        options.translations = false
 
59
    end
 
60
    #    opts.on("-d", "--docs", "TODO Include documentation (Default: docs not included)") do |d|
 
61
        # TODO
 
62
        #options.translations = true
 
63
#    end
 
64
    opts.on("-s", "--no-sign", "Do not sign tarball (Default: tarball is signed)") do |s|
 
65
        options.sign = false
 
66
    end
 
67
    opts.on("-p", "--program <program>", "Which program to use for signing (Default: gpg2)") do |p|
 
68
        options.program = p
 
69
    end
 
70
    opts.on("-l", "--languages <language,..>", "Include comma separated list of languages only (Default: All available languages)") do |l|
 
71
        options.languages = l.split(/\s*,\s*/)
 
72
    end
 
73
    opts.on("-i", "--infolevel <level>", "Select amount of info to print during processing (0-2) (Default: 0)") do |i|
 
74
        options.infolevel = i.to_i
 
75
    end
 
76
end
 
77
 
 
78
begin
 
79
  opts.parse!(ARGV)
 
80
rescue Exception => e
 
81
  puts e, "", opts
 
82
  puts
 
83
  exit
 
84
end
 
85
 
 
86
if (options.help)
 
87
  puts
 
88
  puts opts
 
89
  puts
 
90
  exit
 
91
end
 
92
 
 
93
############# START #############
 
94
    
 
95
app = "calligraplan"
 
96
 
 
97
if options.checkversion
 
98
    if options.cstring.empty?
 
99
        options.cstring = options.version
 
100
    end
 
101
else
 
102
    options.cstring = "No check"
 
103
end
 
104
 
 
105
puts
 
106
puts "-> Processing " + app
 
107
puts  "            Git tag: #{options.tag}"
 
108
puts  "            Version: #{options.version}"
 
109
puts  "      Version check: #{options.cstring}"
 
110
puts  "             Signed: #{options.sign}"
 
111
puts  "            Program: #{options.program}"
 
112
puts  "       Translations: #{options.translations}"
 
113
puts  "             Branch: #{options.branch}"
 
114
print "          Languages: "
 
115
if options.translations
 
116
    if (options.languages.empty?)
 
117
        puts "all"
 
118
    else
 
119
        puts "#{options.languages}"
 
120
    end
 
121
else
 
122
    # no translation, so no languages
 
123
    puts
 
124
end
 
125
# TODO
 
126
# puts "      Documentation: #{options.docs}"
 
127
# puts
 
128
 
 
129
print "Continue? [Y/n]: "
 
130
answer = gets
 
131
answer = answer.lstrip.rstrip.chomp
 
132
if answer.empty?
 
133
    answer = "Y"
 
134
end
 
135
if not answer == "Y"
 
136
    exit
 
137
end
 
138
puts
 
139
 
 
140
gitdir = "calligraplan"
 
141
if options.version
 
142
    gitdir += "-" + options.version
 
143
end
 
144
gittar = "#{gitdir}.tar.xz"
 
145
gitsig = "#{gittar}.sig"
 
146
sumsfile = "#{gittar}.sums"
 
147
 
 
148
puts "-- Create tarball of Calligra Plan: " + gittar
 
149
 
 
150
# clean up first, in case
 
151
calligradir = ".calligra"
 
152
`rm -rf #{calligradir} 2> /dev/null`
 
153
`rm -rf #{gitdir} 2> /dev/null`
 
154
if File.exist?(gittar)
 
155
    File.delete(gittar)
 
156
end
 
157
if File.exist?(gitsig)
 
158
    File.delete(gitsig)
 
159
end
 
160
if File.exist?(sumsfile)
 
161
    File.delete(sumsfile)
 
162
end
 
163
 
 
164
Dir.mkdir(calligradir)
 
165
Dir.chdir(calligradir)
 
166
puts "-> Fetching git archive tag=#{options.tag} .."
 
167
`git archive --remote git://anongit.kde.org/calligra.git #{options.tag} | tar -x`
 
168
Dir.chdir("..")
 
169
 
 
170
# get plan and get rid of rest of calligra
 
171
`mv #{calligradir}/plan #{gitdir}`
 
172
`rm -rf #{calligradir}`
 
173
 
 
174
Dir.chdir(gitdir)
 
175
 
 
176
if !File.exist?("CMakeLists.txt")
 
177
    puts
 
178
    puts "Failed: 'git archive' failed to fetch repository"
 
179
    puts
 
180
    exit
 
181
end
 
182
 
 
183
if options.checkversion
 
184
    cversion=`grep '(PLAN_VERSION_STRING' CMakeLists.txt | cut -d'"' -f2`
 
185
    cversion = cversion.delete("\n").delete("\r").strip
 
186
    cstring = options.version
 
187
    if options.cstring
 
188
        cstring = options.cstring
 
189
    end
 
190
    if cversion != cstring
 
191
        puts
 
192
        puts "Failed: Specified version is not the same as in CMakeLists.txt"
 
193
        puts "        Specified version: '#{cstring}'"
 
194
        puts "        CMakeLists.txt   : '#{cversion}'"
 
195
        puts
 
196
        puts "        Did you forget to update version in CMakeLists.txt?"
 
197
        puts
 
198
        puts "        You can disable this test with the option: --no-check"
 
199
        puts
 
200
        exit
 
201
    end
 
202
end
 
203
 
 
204
# translations
 
205
if options.translations
 
206
    
 
207
    svnbase = "svn+ssh://svn@svn.kde.org/home/kde"
 
208
    
 
209
    if options.branch == "trunk"
 
210
        svnroot = "#{svnbase}/trunk"
 
211
    else
 
212
        svnroot = "#{svnbase}/branches/stable"
 
213
    end
 
214
    rev = ""
 
215
    
 
216
    puts "-> Fetching po file names .."
 
217
    Dir.mkdir("po")
 
218
    if FileTest.exist?("po_tmp")
 
219
        `rm -rf "po_tmp"`
 
220
    end
 
221
    Dir.mkdir("po_tmp")
 
222
    pofilenames = "po_tmp/pofilenames"
 
223
    `x=$(find $gitdir -name 'Messages.sh' | while read messagefile; do \
 
224
            if grep -q '^potfilename=' $messagefile; then \
 
225
                cat $messagefile | grep '^potfilename=' | cut -d'=' -f2 | cut -d'.' -f1; \
 
226
            fi; \
 
227
        done);\
 
228
    echo "$x" >#{pofilenames}`
 
229
 
 
230
    if !File.size?(pofilenames)
 
231
        puts "Failed: Could not fetch any po file names"
 
232
        exit
 
233
    end
 
234
    if options.infolevel > 0
 
235
        c = `wc -l #{pofilenames} | cut -d' ' -f1`
 
236
        puts "     Number of po file names found: " + c
 
237
    end
 
238
 
 
239
    puts "-> Fetching translations .."
 
240
 
 
241
    # get languages
 
242
    i18nlangs = `svn cat #{svnroot}/l10n-kf5/subdirs #{rev}`.split
 
243
    i18nlangsCleaned = []
 
244
    for lang in i18nlangs
 
245
        l = lang.chomp
 
246
        if !options.languages.empty?
 
247
            if options.languages.include?(l)
 
248
                i18nlangsCleaned += [l]
 
249
            end
 
250
        else l != "x-test" && !i18nlangsCleaned.include?(l)
 
251
            i18nlangsCleaned += [l]
 
252
        end
 
253
    end
 
254
    i18nlangs = i18nlangsCleaned
 
255
 
 
256
    if FileTest.exist?("po")
 
257
        `rm -rf "po"`
 
258
    end
 
259
    Dir.mkdir("po")
 
260
    for lang in i18nlangs
 
261
        lang.chomp!
 
262
        tmp = "po_tmp/#{lang}"
 
263
        dest = "po/#{lang}"
 
264
 
 
265
        # always checkout all po-files
 
266
        print "  -> Fetching #{lang} from repository ..\n"
 
267
        pofolder = "l10n-kf5/#{lang}/messages/calligra"
 
268
        if options.infolevel > 0
 
269
            `svn co #{svnroot}/#{pofolder} #{tmp}`
 
270
        else
 
271
            `svn co #{svnroot}/#{pofolder} #{tmp} 2>/dev/null`
 
272
        end
 
273
 
 
274
        # copy over the po-files we actually use in calligraplan
 
275
        File.foreach(pofilenames) do |pofile|
 
276
            pofile.chomp!
 
277
            pofilepath = "#{tmp}/#{pofile}.po"
 
278
            if !FileTest.exist?(pofilepath)
 
279
                # all files have not always been translated
 
280
                if options.infolevel > 1
 
281
                    puts "     Skipping #{pofilepath} .."
 
282
                end
 
283
                next
 
284
            end
 
285
            if !FileTest.exist?(dest)
 
286
                Dir.mkdir(dest)
 
287
            end
 
288
            if FileTest.exist?(pofilepath)
 
289
                if options.infolevel > 0
 
290
                    puts "     Copying #{pofile}.po .."
 
291
                end
 
292
                `mv #{pofilepath} #{dest}`
 
293
            end
 
294
        end
 
295
    end
 
296
    # remove temporary po dir
 
297
    `rm -rf "po_tmp"`
 
298
    
 
299
    # add l10n to compilation.
 
300
    `echo "find_package(KF5I18n CONFIG REQUIRED)" >> CMakeLists.txt`
 
301
    `echo "ki18n_install(po)" >> CMakeLists.txt`
 
302
 
 
303
    if options.docs
 
304
        # add docs to compilation.
 
305
        `echo "find_package(KF5DocTools CONFIG REQUIRED)" >> CMakeLists.txt`
 
306
        `echo "kdoctools_install(po)" >> CMakeLists.txt`
 
307
    end
 
308
end
 
309
 
 
310
# Remove cruft
 
311
`find -name ".svn" | xargs rm -rf`
 
312
 
 
313
Dir.chdir( ".." ) # root folder
 
314
 
 
315
print "-> Compressing ..  "
 
316
`tar -Jcf #{gittar} --group=root --owner=root  #{gitdir}`
 
317
puts " done."
 
318
puts ""
 
319
 
 
320
sums = File.open(sumsfile, 'w')
 
321
sums << "sha1sum  : " << `sha1sum #{gittar}`
 
322
sums << "sha256sum: " << `sha256sum #{gittar}`
 
323
 
 
324
if (options.sign)
 
325
    puts "-> Signing ..  "
 
326
    `#{options.program} -a --output #{gitsig} --detach-sign #{gittar}`
 
327
 
 
328
    sums << "sha1sum  : " << `sha1sum #{gitsig}`
 
329
    sums << "sha256sum: " << `sha256sum #{gitsig}`
 
330
end
 
331
 
 
332
sums.close()
 
333
 
 
334
puts "Sums have been written too: #{sumsfile}"
 
335
puts