summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikolay Zamotaev <nzamotaev@luxoft.com>2018-10-24 20:55:11 +0300
committerNikolay Zamotaev <nzamotaev@luxoft.com>2018-12-13 12:02:16 +0000
commit97403e148e15e21b1f8d82e02df1c8ab7528025f (patch)
tree680f4709b27c86622e34ced2b726c82527dbbcbe
parentbf62f449e41073fee09f87df858489fab23cf018 (diff)
Update for architecture and bitness detection and processing
This is done to match QSysInfo::currentCpuArchitecture(), kernelVersion() and buildAbi() See implementation in neptune3-ui for details. Without this code, neptune3-ui would be unable to get native applications. Change-Id: Ic336b364575bc22c1812693fea254d4898f1ee6f Fixes: AUTOSUITE-670 Reviewed-by: Dominik Holland <dominik.holland@pelagicore.com>
-rw-r--r--store/api.py3
-rw-r--r--store/osandarch.py51
2 files changed, 45 insertions, 9 deletions
diff --git a/store/api.py b/store/api.py
index f2d911e..6e951a4 100644
--- a/store/api.py
+++ b/store/api.py
@@ -43,6 +43,7 @@ from authdecorators import logged_in_or_basicauth, is_staff_member
from models import App, Category, Vendor, savePackageFile
from utilities import parsePackageMetadata, parseAndValidatePackageMetadata, addSignatureToPackage
from utilities import packagePath, iconPath, downloadPath, validateTag
+from osandarch import normalizeArch
def hello(request):
@@ -64,7 +65,7 @@ def hello(request):
break
request.session[j] = taglist
if 'architecture' in request.REQUEST:
- request.session['architecture'] = request.REQUEST['architecture']
+ request.session['architecture'] = normalizeArch(request.REQUEST['architecture'])
else:
request.session['architecture'] = ''
return JsonResponse({'status': status})
diff --git a/store/osandarch.py b/store/osandarch.py
index f3aa388..c7d15a6 100644
--- a/store/osandarch.py
+++ b/store/osandarch.py
@@ -42,6 +42,8 @@
# PE32+ executable (DLL) (GUI) x86-64, for MS Windows
# PE32+ executable (GUI) x86-64, for MS Windows
+import re
+
def parseMachO(str): # os, arch, bits, endianness
if " universal " in str:
# Universal binary - not supported
@@ -50,7 +52,7 @@ def parseMachO(str): # os, arch, bits, endianness
arch = str.split(' ')
arch = arch[2]
bits = str.split(' ')[1].replace('-bit', '')
- endianness = "lsb"
+ endianness = "little_endian"
return [os, arch, bits, endianness]
@@ -65,24 +67,28 @@ def parsePE32(str):
bits = '64'
if arch == '80386':
arch = 'i386'
- endianness = "lsb"
+ endianness = "little_endian"
return [os, arch, bits, endianness]
-def parseElfArch(str, architecture):
+def parseElfArch(str, architecture, bits):
architecture = architecture.strip()
if architecture.startswith("ARM"):
if 'aarch64' in architecture:
- return 'aarch64'
+ return 'arm64'
if 'armhf' in str: # this does not work for some reason - from_file() returns longer data than from_buffer() - needs fix
- return 'armhf'
+ return 'arm' # because qt does not report it directly
elif architecture.startswith("Intel"):
if '80386' in architecture:
return 'i386'
elif architecture.startswith("IBM S/390"):
return 's/390'
elif "PowerPC" in architecture:
- return 'powerpc'
+ if bits == "64":
+ return "power64"
+ else:
+ return 'power'
+ # sparc architecture is currently ignored (should be handled similar to power?)
return architecture.lower()
@@ -90,9 +96,15 @@ def parseElf(str):
os = "Linux"
arch = str.split(',')
arch = arch[1]
- arch = parseElfArch(str, arch)
bits = str.split(' ')[1].replace('-bit', '')
- endianness = str.split(' ')[2].lower()
+ arch = parseElfArch(str, arch, bits)
+ endian = str.split(' ')[2].lower()
+ if endian == "msb":
+ endianness = "big_endian"
+ elif endian == "lsb":
+ endianness = "little_endian"
+ else:
+ raise Exception("Unrecognised endianness")
return [os, arch, bits, endianness]
@@ -117,3 +129,26 @@ def getOsArch(str):
if os:
return result
return None
+
+def normalizeArch(inputArch):
+ """
+ This function brings requested architecture to common form (currently just parses the bits part and turns it into 32/64)
+ Input string format is: arch-endianness-word_size-kernelType
+
+ """
+ parts = inputArch.split('-')
+ #Drop anything non-numeric from word_size field
+ parts[2]=re.sub(r"\D", "", parts[2])
+ #Transform kernelType into binary format
+ temp = parts[3]
+ if "win" in temp:
+ parts[3]="pe32"
+ elif "linux" in temp:
+ parts[3]="elf"
+ elif "freebsd" in temp: #How do we treat QNX?
+ parts[3]="elf"
+ elif "darwin" in temp:
+ parts[3]="mach_o"
+ #Rejoin new architecture
+ arch = '-'.join(parts)
+ return arch