Skip to content

Commit

Permalink
semanage_migrate_store: fix many Python linter warnings
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
fishilico authored and bachradsusi committed Jan 4, 2019
1 parent 9fe4303 commit 3cb974d
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions libsemanage/utils/semanage_migrate_store
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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))

Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -257,7 +269,6 @@ if __name__ == "__main__":
"pkeys.local",
"ibendports.local"]


create_dir(newroot_path(), 0o755)

stores = None
Expand Down Expand Up @@ -286,4 +297,3 @@ if __name__ == "__main__":

if NOREBUILD is False:
rebuild_policy()

0 comments on commit 3cb974d

Please sign in to comment.