Python os 模块,uname() 实例源码
我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用os.uname()。
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,but it
needs some hacks for Linux and Mac OS X.
"""
try:
# Python 2.7 or >=3.2
from sysconfig import get_platform
except ImportError:
from distutils.util import get_platform
plat = get_platform()
if sys.platform == "darwin" and not plat.startswith('macosx-'):
try:
version = _macosx_vers()
machine = os.uname()[4].replace(" ", "_")
return "macosx-%d.%d-%s" % (int(version[0]), int(version[1]),
_macosx_arch(machine))
except ValueError:
# if someone is running a non-Mac darwin system,this will fall
# through to the default implementation
pass
return plat
def index(request):
if request.method == "POST":
user = authenticate(username=request.POST.get('email'), password=request.POST.get('password'))
if user is not None:
if user.is_active:
login(request, user)
return HttpResponseRedirect(request.GET.get('next') or '/')
else:
response_data = {'message': "Your account has been disabled!"}
else:
response_data = {'message': 'The username and password are incorrect.'}
return render(request, 'login.html', response_data)
elif request.user.is_authenticated():
host_name, kernel = uname()[1:3]
return render(request, 'dashboard.html', {'host_name': host_name, 'kernel': kernel, 'ip_addr': HOST_IP_ADDR})
else:
return render(request, 'login.html')
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def _mac_ver_xml():
fn = '/System/Library/CoreServices/SystemVersion.plist'
if not os.path.exists(fn):
return None
try:
import plistlib
except ImportError:
return None
pl = plistlib.readPlist(fn)
release = pl['ProductVersion']
versioninfo=('', '', '')
machine = os.uname()[4]
if machine in ('ppc', 'Power Macintosh'):
# for compatibility with the gestalt based code
machine = 'PowerPC'
return release,versioninfo,machine
def reset(self, variantId, buildId, resultHash):
self.__variantId = variantId
self.__buildId = buildId
self.__resultHash = resultHash
self.__recipes = None
self.__defines = {}
u = os.uname()
self.__build = {
'sysname' : u.sysname,
'nodename' : u.nodename,
'release' : u.release,
'version' : u.version,
'machine' : u.machine,
'date' : datetime.now(timezone.utc).isoformat(),
}
self.__env = ""
self.__metaEnv = {}
self.__scms = []
self.__deps = []
self.__tools = {}
self.__sandbox = None
self.__id = None
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def copy(src, dest, dryrun=False, debug=False):
"""
Copy file/directory using `rsync` with metadata preserved,and to
keep directory contents in sync.
Use `rsync --version` to check the available capabilities.
"""
if os.path.isdir(src):
src = src.rstrip("/") + "/"
dest = dest.rstrip("/") + "/"
logger.info("Copy & sync: %s -> %s" % (src, dest))
args = ["--archive", "--hard-links", "--numeric-ids",
"--delete", "--delete-after"]
if os.uname().sysname == "Linux":
args += ["--acls", "--xattrs"]
if debug:
args += ["--verbose"]
cmd = ["rsync"] + args + [src, dest]
if not dryrun:
subprocess.check_call(cmd)
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def _mac_ver_xml():
fn = '/System/Library/CoreServices/SystemVersion.plist'
if not os.path.exists(fn):
return None
try:
import plistlib
except ImportError:
return None
pl = plistlib.readPlist(fn)
release = pl['ProductVersion']
versioninfo=('',machine
def _syscmd_uname(option,default=''):
""" Interface to the system's uname command.
"""
if sys.platform in ('dos','win32','win16','os2'):
# XXX Others too ?
return default
try:
f = os.popen('uname %s 2> %s' % (option, DEV_NULL))
except (AttributeError,os.error):
return default
output = string.strip(f.read())
rc = f.close()
if not output or rc:
return default
else:
return output
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def __init__(self):
if self.info is not None:
return
info = [ {} ]
ok, output = getoutput('uname -m')
if ok:
info[0]['uname_m'] = output.strip()
try:
fo = open('/proc/cpuinfo')
except EnvironmentError:
e = get_exception()
warnings.warn(str(e), UserWarning)
else:
for line in fo:
name_value = [s.strip() for s in line.split(':', 1)]
if len(name_value) != 2:
continue
name, value = name_value
if not info or name in info[-1]: # next processor
info.append({})
info[-1][name] = value
fo.close()
self.__class__.info = info
def __init__(self):
if self.info is not None:
return
info = command_info(arch='arch',
mach='mach',
uname_i='uname_i',
isainfo_b='isainfo -b',
isainfo_n='isainfo -n',
)
info['uname_X'] = key_value_from_command('uname -X', sep='=')
for line in command_by_line('psrinfo -v 0'):
m = re.match(r'\s*The (?P<p>[\w\d]+) processor operates at', line)
if m:
info['processor'] = m.group('p')
break
self.__class__.info = info
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def getportname():
'''
Use /dev port if on Raspberry Pi (arm processor)
'''
if platform.system() == 'Linux':
if os.uname()[4][:3] == 'arm':
logger.info('Linux detected (ARM processor). Raspberry Pi environment likely. Defaulting to /dev/ttyAMA0')
return '/dev/ttyAMA0'
else:
logger.info('Generic Linux detected. Defaulting to first COM Port')
return 0
elif platform.system() == 'Windows':
logger.info('Windows detected. Defaulting to first COM Port')
return 'COM1'
else:
return 0 # Interpreted by Pyserial as the first serial port
def getportname():
'''
Use /dev port if on Raspberry Pi (arm processor)
'''
if platform.system() == 'Linux':
if os.uname()[4][:3] == 'arm':
logger.info('Linux detected (ARM processor). Raspberry Pi environment likely. Defaulting to /dev/ttyAMA0')
return '/dev/ttyAMA0'
else:
logger.info('Generic Linux detected. Defaulting to first COM Port')
return 0
elif platform.system() == 'Windows':
logger.info('Windows detected. Defaulting to first COM Port')
return 'COM1'
else:
return 0 # Interpreted by Pyserial as the first serial port
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def __fetch_host_release__(self):
"""Helper to return the hosts sanitized RELEASE"""
rel = os.uname()[2]
self.release = rel.rsplit("-", 1)[0]
if "-STABLE" in rel:
# FreeNAS
self.release = f"{self.release}-RELEASE"
elif "-HBSD" in rel:
# HardenedBSD
self.release = re.sub(r"\W\w.", "-", self.release)
self.release = re.sub(r"([A-Z])\w+", "STABLE", self.release)
elif "-RELEASE" not in rel:
self.release = "Not a RELEASE"
return self.release
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat
def get_build_platform():
"""Return this platform's string for platform-specific distributions
XXX Currently this is the same as ``distutils.util.get_platform()``,this will fall
# through to the default implementation
pass
return plat