interrupt, save
On keyboard interrupt in the regular flow of downloading the collected images of this session and of last session are saved so as not to destroy the archive accidentally this way. If an item is added to the new collection, it is removed from the old one. If a save is being dumped (uncleanly saved because of KB interrupt), the old collection is appended to the new one. Upon loading the returned string is split to enable removing of the old items.
This commit is contained in:
parent
ef79c9991b
commit
0323ddbed8
2 changed files with 14 additions and 2 deletions
4
4grab.py
4
4grab.py
|
@ -30,6 +30,7 @@ import util
|
|||
import download
|
||||
import progressbar
|
||||
import sorter
|
||||
import backend
|
||||
|
||||
config._optioncreator = raw_input_with_default
|
||||
|
||||
|
@ -202,6 +203,9 @@ if __name__ == "__main__":
|
|||
print "Failed: ", failed
|
||||
print "Total: ", total
|
||||
except KeyboardInterrupt:
|
||||
be = backend.Backend()
|
||||
be.save(True) # Make sure that the downloaded images are saved anyway
|
||||
|
||||
print
|
||||
print "So you don't want these images? Fine! I'll stop then."
|
||||
util.log(util.LogType.Err, "Quit on user request")
|
||||
|
|
12
backend.py
12
backend.py
|
@ -19,6 +19,9 @@ class _Backend(object):
|
|||
return True
|
||||
|
||||
def add(self, filename):
|
||||
if filename in self.__collection:
|
||||
self.__collection.remove(filename)
|
||||
|
||||
self.__new_collection.append(filename)
|
||||
|
||||
def check(self, filename):
|
||||
|
@ -33,7 +36,10 @@ class _Backend(object):
|
|||
|
||||
return False
|
||||
|
||||
def save(self):
|
||||
def save(self, dump = False):
|
||||
if dump:
|
||||
self.__new_collection.extend(self.__collection)
|
||||
|
||||
if os.path.exists(self.table):
|
||||
os.remove(self.table)
|
||||
|
||||
|
@ -43,7 +49,9 @@ class _Backend(object):
|
|||
|
||||
def load(self):
|
||||
if os.path.exists(self.table):
|
||||
self.__collection = self.store.select(self.table, ['recno'], ['*'], ['filename'], returnType="report")
|
||||
collection = self.store.select(self.table, ['recno'], ['*'], ['filename'], returnType="report")
|
||||
if collection != '':
|
||||
self.__collection = collection.split()
|
||||
|
||||
_backend = None
|
||||
def Backend():
|
||||
|
|
Loading…
Reference in a new issue