summaryrefslogtreecommitdiff
path: root/archey
blob: fe3f8027703beb4a1eb773238979a810d6b97952 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#!/usr/bin/env python
#
# archey [version 0.2.4]
#
# Maintained by Melik Manukyan <melik@archlinux.us>
# Distributed under the terms of the GNU General Public License v3.
# See http://www.gnu.org/licenses/gpl.txt for the full license text.
#
# System information tool for Archlinux written in python.

# 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 = [
 'distro', # Display Distribution
 'hostname', # Display Machine Hostname
 'kernel',  # Display Kernel Version
 'uptime',  # Display System Uptime
 'wm',  # Display Window Manager
 'de', # Display Desktop Environment
 'packages', # Display Number of Packages Installed
 'ram', # Display RAM Usage
 'cpu', # Display CPU Model
 'sh', # Display Current Shell
 'term', # Display Current Terminal
 'fs' # Display / Partition 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.4")
 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',
 'xfconfd': '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 Color Schemes.

# Clear 
clear = '\x1b[0m'

# Arch Linux.
acolor = '\x1b[1;34m'
acolor2 = '\x1b[0;34m' 

# Ubuntu.
ucolor = '\x1b[1;33m'
ucolor2 = '\x1b[1;31m'
ucolor3 = '\x1b[0;31m'

# 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.
DetectLsb = os.path.exists('/etc/lsb-release')
if DetectLsb:
 DetectUbuntu = Popen(['grep', '-i', 'ubuntu', '/etc/lsb-release'], stdout=PIPE)
DetectArch = os.path.exists('/etc/arch-release')

# Print coloured key with normal value.
def output(key, value):
 if DetectUbuntu:
  ucolor = '\x1b[1;31m'
  output ='%s%s:%s %s' % (ucolor, key, clear, value)
 if DetectArch:
  ucolor = '\x1b[1;34m'
  output = '%s%s:%s %s' % (acolor, 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])
 output ('RAM', '%s MB / %s MB' % (used, ram[1]))

# 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 DetectUbuntu: 
  urelease = linecache.getline('/etc/lsb-release', 2).rstrip('\n').split('=')[1].title()
  distro = 'Ubuntu %s %s' % (urelease, arch)
 if DetectArch: 
  distro = 'Arch Linux %s' % arch 
 output('OS', distro)

# Kernel Function.
def kernel_display():
 kernel = Popen(['uname', '-r'], stdout=PIPE).communicate()[0].rstrip('\n')
 output ('Kernel', kernel)

# 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():
 de = 'None found'
 for key in de_dict.keys():
  if key in processes:
   de = de_dict[key]
   output ('Desktop Environment', de)

# Window Manager Function.
def wm_display():
 wm = 'None found'
 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 DetectUbuntu:
  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)
 if DetectArch:
  p1 = Popen(['pacman', '-Q'], stdout=PIPE)
  p2 = Popen(['wc', '-l'], stdin=p1.stdout, stdout=PIPE)
  packages = p2.communicate()[0].rstrip('\n')
  output ('Packages', packages)

# File System Function.
def fs_display():
 supported = ('ext2', 'ext3', 'ext4', 'reiserfs', 'jfs', 'ntfs', 'fat32', 'btrfs')
 p1 = Popen(['df', '-TPh'], stdout=PIPE).communicate()[0]
 filesystems = p1.rstrip().split('\n')
 del filesystems[0]

 for fs in filesystems:
  fs_split = fs.split()
  used = fs_split[3]
  total = fs_split[2]
  type = fs_split[1]
  name = fs_split[6]
  part = '%s / %s (%s)' % (used, total, type)
  if name == '/': name = '/root'
  fs = name.rpartition('/')[2].title() + " FS"
  if type in supported:
   output (fs, part)

# 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 DetectUbuntu:
 print """
%s                              ++++++           %s
%s                             ++++++++          %s
%s                  ++++++++++ %s++++++++          %s 
%s                ++++++++++++ %s++++++++          %s
%s             ++  %s++++++++++++ %s++++++           %s
%s           +++++  %s++++++++++++ %s****            %s
%s          +++++++  %s+++++++++++++++++++         %s
%s         +++++++++          %s+++++++++++        %s
%s        ++++++++++            %s++++++++++       %s
%s        ++++++++               %s++++++++++      %s
%s  ++++++ %s++++++                 %s++++++++++     %s
%s ++++++++ %s+++++                  %s+++++++++     %s
%s +++++++++ %s++++                                %s
%s ++++++++ %s+++++                  %s+++++++++     %s
%s  ++++++ %s++++++                 %s++++++++++     %s
%s        ++++++++               %s++++++++++      %s
%s        +++++++++             %s++++++++++       %s
%s         +++++++++         %s++++++++++++        %s
%s          +++++++  %s+++++++++++++++++++         
%s           +++++  %s++++++++++++ %s,,,,            
%s             ++  %s++++++++++++ %s++++++           
%s                ++++++++++++ %s++++++++          
%s                  ++++++++++ %s++++++++          
%s                             ++++++++          
%s                              ++++++           
%s """ % (ucolor3, result[0], ucolor3, result[1], ucolor2, ucolor3, result[2], ucolor2, ucolor3, result[3], ucolor, ucolor2, ucolor3, result[4], ucolor, ucolor2, ucolor3, result[5], ucolor, ucolor2, result[6], ucolor, ucolor2, result[7], ucolor, ucolor2, result[8], ucolor, ucolor2, result[9], ucolor2, ucolor, ucolor2, result[10], ucolor2, ucolor, ucolor2, result[11], ucolor2, ucolor, result[12], ucolor2, ucolor, ucolor3, result[13], ucolor2, ucolor, ucolor3, result[14], ucolor, ucolor3, result[15], ucolor, ucolor3, result[16], ucolor, ucolor3, ucolor, ucolor, ucolor3, ucolor, ucolor3, ucolor, ucolor, ucolor3, ucolor, ucolor3, ucolor, ucolor3, ucolor, ucolor, ucolor, clear)

if DetectArch:
 print """%s
%s               +                %s
%s               #                %s
%s              ###               %s
%s             #####              %s
%s             ######             %s
%s            ; #####;            %s
%s           +##.#####            %s
%s          +##########           %s
%s         ######%s#####%s##;         %s
%s        ###%s############%s+        %s
%s       #%s######   #######        %s
%s     .######;     ;###;`\".      %s
%s    .#######;     ;#####.       %s
%s    #########.   .########`     %s
%s   ######'           '######    %s
%s  ;####                 ####;   %s
%s  ##'                     '##  %s 
%s #'                         `#  %s
%s """ % (acolor, acolor, result[0], acolor, result[1], acolor, result[2], acolor, result[3], acolor, result[4], acolor, result[5], acolor, result[6], acolor, result[7], acolor, acolor2, acolor, result[8], acolor, acolor2, acolor, result[9], acolor, acolor2, result[10], acolor2, result[11], acolor2, result[12], acolor2, result[13], acolor2, result[14], acolor2, result[15], acolor2, result[16], acolor2, result[17], clear)

if screen == 'True':
 screenshot()