Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
07c37593
Commit
07c37593
authored
Jan 06, 2023
by
Ted Themistokleous
Browse files
Backup of license stamper
parent
a65e2971
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
20 deletions
+28
-20
tools/license_stamper.py
tools/license_stamper.py
+28
-20
No files found.
tools/license_stamper.py
View file @
07c37593
...
...
@@ -26,7 +26,7 @@ import subprocess, os
import
datetime
#Debug flag
debug
=
Fals
e
debug
=
Tru
e
__repo_dir__
=
os
.
path
.
normpath
(
os
.
path
.
join
(
os
.
path
.
realpath
(
__file__
),
'..'
,
'..'
))
...
...
@@ -68,17 +68,18 @@ def hasKeySequence(inputfile, key_message):
line_limit
=
10
target_line
=
-
1
for
line
in
inputfile
:
for
line
in
inputfile
.
split
(
"
\n
"
):
if
key_message
in
line
:
result
=
True
target_line
=
line_cnt
break
line_cnt
=
line_cnt
+
1
if
line_cnt
>=
line_limit
:
break
line_cnt
=
line_cnt
+
1
return
[
result
,
target_line
]
...
...
@@ -157,11 +158,14 @@ def openAndWriteFile(filename, message, commentChar):
#read remaining lines in the original file
save
=
contents
.
read
()
print
(
save
)
hasAmdLic
=
hasKeySequence
(
save
,
"Advanced Micro Devices, Inc. All rights reserved"
)
hasOtherLic
=
hasKeySequence
(
save
,
"Software License"
)
print
(
save
)
#Check if we have a licence stamp already
if
hasAmdLic
[
0
]
or
hasOtherLic
[
0
]
is
True
:
hasOldAmdLic
=
hasKeySequence
(
...
...
@@ -186,24 +190,28 @@ def openAndWriteFile(filename, message, commentChar):
contents
.
close
()
return
if
debug
is
True
:
print
(
"...Writing header"
,
end
=
''
)
if
needs_update
is
True
and
update_line
>
-
1
:
with
open
(
filename
,
rw
)
as
contents
:
data
=
[
next
(
filename
)
for
x
in
range
(
update_line
+
1
)]
index
=
data
[
update_line
].
index
(
"-"
)
data
[
update_line
]
=
data
[
update_line
][:
index
]
+
current_year
+
data
[
update_line
][
index
+
4
:]
if
debug
is
True
:
print
(
"...Updating header
\n
"
,
end
=
''
)
#write remaining contents
contents
.
write
(
data
)
# print(save)
#
# index = data[update_line + 1].find("2015-")
# if index != -1:
# save[update_line + 1] = save[
# update_line+1][:index + 5] + current_year + save[update_line+1][index + 9:]
#
# print(str(data))
#
# with open(filename, 'w') as contents:
# #write remaining contents
# contents.seek(0)
# contents.write(save)
elif
needs_update
is
False
:
if
debug
is
True
:
print
(
"...Writing header"
,
end
=
''
)
with
open
(
filename
,
'w'
)
as
contents
:
#append the licence to the top of the file
...
...
@@ -280,9 +288,9 @@ def main():
fileList
=
proc
.
stdout
.
decode
().
split
(
'
\n
'
)
message
=
message
.
split
(
'
\n
'
)
if
debug
is
True
:
print
(
"Target file list:
\n
"
+
str
(
fileList
))
print
(
"Output Message:
\n
"
+
str
(
message
))
#
if debug is True:
#
print("Target file list:\n" + str(fileList))
#
print("Output Message:\n" + str(message))
for
rfile
in
fileList
:
file
=
os
.
path
.
join
(
__repo_dir__
,
rfile
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment