Skip to content

Commit 390cacf

Browse files
Bandit: fix B605, B108 (#627)
* Bandit: B605: start_process_with_a_shell * Bandit: B108: hardcoded_tmp_directory - false positive
1 parent fd226e7 commit 390cacf

File tree

14 files changed

+85
-62
lines changed

14 files changed

+85
-62
lines changed

Cassiopee/CPlot/setupLegacy.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#from distutils.core import setup, Extension
22
from setuptools import setup, Extension
33
import os
4+
import shutil
5+
from glob import glob
46

57
#=============================================================================
68
# CPlot requires:
@@ -97,12 +99,14 @@
9799
)
98100

99101
# Install shaders + textures ==================================================
100-
os.system("cp CPlot/Shaders/*.vert %s/CPlot/"%KCore.installPath.installPath)
101-
os.system("cp CPlot/Shaders/*.frag %s/CPlot/"%KCore.installPath.installPath)
102-
os.system("cp CPlot/Shaders/*.geom %s/CPlot/"%KCore.installPath.installPath)
103-
os.system("cp CPlot/Shaders/*.tcs %s/CPlot/"%KCore.installPath.installPath)
104-
os.system("cp CPlot/Shaders/*.tes %s/CPlot/"%KCore.installPath.installPath)
105-
os.system("cp CPlot/Textures/*.png %s/CPlot/"%KCore.installPath.installPath)
102+
dest = os.path.join(KCore.installPath.installPath, "CPlot")
103+
os.makedirs(dest, exist_ok=True)
104+
for src in glob("CPlot/Shaders/*.vert"): shutil.copy(src, dest)
105+
for src in glob("CPlot/Shaders/*.frag"): shutil.copy(src, dest)
106+
for src in glob("CPlot/Shaders/*.geom"): shutil.copy(src, dest)
107+
for src in glob("CPlot/Shaders/*.tcs"): shutil.copy(src, dest)
108+
for src in glob("CPlot/Shaders/*.tes"): shutil.copy(src, dest)
109+
for src in glob("CPlot/Shaders/*.png"): shutil.copy(src, dest)
106110

107111
# Check PYTHONPATH ===========================================================
108112
Dist.checkPythonPath(); Dist.checkLdLibraryPath()

Cassiopee/Connector/setupLegacy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
sys.exit()
3434
args = Dist.getForArgs(); opt = ''
3535
for c, v in enumerate(args): opt += 'FOPT'+str(c)+'='+v+' '
36-
os.system("make -e FC="+f77compiler+" WDIR=Connector/Fortran "+opt)
36+
Dist.runMakeFortran(f77compiler, opt, wdir="Connector/Fortran")
3737
prod = os.getenv("ELSAPROD")
3838
if prod is None: prod = 'xx'
3939

Cassiopee/Converter/setupLegacy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
print("Error: a fortran 77 compiler is required for compiling Converter.")
4444
args = Dist.getForArgs(); opt = ''
4545
for c, v in enumerate(args): opt += 'FOPT'+str(c)+'='+v+' '
46-
os.system("make -e FC="+f77compiler+" WDIR=Converter/Fortran "+opt)
46+
Dist.runMakeFortran(f77compiler, opt, wdir="Converter/Fortran")
4747
prod = os.getenv("ELSAPROD")
4848
if prod is None: prod = 'xx'
4949

Cassiopee/Generator/setupLegacy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
print("Error: a fortran 77 compiler is required for compiling Generator.")
3434
args = Dist.getForArgs(); opt = ''
3535
for c, v in enumerate(args): opt += 'FOPT'+str(c)+'='+v+' '
36-
os.system("make -e FC="+f77compiler+" WDIR=Generator/Fortran "+opt)
36+
Dist.runMakeFortran(f77compiler, opt, wdir="Generator/Fortran")
3737
prod = os.getenv("ELSAPROD") or 'xx'
3838

3939
# Setting libraryDirs and libraries ===========================================

Cassiopee/Geom/setupLegacy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
print("Error: a fortran 77 compiler is required for compiling Geom.")
3434
args = Dist.getForArgs(); opt = ''
3535
for c, v in enumerate(args): opt += 'FOPT'+str(c)+'='+v+' '
36-
os.system("make -e FC="+f77compiler+" WDIR=Geom/Fortran "+opt)
36+
Dist.runMakeFortran(f77compiler, opt, wdir="Geom/Fortran")
3737
prod = os.getenv("ELSAPROD") or 'xx'
3838

3939
# Setting libraryDirs and libraries ===========================================

Cassiopee/Initiator/setupLegacy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
print("Error: a fortran 77 compiler is required for compiling Initiator.")
3434
args = Dist.getForArgs(); opt = ''
3535
for c, v in enumerate(args): opt += 'FOPT'+str(c)+'='+v+' '
36-
os.system("make -e FC="+f77compiler+" WDIR=Initiator/Fortran "+opt)
36+
Dist.runMakeFortran(f77compiler, opt, wdir="Initiator/Fortran")
3737
prod = os.getenv("ELSAPROD") or 'xx'
3838

3939
# Setting libraryDirs and libraries ===========================================

Cassiopee/Intersector/setupLegacy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
print("Error: a fortran 77 compiler is required for compiling Intersector.")
3939
args = Dist.getForArgs(); opt = ''
4040
for c, v in enumerate(args): opt += 'FOPT'+str(c)+'='+v+' '
41-
os.system("make -e FC="+f77compiler+" WDIR=Intersector/Fortran "+opt)
41+
Dist.runMakeFortran(f77compiler, opt, wdir="Intersector/Fortran")
4242
prod = os.getenv("ELSAPROD") or 'xx'
4343

4444
# Setting libraryDirs and libraries ===========================================

Cassiopee/KCore/Dist.py

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -258,46 +258,42 @@ def getInstallPath(prefix, type=0):
258258
# Functions returning the names of the remote repo & branch and the commit hash
259259
#==============================================================================
260260
def getGitOrigin(cassiopeeIncDir):
261-
if not shutil.which("git"): return "unknown"
262-
mySystem = getSystem()[0]
263-
if mySystem == 'mingw' or mySystem == 'Windows':
264-
lpath = cassiopeeIncDir.replace('/', '\\')
265-
cmd = "cd {} && git config --get remote.origin.url".format(lpath)
266-
else: # unix
267-
lpath = cassiopeeIncDir
268-
cmd = "cd {}; git config --get remote.origin.url 2>/dev/null".format(lpath)
261+
if not shutil.which("git"):
262+
return "unknown"
269263
try:
270-
origin = subprocess.check_output(cmd, shell=True)
271-
return origin.decode('utf-8', 'ignore').strip()
272-
except: return "unknown"
264+
return subprocess.check_output(
265+
["git", "-C", cassiopeeIncDir,
266+
"config", "--get", "remote.origin.url"],
267+
stderr=subprocess.DEVNULL,
268+
text=True
269+
).strip()
270+
except Exception:
271+
return "unknown"
273272

274273
def getGitBranch(cassiopeeIncDir):
275-
if not shutil.which("git"): return "unknown"
276-
mySystem = getSystem()[0]
277-
if mySystem == 'mingw' or mySystem == 'Windows':
278-
lpath = cassiopeeIncDir.replace('/', '\\')
279-
cmd = "cd {} && git rev-parse --abbrev-ref HEAD".format(lpath)
280-
else: # unix
281-
lpath = cassiopeeIncDir
282-
cmd = "cd {}; git rev-parse --abbrev-ref HEAD 2>/dev/null".format(lpath)
274+
if not shutil.which("git"):
275+
return "unknown"
283276
try:
284-
branchName = subprocess.check_output(cmd, shell=True)
285-
return branchName.decode('utf-8', 'ignore').strip()
286-
except: return "unknown"
277+
return subprocess.check_output(
278+
["git", "-C", cassiopeeIncDir, "rev-parse", "--abbrev-ref", "HEAD"],
279+
stderr=subprocess.DEVNULL,
280+
text=True
281+
).strip()
282+
except Exception:
283+
return "unknown"
284+
287285

288286
def getGitHash(cassiopeeIncDir):
289-
if not shutil.which("git"): return "unknown"
290-
mySystem = getSystem()[0]
291-
if mySystem == 'mingw' or mySystem == 'Windows':
292-
lpath = cassiopeeIncDir.replace('/', '\\')
293-
cmd = "cd {} && git rev-parse --short HEAD".format(lpath)
294-
else: # unix
295-
lpath = cassiopeeIncDir
296-
cmd = "cd {}; git rev-parse --short HEAD 2>/dev/null".format(lpath)
287+
if not shutil.which("git"):
288+
return "unknown"
297289
try:
298-
sha = subprocess.check_output(cmd, shell=True)
299-
return sha.decode('utf-8', 'ignore').strip()
300-
except: return "unknown"
290+
return subprocess.check_output(
291+
["git", "-C", cassiopeeIncDir, "rev-parse", "--short", "HEAD"],
292+
stderr=subprocess.DEVNULL,
293+
text=True
294+
).strip()
295+
except Exception:
296+
return "unknown"
301297

