def remove_file(self, path):
        id = self.__config.get(path, self.REMOTE_ID_OPTION)
        print u'\tDeleting server object {0}'.format(id)
        try:
            obj = MediaObject(id)
            obj.delete()
        except:
            pass

        print u'\tDeleting local cache {0}'.format(path)
        self.__config.remove_section(path)
    def remove_file(self, path):
        id = self.__config.get(path, self.REMOTE_ID_OPTION)
        print u'\tDeleting server object {0}'.format(id)
        try:
            obj = MediaObject(id)
            obj.delete()
        except:
            pass

        print u'\tDeleting local cache {0}'.format(path)
        self.__config.remove_section(path)
    def __directory_changed(self, monitor, file1, file2, evt_type):
        print
        if evt_type == gio.FILE_MONITOR_EVENT_CREATED:
            (parent, name) = os.path.split(file1.get_path())
            for store in self.__store_list:
                parent_id = store.object_id_from_path(parent)
                container = _UscContainer(parent_id)
                store.add_file(container, name, parent)

            if os.path.isdir(file1.get_path()):
                self.__monitor_directory(file1.get_path())
        elif evt_type == gio.FILE_MONITOR_EVENT_MOVED:
            (parent1, name1) = os.path.split(file1.get_path())
            (parent2, name2) = os.path.split(file2.get_path())
            renamed = (parent1 == parent2)

            if file1.get_path() in self.__monitor_list:
                self.__remove_monitor(file1.get_path())

            for store in self.__store_list:
                object_id = store.object_id_from_path(file1.get_path())
                obj = MediaObject(object_id)
                dlna_managed = obj.get_prop('DLNAManaged')

                if renamed and dlna_managed['ChangeMeta']:
                    print u'\tRenaming {0} to {1}'.format(name1, name2)

                    props = {'DisplayName' : name2}
                    obj.update(props, [])

                    store.rename_file(file1.get_path(), file2.get_path())
                else:
                    store.remove_file(file1.get_path())

                    parent_id = store.object_id_from_path(parent2)
                    container = _UscContainer(parent_id)

                    store.add_file(container, name2, parent2)

            if os.path.isdir(file2.get_path()):
                self.__monitor_directory(file2.get_path())
        elif evt_type == gio.FILE_MONITOR_EVENT_DELETED:
            if file1.get_path() in self.__monitor_list:
                self.__remove_monitor(file1.get_path())
            
            for store in self.__store_list:
                store.remove_file(file1.get_path())
        else:
            return

        print u'Type ctrl-c to stop.'
    def __directory_changed(self, monitor, file1, file2, evt_type):
        print
        if evt_type == gio.FILE_MONITOR_EVENT_CREATED:
            (parent, name) = os.path.split(file1.get_path())
            for store in self.__store_list:
                parent_id = store.object_id_from_path(parent)
                container = _UscContainer(parent_id)
                store.add_file(container, name, parent)

            if os.path.isdir(file1.get_path()):
                self.__monitor_directory(file1.get_path())
        elif evt_type == gio.FILE_MONITOR_EVENT_MOVED:
            (parent1, name1) = os.path.split(file1.get_path())
            (parent2, name2) = os.path.split(file2.get_path())
            renamed = (parent1 == parent2)

            if file1.get_path() in self.__monitor_list:
                self.__remove_monitor(file1.get_path())

            for store in self.__store_list:
                object_id = store.object_id_from_path(file1.get_path())
                obj = MediaObject(object_id)
                dlna_managed = obj.get_prop('DLNAManaged')

                if renamed and dlna_managed['ChangeMeta']:
                    print u'\tRenaming {0} to {1}'.format(name1, name2)

                    props = {'DisplayName' : name2}
                    obj.update(props, [])

                    store.rename_file(file1.get_path(), file2.get_path())
                else:
                    store.remove_file(file1.get_path())

                    parent_id = store.object_id_from_path(parent2)
                    container = _UscContainer(parent_id)

                    store.add_file(container, name2, parent2)

            if os.path.isdir(file2.get_path()):
                self.__monitor_directory(file2.get_path())
        elif evt_type == gio.FILE_MONITOR_EVENT_DELETED:
            if file1.get_path() in self.__monitor_list:
                self.__remove_monitor(file1.get_path())
            
            for store in self.__store_list:
                store.remove_file(file1.get_path())
        else:
            return

        print u'Type ctrl-c to stop.'
 def __remove_server(self, server_uuid):
     try:
         root = self.__config.get(server_uuid,
                                  UscController.ROOT_CONTAINER_ID_OPTION)
         MediaObject(root).delete()
     except:
         pass
     self.__config.remove_section(server_uuid)
     
     store = _UscStore(self.__store_path, server_uuid)
     store.remove()