예제 #1
0
    def __init__(self, path, database_file, root_dir, extension,
                 bowerbird_port, localnet_scan_time_ms, concurrent_transfers,
                 transfer_bandwidth, transfer_chunk_size):
        self.path = path
        self.bowerbird_port = bowerbird_port

        # initialise storage
        self._storage = ProxyStorage(database_file, root_dir, extension)

        # create the zeroconf scanner to detect local bowerbirds
        self._scanner = ZeroconfScanner(ZEROCONF_TYPE, localnet_scan_time_ms)

        self._transfer_manager = TransferManager(bowerbird_port,
                                                 concurrent_transfers,
                                                 transfer_bandwidth,
                                                 transfer_chunk_size)
예제 #2
0
    def __init__(self, path, database_file, root_dir, extension,
            bowerbird_port, localnet_scan_time_ms, concurrent_transfers,
            transfer_bandwidth, transfer_chunk_size):
        self.path = path
        self.bowerbird_port = bowerbird_port

        # initialise storage
        self._storage = ProxyStorage(database_file, root_dir, extension)

        # create the zeroconf scanner to detect local bowerbirds
        self._scanner = ZeroconfScanner(ZEROCONF_TYPE, localnet_scan_time_ms)

        self._transfer_manager = TransferManager(bowerbird_port,
                concurrent_transfers, transfer_bandwidth, transfer_chunk_size)
예제 #3
0
class Root(object):
    def __init__(self, path, database_file, root_dir, extension,
                 bowerbird_port, localnet_scan_time_ms, concurrent_transfers,
                 transfer_bandwidth, transfer_chunk_size):
        self.path = path
        self.bowerbird_port = bowerbird_port

        # initialise storage
        self._storage = ProxyStorage(database_file, root_dir, extension)

        # create the zeroconf scanner to detect local bowerbirds
        self._scanner = ZeroconfScanner(ZEROCONF_TYPE, localnet_scan_time_ms)

        self._transfer_manager = TransferManager(bowerbird_port,
                                                 concurrent_transfers,
                                                 transfer_bandwidth,
                                                 transfer_chunk_size)

    @cherrypy.expose
    @template.output('connect.html')
    def connect(self, address=None, remove=None, rescan=False, **ignored):
        # if already connected, then just bounce to the status page
        if hasSession(SESSION_STATION_ADDRESS_KEY):
            raise cherrypy.HTTPRedirect('/status')

        # ignore address if "rescan" was requested
        if not rescan and address:
            # if "Remove" button has been clicked, delete entry from history
            if remove:
                self._storage.removeConnection(address)
            else:
                # get the name from the address
                try:
                    name = self.getRemoteName(address)
                except urllib2.URLError:
                    return self.showConnectionFailure(
                        error="could not be established", address=address)

                self._storage.addConnection(name, address)
                setSession(SESSION_STATION_ADDRESS_KEY, address)
                setSession(SESSION_STATION_NAME_KEY, name)
                # make sure new connection's recordings are not filtered out
                if (hasSession(SESSION_FILTER_STATION_KEY)
                        and getSession(SESSION_FILTER_STATION_KEY) != name):
                    clearSession(SESSION_FILTER_STATION_KEY)
                raise cherrypy.HTTPRedirect('/status')

        return template.render(
            is_proxy=True,
            station=None,
            previous_connections=self._storage.getPreviousConnections(),
            local_connections=self.findLocalBowerbirds(rescan))

    @cherrypy.expose
    def disconnect(self, **ignored):
        # set disconnected
        clearSession(SESSION_STATION_ADDRESS_KEY)
        clearSession(SESSION_STATION_NAME_KEY)
        raise cherrypy.HTTPRedirect('/')

    @cherrypy.expose
    def index(self, **ignored):
        # just redirect to status page if connected, otherwise connect page
        if hasSession(SESSION_STATION_ADDRESS_KEY):
            raise cherrypy.HTTPRedirect('/status')
        else:
            raise cherrypy.HTTPRedirect('/connect')

    @cherrypy.expose
    def status(self, **kwargs):
        return self.updateHtmlFromBowerbird(
            self.tunnelConnectionToBowerbird('status', kwargs))

    @cherrypy.expose
    def config(self, **kwargs):
        # TODO catch station name changes and update connection history
        return self.updateHtmlFromBowerbird(
            self.tunnelConnectionToBowerbird('config', kwargs))

    @cherrypy.expose
    def schedule(self, **kwargs):
        return self.updateHtmlFromBowerbird(
            self.tunnelConnectionToBowerbird('schedule', kwargs))

    @cherrypy.expose
    @template.output('recordings.html')
    def recordings(self,
                   view='month',
                   year=None,
                   month=None,
                   day=None,
                   recording_id=None,
                   set_recording_id=False,
                   clear_recording_id=False,
                   go_to_start=False,
                   go_to_finish=False,
                   go_to_today=False,
                   filter_station=None,
                   filter_title=None,
                   filter_start=None,
                   filter_finish=None,
                   update_filter=None,
                   reset_filter=None,
                   clear_selected_date=False,
                   set_filter_station=None,
                   set_filter_title=None,
                   set_filter_start=None,
                   set_filter_finish=None,
                   retrieve_recording=False,
                   export_recording=False,
                   export_start_time=None,
                   export_finish_time=None,
                   retrieve_selection=False,
                   export_selection=False,
                   sync_with_station=False,
                   delete_cache=False,
                   **ignored):
        # HACK: this helps development slightly
        if ignored:
            print "IGNORED", ignored

        # initialise error list
        errors = []

        if delete_cache:
            # Clear all recordings. The cron job will do the scanning/refilling.
            self._storage.clearRecordings()

        # HACK to stay connected
        #if not hasSession(SESSION_STATION_ADDRESS_KEY):
        #    setSession(SESSION_STATION_ADDRESS_KEY, '192.168.0.201')
        #    setSession(SESSION_STATION_NAME_KEY, 'Frankie')

        # update recordings from connected bowerbird
        if hasSession(SESSION_STATION_ADDRESS_KEY):
            self.updateRecordingsFromBowerbird()

        # handle requests to sync remote bowerbird by adding any missing
        # recording files to the transfer queue
        if sync_with_station and hasSession(SESSION_STATION_ADDRESS_KEY):
            station_address = getSession(SESSION_STATION_ADDRESS_KEY)
            for recording in self._storage.getRecordings(
                    station=getSession(SESSION_STATION_NAME_KEY)):
                if not recording.fileExists():
                    self._transfer_manager.add(recording, station_address)

        if reset_filter:
            filter_station = None
            clearSession(SESSION_FILTER_STATION_KEY)
            filter_title = None
            clearSession(SESSION_FILTER_TITLE_KEY)
            filter_start = None
            clearSession(SESSION_FILTER_START_KEY)
            filter_finish = None
            clearSession(SESSION_FILTER_FINISH_KEY)

        if clear_selected_date:
            clearSession(SESSION_DATE_KEY)

        if clear_recording_id:
            clearSession(SESSION_RECORD_ID_KEY)

            # update filters
        if update_filter:
            # filtering on station
            if filter_station == NO_FILTER_STATION:
                filter_station = None
                clearSession(SESSION_FILTER_STATION_KEY)
            else:
                setSession(SESSION_FILTER_STATION_KEY, filter_station)

            # filtering on title
            if filter_title == NO_FILTER_TITLE:
                filter_title = None
                clearSession(SESSION_FILTER_TITLE_KEY)
            else:
                setSession(SESSION_FILTER_TITLE_KEY, filter_title)

            # filtering on start date & time
            if filter_start is not None:
                if filter_start:
                    try:
                        filter_start = parseDateUI(filter_start)
                        setSession(SESSION_FILTER_START_KEY, filter_start)
                    except ValueError, inst:
                        errors.append('Errror parsing filter start time: %s' %
                                      inst)
                        filter_start = getSession(SESSION_FILTER_START_KEY)
                else:
                    clearSession(SESSION_FILTER_START_KEY)
                    filter_start = None
            if filter_finish is not None:
                if filter_finish:
                    try:
                        filter_finish = parseDateUI(filter_finish)
                        setSession(SESSION_FILTER_FINISH_KEY, filter_finish)
                    except ValueError, inst:
                        errors.append('Errror parsing filter finish time: %s' %
                                      inst)
                        filter_finish = getSession(SESSION_FILTER_FINISH_KEY)
                else:
                    clearSession(SESSION_FILTER_FINISH_KEY)
                    filter_finish = None
예제 #4
0
class Root(object):
    def __init__(self, path, database_file, root_dir, extension,
            bowerbird_port, localnet_scan_time_ms, concurrent_transfers,
            transfer_bandwidth, transfer_chunk_size):
        self.path = path
        self.bowerbird_port = bowerbird_port

        # initialise storage
        self._storage = ProxyStorage(database_file, root_dir, extension)

        # create the zeroconf scanner to detect local bowerbirds
        self._scanner = ZeroconfScanner(ZEROCONF_TYPE, localnet_scan_time_ms)

        self._transfer_manager = TransferManager(bowerbird_port,
                concurrent_transfers, transfer_bandwidth, transfer_chunk_size)


    @cherrypy.expose
    @template.output('connect.html')
    def connect(self, address=None, remove=None, rescan=False, **ignored):
        # if already connected, then just bounce to the status page
        if hasSession(SESSION_STATION_ADDRESS_KEY):
            raise cherrypy.HTTPRedirect('/status')

        # ignore address if "rescan" was requested
        if not rescan and address:
            # if "Remove" button has been clicked, delete entry from history
            if remove:
                self._storage.removeConnection(address)
            else:
                # get the name from the address
                try:
                    name = self.getRemoteName(address)
                except urllib2.URLError:
                    return self.showConnectionFailure(
                            error="could not be established", address=address)

                self._storage.addConnection(name, address)
                setSession(SESSION_STATION_ADDRESS_KEY, address)
                setSession(SESSION_STATION_NAME_KEY, name)
                # make sure new connection's recordings are not filtered out
                if (hasSession(SESSION_FILTER_STATION_KEY)
                        and getSession(SESSION_FILTER_STATION_KEY) != name):
                    clearSession(SESSION_FILTER_STATION_KEY)
                raise cherrypy.HTTPRedirect('/status')

        return template.render(is_proxy=True, station=None,
                previous_connections=self._storage.getPreviousConnections(),
                local_connections=self.findLocalBowerbirds(rescan))


    @cherrypy.expose
    def disconnect(self, **ignored):
        # set disconnected
        clearSession(SESSION_STATION_ADDRESS_KEY)
        clearSession(SESSION_STATION_NAME_KEY)
        raise cherrypy.HTTPRedirect('/')


    @cherrypy.expose
    def index(self, **ignored):
        # just redirect to status page if connected, otherwise connect page
        if hasSession(SESSION_STATION_ADDRESS_KEY):
            raise cherrypy.HTTPRedirect('/status')
        else:
            raise cherrypy.HTTPRedirect('/connect')


    @cherrypy.expose
    def status(self, **kwargs):
        return self.updateHtmlFromBowerbird(self.tunnelConnectionToBowerbird(
                'status', kwargs))


    @cherrypy.expose
    def config(self, **kwargs):
        # TODO catch station name changes and update connection history
        return self.updateHtmlFromBowerbird(self.tunnelConnectionToBowerbird(
                'config', kwargs))


    @cherrypy.expose
    def schedule(self, **kwargs):
        return self.updateHtmlFromBowerbird(self.tunnelConnectionToBowerbird(
                'schedule', kwargs))


    @cherrypy.expose
    @template.output('recordings.html')
    def recordings(self, view='month', year=None, month=None, day=None,
            recording_id=None, set_recording_id=False, clear_recording_id=False,
            go_to_start=False, go_to_finish=False, go_to_today=False,
            filter_station=None, filter_title=None, filter_start=None,
            filter_finish=None, update_filter=None, reset_filter=None,
            clear_selected_date=False,
            set_filter_station=None, set_filter_title=None,
            set_filter_start=None, set_filter_finish=None,
            retrieve_recording=False, export_recording=False,
            export_start_time=None, export_finish_time=None,
            retrieve_selection=False, export_selection=False,
            sync_with_station=False, delete_cache=False,
            **ignored):
        # HACK: this helps development slightly
        if ignored:
            print "IGNORED",ignored

        # initialise error list
        errors = []

        if delete_cache:
            # Clear all recordings. The cron job will do the scanning/refilling.
            self._storage.clearRecordings()

        # HACK to stay connected
        #if not hasSession(SESSION_STATION_ADDRESS_KEY):
        #    setSession(SESSION_STATION_ADDRESS_KEY, '192.168.0.201')
        #    setSession(SESSION_STATION_NAME_KEY, 'Frankie')

        # update recordings from connected bowerbird
        if hasSession(SESSION_STATION_ADDRESS_KEY):
            self.updateRecordingsFromBowerbird()

        # handle requests to sync remote bowerbird by adding any missing
        # recording files to the transfer queue
        if sync_with_station and hasSession(SESSION_STATION_ADDRESS_KEY):
            station_address = getSession(SESSION_STATION_ADDRESS_KEY)
            for recording in self._storage.getRecordings(
                    station=getSession(SESSION_STATION_NAME_KEY)):
                if not recording.fileExists():
                    self._transfer_manager.add(recording, station_address)

        if reset_filter:
            filter_station = None
            clearSession(SESSION_FILTER_STATION_KEY)
            filter_title = None
            clearSession(SESSION_FILTER_TITLE_KEY)
            filter_start = None
            clearSession(SESSION_FILTER_START_KEY)
            filter_finish = None
            clearSession(SESSION_FILTER_FINISH_KEY)

        if clear_selected_date:
            clearSession(SESSION_DATE_KEY)

        if clear_recording_id:
            clearSession(SESSION_RECORD_ID_KEY)

            # update filters
        if update_filter:
            # filtering on station
            if filter_station == NO_FILTER_STATION:
                filter_station = None
                clearSession(SESSION_FILTER_STATION_KEY)
            else:
                setSession(SESSION_FILTER_STATION_KEY, filter_station)

            # filtering on title
            if filter_title == NO_FILTER_TITLE:
                filter_title = None
                clearSession(SESSION_FILTER_TITLE_KEY)
            else:
                setSession(SESSION_FILTER_TITLE_KEY, filter_title)

            # filtering on start date & time
            if filter_start is not None:
                if filter_start:
                    try:
                        filter_start = parseDateUI(filter_start)
                        setSession(SESSION_FILTER_START_KEY, filter_start)
                    except ValueError, inst:
                        errors.append('Errror parsing filter start time: %s'
                                % inst)
                        filter_start = getSession(SESSION_FILTER_START_KEY)
                else:
                    clearSession(SESSION_FILTER_START_KEY)
                    filter_start = None
            if filter_finish is not None:
                if filter_finish:
                    try:
                        filter_finish = parseDateUI(filter_finish)
                        setSession(SESSION_FILTER_FINISH_KEY, filter_finish)
                    except ValueError, inst:
                        errors.append('Errror parsing filter finish time: %s'
                                % inst)
                        filter_finish = getSession(SESSION_FILTER_FINISH_KEY)
                else:
                    clearSession(SESSION_FILTER_FINISH_KEY)
                    filter_finish = None