~ubuntu-branches/ubuntu/precise/grantlee/precise

« back to all changes in this revision

Viewing changes to scripts/updatelicence.py

  • Committer: Bazaar Package Importer
  • Author(s): Harald Sitter
  • Date: 2010-06-11 23:41:45 UTC
  • Revision ID: james.westby@ubuntu.com-20100611234145-oas7rhdrbwy8j55c
Tags: upstream-0.1.1
ImportĀ upstreamĀ versionĀ 0.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
#-*- coding: utf-8 -*-
 
3
 
 
4
 
 
5
import os, fnmatch
 
6
 
 
7
licence = """/*
 
8
  This file is part of the Grantlee template system.
 
9
 
 
10
  Copyright (c) 2009,2010 Stephen Kelly <steveire@gmail.com>
 
11
 
 
12
  This library is free software; you can redistribute it and/or
 
13
  modify it under the terms of the GNU Lesser General Public
 
14
  License as published by the Free Software Foundation; either version
 
15
  2 of the Licence, or (at your option) any later version.
 
16
 
 
17
  This library is distributed in the hope that it will be useful,
 
18
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
20
  Library General Public License for more details.
 
21
 
 
22
  You should have received a copy of the GNU Lesser General Public
 
23
  License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 
24
 
 
25
*/"""
 
26
 
 
27
def updateFile(filename):
 
28
  f = open(filename, "r")
 
29
 
 
30
  content = f.read()
 
31
  f.close()
 
32
  content = content.strip()
 
33
 
 
34
  if content.startswith("/*"):
 
35
    bit, commentplus = content.split("/*", 1)
 
36
    comment, after = commentplus.split("*/", 1)
 
37
 
 
38
    f = open(filename, "w")
 
39
    f.write(bit + licence + after + "\n\n")
 
40
    f.close()
 
41
  else:
 
42
    f = open(filename, "w")
 
43
    f.write(licence + "\n\n" +  content + "\n\n")
 
44
    f.close()
 
45
 
 
46
# http://code.activestate.com/recipes/499305/
 
47
def locate(pattern, root=os.curdir):
 
48
  '''Locate all files matching supplied filename pattern in and below
 
49
  supplied root directory.'''
 
50
  for path, dirs, files in os.walk(os.path.abspath(root)):
 
51
    for filename in fnmatch.filter(files, pattern):
 
52
      yield os.path.join(path, filename)
 
53
 
 
54
if __name__ == "__main__":
 
55
  for filename in locate("*.cpp"):
 
56
    updateFile(filename)
 
57
 
 
58
  for filename in locate("*.h"):
 
59
    updateFile(filename)