--- /dev/null
+#!/usr/bin/python
+#
+# Copyright (C) 2013 IBM Corporation and Others. All Rights Reserved.
+#
+# @author Steven R. Loomis <srl@icu-project.org>
+#
+# Yet Another Resource Builder
+#
+# Usage:
+#
+##$ mkdir loc
+##$ echo 'root { hello { "Hello" } }' > loc/root.txt
+##$ echo 'es { hello { "Hola" } }' > loc/es.txt
+##$ rm -rf ./out
+##$ bldicures.py --name myapp --from ./loc -d ./out
+##$ ls out/myapp.dat
+#
+# use 'bldicures.py --help' for help.
+#
+# BUGS/TODO
+# * dependency calculation
+# * pathnames/PATH for genrb/pkgdata
+# * cleanup of files, ./out, etc
+# * document res_index
+# * probably pathname munging
+# * deuglify python
+
+
+import sys
+
+# for utf-8
+#reload(sys)
+#sys.setdefaultencoding("utf-8")
+
+import argparse
+import os
+
+parser = argparse.ArgumentParser(description='Yet Another ICU Resource Builder', epilog='ICU tool, http://icu-project.org - master copy at http://source.icu-project.org/repos/icu/tools/trunk/scripts/bldicures.py')
+parser.add_argument('-f', '--from', action='append', dest='fromdirs', help='read .txt files from this dir', metavar='fromdir', required=True)
+parser.add_argument('-n', '--name', action='store', help='set the bundle name, such as "myapp"', metavar='bundname', required=True)
+parser.add_argument('-m', '--mode', action='store', help='pkgdata mode', metavar='mode', default="archive")
+parser.add_argument('-d', '--dest', action='store', dest='destdir', help='dest dir, default is ".".', default=".", metavar='destdir')
+parser.add_argument('--verbose', '-v', action='count',default=0)
+
+args = parser.parse_args()
+if args.verbose>0:
+ print "Options: "+str(args)
+
+if args.verbose > 0:
+ print "mkdir " + args.destdir
+os.makedirs(args.destdir)
+tmpdir = 'tmp'
+os.makedirs('%s/%s/' % (args.destdir, tmpdir))
+
+listname = '%s/%s/icufiles.lst' % (args.destdir, tmpdir)
+
+if args.verbose > 0:
+ print ">%s" % (listname)
+listfn = open(listname, 'w')
+
+print >>listfn, '# list for "%s" generated by %s on %s' % (args.name,parser.prog, '(now)')
+print >>listfn, '# args: ' + str(args)
+print >>listfn, '#'
+
+idxname = '%s/%s/res_index.txt' % (args.destdir, tmpdir)
+idxfn = open(idxname, 'w')
+print >>idxfn, """// Warning, this file is autogenerated by %s
+res_index:table(nofallback) {
+ InstalledLocales:table {""" % (parser.prog)
+
+gens = {}
+
+def add_res(resname,txtname, loc):
+ if args.verbose>0:
+ print "+ %s (from %s)" % (loc, txtname)
+ print >>listfn, "# %s" % (txtname)
+ print >>listfn, "%s.res" % (loc)
+ gens[loc] = { "loc": loc, "res": resname, "txt": txtname }
+
+add_res('%s/%s/res_index.res' % (args.destdir,tmpdir), idxname, 'res_index')
+
+def add_loc(path, loc):
+ resf = '%s/%s/%s.res' % (args.destdir,tmpdir,loc)
+ txtf = '%s/%s.txt' % (path, loc)
+ print >>idxfn, " %s {\"\"}" % loc
+ add_res(resf, txtf, loc)
+
+for dir in args.fromdirs:
+ if args.verbose>0:
+ print "Collecting .txt files in %s" % (dir)
+
+ walks = os.walk(dir)
+ for ent in walks:
+ junk = (path,dirs,files) = ent
+ if args.verbose>3:
+ print junk
+ if (path.find("/.svn") != -1):
+ continue
+ for file in files:
+ if (file.find(".txt") == -1):
+ if args.verbose>1:
+ print "Ignoring %s/%s" % (path,file)
+ continue
+ (loc,ext) = file.split('.')
+ if ext != "txt":
+ if args.verbose>1:
+ print "Ignoring (bad ext %s) %s/%s" % (ext, path,file)
+ continue
+ add_loc(path, loc)
+
+print >>idxfn, " }"
+print >>idxfn, "}"
+
+idxfn.close()
+listfn.close()
+
+if (args.verbose>2):
+ print gens
+
+if (args.verbose>3):
+ print "TODO: dependency tracking. For now, dont' care"
+
+for gen in gens:
+ item = gens[gen]
+ cmd = 'genrb -d "%s/%s" "%s"' % (args.destdir, tmpdir, item["txt"])
+ if (args.verbose>1):
+ print "# " + cmd
+ os.system(cmd)
+
+cmd = 'pkgdata -m "%s" -T "%s/%s" -p "%s" -s "%s/%s" -d "%s" "%s"' % (args.mode,args.destdir,tmpdir,args.name,args.destdir,tmpdir,args.destdir,listname)
+if (args.verbose>1):
+ cmd = cmd + " -v"
+ print "# " + cmd
+os.system(cmd)