Loading

Paste #pwrebu48w

  1. diff -r 2f44412c520b .hgignore
  2. --- a/.hgignore Sat Jun 20 23:42:23 2015 +0200
  3. +++ b/.hgignore Sun Sep 20 14:33:47 2015 +0200
  4. @@ -26,6 +26,7 @@
  5.  users.dat
  6.  projects.dat
  7.  rights.dat
  8. +openttd_lang
  9.  
  10.  # Files created by Mac image preview and file browser:
  11.  .DS_Store
  12. diff -r 2f44412c520b scripts/filter_update_langs
  13. --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
  14. +++ b/scripts/filter_update_langs   Sun Sep 20 14:33:47 2015 +0200
  15. @@ -0,0 +1,134 @@
  16. +#!/usr/bin/env python3
  17. +
  18. +import sys, os, os.path, getopt
  19. +
  20. +
  21. +
  22. +# Keywords to use from OpenTTD langfiles
  23. +filterkeywords = [ "##name", "##ownname", "##isocode", "##plural", "##grflangid", "##gender", "##case" ]
  24. +
  25. +
  26. +
  27. +def filter_langfile(filename):
  28. +    """
  29. +    Read and filter OpenTTD lang file for required keywords.
  30. +
  31. +    @param filename: File to read.
  32. +    @type  filename: C{str}
  33. +
  34. +    @return: List of keywords lines.
  35. +    @rtype:  C{list} of C{str}
  36. +    """
  37. +    result = []
  38. +    for l in open(filename, 'r', encoding = 'utf-8'):
  39. +        l = l.strip()
  40. +        if len(l) == 0:
  41. +            continue
  42. +
  43. +        if not l.startswith("#"):
  44. +            break
  45. +
  46. +        if not l.startswith("##"):
  47. +            continue
  48. +
  49. +        if any(l.startswith(key) for key in filterkeywords):
  50. +            result.append(l)
  51. +
  52. +    return result
  53. +
  54. +def read_complete_langfile(filename):
  55. +    """
  56. +    Read complete file.
  57. +
  58. +    @param filename: File to read.
  59. +    @type  filename: C{str}
  60. +
  61. +    @return: List of lines.
  62. +    @rtype:  C{list} of C{str}
  63. +    """
  64. +    return list([ l.strip() for l in open(filename, 'r', encoding = 'utf-8') ])
  65. +
  66. +def write_langfile(filename, content):
  67. +    """
  68. +    Writes complete file.
  69. +
  70. +    @param filename: File to write.
  71. +    @type  filename: C{str}
  72. +
  73. +    @param content: List of lines.
  74. +    @type  content: C{list} of C{str}
  75. +    """
  76. +    with open(filename, "w", encoding = 'utf-8') as f:
  77. +        f.write("\n".join(content))
  78. +        f.write("\n")
  79. +
  80. +
  81. +
  82. +# Parse arguments
  83. +try:
  84. +    opts, args = getopt.getopt(sys.argv[1:], "h", [ "help" ])
  85. +except getopt.GetoptError as err:
  86. +    print("filter_update_langs: " + str(err) + " (try \"filter_update_langs -h\")")
  87. +    sys.exit(2)
  88. +
  89. +# Check arguments
  90. +for opt, val in opts:
  91. +    if opt in ('--help', '-h'):
  92. +        print("Usage: filter_update_langs <input dir> <output dir>")
  93. +        sys.exit(0)
  94. +
  95. +if len(args) != 2:
  96. +    print("Invalid parameters, try \"filter_update_langs -h\"")
  97. +    sys.exit(2)
  98. +
  99. +inputdir = args[0]
  100. +outputdir = args[1]
  101. +
  102. +
  103. +
  104. +# Read input language definitions
  105. +inputlangs = {}
  106. +for f in os.listdir(inputdir):
  107. +    n = os.path.join(inputdir, f)
  108. +    if not os.path.isfile(n):
  109. +        continue
  110. +
  111. +    inputlangs[f] = filter_langfile(n)
  112. +
  113. +
  114. +
  115. +# Scan existing language definitions
  116. +existinglangs = set([ f for f in os.listdir(outputdir) if os.path.isfile(os.path.join(outputdir, f)) ])
  117. +
  118. +newlangs = inputlangs.keys() - existinglangs
  119. +dellangs = existinglangs - inputlangs.keys()
  120. +updlangs = existinglangs & inputlangs.keys()
  121. +
  122. +num_changes = 0
  123. +
  124. +# Copy new languages
  125. +for l in newlangs:
  126. +    print("Adding {}".format(l))
  127. +    write_langfile(os.path.join(outputdir, l), inputlangs[l])
  128. +    num_changes += 1
  129. +
  130. +# Remove old languages
  131. +for l in dellangs:
  132. +    print("Removing {}".format(l))
  133. +    os.remove(os.path.join(outputdir, l))
  134. +    num_changes += 1
  135. +
  136. +# Update altered languages
  137. +for l in updlangs:
  138. +    cur = read_complete_langfile(os.path.join(outputdir, l))
  139. +    new = inputlangs[l]
  140. +    if cur != new:
  141. +        print("Updating {}".format(l))
  142. +        write_langfile(os.path.join(outputdir, l), inputlangs[l])
  143. +        num_changes += 1
  144. +
  145. +# Print summary
  146. +if num_changes > 0:
  147. +    print("{} languages updated. You need to restart Eints".format(num_changes))
  148. +else:
  149. +    print("All languages up to date")
  150. diff -r 2f44412c520b update_openttd_langs
  151. --- /dev/null   Thu Jan 01 00:00:00 1970 +0000
  152. +++ b/update_openttd_langs  Sun Sep 20 14:33:47 2015 +0200
  153. @@ -0,0 +1,23 @@
  154. +#!/bin/sh
  155. +#
  156. +# Update language definitions from OpenTTD SVN
  157. +#
  158. +
  159. +STABLEDIR="stable_languages"
  160. +UNSTABLEDIR="unstable_languages"
  161. +
  162. +SVNURL="svn://svn.openttd.org/trunk/src/lang"
  163. +CHECKOUTDIR="openttd_lang"
  164. +
  165. +
  166. +
  167. +if [ -d ${CHECKOUTDIR} ]
  168. +then svn update ${CHECKOUTDIR}
  169. +else svn checkout ${SVNURL} ${CHECKOUTDIR}
  170. +fi
  171. +
  172. +echo "Checking stable languages"
  173. +scripts/filter_update_langs ${CHECKOUTDIR} ${STABLEDIR}
  174. +
  175. +echo "Checking unstable languages"
  176. +scripts/filter_update_langs ${CHECKOUTDIR}/unfinished ${UNSTABLEDIR}
  177.  

Comments