summaryrefslogtreecommitdiff
path: root/archey.new
blob: 362dae9846ec008d25769ca07f4513fd8f9f0940 (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
#!/usr/bin/env python
#
# Archey [version 0.3.0]
#
# Archey is a simple system information tool written in Python.
#
# Copyright 2010 Melik Manukyan <melik@archlinux.us>
#
# ASCII art by Brett Bohnenkamper <kittykatt@silverirc.com>
# Changes Jerome Launay <jerome@projet-libre.org>
# Fedora support by YeOK <yeok@henpen.org>
#
# 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

#---------------Output---------------#

output = [
 'User',
 'Hostname',
 'Distro',
 'Kernel',
 'Uptime',
 'WindowManager',
 'DesktopEnvironment',
 'Shell',
 'Terminal',
 'Packages',
 'CPU',
 'RAM',
 'Disk'
 ]
 
#---------------Dictionaries---------------#

colorDict = {
	'Arch Linux': ['\x1b[0;34m', '\x1b[1;34m'],
	'Ubuntu': ['\x1b[0;31m', '\x1b[1;31m', '\x1b[0;33m'],
	'Debian': ['\x1b[0;31m', '\x1b[1;31m'],
	'Mint': ['\x1b[0;32m', '\x1b[1;37m'],
	'Crunchbang': ['\x1b[1;37m'],
	'Fedora': ['\x1b[0;34m', '\x1b[1;37m'],
	'Clear': ['\x1b[0m']
	}
	
deDict = {
	'gnome-session': 'GNOME',
	'ksmserver': 'KDE',
	'xfce4-session': 'Xfce',
	'lxsession': 'LXDE'
	}

wmDict = {
	'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'
	}

logosDict = {'Arch Linux': '''{color[1]}
{color[1]}               +                {results[0]}
{color[1]}               #                {results[1]}
{color[1]}              ###               {results[2]}
{color[1]}             #####              {results[3]}
{color[1]}             ######             {results[4]}
{color[1]}            ; #####;            {results[5]}
{color[1]}           +##.#####            {results[6]}
{color[1]}          +##########           {results[7]}
{color[1]}         ######{color[0]}#####{color[1]}##;         {results[8]}
{color[1]}        ###{color[0]}############{color[1]}+        {results[9]}
{color[1]}       #{color[0]}######   #######        {results[10]}
{color[0]}     .######;     ;###;`\".      {results[11]}
{color[0]}    .#######;     ;#####.       {results[12]}
{color[0]}    #########.   .########`     {results[13]}
{color[0]}   ######'           '######    {results[14]}
{color[0]}  ;####                 ####;   {results[15]}
{color[0]}  ##'                     '##   {results[16]} 
{color[0]} #'                         `#  {results[17]}
\x1b[0m'''
}

processes = Popen(['ps', '-u', getuser()],stdout=PIPE).communicate()[0].split(b'\n')

#---------------Classes---------------#

class Output:
	results = []
	results.extend(['']*(13))
	
	def __init__(self):
		self.distro = self.__detectDistro()
		
	def __detectDistro(self):
		if os.path.exists('/etc/pacman.conf'):
			return 'Arch Linux'
		else:
			sys.exit(1)
			
	def append(self, display):
		self.results.append('%s%s: %s%s' % (colorDict[self.distro][1], display.key, colorDict['Clear'][0], display.value))
		
	def output(self):
		print(logosDict[self.distro].format(color = colorDict[self.distro], results = self.results))
			
class User:
	def __init__(self):
		self.key = 'User'
		self.value = os.getenv('USER')

#class Hostname:
#	def __init__(self):
			
#class Distro:
#	def __init__(self):
			
#class Kernel:
#	def __init__(self):
			
class Uptime:		
	def __init__(self):
		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)
		self.key = 'Uptime'
		self.value = uptime
	
class WindowManager:
	def __init__(self):
		wm = ''
		for key in wmDict.keys():
			if key in processes:
				wm = wmDict[key]
				break
					
		self.key = 'Window Manager'
		self.value = wm
			
class DesktopEnvironment:
	def __init__(self):
		de = ''
		for key in deDict.keys():
			if key in processes:
				wm = wmDict[key]
				break
					
		self.key = 'Desktop Environment'
		self.value = de
			
class Shell:
	def __init__(self):
		self.key = 'Shell'
		self.value = os.getenv('SHELL')
			
class Terminal:
	def __init__(self):
		self.key = 'Terminal'
		self.value = os.getenv('TERM')
			
#class Packages:
#	def __init__(self):
			
#class CPU:
#	def __init__(self):
			
#class RAM:
#	def __init__(self):
			
#class Disk:
#	def __init__(self):


## TEST ## <<< TEMPORARY 
out = Output()
out.append(Shell())
out.append(User())
out.append(Terminal())
out.append(Uptime())
out.append(WindowManager())
#out.append(DesktopEnvirornment())
out.output()