Rimco/OSPy

Error after upgrade to last file system options.py

Closed this issue · 4 comments

Hi Rimco,
First of all, I would like to thank you for the wonderful work you have done on the ospy.
I've updated my forp ospy and have a problem with options.py. Can you please advise?
Best regard Martin

Exception in thread Thread-117:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 1082, in run
self.function(*self.args, **self.kwargs)
File "/home/pi/OSPy/ospy/options.py", line 428, in _write
os.rename(OPTIONS_FILE + '.tmp', OPTIONS_FILE)
OSError: [Errno 2] No such file or directory

I added support to the second master 2 of the output and the possibility of languages, while I have all the plugins altered to support languages. You are not interested in incorporating the changes into your OSPy version. Thank you very much

def _write(self):
    """This function saves the current data to disk. Use a timer to limit the call rate."""
    db = shelve.open(OPTIONS_FILE + '.tmp')
    db.clear()
    db.update(self._values)
    db.close()

    if os.path.isfile(OPTIONS_FILE + '.bak') and time.time() - os.path.getmtime(OPTIONS_FILE + '.bak') > 3600\
            and os.path.isfile(OPTIONS_FILE) and (os.path.getsize(OPTIONS_FILE + '.bak') >= os.path.getsize(OPTIONS_FILE) * 0.9 or time.time() - os.path.getmtime(OPTIONS_FILE + '.bak') > 7*3600):
        os.remove(OPTIONS_FILE + '.bak')

    if os.path.isfile(OPTIONS_FILE):
        if not os.path.isfile(OPTIONS_FILE + '.bak'):
            os.rename(OPTIONS_FILE, OPTIONS_FILE + '.bak')
        else:
            os.remove(OPTIONS_FILE)
            
    **if os.path.isfile(OPTIONS_FILE + '.tmp'): # fix error?**
        os.rename(OPTIONS_FILE + '.tmp', OPTIONS_FILE)

Already repaired, thank you.