summaryrefslogtreecommitdiff
path: root/solenv/bin/version.py
blob: 18c04414178d437d8dfab61d9816c25bd9007cd5 (plain)
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
#!/usr/bin/env python

from __future__ import print_function
from optparse import OptionParser
import os.path
import re
import sys

M = {
  'juh': 'javaunohelper',
  'jurt': 'jurt',
  'officebean': 'bean',
  'ridl': 'ridljar',
  'unoil': 'unoil',
  'unoloader': 'ridljar',
}

parser = OptionParser()
_, args = parser.parse_args()

if not len(args):
  parser.error('not enough arguments')
elif len(args) > 1:
  parser.error('too many arguments')

DEST = r'\g<1>%s\g<3>' % args[0]


def replace_in_file(filename, src_pattern):
  try:
    f = open(filename, "r")
    s = f.read()
    f.close()
    s = re.sub(src_pattern, DEST, s)
    f = open(filename, "w")
    f.write(s)
    f.close()
  except IOError as err:
    print('error updating %s: %s' % (filename, err), file=sys.stderr)

src_pattern = re.compile(r'^(\s*<version>)([-.@\w]+)(</version>\s*)$',
                         re.MULTILINE)

for a in ['juh', 'jurt', 'officebean', 'ridl', 'unoil', 'unoloader']:
  replace_in_file(os.path.join(M[a], 'pom.%s.xml' % a), src_pattern)

src_pattern = re.compile(r"^(LIBREOFFICE_VERSION = ')([-.@\w]+)(')$",
                         re.MULTILINE)
replace_in_file('solenv/maven/VERSION', src_pattern)