Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code in cdrom could be better formatted #24

Open
dmuiX opened this issue Mar 31, 2021 · 0 comments
Open

Code in cdrom could be better formatted #24

dmuiX opened this issue Mar 31, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@dmuiX
Copy link
Collaborator

dmuiX commented Mar 31, 2021

Maybe someone has a good solution to write this code here nicer than it is at the moment?

def cdrom():
    lshw = json.loads(str(subprocess.check_output("sudo lshw -json -C disk", shell=True).decode()))
    for disk in lshw:
        if "cdrom" in disk['id']:
            capabilities = {disk['capabilities'][k] for k in disk['capabilities'].keys() - {'removable'}} # removes key 'removable' from dictionary
            capabilities = sorted(capabilities) # sorts capabilities alphabetically
            capabilities = str(capabilities).replace("[","").replace("]", "").replace("'", "") # creates an output that makes sense without square braclets [] and single quotation mark '
            if "DVD" in capabilities:
                return "DVD-Laufwerk: " + capabilities
            elif "CD" in capabilities:
                return "CD-Laufwerk: " + capabilities
        else:
            continue
    return "Laufwerk: Kein Laufwerk verbaut"
@dmuiX dmuiX changed the title Code is not that nice Code in cdrom could be better formatted Mar 31, 2021
@dmuiX dmuiX added the enhancement New feature or request label Apr 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant