BrainSpawnInfosphere / pyarchey

Archey is a system information tool written in Python.
https://pypi.python.org/pypi/pyarchey/
GNU General Public License v3.0
8 stars 6 forks source link

KeyError: 'cpe:/o:slackware:slackware_linux:14.1' with Slackware and pyarchey v0.6.5 #10

Closed ghost closed 9 years ago

ghost commented 9 years ago

pyarchey 0.6.5 don't work with Slackware:

$ pyarchey
Traceback (most recent call last):
  File "pyarchey.py", line 672, in <module>
    main()
  File "pyarchey.py", line 652, in main
    out.append( User() )
  File "pyarchey.py", line 437, in append
    self.results.append('%s%s: %s%s' % (colorDict[self.distro][1], display.key, colorDict['Clear'][0], display.value))
KeyError: 'cpe:/o:slackware:slackware_linux:14.1'

So I suggest a little more clean code to read the file /etc/os-release:

    def readDistro(self):
        """
        1. Checks if a file exists, if so, reads it
        2. looks for distribution name in file
        3. returns name and if not successful, just says 'Linux' which is the default

        pi@calculon ~ $ more /etc/os-release
        PRETTY_NAME="Raspbian GNU/Linux 7 (wheezy)"
        NAME="Raspbian GNU/Linux"
        VERSION_ID="7"
        VERSION="7 (wheezy)"
        ID=raspbian
        ID_LIKE=debian
        ANSI_COLOR="1;31"
        HOME_URL="http://www.raspbian.org/"
        SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
        BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

        $ cat /etc/os-release
        NAME="Arch Linux"
        ID=arch
        PRETTY_NAME="Arch Linux"
        ANSI_COLOR="0;36"
        HOME_URL="https://www.archlinux.org/"
        SUPPORT_URL="https://bbs.archlinux.org/"
        BUG_REPORT_URL="https://bugs.archlinux.org/"
        """
        try:
            f = open('/etc/os-release', 'r')
            r = f.read()
            f.close()
            pretty_name = ''
            name = ''

            for line in r.splitlines():
                if line.startswith("PRETTY_NAME"):
                    pretty_name = line[13:-1]
                if line.startswith("NAME"):
                    name = line[5:]
                name = name.replace('GNU/Linux', '')
                pretty_name = pretty_name.replace('GNU/Linux', '')

            if not name: name = 'Linux'

            return name,pretty_name

        except:
            name = Popen(['lsb_release', '-is'], 
stdout=PIPE).communicate()[0].decode('Utf-8').rstrip('\n')
            if not name: name = 'Linux'
            return name,''
walchko commented 9 years ago

what does your /etc/os-release look like?

ghost commented 9 years ago
NAME=Slackware
VERSION="14.1"
ID=slackware
VERSION_ID=14.1
PRETTY_NAME="Slackware 14.1"
ANSI_COLOR="0;34"
CPE_NAME="cpe:/o:slackware:slackware_linux:14.1"
HOME_URL="http://slackware.com/"
SUPPORT_URL="http://www.linuxquestions.org/questions/slackware-14/"
BUG_REPORT_URL="http://www.linuxquestions.org/questions/slackware-14/"
walchko commented 9 years ago

Thanks!