2012-04-13 03:50:29 +04:00
|
|
|
import inspect
|
|
|
|
import platform
|
2012-04-03 03:52:35 +04:00
|
|
|
import sys
|
2012-04-13 03:50:29 +04:00
|
|
|
import traceback
|
2012-04-03 03:52:35 +04:00
|
|
|
|
2012-04-13 03:50:29 +04:00
|
|
|
def system_name():
|
|
|
|
"""Determine the os from platform.system
|
2012-04-04 00:30:58 +04:00
|
|
|
"""
|
2012-04-13 03:50:29 +04:00
|
|
|
system = platform.system().lower()
|
|
|
|
if system == 'darwin':
|
|
|
|
system = 'mac'
|
|
|
|
return system
|
2012-04-04 00:30:58 +04:00
|
|
|
|
2012-04-13 03:50:29 +04:00
|
|
|
def system_version():
|
|
|
|
"""Determine the os version
|
|
|
|
"""
|
|
|
|
system = platform.system().lower()
|
|
|
|
if system == 'linux':
|
|
|
|
return ' '.join(platform.linux_distribution[0:2])
|
|
|
|
if system == 'darwin':
|
|
|
|
return platform.mac_ver[0]
|
|
|
|
if system == 'windows':
|
|
|
|
return platform.win32_ver()[1]
|
|
|
|
return 'Unknown'
|
|
|
|
|
|
|
|
def download_platform():
|
|
|
|
system = system_name()
|
|
|
|
if system == 'linux':
|
|
|
|
if platform.machine() == 'x86_64':
|
|
|
|
return 'linux64'
|
|
|
|
return 'linux32
|
|
|
|
if system == 'windows':
|
|
|
|
if platform.machine() == 'x86_64':
|
|
|
|
return 'win64'
|
|
|
|
return 'win32'
|
|
|
|
return system
|
|
|
|
|
|
|
|
def download_suffix():
|
|
|
|
system = platform.system().lower()
|
|
|
|
if system == 'linux':
|
|
|
|
return 'tar.gz'
|
|
|
|
if system == 'darwin':
|
|
|
|
return 'dmg'
|
|
|
|
return 'zip'
|
|
|
|
|
|
|
|
def main(_main):
|
|
|
|
"""Mark a function as the main function to run when run as a script.
|
|
|
|
If that function throws an exception, we'll print the traceback to
|
|
|
|
stderr and exit.
|
|
|
|
"""
|
|
|
|
parent = inspect.stack()[1][0]
|
|
|
|
name = parent.f_locals.get('__name__', None)
|
|
|
|
if name == '__main__':
|
|
|
|
try:
|
|
|
|
_main()
|
|
|
|
except Exception, e:
|
|
|
|
traceback.print_tb(sys.exc_info()[2], None, sys.stderr)
|
|
|
|
sys.exit(1)
|
|
|
|
sys.exit(0)
|
|
|
|
return _main
|