Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
cm-projects
RIOT
Commits
cfe28857
Commit
cfe28857
authored
7 years ago
by
Alexandre Abadie
Browse files
Options
Downloads
Patches
Plain Diff
dist/tools/headerguards: fix flake8 issues
parent
9acf7c96
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
dist/tools/headerguards/headerguards.py
+14
-9
14 additions, 9 deletions
dist/tools/headerguards/headerguards.py
with
14 additions
and
9 deletions
dist/tools/headerguards/headerguards.py
+
14
−
9
View file @
cfe28857
#!/usr/bin/env python3
#!/usr/bin/env python3
import
os
,
sys
import
os
import
sys
import
difflib
import
difflib
#from string import maketrans
from
io
import
BytesIO
,
TextIOWrapper
from
io
import
BytesIO
,
TextIOWrapper
_in
=
"
/-.
"
_in
=
"
/-.
"
...
@@ -10,12 +10,14 @@ _out = "___"
...
@@ -10,12 +10,14 @@ _out = "___"
transtab
=
str
.
maketrans
(
_in
,
_out
)
transtab
=
str
.
maketrans
(
_in
,
_out
)
def
path_to_guardname
(
filepath
):
def
path_to_guardname
(
filepath
):
res
=
filepath
.
upper
().
translate
(
transtab
)
res
=
filepath
.
upper
().
translate
(
transtab
)
if
res
.
startswith
(
"
_
"
):
if
res
.
startswith
(
"
_
"
):
res
=
"
PRIV
"
+
res
res
=
"
PRIV
"
+
res
return
res
return
res
def
get_guard_name
(
filepath
):
def
get_guard_name
(
filepath
):
parts
=
filepath
.
split
(
os
.
sep
)
parts
=
filepath
.
split
(
os
.
sep
)
start
=
0
start
=
0
...
@@ -23,17 +25,18 @@ def get_guard_name(filepath):
...
@@ -23,17 +25,18 @@ def get_guard_name(filepath):
for
i
,
part
in
enumerate
(
parts
):
for
i
,
part
in
enumerate
(
parts
):
if
part
==
"
include
"
:
if
part
==
"
include
"
:
found
=
True
found
=
True
start
=
i
+
1
start
=
i
+
1
break
break
if
not
found
:
if
not
found
:
start
=
len
(
parts
)
-
1
start
=
len
(
parts
)
-
1
return
path_to_guardname
(
os
.
path
.
join
(
*
parts
[
start
:]))
return
path_to_guardname
(
os
.
path
.
join
(
*
parts
[
start
:]))
def
fix_headerguard
(
filename
):
def
fix_headerguard
(
filename
):
supposed
=
get_guard_name
(
filename
)
supposed
=
get_guard_name
(
filename
)
with
open
(
filename
,
"
r
"
,
encoding
=
'
utf-8
'
,
errors
=
'
ignore
'
)
as
f
:
with
open
(
filename
,
"
r
"
,
encoding
=
'
utf-8
'
,
errors
=
'
ignore
'
)
as
f
:
inlines
=
f
.
readlines
()
inlines
=
f
.
readlines
()
tmp
=
TextIOWrapper
(
BytesIO
(),
encoding
=
"
utf-8
"
,
errors
=
"
ignore
"
)
tmp
=
TextIOWrapper
(
BytesIO
(),
encoding
=
"
utf-8
"
,
errors
=
"
ignore
"
)
...
@@ -42,7 +45,7 @@ def fix_headerguard(filename):
...
@@ -42,7 +45,7 @@ def fix_headerguard(filename):
guard_found
=
0
guard_found
=
0
guard_name
=
""
guard_name
=
""
ifstack
=
0
ifstack
=
0
for
n
,
line
in
enumerate
(
inlines
)
:
for
line
in
inlines
:
if
guard_found
==
0
:
if
guard_found
==
0
:
if
line
.
startswith
(
"
#ifndef
"
):
if
line
.
startswith
(
"
#ifndef
"
):
guard_found
+=
1
guard_found
+=
1
...
@@ -68,16 +71,18 @@ def fix_headerguard(filename):
...
@@ -68,16 +71,18 @@ def fix_headerguard(filename):
tmp
.
seek
(
0
)
tmp
.
seek
(
0
)
if
guard_found
==
3
:
if
guard_found
==
3
:
for
line
in
difflib
.
unified_diff
(
inlines
,
tmp
.
readlines
(),
"
%s
"
%
filename
,
"
%s
"
%
filename
):
for
line
in
difflib
.
unified_diff
(
inlines
,
tmp
.
readlines
(),
"
%s
"
%
filename
,
"
%s
"
%
filename
):
sys
.
stdout
.
write
(
line
)
sys
.
stdout
.
write
(
line
)
else
:
else
:
print
(
"
%s: no / broken header guard
"
%
filename
,
file
=
sys
.
stderr
)
print
(
"
%s: no / broken header guard
"
%
filename
,
file
=
sys
.
stderr
)
return
False
return
False
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
error
=
False
error
=
False
for
filename
in
sys
.
argv
[
1
:]:
for
filename
in
sys
.
argv
[
1
:]:
if
fix_headerguard
(
filename
)
==
False
:
if
fix_headerguard
(
filename
)
is
False
:
error
=
True
error
=
True
if
error
:
if
error
:
...
...
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