summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSunil Shetye2025-04-11 10:42:24 +0530
committerSunil Shetye2025-04-11 10:42:24 +0530
commit4d4471e9d8c9fdf76d1090d0e3d85d1b40244f1c (patch)
treeb81fdb1286a7304b54739873c210dda724b0e0bd
parentf47eb66e3cc969df5f7da539335ade3dc166f3c4 (diff)
downloadCommon-Interface-Project-4d4471e9d8c9fdf76d1090d0e3d85d1b40244f1c.tar.gz
Common-Interface-Project-4d4471e9d8c9fdf76d1090d0e3d85d1b40244f1c.tar.bz2
Common-Interface-Project-4d4471e9d8c9fdf76d1090d0e3d85d1b40244f1c.zip
change REMOVEFILE to False
-rwxr-xr-xblocks/Xcos/MxGraphParser.py8
-rw-r--r--blocks/Xcos/common/AAAAAA.py7
-rw-r--r--blocks/eda-frontend/src/redux/authSlice.js4
-rw-r--r--blocks/eda-frontend/src/redux/dashboardSlice.js2
-rw-r--r--blocks/simulationAPI/helpers/config.py2
-rw-r--r--blocks/simulationAPI/helpers/ngspice_helper.py29
-rw-r--r--blocks/simulationAPI/helpers/scilab_manager.py30
7 files changed, 43 insertions, 39 deletions
diff --git a/blocks/Xcos/MxGraphParser.py b/blocks/Xcos/MxGraphParser.py
index cf12a400..6c14fd42 100755
--- a/blocks/Xcos/MxGraphParser.py
+++ b/blocks/Xcos/MxGraphParser.py
@@ -14,11 +14,11 @@ if len(sys.argv) != 3:
sys.exit(1)
filename = sys.argv[1]
-workspace_file = sys.argv[2]
(basename, ext) = os.path.splitext(filename)
+workspace_file = sys.argv[2]
if ext != '.xml':
- print("Usage: %s filename.xml" % sys.argv[0])
+ print("Usage: %s filename.xml workspace.dat" % sys.argv[0])
sys.exit(1)
base = r'(_[a-zA-Z]*_on_Cloud)?( *\([0-9]*\))?\.xml$'
title = re.sub(r'^.*/', r'', filename)
@@ -29,8 +29,8 @@ model = tree.getroot()
rootattribid = '0:1:0'
parentattribid = '0:2:0'
-
-outdiagram = process_xcos_model(model, title, rootattribid, parentattribid, workspace_file)
+outdiagram = process_xcos_model(model, title, rootattribid, parentattribid,
+ workspace_file)
outtree = ET.ElementTree(outdiagram)
diff --git a/blocks/Xcos/common/AAAAAA.py b/blocks/Xcos/common/AAAAAA.py
index 87856e5e..7c8f82c5 100644
--- a/blocks/Xcos/common/AAAAAA.py
+++ b/blocks/Xcos/common/AAAAAA.py
@@ -723,8 +723,8 @@ def format_real_number(parameter, workspace_file):
return '0'
elif re.search(r'[dDeE\^]', parameter): # Check for scientific notation
real_number = float(parameter.replace('*10^', 'e').replace('10^', '1e').replace('d', 'e').replace('D', 'e'))
- return "{:.10g}".format(real_number)
- elif re.search(r'[a-zA-Z]', parameter): # Check if parameter contains alphabetic characters
+ return "{:.10g}".format(real_number)
+ elif re.search(r'[a-zA-Z]', parameter): # Check if parameter contains alphabetic characters
print('send to Scilab', workspace_file)
with open("params.txt", "a") as f:
f.write(parameter + "\n")
@@ -1402,7 +1402,8 @@ def getSplitPoints(attrib, switch_split, blkgeometry, sourceVertex, targetVertex
return split_point, split_point2
-def process_xcos_model(model, title, rootattribid, parentattribid):
+def process_xcos_model(model, title, rootattribid, parentattribid,
+ workspace_file=None):
checkModelTag(model)
outdiagram = ET.Element('XcosDiagram')
outdiagram.set('background', '-1')
diff --git a/blocks/eda-frontend/src/redux/authSlice.js b/blocks/eda-frontend/src/redux/authSlice.js
index 9af1fac6..ee5705c1 100644
--- a/blocks/eda-frontend/src/redux/authSlice.js
+++ b/blocks/eda-frontend/src/redux/authSlice.js
@@ -164,7 +164,7 @@ export const googleLogin = createAsyncThunk(
'auth/googleLogin',
async (host, { rejectWithValue }) => {
try {
- const res = await api.get('auth/o/google-oauth2/?redirect_uri=' + host + '/api/auth/google-callback')
+ const res = await api.get(`auth/o/google-oauth2/?redirect_uri=${host}/api/auth/google-callback`)
if (res.status === 200) {
// Open google login page
window.open(res.data.authorization_url, '_self')
@@ -184,7 +184,7 @@ export const githubLogin = createAsyncThunk(
'auth/githubLogin',
async (host, { rejectWithValue }) => {
try {
- const res = await api.get('auth/o/github/?redirect_uri=' + host + '/api/auth/github-callback')
+ const res = await api.get(`auth/o/github/?redirect_uri=${host}/api/auth/github-callback`)
if (res.status === 200) {
// Open GitHub login page
window.open(res.data.authorization_url, '_self')
diff --git a/blocks/eda-frontend/src/redux/dashboardSlice.js b/blocks/eda-frontend/src/redux/dashboardSlice.js
index c1b49046..753b5287 100644
--- a/blocks/eda-frontend/src/redux/dashboardSlice.js
+++ b/blocks/eda-frontend/src/redux/dashboardSlice.js
@@ -66,7 +66,7 @@ export const deleteSchematic = createAsyncThunk(
}
try {
- const res = await api.delete('save/diagram/' + saveId, config)
+ const res = await api.delete(`save/diagram/${saveId}`, config)
if (res.status === 200) {
await dispatch(fetchSchematics())
return saveId
diff --git a/blocks/simulationAPI/helpers/config.py b/blocks/simulationAPI/helpers/config.py
index 0db1da84..246f4c1f 100644
--- a/blocks/simulationAPI/helpers/config.py
+++ b/blocks/simulationAPI/helpers/config.py
@@ -27,4 +27,4 @@ IMAGEDIR = 'images'
# Set CREATEIMAGE to True to create img_test.jpg in IMAGEDIR
CREATEIMAGE = False
-REMOVEFILE = True
+REMOVEFILE = False
diff --git a/blocks/simulationAPI/helpers/ngspice_helper.py b/blocks/simulationAPI/helpers/ngspice_helper.py
index 66df93d2..3fd42e42 100644
--- a/blocks/simulationAPI/helpers/ngspice_helper.py
+++ b/blocks/simulationAPI/helpers/ngspice_helper.py
@@ -13,7 +13,7 @@ from django.db.models import Case, F, Value, When
from django.utils.timezone import now
from simulationAPI.models import Task
-from simulationAPI.helpers.scilab_manager import start_scilab, upload
+from simulationAPI.helpers.scilab_manager import start_scilab, upload, remove, rmdir
logger = get_task_logger(__name__)
XmlToXcos = join(settings.BASE_DIR, 'Xcos/XmlToXcos.sh')
@@ -51,13 +51,13 @@ class CannotRunParser(Exception):
def update_task_status(task_id, status, meta=None):
- print("status:", status, task_id)
+ logger.info(f"status: {status} {task_id}")
# Update Celery backend state
if current_task is not None:
try:
current_task.update_state(state=status, meta=meta or {})
except Exception as e:
- print(f"Error updating Celery task state: {e}")
+ logger.error(f"Error updating Celery task state: {e}")
# Update Django database
Task.objects.filter(task_id=task_id).update(
@@ -81,7 +81,7 @@ def CreateXml(file_path, parameters, task_id, workspace_file):
try:
(xcosfilebase, __) = splitext(file_path)
xcosfile = xcosfilebase + '.xcos'
- logger.info('will run %s %s', 'XmlToXcos', file_path)
+ logger.info('will run %s %s %s', 'XmlToXcos', file_path, workspace_file)
proc = subprocess.Popen([XmlToXcos, file_path, workspace_file],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdout, stderr) = proc.communicate()
@@ -100,13 +100,13 @@ def CreateXml(file_path, parameters, task_id, workspace_file):
except BaseException as e:
logger.exception('Encountered Exception:')
logger.info('removing %s', file_path)
- os.remove(file_path)
+ remove(file_path)
target = os.listdir(current_dir)
for item in target:
logger.info('removing %s', item)
- os.remove(join(current_dir, item))
+ remove(join(current_dir, item))
logger.info('removing %s', current_dir)
- os.rmdir(current_dir)
+ rmdir(current_dir)
logger.info('Deleted Files')
raise e
@@ -143,19 +143,10 @@ def ExecXml(task, task_name, workspace_file):
logger.exception('Encountered Exception during XML Execution:')
logger.info('Cleaning up files for task %s', task_id)
# Cleanup
- try:
- os.remove(file_path)
- except FileNotFoundError:
- pass
+ remove(file_path)
target = os.listdir(current_dir)
for item in target:
- try:
- os.remove(join(current_dir, item))
- except FileNotFoundError:
- continue
- try:
- os.rmdir(current_dir)
- except OSError:
- pass
+ remove(join(current_dir, item))
+ rmdir(current_dir)
logger.info('Deleted Files and Directory for task %s', task_id)
raise e
diff --git a/blocks/simulationAPI/helpers/scilab_manager.py b/blocks/simulationAPI/helpers/scilab_manager.py
index 02304837..8f015d74 100644
--- a/blocks/simulationAPI/helpers/scilab_manager.py
+++ b/blocks/simulationAPI/helpers/scilab_manager.py
@@ -9,7 +9,7 @@ import glob
import json
import fileinput
import os
-from os.path import abspath, exists, isfile, join, splitext
+from os.path import abspath, exists, isdir, isfile, join, splitext
import re
import signal
import subprocess
@@ -85,30 +85,42 @@ def secure_filename(filename: str) -> str:
return filename.strip("._") # Prevent filenames like ".." or "."
-def makedirs(dirname, dirtype):
+def makedirs(dirname, dirtype=None):
if not exists(dirname):
os.makedirs(dirname)
-def rmdir(dirname, dirtype):
+def rmdir(dirname, dirtype=None):
+ if dirname is None:
+ return False
+ if not isdir(dirname):
+ logger.error('dir %s does not exist', dirname)
+ return False
+ if not config.REMOVEFILE:
+ logger.debug('not removing dir %s', dirname)
+ return True
try:
- if exists(dirname):
- os.rmdir(dirname)
+ os.rmdir(dirname)
+ return True
except Exception as e:
- logger.warning('could not remove %s: %s', dirname, str(e))
+ logger.warning('could not remove dir %s: %s', dirname, str(e))
+ return False
def remove(filename):
if filename is None:
return False
+ if not isfile(filename):
+ logger.error('file %s does not exist', filename)
+ return False
if not config.REMOVEFILE:
- logger.debug('not removing %s', filename)
+ logger.debug('not removing file %s', filename)
return True
try:
os.remove(filename)
return True
- except BaseException:
- logger.error('could not remove %s', filename)
+ except Exception as e:
+ logger.error('could not remove file %s: %s', filename, str(e))
return False