uzh / vm-mad

Dynamically grow or shrink GridEngine clusters using cloud-based nodes
https://arxiv.org/abs/1302.2529
Apache License 2.0
3 stars 2 forks source link

`-o` option should overwrite output files by default #6

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The `-o` option should overwrite hte target output file by default, because 
that's the common case; removing the output before running the `simul.py` 
script is inconvenient and error-prone.

Original issue reported on code.google.com by tyanko.a...@gmail.com on 16 Feb 2012 at 4:49

GoogleCodeExporter commented 9 years ago

Original comment by riccardo.murri@gmail.com on 17 Feb 2012 at 9:01

GoogleCodeExporter commented 9 years ago
As the output file is being used for writing the current state of the simulator 
on each iteration an "overwrite procedure" could be defined only during the 
initialization of the simulator: 

88         # Delete input file if such exists form previous simulation.  
89         if os.path.isfile(self.output_file):
90             os.remove(self.output_file)

Is there some other way of doing so? 

Original comment by tyanko.a...@gmail.com on 20 Feb 2012 at 1:30

GoogleCodeExporter commented 9 years ago
| As the output file is being used for writing the current state of the
| simulator on each iteration an "overwrite procedure" could be defined only
| during the initialization of the simulator:
|
| 88         # Delete input file if such exists form previous simulation.
| 89         if os.path.isfile(self.output_file):
| 90             os.remove(self.output_file)
|
| Is there some other way of doing so?

Isn't it just a question of changing the "mode" part in the `open()`
call for the output file?

E.g., to append you do `output_file = open(..., 'a')`, to overwrite
you do: `output_file = open(..., 'w')`.

Original comment by riccardo.murri@gmail.com on 20 Feb 2012 at 2:02

GoogleCodeExporter commented 9 years ago
Yes, this way is also possible. Change the code to:
# Just open the file in write mode in order to overwrite previous one 
with open(self.output_file, 'w') as output:
    output.write("")
    output.closed

Original comment by tyanko.a...@gmail.com on 20 Feb 2012 at 2:46

GoogleCodeExporter commented 9 years ago
| Yes, this way is also possible. Change the code to:
| # Just open the file in write mode in order to overwrite previous one
| with open(self.output_file, 'w') as output:
|    output.write("")
|    output.closed

No :-)

1. The `with open(...)` statement in Python will *close* the file at
   exit of the following block.  So it's good for doing
   temporary/localized work on a file, but this is not the case  in
   `simul.py`: we need the output file open from the start to the end
   of the simulation work.

2. Similarly, the `with open(...)` in `before(...)` should be changed
   to just write to an output file that is opened in the ctor and
   saved as object attribute.

3. Finally, `output.closed` is not a method invocation! It's an
   attribute lookup, that will return whatever value the
   `output.closed` attribute has (or raise an exception if no such
   attribute exists).  Also, --see 1.-- the whole point of using
   `with` blocks is that you should not care about closing files on
   exit...

Original comment by riccardo.murri@gmail.com on 21 Feb 2012 at 12:21

GoogleCodeExporter commented 9 years ago
Changed like this:
in `__init__()`
75         self.output_file = open(output_file, 'w')
in `before()`
..
153         if len(self._running) == 0 and len(self._pending)....
154             log.info("No more jobs, stopping here")
155             self.output_file.close()
156             sys.exit(0)
157 
158         self.output_file.write(

Original comment by tyanko.a...@gmail.com on 21 Feb 2012 at 2:22