# Path: groundstation/settings.py
# PORT=1248 # Port to listen on (udp+tcp)
# BEACON_TIMEOUT=5 # 5 second timeout between beacons
# DEFAULT_BUFSIZE=8192 # 8k bytes
# DEFAULT_CACHE_LIFETIME=30 # 30 Seconds
# STORAGE_BACKEND="git"
# LISTALLOBJECTS_CHUNK_THRESHOLD=1024
# LISTALLCHANNELS_RETRY_TIMEOUT=5
# CLOSEWAIT_TIMEOUT=240 # 2MSL
# 
# Path: groundstation/logger.py
#     LEVEL = getattr(logging, os.getenv("GROUNDSTATION_DEBUG"))
#     LEVEL = logging.DEBUG
# CONSOLE_FORMATTER = _get_formatter()
# CONSOLE_HANDLER = _get_console_handler()
# LOGGERS = {}  # Cache for instanciated loggers
# def fix_oid(oid):
# def _get_formatter():
# def _get_console_handler():
# def getLogger(name):  # Not threadsafe


import groundstation.transfer.request
import groundstation.proto.object_list_pb2
import groundstation.utils
from groundstation import settings
from groundstation import logger


log = logger.getLogger(__name__)


def handle_listallobjects(self):
    if not self.station.recently_queried(self.origin):
        log.info("%s not up to date, issuing LISTALLOBJECTS" % (self.origin))
        #                                                                      Pass in the station for gizmo_factory in the constructor
        listobjects = groundstation.transfer.request.Request("LISTALLOBJECTS", station=self.station, stream=self.stream)
        self.station.register_request(listobjects)
        self.stream.enqueue(listobjects)
    else:
        log.info("object cache for %s still valid" % (self.origin))
    log.info("Handling LISTALLOBJECTS")
    payload = [groundstation.utils.oid2hex(i) for i in self.station.objects()]
    if len(payload) > settings.LISTALLOBJECTS_CHUNK_THRESHOLD:
        log.info("Lots of objects to send, registering an iterator")

        @self.station.register_iter
        def iterator():

# Path: groundstation/settings.py
# PORT=1248 # Port to listen on (udp+tcp)
# BEACON_TIMEOUT=5 # 5 second timeout between beacons
# DEFAULT_BUFSIZE=8192 # 8k bytes
# DEFAULT_CACHE_LIFETIME=30 # 30 Seconds
# STORAGE_BACKEND="git"
# LISTALLOBJECTS_CHUNK_THRESHOLD=1024
# LISTALLCHANNELS_RETRY_TIMEOUT=5
# CLOSEWAIT_TIMEOUT=240 # 2MSL
# 
# Path: groundstation/logger.py
#     LEVEL = getattr(logging, os.getenv("GROUNDSTATION_DEBUG"))
#     LEVEL = logging.DEBUG
# CONSOLE_FORMATTER = _get_formatter()
# CONSOLE_HANDLER = _get_console_handler()
# LOGGERS = {}  # Cache for instanciated loggers
# def fix_oid(oid):
# def _get_formatter():
# def _get_console_handler():
# def getLogger(name):  # Not threadsafe


# Path: groundstation/transfer/request_handlers/listallobjects.py
import groundstation.transfer.request
import groundstation.proto.object_list_pb2
import groundstation.utils
from groundstation import settings
from groundstation import logger



log = logger.getLogger(__name__)


def handle_listallobjects(self):
    if not self.station.recently_queried(self.origin):
        log.info("%s not up to date, issuing LISTALLOBJECTS" % (self.origin))
        #                                                                      Pass in the station for gizmo_factory in the constructor
        listobjects = groundstation.transfer.request.Request("LISTALLOBJECTS", station=self.station, stream=self.stream)
        self.station.register_request(listobjects)
        self.stream.enqueue(listobjects)
    else:
        log.info("object cache for %s still valid" % (self.origin))
    log.info("Handling LISTALLOBJECTS")
    payload = [groundstation.utils.oid2hex(i) for i in self.station.objects()]
    if len(payload) > settings.LISTALLOBJECTS_CHUNK_THRESHOLD:
        log.info("Lots of objects to send, registering an iterator")

        @self.station.register_iter
        def iterator():

            for chunk in groundstation.utils.chunks(payload, settings.LISTALLOBJECTS_CHUNK_THRESHOLD):