summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSunil Shetye2025-04-08 13:29:35 +0530
committerSunil Shetye2025-04-08 13:29:35 +0530
commit27ea203ca1c6b38665d310f607387dadd5c24b31 (patch)
tree402ee9c279ede2d10a9ba319d1c5dcda3a12f947
parentdb24822430015fc1481a260b02653ed9bf2f9d49 (diff)
downloadCommon-Interface-Project-27ea203ca1c6b38665d310f607387dadd5c24b31.tar.gz
Common-Interface-Project-27ea203ca1c6b38665d310f607387dadd5c24b31.tar.bz2
Common-Interface-Project-27ea203ca1c6b38665d310f607387dadd5c24b31.zip
cleanup
-rw-r--r--blocks/.flake82
-rw-r--r--blocks/eda-frontend/src/components/SchematicEditor/SimulationProperties.js3
-rw-r--r--blocks/eda-frontend/src/components/SchematicEditor/ToolbarExtension.js121
-rw-r--r--blocks/eda-frontend/src/utils/GalleryUtils.js4
-rw-r--r--blocks/simulationAPI/helpers/ngspice_helper.py1
-rw-r--r--blocks/simulationAPI/helpers/scilab_manager.py7
-rw-r--r--blocks/simulationAPI/tasks.py7
-rw-r--r--blocks/simulationAPI/views.py5
8 files changed, 61 insertions, 89 deletions
diff --git a/blocks/.flake8 b/blocks/.flake8
index b6eca717..09bce94d 100644
--- a/blocks/.flake8
+++ b/blocks/.flake8
@@ -5,5 +5,5 @@
#ignore = E121,E123,E126,E226,E24,E704,W503,W504
ignore = F401,F403,W504
extend-exclude = docs,env*,migrations,node_modules,Xcos/common,Xcos/blocks,Xcos/ports,Xcos/links
-max-complexity = 30
+max-complexity = 70
max-line-length = 275
diff --git a/blocks/eda-frontend/src/components/SchematicEditor/SimulationProperties.js b/blocks/eda-frontend/src/components/SchematicEditor/SimulationProperties.js
index fbfecbac..1ddbeeb2 100644
--- a/blocks/eda-frontend/src/components/SchematicEditor/SimulationProperties.js
+++ b/blocks/eda-frontend/src/components/SchematicEditor/SimulationProperties.js
@@ -19,6 +19,7 @@ import { setResultTitle, setResultTaskId, resetResult } from '../../redux/simula
import { saveXml } from './Helper/ToolbarTools'
import SimulationScreen, { setGraphStatusClosed } from './SimulationScreen'
import api from '../../utils/Api'
+import { sanitizeTitle } from '../../utils/GalleryUtils'
const useStyles = makeStyles((theme) => ({
toolbar: {
@@ -82,7 +83,7 @@ export default function SimulationProperties () {
// Prepare Netlist to file
const prepareNetlist = (netlist) => {
- const titleA = title
+ const titleA = sanitizeTitle(title)
const myblob = new Blob([netlist], {
type: 'text/plain'
})
diff --git a/blocks/eda-frontend/src/components/SchematicEditor/ToolbarExtension.js b/blocks/eda-frontend/src/components/SchematicEditor/ToolbarExtension.js
index 83c8ce15..84686ce2 100644
--- a/blocks/eda-frontend/src/components/SchematicEditor/ToolbarExtension.js
+++ b/blocks/eda-frontend/src/components/SchematicEditor/ToolbarExtension.js
@@ -40,7 +40,7 @@ import { fetchSchematic, fetchDiagram, setSchScriptDump, setShowDot } from '../.
import { fetchSchematics, fetchGallery } from '../../redux/dashboardSlice'
import { setScriptTaskId } from '../../redux/simulationSlice'
import { blue } from '@material-ui/core/colors'
-import { getDateTime as getDate, getUppercaseInitial, saveToFile } from '../../utils/GalleryUtils'
+import { getDateTime as getDate, getUppercaseInitial, saveToFile, sanitizeTitle } from '../../utils/GalleryUtils'
import { renderGalleryXML } from './Helper/ToolbarTools'
import api from '../../utils/Api'
@@ -52,7 +52,7 @@ const Transition = forwardRef(function Transition (props, ref) {
export function NetlistModal ({ open, close, netlist }) {
const title = useSelector(state => state.saveSchematic.title)
const createNetlistFile = () => {
- const titleA = title.split(' ')[1]
+ const titleA = sanitizeTitle(title)
const name = process.env.REACT_APP_NAME
saveToFile(`${titleA}_${name}_on_Cloud.cir`, 'text/plain', netlist)
}
@@ -341,7 +341,6 @@ HelpScreen.propTypes = {
export function ScriptScreen ({ isOpen, onClose }) {
const scriptDump = useSelector(state => state.saveSchematic.scriptDump)
const title = useSelector(state => state.saveSchematic.title)
- const showDot = useSelector(state => state.saveSchematic.showDot)
const dispatch = useDispatch()
const [result, setResult] = useState('No output yet...')
const [variables, setVariables] = useState([])
@@ -350,9 +349,8 @@ export function ScriptScreen ({ isOpen, onClose }) {
dispatch(setShowDot(true))
}
-
const prepareScriptNetlist = (scriptDump) => {
- const titleA = title
+ const titleA = sanitizeTitle(title)
const myblob = new Blob([scriptDump], {
type: 'text/plain'
})
@@ -371,7 +369,6 @@ export function ScriptScreen ({ isOpen, onClose }) {
console.log('taskId2:', taskId)
setResult(data.output || 'No output available.')
setVariables(data.variables)
-
})
.catch(function (error) {
console.error(error)
@@ -405,7 +402,6 @@ export function ScriptScreen ({ isOpen, onClose }) {
dispatch(setScriptTaskId(''))
setResult('No output yet...')
setVariables('')
-
}
return (
@@ -431,7 +427,7 @@ export function ScriptScreen ({ isOpen, onClose }) {
display: 'grid',
gridTemplateColumns: { xs: '1fr', md: '1fr 1fr' },
gap: 4,
- alignItems: 'stretch',
+ alignItems: 'stretch'
}}
>
<Box
@@ -441,7 +437,7 @@ export function ScriptScreen ({ isOpen, onClose }) {
borderRadius: 2,
display: 'flex',
flexDirection: 'column',
- flexGrow: 1,
+ flexGrow: 1
}}
>
<Typography variant="subtitle1" style={{ fontWeight: 'bold', mb: 1 }}>
@@ -451,36 +447,23 @@ export function ScriptScreen ({ isOpen, onClose }) {
<Box
sx={{
height: '500px',
- overflowY: 'scroll',
+ overflowY: 'auto',
border: '1px solid #ccc',
- borderRadius: 1,
- '&::-webkit-scrollbar': {
- width: '8px',
- },
- '&::-webkit-scrollbar-track': {
- backgroundColor: '#f1f1f1',
- },
- '&::-webkit-scrollbar-thumb': {
- backgroundColor: '#888',
- borderRadius: '4px',
- },
- '&::-webkit-scrollbar-thumb:hover': {
- backgroundColor: '#555',
- },
+ borderRadius: 1
}}
>
<TextField
value={scriptDump}
onChange={scriptHandler}
multiline
- variant="outlined"
+ variant='outlined'
fullWidth
InputProps={{
disableUnderline: true,
sx: {
- fontFamily: 'Courier New, monospace',
- fontSize: '14px',
- },
+ fontFamily: "'Roboto Mono', monospace",
+ fontSize: '14px'
+ }
}}
/>
</Box>
@@ -493,7 +476,7 @@ export function ScriptScreen ({ isOpen, onClose }) {
borderRadius: 2,
display: 'flex',
flexDirection: 'column',
- height: '100%',
+ height: '100%'
}}
>
<Typography variant="subtitle1" style={{ fontWeight: 'bold', mb: 1 }}>
@@ -510,32 +493,20 @@ export function ScriptScreen ({ isOpen, onClose }) {
display: 'flex',
height: '500px',
whiteSpace: 'pre-wrap', // Keep line breaks
- '&::-webkit-scrollbar': {
- width: '8px',
- },
- '&::-webkit-scrollbar-track': {
- backgroundColor: '#f1f1f1',
- },
- '&::-webkit-scrollbar-thumb': {
- backgroundColor: '#888',
- borderRadius: '4px',
- },
- '&::-webkit-scrollbar-thumb:hover': {
- backgroundColor: '#555',
- },
+ fontFamily: "'Roboto Mono', monospace"
}}
>
{result}
</Box>
- <Typography variant="subtitle1" style={{ fontWeight: "bold", marginTop: 16 }}>
+ <Typography variant="subtitle1" style={{ fontWeight: 'bold', marginTop: 16 }}>
Variable Browser :
</Typography>
<Box
style={{
flexGrow: 1,
padding: 8,
- border: "1px solid gray",
+ border: '1px solid gray',
borderRadius: 4
}}
>
@@ -546,30 +517,30 @@ export function ScriptScreen ({ isOpen, onClose }) {
>
<Table size="small" stickyHeader>
<TableHead>
- <TableRow style={{ backgroundColor: "#e0e0e0" }}>
+ <TableRow style={{ backgroundColor: '#e0e0e0' }}>
<TableCell
style={{
- border: "1px solid gray",
- fontWeight: "bold",
- padding: "4px 8px",
+ border: '1px solid gray',
+ fontWeight: 'bold',
+ padding: '4px 8px'
}}
>
Name
</TableCell>
<TableCell
style={{
- border: "1px solid gray",
- fontWeight: "bold",
- padding: "4px 8px",
+ border: '1px solid gray',
+ fontWeight: 'bold',
+ padding: '4px 8px'
}}
>
Value
</TableCell>
<TableCell
style={{
- border: "1px solid gray",
- fontWeight: "bold",
- padding: "4px 8px",
+ border: '1px solid gray',
+ fontWeight: 'bold',
+ padding: '4px 8px'
}}
>
Type
@@ -577,27 +548,29 @@ export function ScriptScreen ({ isOpen, onClose }) {
</TableRow>
</TableHead>
<TableBody>
- {variables.length > 0 ? (
- variables.map((variable, index) => (
- <TableRow key={index}>
- <TableCell style={{ border: "1px solid gray", padding: "4px 8px" }}>
- {variable.name}
- </TableCell>
- <TableCell style={{ border: "1px solid gray", padding: "4px 8px" }}>
- {variable.value}
- </TableCell>
- <TableCell style={{ border: "1px solid gray", padding: "4px 8px" }}>
- {variable.type}
+ {variables.length > 0
+ ? (
+ variables.map((variable, index) => (
+ <TableRow key={index}>
+ <TableCell style={{ border: '1px solid gray', padding: '4px 8px' }}>
+ {variable.name}
+ </TableCell>
+ <TableCell style={{ border: '1px solid gray', padding: '4px 8px' }}>
+ {variable.value}
+ </TableCell>
+ <TableCell style={{ border: '1px solid gray', padding: '4px 8px' }}>
+ {variable.type}
+ </TableCell>
+ </TableRow>
+ ))
+ )
+ : (
+ <TableRow>
+ <TableCell colSpan={3} align="center">
+ No variables available.
</TableCell>
</TableRow>
- ))
- ) : (
- <TableRow>
- <TableCell colSpan={3} align="center">
- No variables available.
- </TableCell>
- </TableRow>
- )}
+ )}
</TableBody>
</Table>
</TableContainer>
@@ -606,8 +579,6 @@ export function ScriptScreen ({ isOpen, onClose }) {
</Box>
-
-
{/* Action Buttons */}
<Box sx={{ mt: 4, display: 'flex', gap: 4 }}>
<Button onClick={executeScript} color='primary' variant='contained'>
diff --git a/blocks/eda-frontend/src/utils/GalleryUtils.js b/blocks/eda-frontend/src/utils/GalleryUtils.js
index d7fe871c..9453695c 100644
--- a/blocks/eda-frontend/src/utils/GalleryUtils.js
+++ b/blocks/eda-frontend/src/utils/GalleryUtils.js
@@ -199,3 +199,7 @@ export const removeBySaveIdInPlace = (schematics, saveId) => {
schematics.splice(index, 1)
}
}
+
+export const sanitizeTitle = (title, replacement = '_') => {
+ return title.replace(/[<>:"/\\|?* ]/g, replacement).trim()
+}
diff --git a/blocks/simulationAPI/helpers/ngspice_helper.py b/blocks/simulationAPI/helpers/ngspice_helper.py
index 3b466760..a7d86262 100644
--- a/blocks/simulationAPI/helpers/ngspice_helper.py
+++ b/blocks/simulationAPI/helpers/ngspice_helper.py
@@ -159,4 +159,3 @@ def ExecXml(task, task_name, workspace_file):
pass
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 fb693167..02304837 100644
--- a/blocks/simulationAPI/helpers/scilab_manager.py
+++ b/blocks/simulationAPI/helpers/scilab_manager.py
@@ -73,7 +73,7 @@ SCILAB_CMD = [SCILAB,
"-nb",
"-nw",
"-e", SCILAB_START
- ]
+ ]
USER_DATA = {}
@@ -245,7 +245,7 @@ class UserData:
f"scriptcount={self.scriptcount}, "
f"scifile={self.scifile}, "
f"timestamp={self.timestamp})")
-
+
def __repr__(self):
return self.__str__()
@@ -728,14 +728,13 @@ def uploadscript(session, task):
command = "exec('%s');save('%s');" % (fname, wfname)
script.instance = run_scilab(command, script)
-
if script.instance is None:
msg = "Resource not available"
script.status = -2
rv = {'status': script.status, 'msg': msg}
return rv
-
+
# Save workspace file in task model
task.workspace_file = wfname
task.save()
diff --git a/blocks/simulationAPI/tasks.py b/blocks/simulationAPI/tasks.py
index 5d18d789..e6e8680a 100644
--- a/blocks/simulationAPI/tasks.py
+++ b/blocks/simulationAPI/tasks.py
@@ -8,7 +8,7 @@ import traceback
from blocks.celery_tasks import app
from simulationAPI.helpers.ngspice_helper import ExecXml, update_task_status
from simulationAPI.models import Task
-from simulationAPI.helpers.scilab_manager import uploadscript, getscriptoutput
+from simulationAPI.helpers.scilab_manager import uploadscript, getscriptoutput
logger = get_task_logger(__name__)
@@ -44,7 +44,7 @@ def process_task(self, task_id):
output = getscriptoutput(task.session, task)
state = 'SUCCESS'
update_task_status(task_id, state,
- meta=output)
+ meta=output)
else:
output = ExecXml(task, self.name, task.workspace_file)
if output == "Streaming":
@@ -55,7 +55,7 @@ def process_task(self, task_id):
current_process = 'Processed Xml, Loading Output'
update_task_status(task_id, state,
- meta={'current_process': current_process})
+ meta={'current_process': current_process})
return output
@@ -70,4 +70,3 @@ def process_task(self, task_id):
finally:
release_lock(lock) # Ensure lock is always released
-
diff --git a/blocks/simulationAPI/views.py b/blocks/simulationAPI/views.py
index 625aa774..55093377 100644
--- a/blocks/simulationAPI/views.py
+++ b/blocks/simulationAPI/views.py
@@ -20,7 +20,6 @@ from simulationAPI.tasks import process_task
from simulationAPI.helpers.ngspice_helper import CreateXcos, update_task_status
-
SCILAB_INSTANCE_TIMEOUT_INTERVAL = 300
MAX_LOG_SIZE = 512 * 1024
LOOK_DELAY = 0.1
@@ -91,8 +90,8 @@ class XmlUploader(APIView):
}
else:
rv = celery_task.get(timeout=10)
- response_data = {**rv, 'task_id':task_id}
-
+ response_data = {**rv, 'task_id': task_id}
+
return Response(response_data)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)