| 1 | #!/usr/bin/python |
|---|
| 2 | |
|---|
| 3 | import glob |
|---|
| 4 | import re |
|---|
| 5 | |
|---|
| 6 | def 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 | # remove 5.16 5.28 5.20 |
|---|
| 21 | versions_new = re.sub(r'5[.](16|18|20)\s+', '', versions_old) |
|---|
| 22 | # new version string (properly formatted for 20 spaces) |
|---|
| 23 | line_new = "perl5.branches {}".format(versions_new) |
|---|
| 24 | # just debug output |
|---|
| 25 | # print(versions_old) |
|---|
| 26 | # print(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 | |
|---|
| 38 | file_list = glob.glob("perl/p5-*/Portfile") |
|---|
| 39 | for l in file_list: |
|---|
| 40 | replace_perl_versions(l) |
|---|