IAP GITLAB
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
corsika
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pranav Sampathkumar
corsika
Commits
fdebe808
Commit
fdebe808
authored
5 years ago
by
ralfulrich
Browse files
Options
Downloads
Patches
Plain Diff
use regex for do-copyright
parent
8133d471
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
do-copyright.py
+77
-15
77 additions, 15 deletions
do-copyright.py
with
77 additions
and
15 deletions
do-copyright.py
+
77
−
15
View file @
fdebe808
#!/usr/bin/python
#!/usr/bin/python
import
os.path
import
os
import
sys
,
getopt
import
re
#
# Note: this is a mutliline regexp:
#
text
=
"""
text
=
"""
/*
/*
* (c) Copyright
2018
CORSIKA Project, corsika-project@lists.kit.edu
* (c) Copyright
YEAR
CORSIKA Project, corsika-project@lists.kit.edu
*
*
* See file AUTHORS for a list of contributors.
* See file AUTHORS for a list of contributors.
*
*
* This software is distributed under the terms of the GNU General Public
* This software is distributed under the terms of the GNU General Public
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license.
* the license.
*/
\n
*/
"""
"""
Debug
=
0
# 0: nothing, 1: checking, 2: filesystem
Debug
=
0
# 0: nothing, 1: checking, 2: filesystem
excludeDirs
=
[
"
ThirdParty
"
,
"
git
"
]
excludeDirs
=
[
"
ThirdParty
"
,
"
git
"
]
excludeFiles
=
[
'
PhysicalConstants.h
'
,
'
CorsikaFenvOSX.cc
'
]
excludeFiles
=
[
'
PhysicalConstants.h
'
,
'
CorsikaFenvOSX.cc
'
,
'
sgn.h
'
]
extensions
=
[
"
.cc
"
,
"
.h
"
,
"
.test
"
]
extensions
=
[
"
.cc
"
,
"
.h
"
,
"
.test
"
]
def
checkNote
(
filename
):
justCheck
=
True
# T: only checking, F: also changing files
foundMissing
=
False
###############################################
#
def
checkNote
(
filename
):
global
foundMissing
,
justCheck
if
Debug
>
0
:
if
Debug
>
0
:
print
(
"
***********************************************
"
)
print
(
"
***********************************************
"
)
print
(
"
file:
"
+
filename
)
print
(
"
file:
"
+
filename
)
...
@@ -63,21 +74,29 @@ def checkNote(filename):
...
@@ -63,21 +74,29 @@ def checkNote(filename):
isSame
=
False
isSame
=
False
if
len
(
startNote
)
>
0
:
if
len
(
startNote
)
>
0
:
isSame
=
True
isSame
=
True
noteLines
=
text
.
split
(
'
\n
'
)
noteLines
=
text
.
split
(
'
\n
'
)
for
iLine
in
range
(
len
(
noteLines
)
-
2
):
for
iLine
in
range
(
len
(
noteLines
)
-
2
):
if
startNote
[
0
]
+
iLine
>=
len
(
lines
):
if
startNote
[
0
]
+
iLine
>=
len
(
lines
):
isSame
=
False
isSame
=
False
break
break
if
noteLines
[
iLine
+
1
].
strip
(
"
\n
"
)
!=
lines
[
startNote
[
0
]
+
iLine
].
strip
(
"
\n
"
):
regex
=
re
.
compile
(
re
.
escape
(
noteLines
[
iLine
+
1
].
strip
(
"
\n
"
)).
replace
(
'
YEAR
'
,
'
....
'
))
if
not
re
.
match
(
regex
,
lines
[
startNote
[
0
]
+
iLine
].
strip
(
"
\n
"
)):
isSame
=
False
isSame
=
False
print
"
need update:
"
+
filename
+
"
new=
\'
"
+
noteLines
[
iLine
+
1
]
+
"
\'
vs old=
\'
"
+
lines
[
startNote
[
0
]
+
iLine
].
rstrip
(
'
\n
'
)
+
"
\'
"
foundMissing
=
True
print
"
needs update:
"
+
filename
+
"
new=
\'
"
+
noteLines
[
iLine
+
1
]
+
"
\'
vs old=
\'
"
+
lines
[
startNote
[
0
]
+
iLine
].
rstrip
(
'
\n
'
)
+
"
\'
"
break
break
if
Debug
>
0
:
if
Debug
>
0
:
print
(
"
isSame=
"
+
str
(
isSame
))
print
(
"
isSame=
"
+
str
(
isSame
)
+
"
"
+
str
(
len
(
startNote
))
)
# check if notice is the same, or we need to remove multiple notices...
# check if notice is the same, or we need to remove multiple notices...
if
isSame
and
len
(
startNote
)
<=
1
:
if
isSame
and
len
(
startNote
)
<=
1
:
return
return
print
(
"
No copyright note in file:
"
+
filename
)
if
justCheck
:
foundMissing
=
True
return
# add (new) copyright notice here:
# add (new) copyright notice here:
print
(
"
File:
"
+
filename
+
"
, make copy to
"
+
filename
+
"
.bak
"
)
print
(
"
File:
"
+
filename
+
"
, make copy to
"
+
filename
+
"
.bak
"
)
...
@@ -109,7 +128,10 @@ def checkNote(filename):
...
@@ -109,7 +128,10 @@ def checkNote(filename):
file
.
close
()
file
.
close
()
def
next_file
(
x
,
dir_name
,
files
):
###############################################
#
#def next_file(x, dir_name, files):
def
next_file
(
dir_name
,
files
):
for
check
in
excludeDirs
:
for
check
in
excludeDirs
:
if
check
in
dir_name
:
if
check
in
dir_name
:
if
Debug
>
1
:
if
Debug
>
1
:
...
@@ -121,16 +143,56 @@ def next_file(x, dir_name, files):
...
@@ -121,16 +143,56 @@ def next_file(x, dir_name, files):
filename
,
file_extension
=
os
.
path
.
splitext
(
check
)
filename
,
file_extension
=
os
.
path
.
splitext
(
check
)
if
'
#
'
in
check
or
'
~
'
in
check
:
if
'
#
'
in
check
or
'
~
'
in
check
:
continue
continue
excludeThisFile
=
False
for
check2
in
excludeFiles
:
for
check2
in
excludeFiles
:
if
check2
in
check
:
if
check2
in
check
:
if
Debug
>
1
:
if
Debug
>
1
:
print
(
"
exclude:
"
+
check2
)
print
(
"
exclude:
"
+
check2
)
continue
excludeThisFile
=
True
if
excludeThisFile
:
continue
if
file_extension
in
extensions
:
if
file_extension
in
extensions
:
checkNote
(
dir_name
+
"
/
"
+
check
)
checkNote
(
os
.
path
.
join
(
dir_name
,
check
)
)
else
:
else
:
if
Debug
>
1
:
if
Debug
>
1
:
print
(
"
exclude-extension:
"
+
dir_name
+
"
/
"
+
check
)
print
(
"
exclude-extension:
"
+
os
.
path
.
join
(
dir_name
,
check
))
###############################################
# the main program
def
main
(
argv
):
global
justCheck
,
foundMissing
,
Debug
justCheck
=
True
Debug
=
0
try
:
opts
,
args
=
getopt
.
getopt
(
argv
,
"
cIhd:
"
,
[
"
check
"
,
"
implement
"
,
"
debug=
"
])
except
getopt
.
GetoptError
:
print
'
do-copyright.py [--check] [--implement] [--debug=0]
'
sys
.
exit
(
2
)
for
opt
,
arg
in
opts
:
if
opt
==
'
-h
'
:
print
'
do-copyright.py [--check] [--implement] [--debug=0]
'
sys
.
exit
()
elif
opt
in
(
"
-c
"
,
"
--check
"
):
justCheck
=
True
elif
opt
in
(
"
-I
"
,
"
--implement
"
):
justCheck
=
False
elif
opt
in
(
"
-d
"
,
"
--debug
"
):
Debug
=
int
(
arg
)
if
justCheck
:
print
'
Only checking. No changes. See
\'
do-copyright.py -h
\'
for options.
'
for
root
,
dirs
,
files
in
os
.
walk
(
'
./
'
):
next_file
(
root
,
files
)
os
.
path
.
walk
(
"
./
"
,
next_file
,
0
)
###############################################
# main entry point
if
__name__
==
"
__main__
"
:
main
(
sys
.
argv
[
1
:])
if
justCheck
and
foundMissing
:
sys
.
exit
(
-
1
)
# found error
print
"
Finished
"
sys
.
exit
(
0
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment