Switch to preferred Python method for checking sys.platform
authorMats Wichmann <mats@linux.com>
Thu, 4 May 2017 16:01:07 +0000 (10:01 -0600)
committerZiran Sun <ziran.sun@samsung.com>
Mon, 26 Jun 2017 13:32:06 +0000 (13:32 +0000)
Older Pythons can set linux or linux2 in sys.platform.
The suffix is meaningless, deprecated, and no longer happens as of Python 3.3.
The preferred idiom (from Python docs) is:

    if sys.platform.startswith('linux'):

Twiddled a few other things, "imports at the top" rule,
and a couple of related error msgs, and a few strings

In a few places, more could have been done to clean up, but skipped
to keep the patches small

Change-Id: Iccdfa9eb77ff4bc1429e3b38837a8732455a5dfd
Signed-off-by: Mats Wichmann <mats@linux.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/19641
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Dave Thaler <dthaler@microsoft.com>
Reviewed-by: George Nash <george.nash@intel.com>
Reviewed-by: Phil Coval <philippe.coval@osg.samsung.com>
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
Reviewed-by: Rick Bell <richard.s.bell@intel.com>
(cherry picked from commit 39f1ec664b3abc4e9d58b48a2e281a66ef11a153)
Reviewed-on: https://gerrit.iotivity.org/gerrit/20925
Reviewed-by: Ossama Othman <ossama.othman@intel.com>
extlibs/android/ndk/SConscript
extlibs/arduino/SConscript
extlibs/boost/SConscript
resource/csdk/stack/samples/arduino/SimpleClientServer/ocserver/SConscript
service/easy-setup/sampleapp/enrollee/arduino/SConscript

index ee4e6ae..e68f909 100644 (file)
@@ -19,7 +19,7 @@ path = os.path.join(src_dir, 'extlibs', 'android', 'ndk', 'android-ndk-r10e')
 # check 'ndk' library, if it doesn't exits, ask user to download it
 if not os.path.exists(path):
        ndk_env = Environment(ENV = os.environ)
-       if host_os == 'linux2' :
+       if host_os.startswith("linux"):
                archType = 8 * struct.calcsize("P")
                if archType == 64:
                        env.Download('android-ndk-r10e.bin', 'http://dl.google.com/android/ndk/android-ndk-r10e-linux-x86_64.bin')
index fcd5cb7..1bd0d9e 100644 (file)
@@ -4,6 +4,7 @@
 ##
 
 import os, subprocess, struct
+from sys import platform as _platform
 import urllib2, urlparse
 import SCons.Errors
 import shutil
@@ -21,19 +22,18 @@ if target_os == 'arduino':
        if not arduino_home:
                print 'Creating ARDUINO_HOME for Arduino lib'
                print '''
-        *******************************************************************************
-        *   Arduino root directory isn't set, you can set enviornment variable        *
-        *   ARDUINO_HOME or add it in command line as follows (Only set if your       *
-        *   version has fixes applied as depicted below. Press ctrl+c now if you      *
-        *   wish to manually set ARDUINO_HOME.):                                      *
-        *      # scons ARDUINO_HOME=<path to arduino root directory> ...              *
-        *******************************************************************************
+*******************************************************************************
+*   Arduino root directory is not set, you can set enviornment variable       *
+*   ARDUINO_HOME or add it in command line as follows (Only set if your       *
+*   version has fixes applied as depicted below. Press ctrl+c now if you      *
+*   wish to manually set ARDUINO_HOME.):                                      *
+*      # scons ARDUINO_HOME=<path to arduino root directory> ...              *
+*******************************************************************************
         '''
                arduinolib_dir      = src_dir + '/extlibs/arduino/arduino-1.5.8'
 
                if not os.path.exists(arduinolib_dir):
-                       from sys import platform as _platform
-                       if _platform == "linux" or _platform == "linux2":
+                       if _platform.startswith("linux"):
                                archType = 8 * struct.calcsize("P")
                                print 'On %s-bit machine.' % (archType)
                                if archType == 32:
index 749156b..30a24da 100644 (file)
@@ -5,7 +5,7 @@ Import('env')
 
 boost_env = env.Clone()
 
