Warning, file /office/calligraplan/devtools/release/plan_create_tarball.rb was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 #!/usr/bin/ruby
0002 #
0003 # Ruby script for generating tarball releases of the Plan repository
0004 # This script can create signed tarballs with source code and translations.
0005 # Documentation is not supported atm.
0006 #
0007 # (c) 2017 Dag Andersen <danders@get2net.dk>
0008 # (c) 2016 Dag Andersen <danders@get2net.dk>
0009 #
0010 # Parts of this script is from create_tarball_kf5.rb, copyright by:
0011 # (c) 2005 Mark Kretschmann <markey@web.de>
0012 # (c) 2006-2008 Tom Albers <tomalbers@kde.nl>
0013 # (c) 2007 Angelo Naselli <anaselli@linux.it> (command line parameters)
0014 # Some parts of this code taken from cvs2dist
0015 #
0016 # License: GNU General Public License V2
0017 
0018 require 'optparse'
0019 require 'ostruct'
0020 require 'find'
0021 require 'fileutils'
0022 
0023 # check command line parameters
0024 options = OpenStruct.new
0025 options.help  = false
0026 options.sign  = true
0027 options.program = "gpg2"
0028 options.translations = true
0029 options.docs = false
0030 options.languages = []
0031 options.branch = "trunk"
0032 options.tag = "HEAD"
0033 options.checkversion = true
0034 #options.version = ""
0035 options.cstring = ""
0036 options.infolevel = 0
0037 
0038 opts = OptionParser.new do |opts|
0039     opts.on_tail("-h", "--help", "Show this usage statement") do |h|
0040         options.help = true
0041     end
0042     opts.on("-v", "--version <version>", "Package version (Default: no version)") do |v|
0043         options.version = v
0044     end
0045     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|
0046         options.cstring = c
0047     end
0048     opts.on("-n", "--no-check", "Disable version check") do |n|
0049         options.checkversion = false;
0050     end
0051     opts.on("-g", "--gittag <tag>", "Git tag (Default: 'HEAD')") do |g|
0052         options.tag = g
0053     end
0054     opts.on("-t", "--no-translations", "Do not include translations (Default: translations included)") do |t|
0055         options.translations = false
0056     end
0057     opts.on("-b", "--branch", "Translation branch [trunk/stable] (Default: 'trunk')") do |t|
0058         options.translations = false
0059     end
0060     #    opts.on("-d", "--docs", "TODO Include documentation (Default: docs not included)") do |d|
0061         # TODO
0062         #options.translations = true
0063 #    end
0064     opts.on("-s", "--no-sign", "Do not sign tarball (Default: tarball is signed)") do |s|
0065         options.sign = false
0066     end
0067     opts.on("-p", "--program <program>", "Which program to use for signing (Default: gpg2)") do |p|
0068         options.program = p
0069     end
0070     opts.on("-l", "--languages <language,..>", "Include comma separated list of languages only (Default: All available languages)") do |l|
0071         options.languages = l.split(/\s*,\s*/)
0072     end
0073     opts.on("-i", "--infolevel <level>", "Select amount of info to print during processing (0-2) (Default: 0)") do |i|
0074         options.infolevel = i.to_i
0075     end
0076 end
0077 
0078 begin
0079   opts.parse!(ARGV)
0080 rescue Exception => e
0081   puts e, "", opts
0082   puts
0083   exit
0084 end
0085 
0086 if (options.help)
0087   puts
0088   puts opts
0089   puts
0090   exit
0091 end
0092 
0093 ############# START #############
0094     
0095 app = "calligraplan"
0096 
0097 if options.checkversion
0098     if options.cstring.empty?
0099         options.cstring = options.version
0100     end
0101 else
0102     options.cstring = "No check"
0103 end
0104 
0105 puts
0106 puts "-> Processing " + app
0107 puts  "            Git tag: #{options.tag}"
0108 puts  "            Version: #{options.version}"
0109 puts  "      Version check: #{options.cstring}"
0110 puts  "             Signed: #{options.sign}"
0111 puts  "            Program: #{options.program}"
0112 puts  "       Translations: #{options.translations}"
0113 puts  "             Branch: #{options.branch}"
0114 print "          Languages: "
0115 if options.translations
0116     if (options.languages.empty?)
0117         puts "all"
0118     else
0119         puts "#{options.languages}"
0120     end
0121 else
0122     # no translation, so no languages
0123     puts
0124 end
0125 # TODO
0126 # puts "      Documentation: #{options.docs}"
0127 # puts
0128 
0129 print "Continue? [Y/n]: "
0130 answer = gets
0131 answer = answer.lstrip.rstrip.chomp
0132 if answer.empty?
0133     answer = "Y"
0134 end
0135 if not answer == "Y"
0136     exit
0137 end
0138 puts
0139 
0140 gitdir = "calligraplan"
0141 if options.version
0142     gitdir += "-" + options.version
0143 end
0144 gittar = "#{gitdir}.tar.xz"
0145 gitsig = "#{gittar}.sig"
0146 sumsfile = "#{gittar}.sums"
0147 
0148 puts "-- Create tarball of Calligra Plan: " + gittar
0149 
0150 # clean up first, in case
0151 calligradir = ".calligra"
0152 `rm -rf #{calligradir} 2> /dev/null`
0153 `rm -rf #{gitdir} 2> /dev/null`
0154 if File.exist?(gittar)
0155     File.delete(gittar)
0156 end
0157 if File.exist?(gitsig)
0158     File.delete(gitsig)
0159 end
0160 if File.exist?(sumsfile)
0161     File.delete(sumsfile)
0162 end
0163 
0164 Dir.mkdir(calligradir)
0165 Dir.chdir(calligradir)
0166 puts "-> Fetching git archive tag=#{options.tag} .."
0167 `git archive --remote git://anongit.kde.org/calligra.git #{options.tag} | tar -x`
0168 Dir.chdir("..")
0169 
0170 # get plan and get rid of rest of calligra
0171 `mv #{calligradir}/plan #{gitdir}`
0172 `rm -rf #{calligradir}`
0173 
0174 Dir.chdir(gitdir)
0175 
0176 if !File.exist?("CMakeLists.txt")
0177     puts
0178     puts "Failed: 'git archive' failed to fetch repository"
0179     puts
0180     exit
0181 end
0182 
0183 if options.checkversion
0184     cversion=`grep '(PLAN_VERSION_STRING' CMakeLists.txt | cut -d'"' -f2`
0185     cversion = cversion.delete("\n").delete("\r").strip
0186     cstring = options.version
0187     if options.cstring
0188         cstring = options.cstring
0189     end
0190     if cversion != cstring
0191         puts
0192         puts "Failed: Specified version is not the same as in CMakeLists.txt"
0193         puts "        Specified version: '#{cstring}'"
0194         puts "        CMakeLists.txt   : '#{cversion}'"
0195         puts
0196         puts "        Did you forget to update version in CMakeLists.txt?"
0197         puts
0198         puts "        You can disable this test with the option: --no-check"
0199         puts
0200         exit
0201     end
0202 end
0203 
0204 # translations
0205 if options.translations
0206     
0207     svnbase = "svn+ssh://svn@svn.kde.org/home/kde"
0208     
0209     if options.branch == "trunk"
0210         svnroot = "#{svnbase}/trunk"
0211     else
0212         svnroot = "#{svnbase}/branches/stable"
0213     end
0214     rev = ""
0215     
0216     puts "-> Fetching po file names .."
0217     Dir.mkdir("po")
0218     if FileTest.exist?("po_tmp")
0219         `rm -rf "po_tmp"`
0220     end
0221     Dir.mkdir("po_tmp")
0222     pofilenames = "po_tmp/pofilenames"
0223     `x=$(find $gitdir -name 'Messages.sh' | while read messagefile; do \
0224             if grep -q '^potfilename=' $messagefile; then \
0225                 cat $messagefile | grep '^potfilename=' | cut -d'=' -f2 | cut -d'.' -f1; \
0226             fi; \
0227         done);\
0228     echo "$x" >#{pofilenames}`
0229 
0230     if !File.size?(pofilenames)
0231         puts "Failed: Could not fetch any po file names"
0232         exit
0233     end
0234     if options.infolevel > 0
0235         c = `wc -l #{pofilenames} | cut -d' ' -f1`
0236         puts "     Number of po file names found: " + c
0237     end
0238 
0239     puts "-> Fetching translations .."
0240 
0241     # get languages
0242     i18nlangs = `svn cat #{svnroot}/l10n-kf5/subdirs #{rev}`.split
0243     i18nlangsCleaned = []
0244     for lang in i18nlangs
0245         l = lang.chomp
0246         if !options.languages.empty?
0247             if options.languages.include?(l)
0248                 i18nlangsCleaned += [l]
0249             end
0250         else l != "x-test" && !i18nlangsCleaned.include?(l)
0251             i18nlangsCleaned += [l]
0252         end
0253     end
0254     i18nlangs = i18nlangsCleaned
0255 
0256     if FileTest.exist?("po")
0257         `rm -rf "po"`
0258     end
0259     Dir.mkdir("po")
0260     for lang in i18nlangs
0261         lang.chomp!
0262         tmp = "po_tmp/#{lang}"
0263         dest = "po/#{lang}"
0264 
0265         # always checkout all po-files
0266         print "  -> Fetching #{lang} from repository ..\n"
0267         pofolder = "l10n-kf5/#{lang}/messages/calligra"
0268         if options.infolevel > 0
0269             `svn co #{svnroot}/#{pofolder} #{tmp}`
0270         else
0271             `svn co #{svnroot}/#{pofolder} #{tmp} 2>/dev/null`
0272         end
0273 
0274         # copy over the po-files we actually use in calligraplan
0275         File.foreach(pofilenames) do |pofile|
0276             pofile.chomp!
0277             pofilepath = "#{tmp}/#{pofile}.po"
0278             if !FileTest.exist?(pofilepath)
0279                 # all files have not always been translated
0280                 if options.infolevel > 1
0281                     puts "     Skipping #{pofilepath} .."
0282                 end
0283                 next
0284             end
0285             if !FileTest.exist?(dest)
0286                 Dir.mkdir(dest)
0287             end
0288             if FileTest.exist?(pofilepath)
0289                 if options.infolevel > 0
0290                     puts "     Copying #{pofile}.po .."
0291                 end
0292                 `mv #{pofilepath} #{dest}`
0293             end
0294         end
0295     end
0296     # remove temporary po dir
0297     `rm -rf "po_tmp"`
0298     
0299     # add l10n to compilation.
0300     `echo "find_package(KF5I18n CONFIG REQUIRED)" >> CMakeLists.txt`
0301     `echo "ki18n_install(po)" >> CMakeLists.txt`
0302 
0303     if options.docs
0304         # add docs to compilation.
0305         `echo "find_package(KF5DocTools CONFIG REQUIRED)" >> CMakeLists.txt`
0306         `echo "kdoctools_install(po)" >> CMakeLists.txt`
0307     end
0308 end
0309 
0310 # Remove cruft
0311 `find -name ".svn" | xargs rm -rf`
0312 
0313 Dir.chdir( ".." ) # root folder
0314 
0315 print "-> Compressing ..  "
0316 `tar -Jcf #{gittar} --group=root --owner=root  #{gitdir}`
0317 puts " done."
0318 puts ""
0319 
0320 sums = File.open(sumsfile, 'w')
0321 sums << "sha1sum  : " << `sha1sum #{gittar}`
0322 sums << "sha256sum: " << `sha256sum #{gittar}`
0323 
0324 if (options.sign)
0325     puts "-> Signing ..  "
0326     `#{options.program} -a --output #{gitsig} --detach-sign #{gittar}`
0327 
0328     sums << "sha1sum  : " << `sha1sum #{gitsig}`
0329     sums << "sha256sum: " << `sha256sum #{gitsig}`
0330 end
0331 
0332 sums.close()
0333 
0334 puts "Sums have been written too: #{sumsfile}"
0335 puts