Ticket #48313: add-perl-5.22.py

File add-perl-5.22.py, 1.1 KB (added by mojca (Mojca Miklavec), 9 years ago)

A simple script to add 5.22 to the end of perl5.branches

Line 
1#!/usr/bin/python
2
3import glob
4import re
5
6def replace_perl_versions(filename):
7    print(filename)
8
9    # read the file
10    f = open(filename)
11    lines = f.readlines()
12    f.close()
13
14    # write the file with a changed version string
15    f = open(filename, 'w')
16    for line in lines:
17        match = re.search(r'^perl5.branches\s+(.*)', line)
18        if match:
19            versions_old = match.group(1)
20            match20 = re.search('5[.]20$', versions_old)
21            if match20:
22                versions_new = "{} 5.22".format(versions_old)
23            else:
24                print("Doesn't match: {}".format(versions_old))
25                versions_new = versions_old
26            line_new     = "perl5.branches      {}".format(versions_new)
27            print(line.strip())
28            print(line_new)
29            print
30            # write the new version string to the file
31            f.write(line_new + "\n")
32        else:
33            # or write the original line if it wasn't about versions
34            f.write(line)
35    f.close()
36
37
38file_list = glob.glob("perl/p5-*/Portfile")
39for l in file_list:
40    replace_perl_versions(l)