Skip to content

Commit d05d8f9

Browse files
crookcas--
authored andcommitted
Import orginal AutoShutdown code
0 parents  commit d05d8f9

File tree

10 files changed

+608
-0
lines changed

10 files changed

+608
-0
lines changed

README

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Dev Guide
2+
1. Use 'create_plugin.py' script to create plugin framework
3+
python create_plugin.py --name AutoShutdown --basepath . --author-name "Ray Chen" --author-email "[email protected]"
4+
5+
2. Go to plugin dir and build development environment
6+
cd AutoShutdown; ./create_dev_link.sh
7+
8+
3. Deploy plugin egg
9+
python setup.py bdist_egg
10+
11+
4. Install plugin to deluge
12+
cp AutoShutdown-0.1-py2.6.egg ~/.config/deluge/plugins

autoshutdown/__init__.py

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#
2+
# __init__.py
3+
#
4+
# Copyright (C) 2009 Ray Chen <[email protected]>
5+
#
6+
# Basic plugin template created by:
7+
# Copyright (C) 2008 Martijn Voncken <[email protected]>
8+
# Copyright (C) 2007-2009 Andrew Resch <[email protected]>
9+
# Copyright (C) 2009 Damien Churchill <[email protected]>
10+
#
11+
# Deluge is free software.
12+
#
13+
# You may redistribute it and/or modify it under the terms of the
14+
# GNU General Public License, as published by the Free Software
15+
# Foundation; either version 3 of the License, or (at your option)
16+
# any later version.
17+
#
18+
# deluge is distributed in the hope that it will be useful,
19+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21+
# See the GNU General Public License for more details.
22+
#
23+
# You should have received a copy of the GNU General Public License
24+
# along with deluge. If not, write to:
25+
# The Free Software Foundation, Inc.,
26+
# 51 Franklin Street, Fifth Floor
27+
# Boston, MA 02110-1301, USA.
28+
#
29+
# In addition, as a special exception, the copyright holders give
30+
# permission to link the code of portions of this program with the OpenSSL
31+
# library.
32+
# You must obey the GNU General Public License in all respects for all of
33+
# the code used other than OpenSSL. If you modify file(s) with this
34+
# exception, you may extend this exception to your version of the file(s),
35+
# but you are not obligated to do so. If you do not wish to do so, delete
36+
# this exception statement from your version. If you delete this exception
37+
# statement from all source files in the program, then also delete it here.
38+
#
39+
40+
from deluge.plugins.init import PluginInitBase
41+
42+
class CorePlugin(PluginInitBase):
43+
def __init__(self, plugin_name):
44+
from core import Core as _plugin_cls
45+
self._plugin_cls = _plugin_cls
46+
super(CorePlugin, self).__init__(plugin_name)
47+
48+
class GtkUIPlugin(PluginInitBase):
49+
def __init__(self, plugin_name):
50+
from gtkui import GtkUI as _plugin_cls
51+
self._plugin_cls = _plugin_cls
52+
super(GtkUIPlugin, self).__init__(plugin_name)
53+
54+
class WebUIPlugin(PluginInitBase):
55+
def __init__(self, plugin_name):
56+
from webui import WebUI as _plugin_cls
57+
self._plugin_cls = _plugin_cls
58+
super(WebUIPlugin, self).__init__(plugin_name)

autoshutdown/common.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#
2+
# common.py
3+
#
4+
# Copyright (C) 2009 Ray Chen <[email protected]>
5+
#
6+
# Basic plugin template created by:
7+
# Copyright (C) 2008 Martijn Voncken <[email protected]>
8+
# Copyright (C) 2007-2009 Andrew Resch <[email protected]>
9+
# Copyright (C) 2009 Damien Churchill <[email protected]>
10+
#
11+
# Deluge is free software.
12+
#
13+
# You may redistribute it and/or modify it under the terms of the
14+
# GNU General Public License, as published by the Free Software
15+
# Foundation; either version 3 of the License, or (at your option)
16+
# any later version.
17+
#
18+
# deluge is distributed in the hope that it will be useful,
19+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21+
# See the GNU General Public License for more details.
22+
#
23+
# You should have received a copy of the GNU General Public License
24+
# along with deluge. If not, write to:
25+
# The Free Software Foundation, Inc.,
26+
# 51 Franklin Street, Fifth Floor
27+
# Boston, MA 02110-1301, USA.
28+
#
29+
# In addition, as a special exception, the copyright holders give
30+
# permission to link the code of portions of this program with the OpenSSL
31+
# library.
32+
# You must obey the GNU General Public License in all respects for all of
33+
# the code used other than OpenSSL. If you modify file(s) with this
34+
# exception, you may extend this exception to your version of the file(s),
35+
# but you are not obligated to do so. If you do not wish to do so, delete
36+
# this exception statement from your version. If you delete this exception
37+
# statement from all source files in the program, then also delete it here.
38+
#
39+
40+
def get_resource(filename):
41+
import pkg_resources, os
42+
return pkg_resources.resource_filename("autoshutdown", os.path.join("data", filename))

autoshutdown/core.py

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#
2+
# core.py
3+
#
4+
# Copyright (C) 2009 Ray Chen <[email protected]>
5+
#
6+
# Basic plugin template created by:
7+
# Copyright (C) 2008 Martijn Voncken <[email protected]>
8+
# Copyright (C) 2007-2009 Andrew Resch <[email protected]>
9+
# Copyright (C) 2009 Damien Churchill <[email protected]>
10+
#
11+
# Deluge is free software.
12+
#
13+
# You may redistribute it and/or modify it under the terms of the
14+
# GNU General Public License, as published by the Free Software
15+
# Foundation; either version 3 of the License, or (at your option)
16+
# any later version.
17+
#
18+
# deluge is distributed in the hope that it will be useful,
19+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21+
# See the GNU General Public License for more details.
22+
#
23+
# You should have received a copy of the GNU General Public License
24+
# along with deluge. If not, write to:
25+
# The Free Software Foundation, Inc.,
26+
# 51 Franklin Street, Fifth Floor
27+
# Boston, MA 02110-1301, USA.
28+
#
29+
# In addition, as a special exception, the copyright holders give
30+
# permission to link the code of portions of this program with the OpenSSL
31+
# library.
32+
# You must obey the GNU General Public License in all respects for all of
33+
# the code used other than OpenSSL. If you modify file(s) with this
34+
# exception, you may extend this exception to your version of the file(s),
35+
# but you are not obligated to do so. If you do not wish to do so, delete
36+
# this exception statement from your version. If you delete this exception
37+
# statement from all source files in the program, then also delete it here.
38+
#
39+
40+
from deluge.log import LOG as log
41+
from deluge.plugins.pluginbase import CorePluginBase
42+
import deluge.component as component
43+
import deluge.configmanager
44+
from deluge.core.rpcserver import export
45+
46+
DEFAULT_PREFS = {
47+
"enable_shutdown" : True,
48+
"enable_hibernate" : False,
49+
}
50+
51+
class Core(CorePluginBase):
52+
def enable(self):
53+
log.debug("Enable AutoShutDown")
54+
self.config = deluge.configmanager.ConfigManager("autoshutdown.conf", DEFAULT_PREFS)
55+
component.get("AlertManager").register_handler("torrent_finished_alert",
56+
self.on_alert_torrent_finished)
57+
58+
def disable(self):
59+
log.debug("Disable AutoShutDown")
60+
component.get("AlertManager").deregister_handler(self.on_alert_torrent_finished)
61+
self.config.save()
62+
63+
def on_alert_torrent_finished(self, alert):
64+
log.debug("Alter for every torrent finished")
65+
66+
# cal how many of torrent right now
67+
all_torrents = component.get("TorrentManager").get_torrent_list()
68+
self.total_torrents = len(all_torrents)
69+
log.info("Now total torrents:%s", self.total_torrents)
70+
71+
# Get the torrent_id
72+
torrent_id = str(alert.handle.info_hash())
73+
# reduce one
74+
self.total_torrents = self.total_torrents - 1
75+
log.debug("%s is finished..%s", torrent_id, self.total_torrents)
76+
77+
# when the number of all torrents is 0, then poweroff.
78+
if self.total_torrents == 0 :
79+
self.begin_to_poweroff()
80+
81+
def begin_to_poweroff(self):
82+
log.debug("begin to poweroff...")
83+
84+
import dbus
85+
bus = dbus.Bus(dbus.Bus.TYPE_SESSION)
86+
devobj = bus.get_object('org.freedesktop.PowerManagement',
87+
'/org/freedesktop/PowerManagement')
88+
self.dev = dbus.Interface(devobj, "org.freedesktop.PowerManagement")
89+
90+
if self.config["enable_shutdown"]:
91+
log.debug("begin to Shutdown...")
92+
self.dev.Shutdown()
93+
94+
if self.config["enable_hibernate"]:
95+
log.debug("begin to Hibernate...")
96+
self.dev.Hibernate()
97+
98+
def update(self):
99+
pass
100+
101+
@export
102+
def set_config(self, config):
103+
"sets the config dictionary"
104+
for key in config.keys():
105+
self.config[key] = config[key]
106+
self.config.save()
107+
108+
@export
109+
def get_config(self):
110+
"returns the config dictionary"
111+
return self.config.config

autoshutdown/data/autoshutdown.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
Script: autoshutdown.js
3+
The client-side javascript code for the AutoShutdown plugin.
4+
5+
Copyright:
6+
(C) Ray Chen 2009 <[email protected]>
7+
This program is free software; you can redistribute it and/or modify
8+
it under the terms of the GNU General Public License as published by
9+
the Free Software Foundation; either version 3, or (at your option)
10+
any later version.
11+
12+
This program is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
GNU General Public License for more details.
16+
17+
You should have received a copy of the GNU General Public License
18+
along with this program. If not, write to:
19+
The Free Software Foundation, Inc.,
20+
51 Franklin Street, Fifth Floor
21+
Boston, MA 02110-1301, USA.
22+
23+
In addition, as a special exception, the copyright holders give
24+
permission to link the code of portions of this program with the OpenSSL
25+
library.
26+
You must obey the GNU General Public License in all respects for all of
27+
the code used other than OpenSSL. If you modify file(s) with this
28+
exception, you may extend this exception to your version of the file(s),
29+
but you are not obligated to do so. If you do not wish to do so, delete
30+
this exception statement from your version. If you delete this exception
31+
statement from all source files in the program, then also delete it here.
32+
*/
33+
34+
AutoShutdownPlugin = Ext.extend(Deluge.Plugin, {
35+
constructor: function(config) {
36+
config = Ext.apply({
37+
name: "AutoShutdown"
38+
}, config);
39+
AutoShutdownPlugin.superclass.constructor.call(this, config);
40+
},
41+
42+
onDisable: function() {
43+
44+
},
45+
46+
onEnable: function() {
47+
48+
}
49+
});
50+
new AutoShutdownPlugin();

