mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-22 22:21:10 +02:00
check_root: fix lint warnings
Per `flake8-3`'s recommendations
This commit is contained in:
parent
2596099207
commit
3eea9d2701
@ -96,7 +96,7 @@ IGNORE_SYMLINK = (
|
|||||||
b"/etc/motd",
|
b"/etc/motd",
|
||||||
|
|
||||||
# Other
|
# Other
|
||||||
b"/etc/lsb-release" # set later in the build process
|
b"/etc/lsb-release" # set later in the build process
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -110,11 +110,13 @@ def provided_sonames():
|
|||||||
for atom in VARDB.settings.soname_provided:
|
for atom in VARDB.settings.soname_provided:
|
||||||
yield atom
|
yield atom
|
||||||
|
|
||||||
|
|
||||||
def ignore_sonames(cpv):
|
def ignore_sonames(cpv):
|
||||||
for key in dep.match_to_list(cpv, IGNORE_MISSING.iterkeys()):
|
for key in dep.match_to_list(cpv, IGNORE_MISSING.iterkeys()):
|
||||||
for atom in IGNORE_MISSING[key]:
|
for atom in IGNORE_MISSING[key]:
|
||||||
yield atom
|
yield atom
|
||||||
|
|
||||||
|
|
||||||
def missing_sonames():
|
def missing_sonames():
|
||||||
provided = frozenset(provided_sonames())
|
provided = frozenset(provided_sonames())
|
||||||
for cpv in VARDB.cpv_all():
|
for cpv in VARDB.cpv_all():
|
||||||
@ -125,6 +127,7 @@ def missing_sonames():
|
|||||||
if missing:
|
if missing:
|
||||||
yield (cpv, missing)
|
yield (cpv, missing)
|
||||||
|
|
||||||
|
|
||||||
def usr_conflicts():
|
def usr_conflicts():
|
||||||
for cpv in VARDB.cpv_all():
|
for cpv in VARDB.cpv_all():
|
||||||
raw = VARDB.aux_get(cpv, ["CONTENTS"])[0]
|
raw = VARDB.aux_get(cpv, ["CONTENTS"])[0]
|
||||||
@ -157,6 +160,7 @@ def usr_conflicts():
|
|||||||
if conflicts:
|
if conflicts:
|
||||||
yield (cpv, conflicts)
|
yield (cpv, conflicts)
|
||||||
|
|
||||||
|
|
||||||
def check_libs():
|
def check_libs():
|
||||||
ok = True
|
ok = True
|
||||||
for cpv, sonames in missing_sonames():
|
for cpv, sonames in missing_sonames():
|
||||||
@ -166,6 +170,7 @@ def check_libs():
|
|||||||
ok = False
|
ok = False
|
||||||
return ok
|
return ok
|
||||||
|
|
||||||
|
|
||||||
def check_usr():
|
def check_usr():
|
||||||
ok = True
|
ok = True
|
||||||
for cpv, conflicts in usr_conflicts():
|
for cpv, conflicts in usr_conflicts():
|
||||||
@ -175,11 +180,13 @@ def check_usr():
|
|||||||
ok = False
|
ok = False
|
||||||
return ok
|
return ok
|
||||||
|
|
||||||
|
|
||||||
def is_exe(path):
|
def is_exe(path):
|
||||||
# just check other, assuming root or group only commands are not scripts.
|
# just check other, assuming root or group only commands are not scripts.
|
||||||
perms = stat.S_IROTH|stat.S_IXOTH
|
perms = stat.S_IROTH | stat.S_IXOTH
|
||||||
mode = os.lstat(path).st_mode
|
mode = os.lstat(path).st_mode
|
||||||
return stat.S_ISREG(mode) and mode&perms == perms
|
return stat.S_ISREG(mode) and (mode & perms) == perms
|
||||||
|
|
||||||
|
|
||||||
def check_shebang():
|
def check_shebang():
|
||||||
ok = True
|
ok = True
|
||||||
@ -187,7 +194,7 @@ def check_shebang():
|
|||||||
root = os.environ.get("ROOT", b"/")
|
root = os.environ.get("ROOT", b"/")
|
||||||
for parent, _, files in os.walk(root):
|
for parent, _, files in os.walk(root):
|
||||||
for path in [os.path.join(parent, f) for f in files]:
|
for path in [os.path.join(parent, f) for f in files]:
|
||||||
if any(fnmatch.fnmatchcase(path,i) for i in IGNORE_SHEBANG):
|
if any(fnmatch.fnmatchcase(path, i) for i in IGNORE_SHEBANG):
|
||||||
continue
|
continue
|
||||||
if not is_exe(path):
|
if not is_exe(path):
|
||||||
continue
|
continue
|
||||||
@ -217,6 +224,7 @@ def check_shebang():
|
|||||||
ok = False
|
ok = False
|
||||||
return ok
|
return ok
|
||||||
|
|
||||||
|
|
||||||
class chrooted():
|
class chrooted():
|
||||||
"""
|
"""
|
||||||
chrooted provides a context so that it can be used via with.
|
chrooted provides a context so that it can be used via with.
|
||||||
@ -228,11 +236,11 @@ class chrooted():
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
self.path=path
|
self.path = path
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
self.restore_fd=os.open(b"/", os.O_RDONLY)
|
self.restore_fd = os.open(b"/", os.O_RDONLY)
|
||||||
self.working_dir=os.getcwd()
|
self.working_dir = os.getcwd()
|
||||||
|
|
||||||
os.chroot(self.path)
|
os.chroot(self.path)
|
||||||
|
|
||||||
@ -245,15 +253,15 @@ class chrooted():
|
|||||||
|
|
||||||
def check_symlink():
|
def check_symlink():
|
||||||
if os.getuid() != 0:
|
if os.getuid() != 0:
|
||||||
error("symlink check must be run as root (chroot)")
|
error("symlink check must be run as root (chroot)")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
ok = True
|
ok = True
|
||||||
root = os.environ.get("ROOT", b"/")
|
root = os.environ.get("ROOT", b"/")
|
||||||
|
|
||||||
with chrooted(root):
|
with chrooted(root):
|
||||||
for parent, dirs, files in os.walk(b"/"):
|
for parent, dirs, files in os.walk(b"/"):
|
||||||
for path in [os.path.join(parent, p) for p in files + dirs ]:
|
for path in [os.path.join(parent, p) for p in files + dirs]:
|
||||||
if any(fnmatch.fnmatchcase(path, i) for i in IGNORE_SYMLINK):
|
if any(fnmatch.fnmatchcase(path, i) for i in IGNORE_SYMLINK):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -264,12 +272,11 @@ def check_symlink():
|
|||||||
return ok
|
return ok
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def error(fmt, *args):
|
def error(fmt, *args):
|
||||||
sys.stderr.write(output.red(fmt % args))
|
sys.stderr.write(output.red(fmt % args))
|
||||||
sys.stderr.write("\n")
|
sys.stderr.write("\n")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
ok = True
|
ok = True
|
||||||
check_funcs = {
|
check_funcs = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user