Skip to content
This repository was archived by the owner on Sep 12, 2024. It is now read-only.

Commit d1c9ac9

Browse files
authored
Use py3 over py2 (#850)
1. Prefer py3 over py2 2. Addressing issue with omsagent installation when python 2&3 coexists 3. Addressing execution issue when english is not system default language
1 parent b3085b9 commit d1c9ac9

34 files changed

+111
-163
lines changed

LCM/dsc/engine/ConsistencyInvoker/ConsistencyInvoker.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ char* getPythonProvider()
6161
char* result = malloc(1);
6262
*result = 0;
6363

64-
FILE* pipe = popen("python2 --version 2>&1", "r");
64+
FILE* pipe = popen("python3 -V 2>&1 | grep -Po '(?<=Python )(.+)'", "r");
6565
if(!pipe) {
6666
printf("Cant start command.");
6767
}
@@ -70,15 +70,15 @@ char* getPythonProvider()
7070
strcat(result,buffer);
7171
}
7272

73-
// If python2 --version does not contain 'not found' return python2
74-
if(strstr(result, "not found") == NULL) {
75-
return PYTHON2_COMMAND;
73+
// If python3 --version exists
74+
if(*result != '\0' && result[0] == '3') {
75+
return PYTHON3_COMMAND;
7676
}
7777

78-
// Look for python3
78+
// Look for python2
7979
result = malloc(1);
8080
*result = 0;
81-
pipe = popen("python3 --version 2>&1", "r");
81+
pipe = popen("python2 -V 2>&1 | grep -Po '(?<=Python )(.+)'", "r");
8282
if(!pipe) {
8383
printf("Cant start command.");
8484
}
@@ -87,11 +87,10 @@ char* getPythonProvider()
8787
strcat(result,buffer);
8888
}
8989

90-
// If python3 --version does not contain 'not found' return python3
91-
if(strstr(result, "not found") == NULL) {
92-
return PYTHON3_COMMAND;
90+
// If python2 --version exists
91+
if(*result != '\0' && result[0] == '2') {
92+
return PYTHON2_COMMAND;
9393
}
9494

9595
return PYTHON_COMMAND;
96-
9796
}

LCM/dsc/engine/ca/CAInfrastructure/WebPullClient.c

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,24 +2076,21 @@ MI_Result MI_CALL Pull_GetModules(_Out_ MI_Uint32 * numModulesInstalled,
20762076
int isPython2 = 1;
20772077
DSC_LOG_INFO("Assuming python2 in WebPullClient\n");
20782078

2079-
// Look for python2
2080-
FILE * pipe = popen("python2 --version 2>&1", "r");
2079+
// Look for python3
2080+
FILE * pipe = popen("python3 -V 2>&1 | grep -Po '(?<=Python )(.+)'", "r");
20812081
fgets(data, BUFSIZ, pipe);
2082-
if (!strstr(data, "not found"))
2083-
{
2084-
DSC_LOG_INFO("Found python2 in WebPullClient.\n");
2085-
isPython2 = 1;
2086-
}
2087-
else
2088-
{
2089-
// If python2 does not exist, look for python3
2082+
if (data[0] == '3') {
2083+
DSC_LOG_INFO("Found python3 in WebPullClient.\n");
2084+
isPython2 = 0;
2085+
} else {
2086+
// If python3 does not exist, look for python2
20902087
memset(&data[0], 0, sizeof(data));
2091-
pipe = popen("python3 --version 2>&1", "r");
2092-
fgets(data, BUFSIZ, pipe);
2093-
if (!strstr(data, "not found")) {
2094-
DSC_LOG_INFO("Found python3 in WebPullClient.\n");
2095-
isPython2 = 0;
2096-
}
2088+
pipe = popen("python2 -V 2>&1 | grep -Po '(?<=Python )(.+)'", "r");
2089+
fgets(data, BUFSIZ, pipe);
2090+
if (data[0] == '2') {
2091+
DSC_LOG_INFO("Found python2 in WebPullClient.\n");
2092+
isPython2 = 1;
2093+
}
20972094
}
20982095

20992096
if (isPython2 == 1)

LCM/scripts/GetDscConfiguration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/python2
22
import fileinput
33
import sys
44
import subprocess

LCM/scripts/GetDscLocalConfigurationManager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/python2
22
import fileinput
33
import sys
44
import subprocess

LCM/scripts/InstallModule.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/python2
22
import imp
33
import os
44
import stat
@@ -66,7 +66,7 @@ def getPlatformArchitectureFolderName():
6666

6767
def regenerateDscPythonScriptInitFiles():
6868
regenerateInitFilesScriptPath = join(helperlib.DSC_SCRIPT_PATH, 'RegenerateInitFiles.py')
69-
regenerateInitFilesResult = subprocess.call("(python " + regenerateInitFilesScriptPath + ")", shell=True)
69+
regenerateInitFilesResult = subprocess.call("(python2 " + regenerateInitFilesScriptPath + ")", shell=True)
7070
if regenerateInitFilesResult != 0:
7171
exitWithError("Failed to regenerate the DSC __init__.py files with the result code", regenerateInitFilesResult)
7272

LCM/scripts/OMS_MetaConfigHelper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/python2
22
import os
33
import sys
44
import imp

LCM/scripts/OmsConfigHostHelpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/python2
22
import json
33
import time
44
import datetime

LCM/scripts/OperationStatusUtility.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/python2
22
from datetime import datetime
33
from errno import EINVAL
44
from imp import load_source

LCM/scripts/PerformInventory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/python2
22
from fcntl import flock, LOCK_EX, LOCK_UN, LOCK_NB
33
from imp import load_source
44
from os import listdir, system

LCM/scripts/PerformRequiredConfigurationChecks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/python2
22
import sys
33
from imp import load_source
44
from os.path import dirname, join, realpath, isfile

0 commit comments

Comments
 (0)