autoshutdown/data/config.glade

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
2+
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
3+
4+
<glade-interface>
5+
6+
<widget class="GtkWindow" id="window1">
7+
<property name="title" translatable="yes"></property>
8+
<property name="type">GTK_WINDOW_TOPLEVEL</property>
9+
<property name="window_position">GTK_WIN_POS_NONE</property>
10+
<property name="modal">False</property>
11+
<property name="resizable">True</property>
12+
<property name="destroy_with_parent">False</property>
13+
<property name="decorated">True</property>
14+
<property name="skip_taskbar_hint">False</property>
15+
<property name="skip_pager_hint">False</property>
16+
<property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
17+
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
18+
<property name="focus_on_map">True</property>
19+
<property name="urgency_hint">False</property>
20+
21+
<child>
22+
<widget class="GtkHBox" id="prefs_box">
23+
<property name="visible">True</property>
24+
<property name="homogeneous">False</property>
25+
<property name="spacing">0</property>
26+
27+
<child>
28+
<widget class="GtkVBox" id="vbox1">
29+
<property name="border_width">1</property>
30+
<property name="visible">True</property>
31+
<property name="homogeneous">True</property>
32+
<property name="spacing">0</property>
33+
34+
<child>
35+
<widget class="GtkLabel" id="label1">
36+
<property name="visible">True</property>
37+
<property name="label" translatable="yes">Please choose action when all torrents finish:</property>
38+
<property name="use_underline">False</property>
39+
<property name="use_markup">False</property>
40+
<property name="justify">GTK_JUSTIFY_LEFT</property>
41+
<property name="wrap">False</property>
42+
<property name="selectable">False</property>
43+
<property name="xalign">0.5</property>
44+
<property name="yalign">0.5</property>
45+
<property name="xpad">0</property>
46+
<property name="ypad">0</property>
47+
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
48+
<property name="width_chars">-1</property>
49+
<property name="single_line_mode">False</property>
50+
<property name="angle">0</property>
51+
</widget>
52+
<packing>
53+
<property name="padding">0</property>
54+
<property name="expand">False</property>
55+
<property name="fill">False</property>
56+
</packing>
57+
</child>
58+
59+
<child>
60+
<widget class="GtkHBox" id="hbox1">
61+
<property name="visible">True</property>
62+
<property name="homogeneous">True</property>
63+
<property name="spacing">0</property>
64+
65+
<child>
66+
<widget class="GtkRadioButton" id="button_shutdown">
67+
<property name="visible">True</property>
68+
<property name="can_focus">True</property>
69+
<property name="label" translatable="yes">Shutdown</property>
70+
<property name="use_underline">True</property>
71+
<property name="relief">GTK_RELIEF_NORMAL</property>
72+
<property name="focus_on_click">True</property>
73+
<property name="active">False</property>
74+
<property name="inconsistent">False</property>
75+
<property name="draw_indicator">True</property>
76+
</widget>
77+
<packing>
78+
<property name="padding">0</property>
79+
<property name="expand">False</property>
80+
<property name="fill">False</property>
81+
</packing>
82+
</child>
83+
84+
<child>
85+
<widget class="GtkRadioButton" id="button_hibernate">
86+
<property name="visible">True</property>
87+
<property name="can_focus">True</property>
88+
<property name="label" translatable="yes">Hibernate</property>
89+
<property name="use_underline">True</property>
90+
<property name="relief">GTK_RELIEF_NORMAL</property>
91+
<property name="focus_on_click">True</property>
92+
<property name="active">False</property>
93+
<property name="inconsistent">False</property>
94+
<property name="draw_indicator">True</property>
95+
<property name="group">button_shutdown</property>
96+
</widget>
97+
<packing>
98+
<property name="padding">0</property>
99+
<property name="expand">False</property>
100+
<property name="fill">False</property>
101+
</packing>
102+
</child>
103+
</widget>
104+
<packing>
105+
<property name="padding">0</property>
106+
<property name="expand">True</property>
107+
<property name="fill">True</property>
108+
</packing>
109+
</child>
110+
</widget>
111+
<packing>
112+
<property name="padding">0</property>
113+
<property name="expand">True</property>
114+
<property name="fill">True</property>
115+
</packing>
116+
</child>
117+
</widget>
118+
</child>
119+
</widget>
120+
121+
</glade-interface>

0 commit comments

Comments
 (0)