File: elxCheckCopyrightNotice.py

package info (click to toggle)
elastix 5.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 42,480 kB
  • sloc: cpp: 68,403; lisp: 4,118; python: 1,013; xml: 182; sh: 177; makefile: 33
file content (48 lines) | stat: -rw-r--r-- 1,417 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import sys
import os
import os.path
import fnmatch
import shutil
import glob


#-------------------------------------------------------------------------------
# the main function
# cd tools
# python elxReplaceCopyrightNotice.py
def main() :

  # The path to the source files relative to this script
  srcdir = os.path.join( "..", "src" );

  # Get a list of all files
  #exclude = set( [ os.path.join( "..", "src", "Testing", "Baselines" ) ] );
  exclude = set( [ "Baselines", "ann_1.1", "CMake", "Data" ] );
  patterns = ( '*.h', '*.hxx', '*.cxx', '*.cuh', '*.cu', '*.in' );
  matches = [];
  for pattern in patterns :
    for root, dirnames, filenames in os.walk( srcdir ) :
      dirnames[:] = [ d for d in dirnames if d not in exclude ];
      for filename in fnmatch.filter( filenames, pattern ) :
        matches.append( os.path.join( root, filename ) );

  # Read the new copyright notice from file
  cnotice = "CopyrightNotice_Apache.txt";
  needle = open( cnotice, 'rU' ).read().strip();

  for match in matches :
    # Read the current file
    inp = open( match, 'rU' );
    fileAsString = inp.read();
    inp.close();

    #print( fileAsString );
    if not fileAsString.startswith( needle ) :
      print( match + "    - copyright notice NOT found" );

  # Exit
  return 0

#-------------------------------------------------------------------------------
if __name__ == '__main__':
    sys.exit(main())