Exemplo n.º 1
0
 def on_file_changed(self, monitor: Gio.FileMonitor, file: Gio.File,
                     _other_file: Gio.File,
                     event_type: Gio.FileMonitorEvent, port: int) -> None:
     if event_type == Gio.FileMonitorEvent.DELETED:
         logging.info('%s got deleted' % file.get_path())
         monitor.disconnect_by_func(self.on_file_changed, port)
     elif event_type == Gio.FileMonitorEvent.ATTRIBUTE_CHANGED:
         self.try_replace_root_watcher(monitor, file.get_path(), port)
Exemplo n.º 2
0
    def set_keyfile(self, keyfile: Gio.File) -> None:
        self.keyfile_path = keyfile.get_path()
        keyfile.load_bytes_async(None, self.load_keyfile_callback)

        self.keyfile_stack.props.visible_child_name = "spinner"
        self.keyfile_spinner.start()
        self.keyfile_button.props.sensitive = False

        logging.debug("Keyfile selected: %s", keyfile.get_path())
Exemplo n.º 3
0
 def on_file_changed(self, monitor: Gio.FileMonitor, file: Gio.File,
                     _other_file: Gio.File,
                     event_type: Gio.FileMonitorEvent, port: int) -> None:
     if event_type == Gio.FileMonitorEvent.DELETED:
         logging.info('%s got deleted' % file.get_path())
         if port in self._handlerids:
             handler_id = self._handlerids.pop(port)
             monitor.disconnect(handler_id)
         else:
             logging.warning(f"No handler id for {port}")
     elif event_type == Gio.FileMonitorEvent.ATTRIBUTE_CHANGED:
         self.try_replace_root_watcher(monitor, file.get_path(), port)
Exemplo n.º 4
0
    def __init__(self, window: Window, database_file: Gio.File) -> None:
        super().__init__()

        filepath = database_file.get_path()

        self.window = window

        # Reset headerbar to initial state if it already exists.
        self.headerbar.title.props.title = database_file.get_basename()

        self.install_action("clear-keyfile", None, self.on_clear_keyfile)

        database = self.window.unlocked_db
        if database:
            is_current = database.database_manager.path == filepath
            if is_current:
                self.database_manager = database.database_manager

        if not self.database_manager:
            self.database_manager = DatabaseManager(filepath)

        if gsecrets.config_manager.get_remember_composite_key():
            self._set_last_used_keyfile()

        if gsecrets.const.IS_DEVEL:
            self.status_page.props.icon_name = gsecrets.const.APP_ID
Exemplo n.º 5
0
 def _file_changed(self, _monitor, main_file: Gio.File,
                   other_file: Optional[Gio.File],
                   event_type: Gio.FileMonitorEvent) -> None:
     file_path = main_file.get_path()
     other_path = (Path(normalize_path(other_file.get_path(), True))
                   if other_file else None)
     print_d(f"Got event {event_type} on {file_path}->{other_path}")
     self.changed.append((event_type, file_path))
Exemplo n.º 6
0
    def _monitor_handler(
            self, monitor: Gio.FileMonitor, child: Gio.File,
            other_file: Gio.File, event_type: Gio.FileMonitorEvent) -> None:
        # The final path component contains the snapshot number.
        try:
            number = int(pathlib.Path(child.get_path()).name)
        except ValueError:
            return

        bootenv = self._bootenvs / str(number)

        if Gio.FileMonitorEvent.DELETED == event_type and bootenv.exists():
            self._clean_up(number)
Exemplo n.º 7
0
Arquivo: vcview.py Projeto: Mu-L/meld
    def on_file_selected(self, button: Gtk.Button, pane: int,
                         file: Gio.File) -> None:

        path = file.get_path()
        self.set_location(path)
Exemplo n.º 8
0
    def __file_changed(self, _monitor, main_file: Gio.File,
                       other_file: Optional[Gio.File],
                       event: Gio.FileMonitorEvent) -> None:
        if event == Event.CHANGES_DONE_HINT:
            # This seems to work fine on most Linux, but not on Windows / macOS
            # Or at least, not in CI anyway.
            # So shortcut the whole thing
            return
        try:
            file_path = main_file.get_path()
            if file_path is None:
                return
            file_path = normalize_path(file_path, True)
            song = self.get(file_path)
            file_path = Path(file_path)
            other_path = (Path(normalize_path(other_file.get_path(), True))
                          if other_file else None)
            if event in (Event.CREATED, Event.MOVED_IN):
                if file_path.is_dir():
                    self.monitor_dir(file_path)
                    copool.add(self.scan, [str(file_path)])
                elif not song:
                    print_d(f"Auto-adding created file: {file_path}", self._name)
                    self.add_filename(file_path)
            elif event == Event.RENAMED:
                if not other_path:
                    print_w(f"No destination found for rename of {file_path}",
                            self._name)
                if song:
                    print_d(f"Moving {file_path} to {other_path}...", self._name)
                    if self.move_song(song, str(other_path)):  # type:ignore
                        print_w(f"Song {file_path} has gone")
                elif self.is_monitored_dir(file_path):
                    if self.librarian:
                        print_d(f"Moving tracks from {file_path} -> {other_path}...",
                                self._name)
                        copool.add(self.librarian.move_root,
                                   str(file_path), str(other_path),
                                   write_files=False,
                                   priority=GLib.PRIORITY_DEFAULT)
                    self.unmonitor_dir(file_path)
                    if other_path:
                        self.monitor_dir(other_path)
                else:
                    print_w(f"Seems {file_path} is not a track (deleted?)", self._name)
                    # On some (Windows?) systems CHANGED is called which can remove
                    # before we get here, so let's try adding the new path back
                    self.add_filename(other_path)
            elif event == Event.CHANGED:
                if song:
                    # QL created (or knew about) this one; still check if it changed
                    if not song.valid():
                        self.reload(song)
                else:
                    print_d(f"Auto-adding new file: {file_path}", self._name)
                    self.add_filename(file_path)
            elif event in (Event.MOVED_OUT, Event.DELETED):
                if song:
                    print_d(f"...so deleting {file_path}", self._name)
                    self.reload(song)
                else:
                    # either not a song, or a song that was renamed by QL
                    if self.is_monitored_dir(file_path):
                        self.unmonitor_dir(file_path)

                    # And try to remove all songs under that dir. Slowly.
                    gone = set()
                    for key, song in self.iteritems():
                        if file_path in Path(key).parents:
                            gone.add(song)
                    if gone:
                        print_d(f"Removing {len(gone)} contained songs in {file_path}",
                                self._name)
                        actually_gone = self.remove(gone)
                        if gone != actually_gone:
                            print_w(f"Couldn't remove all: {gone - actually_gone}",
                                    self._name)
            else:
                print_d(f"Unhandled event {event} on {file_path} ({other_path})",
                        self._name)
                return
        except Exception:
            print_w("Failed to run file monitor callback", self._name)
            print_exc()
        print_d(f"Finished handling {event}", self._name)