diff options
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/contrib/convert-srcuri.py | 63 | 
1 files changed, 63 insertions, 0 deletions
| diff --git a/scripts/contrib/convert-srcuri.py b/scripts/contrib/convert-srcuri.py new file mode 100755 index 0000000000..4bf9e3013d --- /dev/null +++ b/scripts/contrib/convert-srcuri.py | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | #!/usr/bin/env python3 | ||
| 2 | # | ||
| 3 | # Conversion script to update SRC_URI to add branch to git urls | ||
| 4 | # | ||
| 5 | # Copyright (C) 2021 Richard Purdie | ||
| 6 | # | ||
| 7 | # SPDX-License-Identifier: GPL-2.0-only | ||
| 8 | # | ||
| 9 | |||
| 10 | import re | ||
| 11 | import os | ||
| 12 | import sys | ||
| 13 | import tempfile | ||
| 14 | import shutil | ||
| 15 | import mimetypes | ||
| 16 | |||
| 17 | if len(sys.argv) < 2: | ||
| 18 | print("Please specify a directory to run the conversion script against.") | ||
| 19 | sys.exit(1) | ||
| 20 | |||
| 21 | def processfile(fn): | ||
| 22 | print("processing file '%s'" % fn) | ||
| 23 | try: | ||
| 24 | fh, abs_path = tempfile.mkstemp() | ||
| 25 | modified = False | ||
| 26 | with os.fdopen(fh, 'w') as new_file: | ||
| 27 | with open(fn, "r") as old_file: | ||
| 28 | for line in old_file: | ||
| 29 | if ("git://" in line or "gitsm://" in line) and "branch=" not in line and "MIRROR" not in line and ".*" not in line: | ||
| 30 | if line.endswith('"\n'): | ||
| 31 | line = line.replace('"\n', ';branch=master"\n') | ||
| 32 | elif line.endswith(" \\\n"): | ||
| 33 | line = line.replace(' \\\n', ';branch=master \\\n') | ||
| 34 | modified = True | ||
| 35 | new_file.write(line) | ||
| 36 | if modified: | ||
| 37 | shutil.copymode(fn, abs_path) | ||
| 38 | os.remove(fn) | ||
| 39 | shutil.move(abs_path, fn) | ||
| 40 | except UnicodeDecodeError: | ||
| 41 | pass | ||
| 42 | |||
| 43 | ourname = os.path.basename(sys.argv[0]) | ||
| 44 | ourversion = "0.1" | ||
| 45 | |||
| 46 | if os.path.isfile(sys.argv[1]): | ||
| 47 | processfile(sys.argv[1]) | ||
| 48 | sys.exit(0) | ||
| 49 | |||
| 50 | for targetdir in sys.argv[1:]: | ||
| 51 | print("processing directory '%s'" % targetdir) | ||
| 52 | for root, dirs, files in os.walk(targetdir): | ||
| 53 | for name in files: | ||
| 54 | if name == ourname: | ||
| 55 | continue | ||
| 56 | fn = os.path.join(root, name) | ||
| 57 | if os.path.islink(fn): | ||
| 58 | continue | ||
| 59 | if "/.git/" in fn or fn.endswith(".html") or fn.endswith(".patch") or fn.endswith(".m4") or fn.endswith(".diff"): | ||
| 60 | continue | ||
| 61 | processfile(fn) | ||
| 62 | |||
| 63 | print("All files processed with version %s" % ourversion) | ||