302298
#=============================================================================
303299
# nom de l'egg cree par setup tools
@@ -2216,6 +2212,14 @@ def checkFortranLibs():
22162212

22172213
return (ret, libs, paths)
22182214

2215+
# Run the make command to build the wdir target
2216+
def runMakeFortran(forCompiler, opt, wdir):
2217+
import shlex
2218+
subprocess.run(
2219+
["make", "-e", f"FC={forCompiler}", f"WDIR={wdir}", *shlex.split(opt)],
2220+
check=True
2221+
)
2222+
22192223
#=============================================================================
22202224
# Check Cpp libs
22212225
# additionalLibs: si les libs requises ont des noms non conventionnels

Cassiopee/KCore/setupLegacy.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@
3131
print("Error: a fortran 77 compiler is required for compiling KCore.")
3232
args = Dist.getForArgs(); opt = ''
3333
for c, v in enumerate(args): opt += 'FOPT%d=%s '%(c, v)
34-
os.system("make -e FC="+f77compiler+" WDIR=KCore/Fld "+opt)
35-
os.system("make -e FC="+f77compiler+" WDIR=KCore/Interp "+opt)
36-
os.system("make -e FC="+f77compiler+" WDIR=KCore/Metric "+opt)
37-
os.system("make -e FC="+f77compiler+" WDIR=KCore/CompGeom "+opt)
38-
os.system("make -e FC="+f77compiler+" WDIR=KCore/Loc "+opt)
39-
os.system("make -e FC="+f77compiler+" WDIR=KCore/Linear "+opt)
34+
Dist.runMakeFortran(f77compiler, opt, wdir="KCore/Fld")
35+
Dist.runMakeFortran(f77compiler, opt, wdir="KCore/Interp")
36+
Dist.runMakeFortran(f77compiler, opt, wdir="KCore/Metric")
37+
Dist.runMakeFortran(f77compiler, opt, wdir="KCore/CompGeom")
38+
Dist.runMakeFortran(f77compiler, opt, wdir="KCore/Loc")
39+
Dist.runMakeFortran(f77compiler, opt, wdir="KCore/Linear")
4040
prod = os.getenv("ELSAPROD") or 'xx'
4141

4242
# Setting libraries path =====================================================

Cassiopee/Post/setupLegacy.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#from distutils.core import setup, Extension
22
from setuptools import setup, Extension
33
import os, sys
4+
import subprocess
45

56
#=============================================================================
67
# Post requires:
@@ -29,15 +30,27 @@
2930
(kcoreVersion, kcoreIncDir, kcoreLibDir) = Dist.checkModuleCassiopee("KCore")
3031

3132
# Compilation des fortrans ===================================================
33+
def runMakeFortran(f77compiler, opt, f90compiler=None):
34+
targets = ["Post/Fortran", "Post/zipper"]
35+
for wdir in targets:
36+
subprocess.run(
37+
["make", "-e", f"FC={f77compiler}", "F90=true", f"WDIR={wdir}", *opt.split()],
38+
check=True
39+
)
40+
usurp_dir = "Post/usurp"
41+
if f90compiler is not None and os.access(usurp_dir, os.F_OK):
42+
subprocess.run(
43+
["make", "-e", f"FC={f77compiler}", f"F90={f90compiler}", *opt.split()],
44+
cwd=usurp_dir,
45+
check=True
46+
)
47+
3248
if f77compiler is None:
3349
print("Error: a fortran 77 compiler is required for compiling Post.")
3450
sys.exit()
3551
args = Dist.getForArgs(); opt = ''
3652
for c, v in enumerate(args): opt += 'FOPT'+str(c)+'='+v+' '
37-
os.system("make -e FC="+f77compiler+" F90=true WDIR=Post/Fortran "+opt)
38-
os.system("make -e FC="+f77compiler+" F90=true WDIR=Post/zipper "+opt)
39-
if f90compiler is not None and os.access('Post/usurp', os.F_OK):
40-
os.system("(cd Post/usurp; make -e FC="+f77compiler+" F90="+f90compiler+" "+opt+")")
53+
runMakeFortran(f77compiler, opt, f90compiler=f90compiler)
4154
prod = os.getenv("ELSAPROD") or 'xx'
4255

4356
# Setting libraryDirs and libraries ===========================================

0 commit comments

Comments
 (0)