mirror of
https://github.com/SELinuxProject/selinux
synced 2024-12-30 10:02:15 +00:00
semanage_migrate_store: fix many Python linter warnings
flake8 reports many warnings on script semanage_migrate_store: E225 missing whitespace around operator E302 expected 2 blank lines, found 1 E701 multiple statements on one line (colon) E703 statement ends with a semicolon E722 do not use bare 'except' ... Fix some of them in order to reduce the noise. Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
This commit is contained in:
parent
9fe430345a
commit
3cb974d2d2
@ -27,12 +27,13 @@ def copy_file(src, dst):
|
||||
shutil.copy(src, dst)
|
||||
except OSError as the_err:
|
||||
(err, strerr) = the_err.args
|
||||
print("Could not copy %s to %s, %s" %(src, dst, strerr), file=sys.stderr)
|
||||
print("Could not copy %s to %s, %s" % (src, dst, strerr), file=sys.stderr)
|
||||
exit(1)
|
||||
|
||||
|
||||
def create_dir(dst, mode):
|
||||
if DEBUG: print("Making directory %s" % dst)
|
||||
if DEBUG:
|
||||
print("Making directory %s" % dst)
|
||||
try:
|
||||
os.makedirs(dst, mode)
|
||||
except OSError as the_err:
|
||||
@ -45,7 +46,8 @@ def create_dir(dst, mode):
|
||||
|
||||
|
||||
def create_file(dst):
|
||||
if DEBUG: print("Making file %s" % dst)
|
||||
if DEBUG:
|
||||
print("Making file %s" % dst)
|
||||
try:
|
||||
open(dst, 'a').close()
|
||||
except OSError as the_err:
|
||||
@ -55,7 +57,8 @@ def create_file(dst):
|
||||
|
||||
|
||||
def copy_module(store, name, base):
|
||||
if DEBUG: print("Install module %s" % name)
|
||||
if DEBUG:
|
||||
print("Install module %s" % name)
|
||||
(file, ext) = os.path.splitext(name)
|
||||
if ext != ".pp":
|
||||
# Stray non-pp file in modules directory, skip
|
||||
@ -78,24 +81,25 @@ def copy_module(store, name, base):
|
||||
efile.write("pp")
|
||||
efile.close()
|
||||
|
||||
except:
|
||||
except (IOError, OSError):
|
||||
print("Error installing module %s" % name, file=sys.stderr)
|
||||
exit(1)
|
||||
|
||||
|
||||
def disable_module(file, name, disabledmodules):
|
||||
if DEBUG: print("Disabling %s" % name)
|
||||
if DEBUG:
|
||||
print("Disabling %s" % name)
|
||||
(disabledname, disabledext) = os.path.splitext(file)
|
||||
create_file("%s/%s" % (disabledmodules, disabledname))
|
||||
|
||||
def migrate_store(store):
|
||||
|
||||
oldstore = oldstore_path(store);
|
||||
oldmodules = oldmodules_path(store);
|
||||
disabledmodules = disabledmodules_path(store);
|
||||
newstore = newstore_path(store);
|
||||
newmodules = newmodules_path(store);
|
||||
bottomdir = bottomdir_path(store);
|
||||
def migrate_store(store):
|
||||
oldstore = oldstore_path(store)
|
||||
oldmodules = oldmodules_path(store)
|
||||
disabledmodules = disabledmodules_path(store)
|
||||
newstore = newstore_path(store)
|
||||
newmodules = newmodules_path(store)
|
||||
bottomdir = bottomdir_path(store)
|
||||
|
||||
print("Migrating from %s to %s" % (oldstore, newstore))
|
||||
|
||||
@ -134,6 +138,7 @@ def migrate_store(store):
|
||||
else:
|
||||
copy_module(store, name, 0)
|
||||
|
||||
|
||||
def rebuild_policy():
|
||||
# Ok, the modules are loaded, lets try to rebuild the policy
|
||||
print("Attempting to rebuild policy from %s" % newroot_path())
|
||||
@ -182,24 +187,31 @@ def rebuild_policy():
|
||||
def oldroot_path():
|
||||
return "%s/etc/selinux" % ROOT
|
||||
|
||||
|
||||
def oldstore_path(store):
|
||||
return "%s/%s/modules/active" % (oldroot_path(), store)
|
||||
|
||||
|
||||
def oldmodules_path(store):
|
||||
return "%s/modules" % oldstore_path(store)
|
||||
|
||||
|
||||
def disabledmodules_path(store):
|
||||
return "%s/disabled" % newmodules_path(store)
|
||||
|
||||
|
||||
def newroot_path():
|
||||
return "%s%s" % (ROOT, PATH)
|
||||
|
||||
|
||||
def newstore_path(store):
|
||||
return "%s/%s/active" % (newroot_path(), store)
|
||||
|
||||
|
||||
def newmodules_path(store):
|
||||
return "%s/modules" % newstore_path(store)
|
||||
|
||||
|
||||
def bottomdir_path(store):
|
||||
return "%s/%s" % (newmodules_path(store), PRIORITY)
|
||||
|
||||
@ -257,7 +269,6 @@ if __name__ == "__main__":
|
||||
"pkeys.local",
|
||||
"ibendports.local"]
|
||||
|
||||
|
||||
create_dir(newroot_path(), 0o755)
|
||||
|
||||
stores = None
|
||||
@ -286,4 +297,3 @@ if __name__ == "__main__":
|
||||
|
||||
if NOREBUILD is False:
|
||||
rebuild_policy()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user