Commit fe3c951b by mehtank

better file handling in code/electrical composables

1 parent c9edebf6
......@@ -137,8 +137,24 @@ class CodeComposable(Composable):
return [self._components, self._virtualPins,
self._dataMap, self._controllerDirs]
def rmdirTemp(self):
# Remove temp directory
# Our portion is now empty, but do a recursive delete in case a previous
# program execution did not terminate correctly and did not clear out its temp files
for root, dirs, files in os.walk(self._tempOutputDir, topdown=False):
for name in files:
os.remove(os.path.join(root, name))
for name in dirs:
os.rmdir(os.path.join(root, name))
os.rmdir(self._tempOutputDir)
# Make the final output
def makeOutput(self, filedir, **kwargs):
if not filedir:
### XXX TODO : Handle return to string
self.rmdirTemp()
return
a = None
tab = ' '
res = '\nCodeComposable MakeOutput'
......@@ -338,15 +354,7 @@ class CodeComposable(Composable):
os.rmdir(controllerDir + self._insertionsDir)
os.rmdir(controllerDir)
# Remove temp directory
# Our portion is now empty, but do a recursive delete in case a previous
# program execution did not terminate correctly and did not clear out its temp files
for root, dirs, files in os.walk(self._tempOutputDir, topdown=False):
for name in files:
os.remove(os.path.join(root, name))
for name in dirs:
os.rmdir(os.path.join(root, name))
os.rmdir(self._tempOutputDir)
self.rmdirTemp()
fout = open(filedir + '/' + 'virtual_pins.txt', 'w+')
for num, port in enumerate(self._virtualPins):
......
......@@ -122,9 +122,13 @@ class ElectricalComposable(Composable):
if len(deviceRes) > 0:
fres += '\n\tDevice ' + device.getName() + ':'
fres += deviceRes
f = open(filedir + '/wiring_instructions.txt', 'w')
f.write(fres)
f.close()
if filedir:
with open(filedir + '/wiring_instructions.txt', 'w') as f:
f.write(fres)
else:
return fres
res += fres
#print fres
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!