@@ -72,9 +72,9 @@ const listEMMEPythonPaths = () => {
72
72
const paths = [ ]
73
73
commonEmmePaths . forEach ( commonEmmePath => {
74
74
paths . push (
75
- `\\ Program Files\\${ commonEmmePath } ` ,
76
- `\\ Program Files (x86)\\${ commonEmmePath } ` ,
77
- `\\ ${ commonEmmePath } ` ,
75
+ `Program Files\\${ commonEmmePath } ` ,
76
+ `Program Files (x86)\\${ commonEmmePath } ` ,
77
+ `${ commonEmmePath } ` ,
78
78
)
79
79
} )
80
80
paths . push ( `usr/bin/python${ pythonVersion . major } ` ) ; // mainly for developers on Mac & Linux
@@ -83,7 +83,7 @@ const listEMMEPythonPaths = () => {
83
83
const allPathCombinations = drives . reduce (
84
84
( accumulator , d ) => {
85
85
// Combine each (d)rive to all (p)aths, and merge results via reduce
86
- return accumulator . concat ( paths . map ( ( p ) => ` ${ d } ${ p } ` ) ) ;
86
+ return accumulator . concat ( paths . map ( ( p ) => path . join ( d , p ) ) ) ;
87
87
} , [ ] ) ;
88
88
allPathCombinations . forEach ( ( pathCombination ) => {
89
89
const foundPythonEnv = hasPythonEnv ( pathCombination ) ;
@@ -112,50 +112,48 @@ function getVersion(semver) {
112
112
}
113
113
114
114
function hasPythonEnv ( basePath ) {
115
- const pathExists = fs . existsSync ( basePath ) && fs . lstatSync ( basePath ) . isDirectory ( ) ;
115
+ const pathExists = fs . existsSync ( basePath ) ;
116
116
console . log ( basePath ) ;
117
117
console . log ( pathExists ) ;
118
118
let exePaths = [ ] ;
119
119
if ( pathExists ) {
120
- const subPaths = fs . readdirSync ( basePath )
121
- subPaths . forEach ( path => {
122
- if ( path . startsWith ( "Emme " ) ) {
123
- const majorVersionFolderPath = ` ${ basePath } ${ getDirSeparator ( ) } ${ path } ` ;
124
- const majorVersionFolderPathFiles = fs . readdirSync ( majorVersionFolderPath ) ;
125
-
126
- console . log ( majorVersionFolderPathFiles ) ;
127
-
128
- // Filter away every folder except possible Emme installation folders
129
- const subVersionFolders = majorVersionFolderPathFiles . filter ( file => file . startsWith ( " Emme-" ) ) ;
130
- subVersionFolders . forEach ( subVersionFolder => {
131
- // Go through the subdirectory and look for a python executable, should be in Emme-x.xx.xx.xx/Python/python.exe on Windows machines.
132
- const emmeFolderFilesPath = majorVersionFolderPath . concat ( getDirSeparator ( ) , subVersionFolder ) ;
133
- const emmeFolderFiles = fs . readdirSync ( emmeFolderFilesPath ) ;
134
- console . log ( emmeFolderFilesPath ) ;
135
- console . log ( emmeFolderFiles ) ;
136
- emmeFolderFiles . forEach ( folderPath => {
137
- if ( folderPath . startsWith ( "Python" ) ) {
138
- const pythonFolderPath = emmeFolderFilesPath . concat ( getDirSeparator ( ) , folderPath ) ;
139
- const pythonPathFiles = fs . readdirSync ( pythonFolderPath ) ;
140
- pythonPathFiles . forEach ( fileName => {
141
- if ( fileName === 'python.exe' ) {
142
- exePaths . push ( pythonFolderPath . concat ( getDirSeparator ( ) , fileName ) ) ;
143
- }
144
- } )
145
- }
120
+ try {
121
+ const subPaths = fs . readdirSync ( basePath )
122
+ subPaths . forEach ( subPath => {
123
+ if ( subPath . startsWith ( "Emme " ) ) {
124
+ const majorVersionFolderPath = path . join ( basePath , subPath ) ;
125
+ const majorVersionFolderPathFiles = fs . readdirSync ( majorVersionFolderPath ) ;
126
+
127
+ console . log ( majorVersionFolderPathFiles ) ;
128
+
129
+ // Filter away every folder except possible Emme installation folders
130
+ const subVersionFolders = majorVersionFolderPathFiles . filter ( file => file . startsWith ( "Emme-" ) ) ;
131
+ subVersionFolders . forEach ( subVersionFolder => {
132
+ // Go through the subdirectory and look for a python executable, should be in Emme-x.xx.xx.xx/Python/python.exe on Windows machines.
133
+ const emmeFolderFilesPath = path . join ( majorVersionFolderPath , subVersionFolder ) ;
134
+ const emmeFolderFiles = fs . readdirSync ( emmeFolderFilesPath ) ;
135
+ emmeFolderFiles . forEach ( emmeFolderPath => {
136
+ if ( emmeFolderPath . startsWith ( "Python" ) ) {
137
+ const pythonFolderPath = path . join ( emmeFolderFilesPath , emmeFolderPath ) ;
138
+ const pythonPathFiles = fs . readdirSync ( pythonFolderPath ) ;
139
+ pythonPathFiles . forEach ( fileName => {
140
+ if ( fileName === 'python.exe' ) {
141
+ exePaths . push ( path . join ( pythonFolderPath , fileName ) ) ;
142
+ }
143
+ } )
144
+ }
145
+ } )
146
146
} )
147
- } )
148
- }
149
- } )
147
+ }
148
+ } )
149
+ }
150
+ catch ( e ) {
151
+ console . log ( `Error traversing path ${ basePath } ` ) ;
152
+ }
150
153
}
151
154
return exePaths ;
152
155
}
153
156
154
- function getDirSeparator ( ) {
155
- const isRunningOnWindows = os . platform ( ) === 'win32' ;
156
- return isRunningOnWindows ? '\\' : '/'
157
- }
158
-
159
157
module . exports = {
160
158
searchEMMEPython : searchEMMEPython ,
161
159
listEMMEPythonPaths : listEMMEPythonPaths ,
0 commit comments