From 99e8077f5900d935ea265c82fc54cd7b0facc888 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Sun, 24 Jun 2007 12:43:48 +0000 Subject: Implement fix-copyright and fix some of them --- diff --git a/maint-helper.py b/maint-helper.py index 10fa578..45be31f 100755 --- a/maint-helper.py +++ b/maint-helper.py @@ -19,6 +19,14 @@ import os import sys import re +import datetime + +source_exts = [ '.py', '.c', '.h', '.cpp' ] + +def is_source(path): + for ext in source_exts: + if path.endswith(ext): + return True def get_name_and_version(): f = open('configure.ac', 'r') @@ -35,8 +43,9 @@ def get_name_and_version(): def cmd_help(): print 'Usage: \n\ -maint-helper.py build-snapshot - build a source snapshot \n\ -maint-helper.py check-licenses - check licenses in the source' +maint-helper.py build-snapshot - build a source snapshot \n\ +maint-helper.py fix-copyright [path] - fix the copyright year \n\ +maint-helper.py check-licenses - check licenses in the source' def cmd_build_snapshot(): [ name, version ] = get_name_and_version() @@ -53,7 +62,6 @@ def cmd_build_snapshot(): def check_licenses(path, license, missing): matchers = { 'LGPL' : 'GNU Lesser General Public', 'GPL' : 'GNU General Public License' } - source_exts = [ '.py', '.c', '.h', '.cpp' ] license_file = os.path.join(path, '.license') if os.path.isfile(license_file): @@ -67,10 +75,7 @@ def check_licenses(path, license, missing): if os.path.isdir(full_path): check_licenses(full_path, license, missing) else: - check_source = False - for ext in source_exts: - if item.endswith(ext): - check_source = True + check_source = is_source(item) # Special cases. if item.find('marshal') > 0 or \ @@ -105,9 +110,52 @@ def cmd_check_licenses(): print path print '\n' +COPYRIGHT = 'Copyright (C) ' + +def fix_copyright(path): + for item in os.listdir(path): + full_path = os.path.join(path, item) + + if os.path.isdir(full_path): + fix_copyright(full_path) + elif is_source(item): + f = open(full_path, 'r') + source = f.read() + f.close() + + year_start = -1 + year_end = -1 + + i1 = source.find(COPYRIGHT) + if i1 != -1: + i1 += len(COPYRIGHT) + i2 = i1 + source[i1:].find(' ') + if i1 > 0: + try: + year_start = int(source[i1:i1 + 4]) + year_end = int(source[i1 + 6: i1 + 10]) + except ValueError: + pass + + if year_start > 0 and year_end < 0: + year_end = year_start + + year = datetime.date.today().year + if year_end < year: + result = '%s%d-%d%s' % (source[:i1], year_start, + year, source[i2:]) + f = open(full_path, 'w') + f.write(result) + f.close() + +def cmd_fix_copyright(path): + fix_copyright(path) + if len(sys.argv) < 2: cmd_help() elif sys.argv[1] == 'build-snapshot': cmd_build_snapshot() elif sys.argv[1] == 'check-licenses': cmd_check_licenses() +elif sys.argv[1] == 'fix-copyright' and len(sys.argv) > 2: + cmd_fix_copyright(sys.argv[2]) diff --git a/sugar/activity/activity.py b/sugar/activity/activity.py index ec6c50a..56b0a1c 100644 --- a/sugar/activity/activity.py +++ b/sugar/activity/activity.py @@ -3,7 +3,7 @@ This is currently the only reference for what an activity must do to participate in the Sugar desktop. """ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/activity/activityfactory.py b/sugar/activity/activityfactory.py index 2cdf9a1..4bfccf0 100644 --- a/sugar/activity/activityfactory.py +++ b/sugar/activity/activityfactory.py @@ -1,5 +1,5 @@ """Shell side object which manages request to start activity""" -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/activity/activityfactoryservice.py b/sugar/activity/activityfactoryservice.py index ea0ff8c..bc7c4e7 100644 --- a/sugar/activity/activityfactoryservice.py +++ b/sugar/activity/activityfactoryservice.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/activity/activityhandle.py b/sugar/activity/activityhandle.py index e683ac1..26d0d47 100644 --- a/sugar/activity/activityhandle.py +++ b/sugar/activity/activityhandle.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/activity/activityservice.py b/sugar/activity/activityservice.py index 3251177..97a6034 100644 --- a/sugar/activity/activityservice.py +++ b/sugar/activity/activityservice.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/activity/bundlebuilder.py b/sugar/activity/bundlebuilder.py index b66a162..dce3155 100644 --- a/sugar/activity/bundlebuilder.py +++ b/sugar/activity/bundlebuilder.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/activity/registry.py b/sugar/activity/registry.py index 255185b..171f740 100644 --- a/sugar/activity/registry.py +++ b/sugar/activity/registry.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/datastore/dbus_helpers.py b/sugar/datastore/dbus_helpers.py index bd868a0..2dfccac 100644 --- a/sugar/datastore/dbus_helpers.py +++ b/sugar/datastore/dbus_helpers.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # Copyright (C) 2007, One Laptop Per Child # # This library is free software; you can redistribute it and/or diff --git a/sugar/env.py b/sugar/env.py index 03cfea7..8707fd9 100644 --- a/sugar/env.py +++ b/sugar/env.py @@ -1,5 +1,5 @@ """Calculates file-paths for the Sugar working environment""" -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/graphics/canvasicon.py b/sugar/graphics/canvasicon.py index ec141d0..274291a 100644 --- a/sugar/graphics/canvasicon.py +++ b/sugar/graphics/canvasicon.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/graphics/frame.py b/sugar/graphics/frame.py index 4b800fd..c8e6f9a 100644 --- a/sugar/graphics/frame.py +++ b/sugar/graphics/frame.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/graphics/icon.py b/sugar/graphics/icon.py index f5cc25d..03b1927 100644 --- a/sugar/graphics/icon.py +++ b/sugar/graphics/icon.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/graphics/menu.py b/sugar/graphics/menu.py index c8afb24..14f471e 100644 --- a/sugar/graphics/menu.py +++ b/sugar/graphics/menu.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/graphics/menushell.py b/sugar/graphics/menushell.py index 61b98b0..f2ff9fa 100644 --- a/sugar/graphics/menushell.py +++ b/sugar/graphics/menushell.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/graphics/roundbox.py b/sugar/graphics/roundbox.py index f638a44..ba9ec98 100644 --- a/sugar/graphics/roundbox.py +++ b/sugar/graphics/roundbox.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/graphics/snowflakebox.py b/sugar/graphics/snowflakebox.py index af68d56..81e5981 100644 --- a/sugar/graphics/snowflakebox.py +++ b/sugar/graphics/snowflakebox.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/graphics/spreadbox.py b/sugar/graphics/spreadbox.py index 1002a44..1c1ffc9 100644 --- a/sugar/graphics/spreadbox.py +++ b/sugar/graphics/spreadbox.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/graphics/units.py b/sugar/graphics/units.py index 47aaf1b..2487c59 100644 --- a/sugar/graphics/units.py +++ b/sugar/graphics/units.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/graphics/xocolor.py b/sugar/graphics/xocolor.py index 2fcc791..f2e892d 100644 --- a/sugar/graphics/xocolor.py +++ b/sugar/graphics/xocolor.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/logger.py b/sugar/logger.py index 495d7a0..a9042a0 100644 --- a/sugar/logger.py +++ b/sugar/logger.py @@ -1,5 +1,5 @@ """Logging module configuration for Sugar""" -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/ltihooks.py b/sugar/ltihooks.py index d68f2eb..1de3034 100644 --- a/sugar/ltihooks.py +++ b/sugar/ltihooks.py @@ -2,7 +2,7 @@ # vi:si:et:sw=4:sts=4:ts=4 # ltihooks.py: python import hooks that understand libtool libraries. -# Copyright (C) 2000 James Henstridge. +# Copyright (C) 2000-2007 James Henstridge. # renamed to gstltihooks.py so it does not accidentally get imported by # an installed copy of gtk # diff --git a/sugar/network.py b/sugar/network.py index e315cdb..4792777 100644 --- a/sugar/network.py +++ b/sugar/network.py @@ -1,4 +1,4 @@ -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public diff --git a/sugar/profile.py b/sugar/profile.py index 8041a4e..1638b2c 100644 --- a/sugar/profile.py +++ b/sugar/profile.py @@ -1,5 +1,5 @@ """User settings/configuration loading""" -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/sugar/util.py b/sugar/util.py index 58fcc7b..8e15e92 100644 --- a/sugar/util.py +++ b/sugar/util.py @@ -1,5 +1,5 @@ """Various utility functions""" -# Copyright (C) 2006, Red Hat, Inc. +# Copyright (C) 2006-2007 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public -- cgit v0.9.1