def servers(self): """Displays media servers available on the network. Displays media servers information as well as the tracked status. """ print u'Running servers:' for item in self.__upnp.get_servers(): try: server = Container(item) try: folder_name = server.get_prop('FriendlyName') except Exception: folder_name = server.get_prop('DisplayName') device = Device(item) dev_uuid = device.get_prop('UDN') dev_path = device.get_prop('Path') print u'{0:<25} Tracked({2}) {3} {1}'.format(folder_name, dev_path, self.__config.has_option(dev_uuid, DscController.SUID_OPTION), dev_uuid) except dbus.exceptions.DBusException as err: print u'Cannot retrieve properties for ' + item print str(err).strip()[:-1]
def servers(self): """Displays media servers available on the network. Displays media servers information as well as the synchronized status. """ print u'Running servers:' for item in self.__upnp.get_servers(): try: server = Container(item) try: folder_name = server.get_prop('FriendlyName') except Exception: folder_name = server.get_prop('DisplayName') device = Device(item) dev_uuid = device.get_prop('UDN') dev_path = device.get_prop('Path') print u'{0:<25} Synchronized({2}) {3} {1}'.format( folder_name, dev_path, self.__config.has_section(dev_uuid), dev_uuid) except dbus.exceptions.DBusException as err: print u'Cannot retrieve properties for ' + item print str(err).strip()[:-1]
def remove_server(self, server_path): """Removes a media server from the controller's list. Also removes the server side synchronized file and folders. server_path: d-bus path for the media server """ server = Device(server_path) server_uuid = server.get_prop('UDN') if self.__config.has_section(server_uuid): self.__remove_server(server_uuid) self.__write_config()
def add_server(self, server_path): """Adds a media server to the controller's list. server_path: d-bus path for the media server """ server = Device(server_path) server_uuid = server.get_prop('UDN') if not self.__config.has_section(server_uuid): srt = self.__check_trackable(server) if srt != None: self.__config.add_section(server_uuid) self.__write_config() else: print u"Sorry, the server {0} has no such capability and " \ "will not be synchronized.".format(server_path)
def __need_sync(self, servers): for item in servers: device = Device(item) uuid = device.get_prop('UDN') new_srt = device.get_prop('ServiceResetToken') new_id = device.get_prop('SystemUpdateID') if self.__config.has_section(uuid): cur_id = self.__config.getint(uuid, DscController.SUID_OPTION) cur_srt = self.__config.get(uuid, DscController.SRT_OPTION) if cur_id == -1 or cur_srt != new_srt: print print u'Server {0} needs *full* sync:'.format(uuid) yield item, uuid, 0, new_id, True elif cur_id < new_id: print print u'Server {0} needs sync:'.format(uuid) yield item, uuid, cur_id, new_id, False
def __need_sync(self, servers): for item in servers: device = Device(item) uuid = device.get_prop('UDN') if self.__config.has_section(uuid): new_id = device.get_prop('SystemUpdateID') new_srt = device.get_prop('ServiceResetToken') cur_id = self.__config.getint(uuid, DscController.SUID_OPTION) cur_srt = self.__config.get(uuid, DscController.SRT_OPTION) if cur_id == -1 or cur_srt != new_srt: print print u'Server {0} needs *full* sync:'.format(uuid) yield item, uuid, 0, new_id, new_srt, True elif cur_id < new_id: print print u'Server {0} needs sync:'.format(uuid) yield item, uuid, cur_id, new_id, new_srt, False
def track(self, server_path, track = True, sync_contents = True): """Adds or removes a media server to/from the controller's list. server_path: d-bus path for the media server track: when 'True', adds a server to the list when 'False' removes a server from the list sync_contents: when 'True', downloads media contents to the local storage upon synchronization. """ server = Device(server_path) server_uuid = server.get_prop('UDN') if track and not self.__config.has_section(server_uuid): srt = self.__check_trackable(server) if srt != None: self.__config.add_section(server_uuid) self.__config.set(server_uuid, DscController.SUID_OPTION, '-1') self.__config.set(server_uuid, DscController.SRT_OPTION, srt) if sync_contents: self.__config.set(server_uuid, DscController.SYNC_OPTION, 'yes') else: self.__config.set(server_uuid, DscController.SYNC_OPTION, 'no') self.__write_config() else: print u"Sorry, the server {0} has no such capability and " \ "will not be tracked.".format(server_path) elif not track and self.__config.has_section(server_uuid): self.__config.remove_section(server_uuid) self.__write_config() store = _DscStore(self.__store_path, server_uuid) store.remove()
def track(self, server_path, track=True, sync_contents=True): """Adds or removes a media server to/from the controller's list. server_path: d-bus path for the media server track: when 'True', adds a server to the list when 'False' removes a server from the list sync_contents: when 'True', downloads media contents to the local storage upon synchronization. """ server = Device(server_path) server_uuid = server.get_prop('UDN') if track and not self.__config.has_section(server_uuid): srt = self.__check_trackable(server) if srt != None: self.__config.add_section(server_uuid) self.__config.set(server_uuid, DscController.SUID_OPTION, '-1') self.__config.set(server_uuid, DscController.SRT_OPTION, srt) if sync_contents: self.__config.set(server_uuid, DscController.SYNC_OPTION, 'yes') else: self.__config.set(server_uuid, DscController.SYNC_OPTION, 'no') self.__write_config() else: print u"Sorry, the server {0} has no such capability and " \ "will not be tracked.".format(server_path) elif not track and self.__config.has_section(server_uuid): self.__config.remove_section(server_uuid) self.__write_config() store = _DscStore(self.__store_path, server_uuid) store.remove()
def __init__(self, path): Device.__init__(self, path)