← Back to team overview

widelands-dev team mailing list archive

Re: [Merge] lp:~widelands-dev/widelands/update_copyright_script into lp:widelands

 

Thanks for the review - added replies to your comments.

Diff comments:

> 
> === added file 'utils/file_utils.py'
> --- utils/file_utils.py	1970-01-01 00:00:00 +0000
> +++ utils/file_utils.py	2017-01-23 12:35:34 +0000
> @@ -0,0 +1,32 @@
> +#!/usr/bin/env python
> +# -*- coding: utf-8 -*-
> +
> +
> +"""Some common file util functions."""
> +
> +import os
> +import sys
> +
> +PYTHON3 = sys.version_info >= (3, 0)
> +
> +def read_text_file(filename):
> +    """Reads the contens of a text file."""
> +    if PYTHON3:
> +        return open(filename, 'r', encoding='utf-8').read()
> +    else:
> +        return open(filename, 'r').read().decode('utf-8')

They should be - it would be a bug anyway otherwise. I think it's not a problem anyway unless the files contain non-ASCII characters, which would be in localizeable strings only. If that should ever happen, our translators will report the bug pretty quickly.

> +
> +
> +def write_text_file(filename, content):
> +    """Writes 'content' into a text file."""
> +    if PYTHON3:
> +        open(filename, 'w', encoding='utf-8').write(content)
> +    else:
> +        open(filename, 'w').write(content.encode('utf-8'))
> +
> +
> +def find_files(startpath, extensions):
> +    for (dirpath, _, filenames) in os.walk(startpath):
> +        for filename in filenames:
> +            if os.path.splitext(filename)[-1].lower() in extensions:
> +                yield os.path.join(dirpath, filename)
> 
> === added file 'utils/update_copyright.py'
> --- utils/update_copyright.py	1970-01-01 00:00:00 +0000
> +++ utils/update_copyright.py	2017-01-23 12:35:34 +0000
> @@ -0,0 +1,54 @@
> +#!/usr/bin/env python
> +# encoding: utf-8
> +
> +import os.path
> +import re
> +import sys
> +
> +file_utils_script = os.path.abspath(os.path.join(os.path.dirname(__file__), 'file_utils.py'))
> +exec(compile(source=open(file_utils_script).read(), filename=file_utils_script, mode='exec'))
> +
> +def main():
> +    """Updates the copyright year in all source files to the given year."""
> +    if len(sys.argv) != 2:
> +        print('Usage: update_copyright.py <year>')
> +        return 1
> +
> +    try:
> +        year = sys.argv[1]
> +        sys.stdout.write('Updating copyright year to: ' + year + ' ')
> +        src_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../src"))
> +        # Fix copyright headers in C++ files
> +        for filename in find_files(src_path, ['.h', '.cc']):
> +            sys.stdout.write('.')
> +            sys.stdout.flush()
> +            lines = read_text_file(filename).strip().split('\n')
> +            new_lines = []
> +            regex = re.compile('(.*Copyright \(C\) \d\d\d\d)(.*)( by the Widelands Development Team.*)')
> +            for line in lines:
> +                match = regex.match(line)
> +                if match:
> +                    line = match.group(1) + "-" + year + match.group(3)
> +                new_lines.append(line.rstrip() + '\n')
> +            write_text_file(filename, ''.join(new_lines))

I don't think it's likely that in-line comments will contain "... Copyright (C) ... by the Widelands Development Team. ..." And if they do, they will simply get their copyright years updated without removing the code, because the regex starts and ends with .*

> +
> +        # Now update the Buildinfo
> +        filename = os.path.join(src_path, "build_info.h")
> +        lines = read_text_file(filename).strip().split('\n')
> +        new_lines = []
> +        regex = re.compile('(.*constexpr uint16_t kWidelandsCopyrightEnd = )(\d\d\d\d)(;)')
> +        for line in lines:
> +            match = regex.match(line)
> +            if match:
> +                line = match.group(1) + year + match.group(3)
> +            new_lines.append(line.rstrip() + '\n')
> +        write_text_file(filename, ''.join(new_lines))
> +        print(' done.')
> +
> +    except Exception:
> +        print('Something went wrong:')
> +        traceback.print_exc()
> +        return 1
> +
> +if __name__ == '__main__':
> +    sys.exit(main())


-- 
https://code.launchpad.net/~widelands-dev/widelands/update_copyright_script/+merge/315352
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/update_copyright_script into lp:widelands.


References