widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #09504
Re: [Merge] lp:~widelands-dev/widelands/update_copyright_script into lp:widelands
Added some diff comments to use the 'with' statement as example.
There is also a bash script 'find_not_updated_copyright_year_in_modified_src_files'. Is this needed anymore then?
Diff comments:
>
> === added file 'utils/__init__.py'
> === added file 'utils/file_utils.py'
> --- utils/file_utils.py 1970-01-01 00:00:00 +0000
> +++ utils/file_utils.py 2017-01-25 08:05:35 +0000
> @@ -0,0 +1,33 @@
> +#!/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')
> +
> +
> +def write_text_file(filename, content):
> + """Writes 'content' into a text file."""
> + if PYTHON3:
> + open(filename, 'w', encoding='utf-8').write(content)
Using:
with open(filename, 'w', encoding='utf-8') as f:
f.write(content)
?
> + else:
> + open(filename, 'w').write(content.encode('utf-8'))
with open(filename, 'w') as f:
f.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)
--
https://code.launchpad.net/~widelands-dev/widelands/update_copyright_script/+merge/315352
Your team Widelands Developers is subscribed to branch lp:~widelands-dev/widelands/update_copyright_script.
References