widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #09457
[Merge] lp:~widelands-dev/widelands/update_copyright_script into lp:widelands
GunChleoc has proposed merging lp:~widelands-dev/widelands/update_copyright_script into lp:widelands.
Commit message:
Added a new Python script 'utils/update_copyright.py' for updating the copyright year in the C++ source files.
Requested reviews:
Widelands Developers (widelands-dev)
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/update_copyright_script/+merge/315352
We can run the script after merging - I didn't run it yet to keep the diff small & for better testing.
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/update_copyright_script into lp:widelands.
=== modified file 'src/ui_basic/fileview_panel.cc'
--- src/ui_basic/fileview_panel.cc 2016-12-10 09:41:53 +0000
+++ src/ui_basic/fileview_panel.cc 2017-01-23 12:28:10 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 by Widelands Development Team
+ * Copyright (C) 2016 by the Widelands Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
=== modified file 'src/ui_basic/multilineeditbox.h'
--- src/ui_basic/multilineeditbox.h 2016-10-06 14:32:33 +0000
+++ src/ui_basic/multilineeditbox.h 2017-01-23 12:28:10 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2002-2016 by Widelands Development Team
+ * Copyright (C) 2002-2016 by the Widelands Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
=== modified file 'src/ui_fsmenu/about.cc'
--- src/ui_fsmenu/about.cc 2016-12-10 09:41:53 +0000
+++ src/ui_fsmenu/about.cc 2017-01-23 12:28:10 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016 by Widelands Development Team
+ * Copyright (C) 2016 by the Widelands Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
=== modified file 'src/ui_fsmenu/options.cc'
--- src/ui_fsmenu/options.cc 2016-12-10 14:13:11 +0000
+++ src/ui_fsmenu/options.cc 2017-01-23 12:28:10 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2002-2004, 2006-2010, 2012 by Widelands Development Team
+ * Copyright (C) 2002-2004, 2006-2010, 2012 by the Widelands Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
=== 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:28:10 +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')
+
+
+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)
=== modified file 'utils/fix_formatting.py'
--- utils/fix_formatting.py 2016-12-10 19:38:05 +0000
+++ utils/fix_formatting.py 2017-01-23 12:28:10 +0000
@@ -21,8 +21,11 @@
import sys
from subprocess import call
+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'))
+
+
LEADING_TABS = re.compile(r'^\s*\t+\s*')
-PYTHON3 = sys.version_info >= (3, 0)
SPACES_PER_TAB = 3
@@ -33,30 +36,6 @@
' Recurses over all relevant files.')
return p.parse_args()
-
-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)
- 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)
-
-
def main():
parse_args()
=== 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:28:10 +0000
@@ -0,0 +1,55 @@
+#!/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))
+
+ # Now update the Buildinfo
+ filename = os.path.join(src_path, "build_info.h")
+ #print(filename)
+ 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())
Follow ups
-
[Merge] lp:~widelands-dev/widelands/update_copyright_script into lp:widelands
From: noreply, 2017-01-25
-
Re: [Merge] lp:~widelands-dev/widelands/update_copyright_script into lp:widelands
From: GunChleoc, 2017-01-25
-
Re: [Merge] lp:~widelands-dev/widelands/update_copyright_script into lp:widelands
From: kaputtnik, 2017-01-25
-
Re: [Merge] lp:~widelands-dev/widelands/update_copyright_script into lp:widelands
From: kaputtnik, 2017-01-25
-
Re: [Merge] lp:~widelands-dev/widelands/update_copyright_script into lp:widelands
From: Tino, 2017-01-25
-
Re: [Merge] lp:~widelands-dev/widelands/update_copyright_script into lp:widelands
From: Tino, 2017-01-25
-
Re: [Merge] lp:~widelands-dev/widelands/update_copyright_script into lp:widelands
From: GunChleoc, 2017-01-25
-
Re: [Merge] lp:~widelands-dev/widelands/update_copyright_script into lp:widelands
From: GunChleoc, 2017-01-24
-
Re: [Merge] lp:~widelands-dev/widelands/update_copyright_script into lp:widelands
From: Klaus Halfmann, 2017-01-24
-
Re: [Merge] lp:~widelands-dev/widelands/update_copyright_script into lp:widelands
From: kaputtnik, 2017-01-24
-
Re: [Merge] lp:~widelands-dev/widelands/update_copyright_script into lp:widelands
From: GunChleoc, 2017-01-24
-
[Merge] lp:~widelands-dev/widelands/update_copyright_script into lp:widelands
From: bunnybot, 2017-01-23
-
Re: [Merge] lp:~widelands-dev/widelands/update_copyright_script into lp:widelands
From: Klaus Halfmann, 2017-01-23