home *** CD-ROM | disk | FTP | other *** search
- #
- # sysInfo.py
- # JunkMatcher
- #
- # Created by Benjamin Han on 3/11/05.
- # Copyright (c) 2005 Benjamin Han. All rights reserved.
- #
-
- # 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 2
- # of the License, or (at your option) any later version.
-
- # 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.
-
- # You should have received a copy of the GNU General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
- #/usr/bin/env python
-
- import os, sys, re
-
-
- def sysInfo ():
- myID=os.environ['USER']
-
- osVersion = os.popen('sw_vers -productVersion').read().rstrip()
- osBuild = os.popen('sw_vers -buildVersion').read().rstrip()
- darwinVer = os.popen('uname -r').read().rstrip()
-
- admins = os.popen('/usr/bin/niutil -readprop . /groups/admin users').read().rstrip().split(' ')
- shell = os.popen('/usr/bin/niutil -readprop . /users/%s shell' % myID).read().rstrip()
-
- sysProfile = os.popen('/usr/sbin/system_profiler SPHardwareDataType').read().strip()
- machineModel = re.compile(r'(?i)Machine Model: ([^\n]+)').search(sysProfile).group(1)
- cpu = re.compile(r'(?i)CPU Speed: ([^\n]+)').search(sysProfile).group(1)
- mem = re.compile(r'(?i)Memory: ([^\n]+)').search(sysProfile).group(1)
-
- ret = []
- ret.append('OS: %s %s (%s)' % (osVersion, osBuild, darwinVer))
- ret.append('Machine: %s; CPU: %s; Memory: %s' % (machineModel , cpu, mem))
- if myID in admins:
- ret.append('Running as an admin, using shell %s' % shell)
- else:
- ret.append('Running as a non-admin, using shell %s' % shell)
-
- ret.append('Python version %s' % sys.version)
-
- return '\n'.join(ret)
-
-
- if __name__ == '__main__':
- print sysInfo()
-