Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # myarchey for fogbox
- # Archey [version 0.2.8]
- #
- # Archey is a system information tool written in Python.
- #
- # Maintained by Melik Manukyan <[email protected]>
- # ASCII art by Brett Bohnenkamper <[email protected]>
- # Changes Jerome Launay <[email protected]>
- # Fedora support by YeOK <[email protected]>
- # Distributed under the terms of the GNU General Public License v3.
- # See http://www.gnu.org/licenses/gpl.txt for the full license text.
- # Import libraries
- import os, sys, subprocess, optparse, re, linecache
- from subprocess import Popen, PIPE
- from optparse import OptionParser
- from getpass import getuser
- from time import ctime, sleep
- # Display [Comment/Uncomment to Enable/Disable information.]
- display = [
- 'user', # Display Username
- 'hostname', # Display Machine Hostname
- 'distro', # Display Distribution
- 'kernel', # Display Kernel Version
- 'uptime', # Display System Uptime
- 'wm', # Display Window Manager
- 'de', # Display Desktop Environment
- 'sh', # Display Current Shell
- 'term', # Display Current Terminal
- 'packages', # Display Number of Packages Installed
- 'cpu', # Display CPU Model
- 'ram', # Display RAM Usage
- 'disk' # Display Disk Usage
- ]
- # Array containing Values
- result = []
- # Options
- if __name__=='__main__':
- parser = OptionParser(usage='%prog [-s, --screenshot]', description='Archey is a system information tool written in Python.', version="%prog 0.2.8")
- parser.add_option('-s', '--screenshot',
- action='store_true', dest='screenshot', help='take a screenshot')
- (options, args) = parser.parse_args()
- # Define processes for identifying Desktop Environmentss, Window Managers, Shells.
- de_dict = {
- 'gnome-session': 'GNOME',
- 'ksmserver': 'KDE',
- 'xfce4-session': 'Xfce'}
- wm_dict = {
- 'awesome': 'Awesome',
- 'beryl': 'Beryl',
- 'blackbox': 'Blackbox',
- 'compiz': 'Compiz',
- 'dwm': 'DWM',
- 'enlightenment': 'Enlightenment',
- 'fluxbox': 'Fluxbox',
- 'fvwm': 'FVWM',
- 'i3': 'i3',
- 'icewm': 'IceWM',
- 'kwin': 'KWin',
- 'metacity': 'Metacity',
- 'musca': 'Musca',
- 'openbox': 'Openbox',
- 'pekwm': 'PekWM',
- 'ratpoison': 'ratpoison',
- 'scrotwm': 'ScrotWM',
- 'wmaker': 'Window Maker',
- 'wmfs': 'Wmfs',
- 'wmii': 'wmii',
- 'xfwm4': 'Xfwm',
- 'xmonad': 'xmonad'}
- sh_dict = {
- 'zsh': 'Zsh',
- 'bash': 'Bash',
- 'dash': 'Dash',
- 'fish': 'Fish',
- 'ksh': 'Ksh',
- 'csh': 'Csh',
- 'jsh': 'Jsh',
- 'tcsh': 'Tcsh'}
- # Define Colour Scheme
- clear = '\x1b[0m'
- blackB = '\x1b[0;30m'
- blackB = '\x1b[1;30m'
- redN = '\x1b[0;31m'
- redB = '\x1b[1;31m'
- greenN = '\x1b[0;32m'
- greenB = '\x1b[1;32m'
- yellowN = '\x1b[0;33m'
- yellowB = '\x1b[1;33m'
- blueN = '\x1b[0;34m'
- blueB = '\x1b[1;34m'
- magentaN = '\x1b[0;35m'
- magentaB = '\x1b[1;35m'
- cyanN = '\x1b[0;36m'
- cyanB = '\x1b[1;36m'
- whiteN = '\x1b[0;37m'
- whiteB = '\x1b[1;37m'
- # Find running processes.
- def xmonadfix(str):
- if re.compile("xmonad").match(str): return "xmonad"
- return str
- p1 = Popen(['ps', '-u', getuser()], stdout=PIPE).communicate()[0].split('\n')
- processes = map(xmonadfix, [process.split()[3] for process in p1 if process])
- p1 = None
- # Find Distro.
- DetectDistro = Popen(['lsb_release', '-i'], stdout=PIPE).communicate()[0].split(':')[1].lstrip('\t').rstrip('\n')
- # Print coloured key with normal value.
- def output(key, value):
- if DetectDistro == 'fogbox':
- output ='%s%s:%s %s' % (blueN, key, clear, value)
- result.append(output)
- # RAM Function.
- def ram_display():
- raminfo = Popen(['free', '-m'], stdout=PIPE).communicate()[0].split('\n')
- ram = ''.join(filter(re.compile('M').search, raminfo)).split()
- used = int(ram[2]) - int(ram[5]) - int(ram[6])
- usedpercent = ((float(used) / float(ram[1])) * 100)
- if usedpercent <= 33:
- ramdisplay = '%s%s MB %s/ %s MB' % (greenB, used, clear, ram[1])
- output('RAM', ramdisplay)
- if usedpercent > 33 and usedpercent < 67:
- ramdisplay = '%s%s MB %s/ %s MB' % (yellowB, used, clear, ram[1])
- output('RAM', ramdisplay)
- if usedpercent >= 67:
- ramdisplay = '%s%s MB %s/ %s MB' % (redB, used, clear, ram[1])
- output('RAM', ramdisplay)
- # Screenshot Function.
- screen = '%s' % options.screenshot
- def screenshot():
- print 'Taking shot in',
- list = range(1,6)
- list.reverse()
- for x in list:
- print '%s..' % x,
- sys.stdout.flush()
- sleep(1)
- print 'Say Cheeze!'
- subprocess.check_call(['scrot'])
- # Operating System Function.
- def distro_display():
- arch = Popen(['uname', '-m'], stdout=PIPE).communicate()[0].rstrip('\n')
- if DetectDistro == 'fogbox':
- release = Popen(['lsb_release', '-r'], stdout=PIPE).communicate()[0].split(':')[1].lstrip('\t').rstrip('\n')
- distro = 'fogbox %s %s' % (release, arch)
- output('OS', distro)
- # Kernel Function.
- def kernel_display():
- kernel = Popen(['uname', '-r'], stdout=PIPE).communicate()[0].rstrip('\n')
- output ('Kernel', kernel)
- def user_display():
- username= os.getenv('USER')
- output ('User', username)
- # Hostname Function.
- def hostname_display():
- hostname = Popen(['uname', '-n'], stdout=PIPE).communicate()[0].rstrip('\n')
- output('Hostname', hostname)
- # CPU Function.
- def cpu_display():
- file = open('/proc/cpuinfo').readlines()
- cpuinfo = re.sub(' +', ' ', file[4].replace('model name\t: ', '').rstrip('\n'))
- output ('CPU', cpuinfo)
- # Uptime Function.
- def uptime_display():
- fuptime = int(open('/proc/uptime').read().split('.')[0])
- day = int(fuptime / 86400)
- fuptime = fuptime % 86400
- hour = int(fuptime / 3600)
- fuptime = fuptime % 3600
- minute = int(fuptime / 60)
- uptime = ''
- if day == 1:
- uptime += '%d day, ' % day
- if day > 1:
- uptime += '%d days, ' % day
- uptime += '%d:%02d' % (hour, minute)
- output('Uptime', uptime)
- # Desktop Environment Function.
- def de_display():
- for key in de_dict.keys():
- if key in processes:
- de = de_dict[key]
- output ('Desktop Environment', de)
- # Window Manager Function.
- def wm_display():
- for key in wm_dict.keys():
- if key in processes:
- wm = wm_dict[key]
- output ('Window Manager', wm)
- # Shell Function.
- def sh_display():
- sh = os.getenv("SHELL").split('/')[-1].capitalize()
- output ('Shell', sh)
- # Terminal Function.
- def term_display():
- term = os.getenv("TERM").split('/')[-1].capitalize()
- output ('Terminal', term)
- # Packages Function.
- def packages_display():
- if DetectDistro == 'fogbox':
- p1 = Popen(['dpkg', '--get-selections'], stdout=PIPE)
- p2 = Popen(['grep', '-v', 'deinstall'], stdin=p1.stdout, stdout=PIPE)
- p3 = Popen(['wc', '-l'], stdin=p2.stdout, stdout=PIPE)
- packages = p3.communicate()[0].rstrip('\n')
- output ('Packages', packages)
- # Disk Function.
- def disk_display():
- p1 = Popen(['df', '-Tlh', '--total', '-t', 'ext4', '-t', 'ext3', '-t', 'ext2', '-t', 'reiserfs', '-t', 'jfs', '-t', 'ntfs', '-t', 'fat32', '-t', 'btrfs', '-t', 'fuseblk'], stdout=PIPE).communicate()[0]
- total = p1.splitlines()[-1]
- used = total.split()[3]
- size = total.split()[2]
- usedpercent = float(re.sub("[A-Z]", "", used)) / float(re.sub("[A-Z]", "", size)) * 100
- if usedpercent <= 33:
- fs = '%s%s %s/ %s' % (greenB, used, clear, size)
- output ('Disk', fs)
- if usedpercent > 33 and usedpercent < 67:
- fs = '%s%s %s/ %s' % (yellowB, used, clear, size)
- output ('Disk', fs)
- if usedpercent >= 67:
- fs = '%s%s %s/ %s' % (redB, used, clear, size)
- output ('Disk', fs)
- # Run functions found in 'display' array.
- for x in display:
- funcname=x+'_display'
- func=locals()[funcname]
- func()
- # Array containing values.
- result.extend(['']*(20 - len(display)))
- # Result.
- if DetectDistro == 'fogbox':
- print """
- %s ..ed$$$$$be.. %s
- %s .d$$$$$$$$$$$$$$c %s
- %s .$$$$P"" $$$ ""*$$$$c %s
- %s z$$$*" $$$ *$$$e %s
- %s z$$$" $$$ ^$$$L %s
- %s $$$F $$$ '$$$ %s
- %s 4$$$ d$$$$. $$$F %s
- %s 4$$$ .$$$$$$$e $$$F %s
- %s $$$r d$$P$$$$$$$. .$$$" %s
- %s *$$$..$$$" $$$ "$$$e $$$P %s
- %s *$$$$$P" $$$ ^*$$$$$$ %s
- %s *$$$$c. $$$ .z$$$$P %s
- %s ^*$$$$$$$$$$$$$$$P" %s
- %s "*$$$$$$$$$*"" %s
- %s""" % ( redN, result[0], redN, result[1], redN, result[2], redN, result[3], redN, result[4], redN, result[5], redN, result[6], redN, result[7], redN, result[8], redN, result[9], redN, result[10], redN, result[11], redN, result[12], redN, result[13], clear )
- if screen == 'True':
- screenshot()
Advertisement
Add Comment
Please, Sign In to add comment