Skip to content

Instantly share code, notes, and snippets.

@beugley
Created February 6, 2017 21:16
Show Gist options
  • Select an option

  • Save beugley/47b4812df0837fc90e783347faee2432 to your computer and use it in GitHub Desktop.

Select an option

Save beugley/47b4812df0837fc90e783347faee2432 to your computer and use it in GitHub Desktop.

Revisions

  1. beugley created this gist Feb 6, 2017.
    43 changes: 43 additions & 0 deletions perm_to_text.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    def perm_to_text(perm):
    perms = {
    "0": "---",
    "1": "--x",
    "2": "-w-",
    "3": "-wx",
    "4": "r--",
    "5": "r-x",
    "6": "rw-",
    "7": "rwx"
    }
    if len(perm) == 4:
    first = perm[0]
    perm = perm[1:]
    else:
    first = ""

    try:
    outperms = ""
    for p in perm:
    outperms += perms[p]
    except KeyError as e:
    outperms = perm

    if first != "":
    if first == '0':
    pass
    elif first == '1':
    pass
    elif first == '2':
    if outperms[5] == 'x':
    outperms = outperms[:5]+'s'+outperms[6:]
    else:
    outperms = outperms[:5]+'S'+outperms[6:]
    elif first == '4':
    if outperms[2] == 'x':
    outperms = outperms[:2]+'s'+outperms[3:]
    else:
    outperms = outperms[:2]+'S'+outperms[3:]
    else:
    outperms = perm

    return "-"+outperms