├── README.md ├── COPYING └── archey /README.md: -------------------------------------------------------------------------------- 1 | Archey is a system information tool written in Python. 2 | 3 | I am planning to do a complete re-write of Archey. Please stay tuned. 4 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 2 | 3 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 4 | 5 | You should have received a copy of the GNU General Public License along with this program. If not, see . 6 | -------------------------------------------------------------------------------- /archey: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # Archey [version 0.3.0] 4 | # 5 | # Archey is a simple system information tool written in Python. 6 | # 7 | # Copyright 2010 Melik Manukyan 8 | # Copyright 2010 David Vazgenovich Shakaryan 9 | # 10 | # ASCII art by Brett Bohnenkamper 11 | # Changes Jerome Launay 12 | # Fedora support by YeOK 13 | # 14 | # Distributed under the terms of the GNU General Public License v3. 15 | # See http://www.gnu.org/licenses/gpl.txt for the full license text. 16 | 17 | # Import libraries 18 | 19 | import os, sys, subprocess, optparse, re, linecache 20 | from subprocess import Popen, PIPE 21 | from optparse import OptionParser 22 | from getpass import getuser 23 | from time import ctime, sleep 24 | 25 | #---------------Output---------------# 26 | 27 | output = [ 'User', 'Hostname', 'Distro', 'Kernel', 'Uptime', 'WindowManager', 'DesktopEnvironment', 'Shell', 'Terminal', 'Packages', 'CPU', 'RAM', 'Disk' ] 28 | 29 | #---------------Dictionaries---------------# 30 | 31 | colorDict = { 32 | 'Arch Linux': ['\x1b[0;34m', '\x1b[1;34m'], 33 | 'Ubuntu': ['\x1b[0;31m', '\x1b[1;31m', '\x1b[0;33m'], 34 | 'Debian': ['\x1b[0;31m', '\x1b[1;31m'], 35 | 'Mint': ['\x1b[0;32m', '\x1b[1;37m'], 36 | 'Crunchbang': ['\x1b[1;37m'], 37 | 'Fedora': ['\x1b[0;34m', '\x1b[1;37m'], 38 | 'Sensors': ['\x1b[0;31m', '\x1b[0;32m', '\x1b[0;33m'], 39 | 'Clear': ['\x1b[0m'] 40 | } 41 | 42 | deDict = { 43 | 'cinnamon-sessio': 'Cinnamon', 44 | 'gnome-session': 'GNOME', 45 | 'mate-session': 'MATE', 46 | 'ksmserver': 'KDE', 47 | 'xfce4-session': 'Xfce', 48 | 'lxsession': 'LXDE' 49 | } 50 | 51 | wmDict = { 52 | 'awesome': 'Awesome', 53 | 'beryl': 'Beryl', 54 | 'blackbox': 'Blackbox', 55 | 'compiz': 'Compiz', 56 | 'dwm': 'DWM', 57 | 'enlightenment': 'Enlightenment', 58 | 'herbstluftwm': 'herbstluftwm', 59 | 'fluxbox': 'Fluxbox', 60 | 'fvwm': 'FVWM', 61 | 'i3': 'i3', 62 | 'icewm': 'IceWM', 63 | 'kwin': 'KWin', 64 | 'metacity': 'Metacity', 65 | 'musca': 'Musca', 66 | 'nemo': 'Nemo', 67 | 'openbox': 'Openbox', 68 | 'pekwm': 'PekWM', 69 | 'ratpoison': 'ratpoison', 70 | 'scrotwm': 'ScrotWM', 71 | 'wmaker': 'Window Maker', 72 | 'wmfs': 'Wmfs', 73 | 'wmii': 'wmii', 74 | 'xfwm4': 'Xfwm', 75 | 'xmonad': 'xmonad' 76 | } 77 | 78 | logosDict = {'Arch Linux': '''{color[1]} 79 | {color[1]} + {results[0]} 80 | {color[1]} # {results[1]} 81 | {color[1]} ### {results[2]} 82 | {color[1]} ##### {results[3]} 83 | {color[1]} ###### {results[4]} 84 | {color[1]} ; #####; {results[5]} 85 | {color[1]} +##.##### {results[6]} 86 | {color[1]} +########## {results[7]} 87 | {color[1]} ######{color[0]}#####{color[1]}##; {results[8]} 88 | {color[1]} ###{color[0]}############{color[1]}+ {results[9]} 89 | {color[1]} #{color[0]}###### ####### {results[10]} 90 | {color[0]} .######; ;###;`\". {results[11]} 91 | {color[0]} .#######; ;#####. {results[12]} 92 | {color[0]} #########. .########` {results[13]} 93 | {color[0]} ######' '###### {results[14]} 94 | {color[0]} ;#### ####; {results[15]} 95 | {color[0]} ##' '## {results[16]} 96 | {color[0]} #' `# {results[17]} 97 | \x1b[0m''' 98 | } 99 | 100 | processes = str(subprocess.check_output(('ps', '-u', getuser(), '-o', 'comm', 101 | '--no-headers')), encoding='utf8').rstrip('\n').split('\n') 102 | 103 | #---------------Classes---------------# 104 | 105 | class Output: 106 | results = [] 107 | results.extend(['']*(18-len(output))) 108 | 109 | def __init__(self): 110 | self.distro = self.__detectDistro() 111 | 112 | def __detectDistro(self): 113 | if os.path.exists('/etc/pacman.conf'): 114 | return 'Arch Linux' 115 | else: 116 | sys.exit(1) 117 | 118 | def append(self, display): 119 | self.results.append('%s%s: %s%s' % (colorDict[self.distro][1], display.key, colorDict['Clear'][0], display.value)) 120 | 121 | def output(self): 122 | print(logosDict[self.distro].format(color = colorDict[self.distro], results = self.results)) 123 | 124 | class User: 125 | def __init__(self): 126 | self.key = 'User' 127 | self.value = os.getenv('USER') 128 | 129 | class Hostname: 130 | def __init__(self): 131 | hostname = Popen(['uname', '-n'], stdout=PIPE).communicate()[0].decode('Utf-8').rstrip('\n') 132 | self.key = 'Hostname' 133 | self.value = hostname 134 | 135 | class Distro: 136 | def __init__(self): 137 | if os.path.exists('/etc/pacman.conf'): 138 | distro = 'Arch Linux' 139 | self.key = 'Distro' 140 | self.value = distro 141 | 142 | class Kernel: 143 | def __init__(self): 144 | kernel = Popen(['uname', '-r'], stdout=PIPE).communicate()[0].decode('Utf-8').rstrip('\n') 145 | self.key = 'Kernel' 146 | self.value = kernel 147 | 148 | class Uptime: 149 | def __init__(self): 150 | fuptime = int(open('/proc/uptime').read().split('.')[0]) 151 | day = int(fuptime / 86400) 152 | fuptime = fuptime % 86400 153 | hour = int(fuptime / 3600) 154 | fuptime = fuptime % 3600 155 | minute = int(fuptime / 60) 156 | uptime = '' 157 | if day == 1: 158 | uptime += '%d day, ' % day 159 | if day > 1: 160 | uptime += '%d days, ' % day 161 | uptime += '%d:%02d' % (hour, minute) 162 | self.key = 'Uptime' 163 | self.value = uptime 164 | 165 | class WindowManager: 166 | def __init__(self): 167 | wm = '' 168 | for key in wmDict.keys(): 169 | if key in processes: 170 | wm = wmDict[key] 171 | break 172 | 173 | self.key = 'Window Manager' 174 | self.value = wm 175 | 176 | class DesktopEnvironment: 177 | def __init__(self): 178 | de = '' 179 | for key in deDict.keys(): 180 | if key in processes: 181 | de = deDict[key] 182 | break 183 | 184 | self.key = 'Desktop Environment' 185 | self.value = de 186 | 187 | class Shell: 188 | def __init__(self): 189 | self.key = 'Shell' 190 | self.value = os.getenv('SHELL') 191 | 192 | class Terminal: 193 | def __init__(self): 194 | self.key = 'Terminal' 195 | self.value = os.getenv('TERM') 196 | 197 | class Packages: 198 | def __init__(self): 199 | p1 = Popen(['pacman', '-Q'], stdout=PIPE).communicate()[0].decode("Utf-8") 200 | packages = len(p1.rstrip('\n').split('\n')) 201 | self.key = 'Packages' 202 | self.value = packages 203 | 204 | class CPU: 205 | def __init__(self): 206 | file = open('/proc/cpuinfo').readlines() 207 | cpuinfo = re.sub(' +', ' ', file[4].replace('model name\t: ', '').rstrip('\n')) 208 | self.key = 'CPU' 209 | self.value = cpuinfo 210 | 211 | class RAM: 212 | def __init__(self): 213 | raminfo = Popen(['free', '-m'], stdout=PIPE).communicate()[0].decode('Utf-8').split('\n') 214 | ram = ''.join(filter(re.compile('M').search, raminfo)).split() 215 | used = int(ram[1]) - int(ram[5]) - int(ram[6]) 216 | usedpercent = ((float(used) / float(ram[1])) * 100) 217 | if usedpercent <= 33: 218 | ramdisplay = '%s%s MB %s/ %s MB' % (colorDict['Sensors'][1], used, colorDict['Clear'][0], ram[1]) 219 | if usedpercent > 33 and usedpercent < 67: 220 | ramdisplay = '%s%s MB %s/ %s MB' % (colorDict['Sensors'][2], used, colorDict['Clear'][0], ram[1]) 221 | if usedpercent >= 67: 222 | ramdisplay = '%s%s MB %s/ %s MB' % (colorDict['Sensors'][0], used, colorDict['Clear'][0], ram[1]) 223 | self.key = 'RAM' 224 | self.value = ramdisplay 225 | 226 | class Disk: 227 | def __init__(self): 228 | p1 = Popen(['df', '-Tlh', '--total', '-t', 'ext4', '-t', 'ext3', '-t', 'ext2', '-t', 'reiserfs', '-t', 'jfs', '-t', 'ntfs', '-t', 'fat32', '-t', 'btrfs', '-t', 'fuseblk', '-t', 'xfs'], stdout=PIPE).communicate()[0].decode("Utf-8") 229 | total = p1.splitlines()[-1] 230 | used = total.split()[3] 231 | size = total.split()[2] 232 | usedpercent = float(total.split()[5][:-1]) 233 | 234 | if usedpercent <= 33: 235 | disk = '%s%s %s/ %s' % (colorDict['Sensors'][1], used, colorDict['Clear'][0], size) 236 | if usedpercent > 33 and usedpercent < 67: 237 | disk = '%s%s %s/ %s' % (colorDict['Sensors'][2], used, colorDict['Clear'][0], size) 238 | if usedpercent >= 67: 239 | disk = '%s%s %s/ %s' % (colorDict['Sensors'][0], used, colorDict['Clear'][0], size) 240 | self.key = 'Disk' 241 | self.value = disk 242 | 243 | classes = { 244 | 'User': User, 245 | 'Hostname': Hostname, 246 | 'Distro': Distro, 247 | 'Kernel': Kernel, 248 | 'Uptime': Uptime, 249 | 'WindowManager': WindowManager, 250 | 'DesktopEnvironment': DesktopEnvironment, 251 | 'Shell': Shell, 252 | 'Terminal': Terminal, 253 | 'Packages': Packages, 254 | 'CPU': CPU, 255 | 'RAM': RAM, 256 | 'Disk': Disk 257 | } 258 | 259 | out = Output() 260 | for x in output: 261 | out.append(classes[x]()) 262 | out.output() 263 | --------------------------------------------------------------------------------