-modules = ['thread','program_options', 'system', 'date_time']
+modules = ['thread', 'program_options', 'system', 'date_time']
 
 target_os = env.get('TARGET_OS')
 target_arch = env.get('TARGET_ARCH')
@@ -25,10 +25,11 @@ boost_url       = 'http://downloads.sourceforge.net/project/boost/boost/'+boost_
 boost_dir = os.path.join(src_dir,'extlibs','boost','boost')
 boost_bootstrap = os.path.join(boost_dir,'bootstrap.bat')
 
-if 'linux' == target_os :
+if 'linux' == target_os:
     # Check for Boost libraries in /usr/boost
     print 'TODO: Perform platform check for linux'
-    raise SCons.Errors.EnvironmentError('Unsupported platform')
+    msg = "Target platform (%s) is currently not supported for boost builds" % target_os
+    raise SCons.Errors.EnvironmentError(msg)
 
 elif target_os in ['windows']:
     boost_zip_file   = os.path.join(src_dir,'extlibs','boost',boost_arch_name)
@@ -52,7 +53,7 @@ elif target_os in ['windows']:
     # Sanity check, in case the above method didn't work
     if not os.path.exists(boost_bootstrap):
         print '''
-*********************************** Error: ****************************************
+*********************************** Error: ************************************
 * Please download boost from the following website:
 *
 *   ''' + boost_url + '''
@@ -61,11 +62,11 @@ elif target_os in ['windows']:
 *
 *    ''' + boost_dir + '''
 *
-* such that this build system can find:
+* such that the build system can find:
 *
 * ''' + boost_bootstrap + '''
 *
-***********************************************************************************
+*******************************************************************************
 '''
         Exit(1)
 
@@ -77,9 +78,9 @@ elif target_os in ['android']:
 
     host_os = sys.platform
 
-    if host_os == 'linux2' :
+    if host_os.startswith("linux"):
         boost_bootstrap = boost_base_name+os.sep+'bootstrap.sh'
-    else :
+    else:
         msg="Host platform (%s) is currently not supported for boost builds" % host_os
         raise SCons.Errors.EnvironmentError(msg)
 
index 4982a8b..fc7ac11 100644 (file)
@@ -18,6 +18,8 @@
 #
 #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
+import sys
+
 Import('stacksamples_env')
 
 arduino_simplecs_env = stacksamples_env.Clone()
@@ -50,8 +52,7 @@ Alias('arduino_simplecs', i_arduino_simplecs)
 arduino_simplecs_env.AppendTarget('arduino_simplecs')
 
 if(arduino_simplecs_env['UPLOAD'] == True):
-       from sys import platform as _platform
-       if _platform == "linux" or _platform == "linux2":
+       if sys.platform.startswith("linux"):
                arduino_simplecs_env.Upload(arduino_simplecs_env.get('BUILD_DIR') + '/resource/csdk/stack/samples/arduino/SimpleClientServer/ocserver/SimpleClientServer.hex')
        else:
-               print 'Please use appropriate install method for your developing machine. Linux is the only supported platform right now.'
+               print 'Please use appropriate install method for your development machine. Linux is the only supported platform right now.'
index 33a16fc..e390759 100644 (file)
@@ -22,6 +22,8 @@
 # Build script for Arduino Enrollee Sample App
 ######################################################################
 
+import sys
+
 Import('env')
 
 enrollee_env = env.Clone()
@@ -55,8 +57,7 @@ Alias('enrollee', i_enrollee)
 env.AppendTarget('enrollee')
 
 if(enrollee_env['UPLOAD'] == True):
-       from sys import platform as _platform
-       if _platform == "linux" or _platform == "linux2":
+       if sys.platform.startswith("linux"):
                enrollee_env.Upload(env.get('BUILD_DIR') + '/service/easy-setup/sampleapp/enrollee/arduino/enrollee.hex')
        else:
-               print 'Please use appropriate install method for your developing machine. Linux is the only supported platform right now.'
+               print 'Please use appropriate install method for your development machine. Linux is the only supported platform right now.'