Detect Python Arch under Windows OS

This commit is contained in:
Ivan Kravets
2016-10-13 00:42:16 +03:00
parent 90e9dfcd33
commit 9348dc12be

View File

@ -16,6 +16,7 @@ import collections
import functools import functools
import json import json
import os import os
import platform
import re import re
import socket import socket
import stat import stat
@ -24,7 +25,6 @@ import sys
from glob import glob from glob import glob
from os.path import (abspath, basename, dirname, expanduser, isdir, isfile, from os.path import (abspath, basename, dirname, expanduser, isdir, isfile,
join, normpath, splitdrive) join, normpath, splitdrive)
from platform import system, uname
from shutil import rmtree from shutil import rmtree
from threading import Thread from threading import Thread
from time import sleep from time import sleep
@ -159,9 +159,10 @@ def load_json(file_path):
def get_systype(): def get_systype():
data = uname() type_ = platform.system().lower()
type_ = data[0].lower() arch = platform.machine().lower()
arch = data[4].lower() if data[4] else "" if type_ == "windows":
arch = "amd64" if platform.architecture()[0] == "64bit" else "x86"
return "%s_%s" % (type_, arch) if arch else type_ return "%s_%s" % (type_, arch) if arch else type_
@ -359,7 +360,7 @@ def get_serialports():
for p, d, h in comports(): for p, d, h in comports():
if not p: if not p:
continue continue
if system() == "Windows": if platform.system() == "Windows":
try: try:
d = unicode(d, errors="ignore") d = unicode(d, errors="ignore")
except TypeError: except TypeError:
@ -367,7 +368,7 @@ def get_serialports():
result.append({"port": p, "description": d, "hwid": h}) result.append({"port": p, "description": d, "hwid": h})
# fix for PySerial # fix for PySerial
if not result and system() == "Darwin": if not result and platform.system() == "Darwin":
for p in glob("/dev/tty.*"): for p in glob("/dev/tty.*"):
result.append({"port": p, "description": "n/a", "hwid": "n/a"}) result.append({"port": p, "description": "n/a", "hwid": "n/a"})
return result return result
@ -375,7 +376,7 @@ def get_serialports():
def get_logicaldisks(): def get_logicaldisks():
disks = [] disks = []
if system() == "Windows": if platform.system() == "Windows":
result = exec_command( result = exec_command(
["wmic", "logicaldisk", "get", "name,VolumeName"]).get("out", "") ["wmic", "logicaldisk", "get", "name,VolumeName"]).get("out", "")
disknamere = re.compile(r"^([A-Z]{1}\:)\s*(\S+)?") disknamere = re.compile(r"^([A-Z]{1}\:)\s*(\S+)?")