Skip to content

Fixed AttributeError checking for all properties #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 28, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 35 additions & 33 deletions osinfo.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
# Script Name : osinfo.py
# Author : Craig Richards
# Created : 5th April 2012
# Last Modified : April 02 2016
# Version : 1.0

# Modifications : Changed the list to a dictionary. Although the order is lost, the info is with its label.

# Description : Displays some information about the OS you are running this script on

import platform

profile = {
'Architecture: ': platform.architecture(),
#'Linux Distribution: ': platform.linux_distribution(),
'mac_ver: ': platform.mac_ver(),
'machine: ': platform.machine(),
'node: ': platform.node(),
'platform: ': platform.platform(),
'processor: ': platform.processor(),
'python build: ': platform.python_build(),
'python compiler: ': platform.python_compiler(),
'python version: ': platform.python_version(),
'release: ': platform.release(),
'system: ': platform.system(),
'uname: ': platform.uname(),
'version: ': platform.version(),
}

if hasattr(platform, 'linux_distribution'):
#to avoid AttributeError exception in some old versions of the module
profile['linux_distribution'] = platform.linux_distribution()
#FIXME: do this for all properties but in a loop
# Authors : {'geekcomputers': 'Craig Richards', 'dmahugh': 'Doug Mahugh','rutvik1010':'Rutvik Narayana Nadimpally','y12uc231': 'Satyapriya Krishna', 'minto4644':'Mohit Kumar'}
# Created : 5th April 2012
# Last Modified : July 19 2016
# Version : 1.0

# Modification 1 : Changed the profile to list again. Order is important. Everytime we run script we don't want to see different ordering.
# Modification 2 : Fixed the AttributeError checking for all properties. Using hasttr().
# Modification 3 : Removed ': ' from properties inside profile.


# Description : Displays some information about the OS you are running this script on

import platform as pl

profile = [
'architecture',
'linux_distribution',
'mac_ver',
'machine',
'node',
'platform',
'processor',
'python_build',
'python_compiler',
'python_version',
'release',
'system',
'uname',
'version',
]



for key in profile:
print(key + str(profile[key]))
if hasattr(pl,key):
print(key + ": "+ str(getattr(pl,key)()))