made uploadqueue lint compliant
parent
1019ff0773
commit
b5a8f295c9
|
@ -1,8 +1,17 @@
|
||||||
"""
|
"""Onionr - Private P2P Communication.
|
||||||
Onionr - Private P2P Communication
|
|
||||||
|
|
||||||
Class to remember blocks that need to be uploaded and not shared on startup/shutdown
|
Class to remember blocks that need to be uploaded
|
||||||
|
and not shared on startup/shutdown
|
||||||
"""
|
"""
|
||||||
|
import atexit
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
import deadsimplekv
|
||||||
|
|
||||||
|
import filepaths
|
||||||
|
from onionrutils import localcommand
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from communicator import OnionrCommunicatorDaemon
|
||||||
"""
|
"""
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
@ -18,43 +27,37 @@
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import atexit
|
|
||||||
import json
|
|
||||||
|
|
||||||
import deadsimplekv
|
|
||||||
|
|
||||||
import filepaths
|
|
||||||
from onionrutils import localcommand
|
|
||||||
|
|
||||||
UPLOAD_MEMORY_FILE = filepaths.upload_list
|
UPLOAD_MEMORY_FILE = filepaths.upload_list
|
||||||
|
|
||||||
|
|
||||||
def _add_to_hidden_blocks(cache):
|
def _add_to_hidden_blocks(cache):
|
||||||
for bl in cache:
|
for bl in cache:
|
||||||
localcommand.local_command('waitforshare/' + bl, post=True)
|
localcommand.local_command('waitforshare/' + bl, post=True)
|
||||||
|
|
||||||
|
|
||||||
class UploadQueue:
|
class UploadQueue:
|
||||||
"""
|
"""Saves and loads block upload info from json file."""
|
||||||
Saves and loads block upload info from json file
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, communicator: 'OnionrCommunicatorDaemon'):
|
def __init__(self, communicator: 'OnionrCommunicatorDaemon'):
|
||||||
"""Start the UploadQueue object, loading left over uploads into queue
|
"""Start the UploadQueue object, loading left over uploads into queue.
|
||||||
and registering save shutdown function
|
|
||||||
|
register save shutdown function
|
||||||
"""
|
"""
|
||||||
self.communicator = communicator
|
self.communicator = communicator
|
||||||
cache = deadsimplekv.DeadSimpleKV(UPLOAD_MEMORY_FILE)
|
cache: deadsimplekv.DeadSimpleKV = deadsimplekv.DeadSimpleKV(
|
||||||
|
UPLOAD_MEMORY_FILE)
|
||||||
self.store_obj = cache
|
self.store_obj = cache
|
||||||
cache: list = cache.get('uploads')
|
cache = cache.get('uploads')
|
||||||
if cache == None:
|
if cache is None:
|
||||||
cache = []
|
cache = []
|
||||||
|
|
||||||
_add_to_hidden_blocks(cache)
|
_add_to_hidden_blocks(cache)
|
||||||
self.communicator.blocksToUpload.extend(cache)
|
self.communicator.blocksToUpload.extend(cache)
|
||||||
|
|
||||||
atexit.register(self.save)
|
atexit.register(self.save)
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
"""Saves to disk on shutdown or if called manually"""
|
"""Save to disk on shutdown or if called manually."""
|
||||||
bl: list = self.communicator.blocksToUpload
|
bl: deadsimplekv.DeadSimpleKV = self.communicator.blocksToUpload
|
||||||
self.store_obj.put('uploads', bl)
|
self.store_obj.put('uploads', bl)
|
||||||
self.store_obj.flush()
|
self.store_obj.flush()
|
||||||
|
|
Loading…
Reference in New Issue