KTorrent: シェル スクリプトでデータを移動する

KTorrent: シェル スクリプトでデータを移動する

私は、アプリケーションの「データの移動」コンテキスト メニュー アクションと同様に、KTorrent がデータの場所を見失うことなく、ファイルをシード ディレクトリに移動する、マジック フォルダー用のスクリプトを作成しようとしています。dbus API をいろいろと調べましたが、今のところ次のようになっています。

for x in `qdbus org.ktorrent.ktorrent /core org.ktorrent.core.torrents`; do
    name=`qdbus org.ktorrent.ktorrent /torrent/$x org.ktorrent.torrent.name`
    if [ "$name" = "$1" ]; then
        # Tell KTorrent to move the data to the seeding directory
    fi
done

問題は、何も見つからないことですAPIについてそれを実行したり、手動で移動した後に新しい場所を設定したりすることもできます。

私は、GUI を直接操作してコンテキスト メニュー アクションをアクティブ化することでこれを実行するというアイデアを試してみました (そこまでできれば満足です)。そして、次のことがわかりました。

qdbus org.ktorrent.ktorrent /ktorrent/MainWindow_1 org.kde.KMainWindow.activateAction view_move_data

これは私が望むことを実行しますが、常に現在選択されているトレントに対して実行され、実際に移動したいトレントを選択するための最初の手順さえわかりません。

何か案は?

答え1

私は自分の問題に対するより良い解決策を見つけました。完了したダウンロードを特定のディレクトリに移動して、使い終わったら元に戻すのではなく、完了した信号をキャッチしてシンボリックリンク表示したいディレクトリ内のファイルに移動します。作業が終わったら、シンボリック リンクを削除するだけで、実際のデータを移動する必要がなくなるため、はるかに効率的です。

パッケージ化されたスクリプトとソースをここで公開しました:

http://schmunsler.no-ip.org/code/shared/file_linker/

念のため、メインスクリプトの内容をここに投稿します。

#!/usr/bin/env kross
# -*- coding: utf-8 -*-
import KTorrent
import KTScriptingPlugin
import Kross

import os
import socket

class FileLinker:
    def __init__(self):
        self.link_dir = KTScriptingPlugin.readConfigEntry("downloads","completedDir",os.path.expanduser("~/"))+"/"
        if self.link_dir.startswith("file://"):
            self.link_dir = self.link_dir[7:]
        KTorrent.log("linkDir is "+self.link_dir)
        KTorrent.connect("torrentAdded(const QString &)",self.torrentAdded)
        tors = KTorrent.torrents()
        # bind to signals for each torrent
        for t in tors:
            self.torrentAdded(t)

    def torrentFinished(self,tor):
        KTorrent.log("Symlinking "+tor.pathOnDisk()+" to "+self.link_dir+tor.name())
        os.symlink(""+tor.pathOnDisk(),""+self.link_dir+tor.name())

    def connectSignals(self,tor):
        KTorrent.log("connectSignals " + tor.name())
        tor.connect("finished(QObject* )",self.torrentFinished)

    def torrentAdded(self,ih):
        tor = KTorrent.torrent(ih)
        self.connectSignals(tor)

# load settings
linker = FileLinker()

def unload():
    global linker
    del linker

関連情報