| •1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
import os, argparse |
| 16 |
|
| 17 |
INC_NAME = '.cvsinclude' |
| 18 |
|
| 19 |
def main(): |
| 20 |
if args.dir: |
| 21 |
os.chdir(args.dir) |
| 22 |
|
| 23 |
cvs_includes = set() |
| 24 |
for root, dirs, files in os.walk('.'): |
| 25 |
if INC_NAME in files: |
| 26 |
cvs_includes.add((root + '/' + INC_NAME)[2:]) |
| 27 |
if root.endswith('/CVS') and 'Entries' in files: |
| 28 |
entries = root[2:] + '/Entries' |
| 29 |
includes = [ ] |
| 30 |
with open(entries) as fh: |
| 31 |
for line in fh: |
| 32 |
if line.startswith(('/', 'D/')): |
| 33 |
includes.append(line.split('/', 2)[1]) |
| 34 |
if includes: |
| 35 |
inc = root[2:-3] + INC_NAME |
| 36 |
cvs_includes.discard(inc) |
| 37 |
try: |
| 38 |
with open(inc) as fh: |
| 39 |
old_txt = fh.read() |
| 40 |
except OSError: |
| 41 |
old_txt = '' |
| 42 |
txt = ''.join(f"+ /{x}\n" for x in includes) |
| 43 |
if txt == old_txt: |
| 44 |
print("Unchanged", inc) |
| 45 |
else: |
| 46 |
print("Updating", inc) |
| 47 |
with open(inc, 'w') as fh: |
| 48 |
fh.write(txt) |
| 49 |
dirs.sort() |
| 50 |
|
| 51 |
for inc in sorted(cvs_includes): |
| 52 |
print("Removing", inc) |
| 53 |
os.unlink(inc) |
| 54 |
|
| 55 |
|
| 56 |
if __name__ == '__main__': |
| 57 |
parser = argparse.ArgumentParser(description=f"Transform CVS/Entries into {INC_NAME} files.", add_help=False) |
| 58 |
parser.add_argument("--help", "-h", action="help", help="Output this help message and exit.") |
| 59 |
parser.add_argument("dir", nargs='?', help="The top CVS dir. Defaults to the current directory.") |
| 60 |
args = parser.parse_args() |
| 61 |
main() |
| 62 |
|
| 63 |
|