Imported Upstream version 1.3.13+git20161130.48cedf63
Andrew Starr-Bochicchio
7 years ago
34 | 34 | |
35 | 35 | |
36 | 36 | """Common functions for various parts of Deluge to use.""" |
37 | ||
38 | from __future__ import with_statement | |
37 | 39 | |
38 | 40 | import os |
39 | 41 | import time |
176 | 178 | if not windows_check(): |
177 | 179 | from xdg.BaseDirectory import xdg_config_home |
178 | 180 | try: |
179 | for line in open(os.path.join(xdg_config_home, 'user-dirs.dirs'), 'r'): | |
180 | if not line.startswith('#') and line.startswith('XDG_DOWNLOAD_DIR'): | |
181 | download_dir = os.path.expandvars(line.partition("=")[2].rstrip().strip('"')) | |
182 | break | |
181 | with open(os.path.join(xdg_config_home, 'user-dirs.dirs'), 'r') as _file: | |
182 | for line in _file: | |
183 | if not line.startswith('#') and line.startswith('XDG_DOWNLOAD_DIR'): | |
184 | download_dir = os.path.expandvars(line.partition("=")[2].rstrip().strip('"')) | |
185 | break | |
183 | 186 | except IOError: |
184 | 187 | pass |
185 | 188 |
65 | 65 | version as this will be done internally. |
66 | 66 | |
67 | 67 | """ |
68 | ||
69 | from __future__ import with_statement | |
68 | 70 | |
69 | 71 | import cPickle as pickle |
70 | 72 | import shutil |
355 | 357 | filename = self.__config_file |
356 | 358 | |
357 | 359 | try: |
358 | data = open(filename, "rb").read() | |
360 | with open(filename, "rb") as _file: | |
361 | data = _file.read() | |
359 | 362 | except IOError, e: |
360 | 363 | log.warning("Unable to open config file %s: %s", filename, e) |
361 | 364 | return |
403 | 406 | # Check to see if the current config differs from the one on disk |
404 | 407 | # We will only write a new config file if there is a difference |
405 | 408 | try: |
406 | data = open(filename, "rb").read() | |
409 | with open(filename, "rb") as _file: | |
410 | data = _file.read() | |
407 | 411 | objects = find_json_objects(data) |
408 | 412 | start, end = objects[0] |
409 | 413 | version = json.loads(data[start:end]) |
31 | 31 | # statement from all source files in the program, then also delete it here. |
32 | 32 | # |
33 | 33 | # |
34 | ||
35 | from __future__ import with_statement | |
34 | 36 | |
35 | 37 | import os |
36 | 38 | import random |
117 | 119 | f = [localclient] |
118 | 120 | else: |
119 | 121 | # Load the auth file into a dictionary: {username: password, ...} |
120 | f = open(auth_file, "r").readlines() | |
122 | with open(auth_file, "r") as _file: | |
123 | f = _file.readlines() | |
121 | 124 | |
122 | 125 | for line in f: |
123 | 126 | line = line.strip() |
142 | 145 | self.__auth[username.strip()] = (password.strip(), level) |
143 | 146 | |
144 | 147 | if "localclient" not in self.__auth: |
145 | open(auth_file, "a").write(self.__create_localclient_account()) | |
148 | with open(auth_file, "a") as _file: | |
149 | _file.write(self.__create_localclient_account()) |
32 | 32 | # |
33 | 33 | # |
34 | 34 | |
35 | from __future__ import with_statement | |
36 | ||
35 | 37 | from deluge._libtorrent import lt |
36 | 38 | |
37 | 39 | import os |
185 | 187 | def __load_session_state(self): |
186 | 188 | """Loads the libtorrent session state""" |
187 | 189 | try: |
188 | self.session.load_state(lt.bdecode( | |
189 | open(deluge.configmanager.get_config_dir("session.state"), "rb").read())) | |
190 | with open(deluge.configmanager.get_config_dir("session.state"), "rb") as _file: | |
191 | self.session.load_state(lt.bdecode(_file.read())) | |
190 | 192 | except Exception, e: |
191 | 193 | log.warning("Failed to load lt state: %s", e) |
192 | 194 | |
660 | 662 | if add_to_session: |
661 | 663 | options = {} |
662 | 664 | options["download_location"] = os.path.split(path)[0] |
663 | self.add_torrent_file(os.path.split(target)[1], open(target, "rb").read(), options) | |
665 | with open(target, "rb") as _file: | |
666 | self.add_torrent_file(os.path.split(target)[1], _file.read(), options) | |
664 | 667 | |
665 | 668 | @export |
666 | 669 | def upload_plugin(self, filename, filedump): |
31 | 31 | # statement from all source files in the program, then also delete it here. |
32 | 32 | # |
33 | 33 | |
34 | from __future__ import with_statement | |
35 | ||
34 | 36 | import os |
35 | 37 | import gettext |
36 | 38 | import locale |
51 | 53 | if os.path.isfile(deluge.configmanager.get_config_dir("deluged.pid")): |
52 | 54 | # Get the PID and the port of the supposedly running daemon |
53 | 55 | try: |
54 | (pid, port) = open(deluge.configmanager.get_config_dir("deluged.pid")).read().strip().split(";") | |
56 | with open(deluge.configmanager.get_config_dir("deluged.pid")) as _file: | |
57 | (pid, port) = _file.read().strip().split(";") | |
55 | 58 | pid = int(pid) |
56 | 59 | port = int(port) |
57 | 60 | except ValueError: |
168 | 171 | if not classic: |
169 | 172 | # Write out a pid file all the time, we use this to see if a deluged is running |
170 | 173 | # We also include the running port number to do an additional test |
171 | open(deluge.configmanager.get_config_dir("deluged.pid"), "wb").write( | |
172 | "%s;%s\n" % (os.getpid(), port)) | |
174 | with open(deluge.configmanager.get_config_dir("deluged.pid"), "wb") as _file: | |
175 | _file.write("%s;%s\n" % (os.getpid(), port)) | |
173 | 176 | |
174 | 177 | component.start() |
175 | 178 | try: |
90 | 90 | # Check all the torrent's tracker_status for 'Error:' and only return torrent_ids |
91 | 91 | # that have this substring in their tracker_status |
92 | 92 | for torrent_id in torrent_ids: |
93 | if _("Error") + ":" in tm[torrent_id].get_status(["tracker_status"])["tracker_status"]: | |
93 | if "Error:" in tm[torrent_id].get_status(["tracker_status"])["tracker_status"]: | |
94 | 94 | filtered_torrent_ids.append(torrent_id) |
95 | 95 | |
96 | 96 | return filtered_torrent_ids |
32 | 32 | # |
33 | 33 | # |
34 | 34 | |
35 | from __future__ import with_statement | |
35 | 36 | |
36 | 37 | import os.path |
37 | 38 | import threading |
297 | 298 | if value: |
298 | 299 | state = None |
299 | 300 | try: |
300 | state = lt.bdecode(open(state_file, "rb").read()) | |
301 | with open(state_file, "rb") as _file: | |
302 | state = lt.bdecode(_file.read()) | |
301 | 303 | except Exception, e: |
302 | 304 | log.warning("Unable to read DHT state file: %s", e) |
303 | 305 | |
497 | 499 | if geoip_db: |
498 | 500 | try: |
499 | 501 | self.session.load_country_db(str(geoip_db)) |
500 | except Exception, e: | |
502 | except RuntimeError, e: | |
501 | 503 | log.error("Unable to load geoip database!") |
502 | 504 | log.exception(e) |
505 | except AttributeError: | |
506 | log.warning("GeoIP Unavailable") | |
503 | 507 | |
504 | 508 | def _on_cache_size(self, key, value): |
505 | 509 | log.debug("%s: %s", key, value) |
33 | 33 | # |
34 | 34 | |
35 | 35 | """RPCServer Module""" |
36 | ||
37 | from __future__ import with_statement | |
36 | 38 | |
37 | 39 | import sys |
38 | 40 | import zlib |
516 | 518 | |
517 | 519 | # Write out files |
518 | 520 | ssl_dir = deluge.configmanager.get_config_dir("ssl") |
519 | open(os.path.join(ssl_dir, "daemon.pkey"), "w").write(crypto.dump_privatekey(crypto.FILETYPE_PEM, pkey)) | |
520 | open(os.path.join(ssl_dir, "daemon.cert"), "w").write(crypto.dump_certificate(crypto.FILETYPE_PEM, cert)) | |
521 | with open(os.path.join(ssl_dir, "daemon.pkey"), "w") as _file: | |
522 | _file.write(crypto.dump_privatekey(crypto.FILETYPE_PEM, pkey)) | |
523 | with open(os.path.join(ssl_dir, "daemon.cert"), "w") as _file: | |
524 | _file.write(crypto.dump_certificate(crypto.FILETYPE_PEM, cert)) | |
521 | 525 | # Make the files only readable by this user |
522 | 526 | for f in ("daemon.pkey", "daemon.cert"): |
523 | 527 | os.chmod(os.path.join(ssl_dir, f), stat.S_IREAD | stat.S_IWRITE) |
33 | 33 | |
34 | 34 | """Internal Torrent class""" |
35 | 35 | |
36 | from __future__ import with_statement | |
37 | ||
36 | 38 | import os |
37 | 39 | import time |
38 | 40 | from urllib import unquote |
589 | 591 | ret.append(float(file_progress[i]) / float(f["size"])) |
590 | 592 | except ZeroDivisionError: |
591 | 593 | ret.append(0.0) |
594 | except IndexError: | |
595 | return [] | |
592 | 596 | |
593 | 597 | return ret |
594 | 598 | |
956 | 960 | md = lt.bdecode(self.torrent_info.metadata()) |
957 | 961 | torrent_file = {} |
958 | 962 | torrent_file["info"] = md |
959 | open(path, "wb").write(lt.bencode(torrent_file)) | |
963 | with open(path, "wb") as _file: | |
964 | _file.write(lt.bencode(torrent_file)) | |
960 | 965 | except Exception, e: |
961 | 966 | log.warning("Unable to save torrent file: %s", e) |
962 | 967 |
739 | 739 | os.fsync(state_file.fileno()) |
740 | 740 | state_file.close() |
741 | 741 | os.rename(filepath_tmp, filepath) |
742 | except IOError: | |
742 | except IOError, ex: | |
743 | 743 | log.error("Unable to save %s: %s", filepath, ex) |
744 | 744 | if os.path.isfile(filepath_bak): |
745 | 745 | log.info("Restoring backup of state from: %s", filepath_bak) |
1013 | 1013 | |
1014 | 1014 | # Set the tracker status for the torrent |
1015 | 1015 | if alert.message() != "Got peers from DHT": |
1016 | torrent.set_tracker_status(_("Announce OK")) | |
1016 | torrent.set_tracker_status("Announce OK") | |
1017 | 1017 | |
1018 | 1018 | # Check to see if we got any peer information from the tracker |
1019 | 1019 | if alert.handle.status().num_complete == -1 or \ |
1029 | 1029 | return |
1030 | 1030 | |
1031 | 1031 | # Set the tracker status for the torrent |
1032 | torrent.set_tracker_status(_("Announce Sent")) | |
1032 | torrent.set_tracker_status("Announce Sent") | |
1033 | 1033 | |
1034 | 1034 | def on_alert_tracker_warning(self, alert): |
1035 | 1035 | log.debug("on_alert_tracker_warning") |
1037 | 1037 | torrent = self.torrents[str(alert.handle.info_hash())] |
1038 | 1038 | except: |
1039 | 1039 | return |
1040 | tracker_status = '%s: %s' % (_("Warning"), decode_string(alert.message())) | |
1040 | tracker_status = '%s: %s' % ("Warning", decode_string(alert.message())) | |
1041 | 1041 | # Set the tracker status for the torrent |
1042 | 1042 | torrent.set_tracker_status(tracker_status) |
1043 | 1043 | |
1054 | 1054 | except (RuntimeError, KeyError): |
1055 | 1055 | return |
1056 | 1056 | |
1057 | torrent.set_tracker_status("%s: %s" % (_("Error"), error_message)) | |
1057 | torrent.set_tracker_status("Error: %s" % error_message) | |
1058 | 1058 | |
1059 | 1059 | def on_alert_storage_moved(self, alert): |
1060 | 1060 | log.debug("on_alert_storage_moved") |
37 | 37 | # user runs the command 'deluge'. |
38 | 38 | |
39 | 39 | """Main starting point for Deluge. Contains the main() entry point.""" |
40 | ||
41 | from __future__ import with_statement | |
40 | 42 | |
41 | 43 | import os |
42 | 44 | import sys |
206 | 208 | # Writes out a pidfile if necessary |
207 | 209 | def write_pidfile(): |
208 | 210 | if options.pidfile: |
209 | open(options.pidfile, "wb").write("%s\n" % os.getpid()) | |
211 | with open(options.pidfile, "wb") as _file: | |
212 | _file.write("%s\n" % os.getpid()) | |
210 | 213 | |
211 | 214 | # If the donot daemonize is set, then we just skip the forking |
212 | 215 | if not options.donot: |
31 | 31 | # statement from all source files in the program, then also delete it here. |
32 | 32 | # |
33 | 33 | # |
34 | ||
35 | from __future__ import with_statement | |
34 | 36 | |
35 | 37 | import sys |
36 | 38 | import os |
217 | 219 | progress(len(pieces), num_pieces) |
218 | 220 | |
219 | 221 | r = fd.read(piece_size) |
222 | fd.close() | |
220 | 223 | |
221 | 224 | torrent["info"]["pieces"] = "".join(pieces) |
222 | 225 | |
223 | 226 | # Write out the torrent file |
224 | open(torrent_path, "wb").write(bencode(torrent)) | |
227 | with open(torrent_path, "wb") as _file: | |
228 | _file.write(bencode(torrent)) | |
225 | 229 | |
226 | 230 | def get_data_path(self): |
227 | 231 | """ |
141 | 141 | command = os.path.expanduser(command) |
142 | 142 | |
143 | 143 | cmd_args = [torrent_id, torrent_name, save_path] |
144 | if windows_check: | |
144 | if windows_check(): | |
145 | 145 | # Escape ampersand on windows (see #2784) |
146 | 146 | cmd_args = [arg.replace("&", "^^^&") for arg in cmd_args] |
147 | 147 |
37 | 37 | all the interfaces. |
38 | 38 | """ |
39 | 39 | |
40 | from __future__ import with_statement | |
41 | ||
40 | 42 | import os |
41 | 43 | import sys |
42 | 44 | import urlparse |
53 | 55 | from deluge.log import LOG as log |
54 | 56 | import deluge.configmanager |
55 | 57 | |
58 | ||
59 | # Dummy translation list so tracker status is translatable. | |
60 | def _(message): | |
61 | return message | |
62 | ||
63 | ||
64 | TRACKER_STATUS_TRANSLATION = [ | |
65 | _('Error'), | |
66 | _('Warning'), | |
67 | _('Announce OK'), | |
68 | _('Announce Sent') | |
69 | ] | |
70 | del _ | |
71 | ||
72 | ||
56 | 73 | class TorrentInfo(object): |
57 | 74 | """ |
58 | 75 | Collects information about a torrent file. |
65 | 82 | # Get the torrent data from the torrent file |
66 | 83 | try: |
67 | 84 | log.debug("Attempting to open %s.", filename) |
68 | self.__m_filedata = open(filename, "rb").read() | |
85 | with open(filename, "rb") as _file: | |
86 | self.__m_filedata = _file.read() | |
69 | 87 | self.__m_metadata = bencode.bdecode(self.__m_filedata) |
70 | 88 | except Exception, e: |
71 | 89 | log.warning("Unable to open %s: %s", filename, e) |
106 | 124 | f["path"] = path |
107 | 125 | f["index"] = index |
108 | 126 | if "sha1" in f and len(f["sha1"]) == 20: |
109 | f["sha1"] = f["sha1"].encode('hex') | |
127 | f["sha1"] = f["sha1"].encode('hex') | |
110 | 128 | if "ed2k" in f and len(f["ed2k"]) == 16: |
111 | f["ed2k"] = f["ed2k"].encode('hex') | |
129 | f["ed2k"] = f["ed2k"].encode('hex') | |
130 | if "filehash" in f and len(f["filehash"]) == 20: | |
131 | f["filehash"] = f["filehash"].encode('hex') | |
112 | 132 | paths[path] = f |
113 | 133 | dirname = os.path.dirname(path) |
114 | 134 | while dirname: |
408 | 428 | """ |
409 | 429 | auth_file = deluge.configmanager.get_config_dir("auth") |
410 | 430 | if os.path.exists(auth_file): |
411 | for line in open(auth_file): | |
412 | line = line.strip() | |
413 | if line.startswith("#") or not line: | |
414 | # This is a comment or blank line | |
415 | continue | |
416 | ||
417 | try: | |
418 | lsplit = line.split(":") | |
419 | except Exception, e: | |
420 | log.error("Your auth file is malformed: %s", e) | |
421 | continue | |
422 | ||
423 | if len(lsplit) == 2: | |
424 | username, password = lsplit | |
425 | elif len(lsplit) == 3: | |
426 | username, password, level = lsplit | |
427 | else: | |
428 | log.error("Your auth file is malformed: Incorrect number of fields!") | |
429 | continue | |
430 | ||
431 | if username == "localclient": | |
432 | return (username, password) | |
431 | with open(auth_file) as _file: | |
432 | for line in _file: | |
433 | line = line.strip() | |
434 | if line.startswith("#") or not line: | |
435 | # This is a comment or blank line | |
436 | continue | |
437 | ||
438 | try: | |
439 | lsplit = line.split(":") | |
440 | except Exception, e: | |
441 | log.error("Your auth file is malformed: %s", e) | |
442 | continue | |
443 | ||
444 | if len(lsplit) == 2: | |
445 | username, password = lsplit | |
446 | elif len(lsplit) == 3: | |
447 | username, password, level = lsplit | |
448 | else: | |
449 | log.error("Your auth file is malformed: Incorrect number of fields!") | |
450 | continue | |
451 | ||
452 | if username == "localclient": | |
453 | return (username, password) | |
433 | 454 | return ("", "") |
32 | 32 | # statement from all source files in the program, then also delete it here. |
33 | 33 | # |
34 | 34 | # |
35 | ||
36 | from __future__ import with_statement | |
37 | ||
35 | 38 | from twisted.internet import defer |
36 | 39 | |
37 | 40 | from deluge.ui.console.main import BaseCommand |
85 | 88 | continue |
86 | 89 | self.console.write("{!info!}Attempting to add torrent: %s" % arg) |
87 | 90 | filename = os.path.split(arg)[-1] |
88 | filedump = base64.encodestring(open(arg, "rb").read()) | |
91 | with open(arg, "rb") as _file: | |
92 | filedump = base64.encodestring(_file.read()) | |
89 | 93 | deferreds.append(client.core.add_torrent_file(filename, filedump, t_options).addCallback(on_success).addErrback(on_fail)) |
90 | 94 | |
91 | 95 | return defer.DeferredList(deferreds) |
737 | 737 | dialog.set_default_response(gtk.RESPONSE_OK) |
738 | 738 | dialog.set_transient_for(self.dialog) |
739 | 739 | entry.grab_focus() |
740 | ||
741 | text = (gtk.clipboard_get(selection='PRIMARY').wait_for_text() or | |
742 | gtk.clipboard_get().wait_for_text()).strip() | |
743 | if len(text) == 40: | |
744 | entry.set_text(text) | |
745 | ||
740 | 746 | dialog.show_all() |
741 | 747 | response = dialog.run() |
742 | if response == gtk.RESPONSE_OK and len(entry.get_text()) == 40: | |
748 | infohash = entry.get_text().strip() | |
749 | if response == gtk.RESPONSE_OK and len(infohash) == 40: | |
743 | 750 | trackers = [] |
744 | 751 | b = textview.get_buffer() |
745 | 752 | lines = b.get_text(b.get_start_iter(), b.get_end_iter()).strip().split("\n") |
750 | 757 | # Convert the information to a magnet uri, this is just easier to |
751 | 758 | # handle this way. |
752 | 759 | log.debug("trackers: %s", trackers) |
753 | magnet = deluge.common.create_magnet_uri( | |
754 | infohash=entry.get_text().decode("utf_8"), | |
755 | trackers=trackers) | |
760 | magnet = deluge.common.create_magnet_uri(infohash, infohash, trackers) | |
756 | 761 | log.debug("magnet uri: %s", magnet) |
757 | 762 | self.add_from_magnets([magnet]) |
758 | 763 |
267 | 267 | |
268 | 268 | if deluge.common.osx_check() and gtk.gdk.WINDOWING == "quartz": |
269 | 269 | def nsapp_open_file(osxapp, filename): |
270 | # Will be raised at app launch (python opening main script) | |
271 | if filename.endswith('Deluge-bin'): | |
270 | # Ignore command name which is raised at app launch (python opening main script). | |
271 | if filename == sys.argv[0]: | |
272 | 272 | return True |
273 | 273 | from deluge.ui.gtkui.ipcinterface import process_args |
274 | 274 | process_args([filename]) |
32 | 32 | # |
33 | 33 | # |
34 | 34 | |
35 | from __future__ import with_statement | |
35 | 36 | |
36 | 37 | import sys |
37 | 38 | import os |
105 | 106 | port = random.randrange(20000, 65535) |
106 | 107 | reactor.listenTCP(port, self.factory) |
107 | 108 | # Store the port number in the socket file |
108 | open(socket, "w").write(str(port)) | |
109 | with open(socket, "w") as _file: | |
110 | _file.write(str(port)) | |
109 | 111 | # We need to process any args when starting this process |
110 | 112 | process_args(args) |
111 | 113 | else: |
112 | 114 | # Send to existing deluge process |
113 | port = int(open(socket, "r").readline()) | |
115 | with open(socket) as _file: | |
116 | port = int(_file.readline()) | |
114 | 117 | self.factory = ClientFactory() |
115 | 118 | self.factory.args = args |
116 | 119 | self.factory.protocol = IPCProtocolClient |
220 | 223 | component.get("AddTorrentDialog").add_from_files([path]) |
221 | 224 | component.get("AddTorrentDialog").show(config["focus_add_dialog"]) |
222 | 225 | else: |
223 | client.core.add_torrent_file(os.path.split(path)[-1], base64.encodestring(open(path, "rb").read()), None) | |
226 | with open(path, "rb") as _file: | |
227 | filedump = base64.encodestring(_file.read()) | |
228 | client.core.add_torrent_file(os.path.split(path)[-1], filedump, None) |
32 | 32 | # |
33 | 33 | # |
34 | 34 | |
35 | from __future__ import with_statement | |
35 | 36 | |
36 | 37 | import pygtk |
37 | 38 | pygtk.require('2.0') |
957 | 958 | |
958 | 959 | if not client.is_localhost(): |
959 | 960 | # We need to send this plugin to the daemon |
960 | filedump = base64.encodestring(open(filepath, "rb").read()) | |
961 | with open(filepath, "rb") as _file: | |
962 | filedump = base64.encodestring(_file.read()) | |
961 | 963 | client.core.upload_plugin(filename, filedump) |
962 | 964 | |
963 | 965 | client.core.rescan_plugins() |
39 | 39 | from deluge.ui.client import client |
40 | 40 | import deluge.component as component |
41 | 41 | import deluge.common |
42 | from deluge.ui.common import TRACKER_STATUS_TRANSLATION | |
42 | 43 | from deluge.ui.gtkui.torrentdetails import Tab |
43 | 44 | from deluge.log import LOG as log |
45 | ||
44 | 46 | |
45 | 47 | def fpeer_sized(first, second): |
46 | 48 | return "%s (%s)" % (deluge.common.fsize(first), deluge.common.fsize(second)) |
61 | 63 | return "%s (%s %s)" % (deluge.common.fspeed(value), max_value, _("KiB/s")) |
62 | 64 | else: |
63 | 65 | return deluge.common.fspeed(value) |
66 | ||
67 | def ftranslate(text): | |
68 | if text in TRACKER_STATUS_TRANSLATION: | |
69 | text = _(text) | |
70 | elif text: | |
71 | for status in TRACKER_STATUS_TRANSLATION: | |
72 | if status in text: | |
73 | text = text.replace(status, _(status)) | |
74 | break | |
75 | return text | |
76 | ||
64 | 77 | |
65 | 78 | class StatusTab(Tab): |
66 | 79 | def __init__(self): |
84 | 97 | (glade.get_widget("summary_peers"), deluge.common.fpeer, ("num_peers", "total_peers")), |
85 | 98 | (glade.get_widget("summary_eta"), deluge.common.ftime, ("eta",)), |
86 | 99 | (glade.get_widget("summary_share_ratio"), fratio, ("ratio",)), |
87 | (glade.get_widget("summary_tracker_status"), None, ("tracker_status",)), | |
100 | (glade.get_widget("summary_tracker_status"), ftranslate, ("tracker_status",)), | |
88 | 101 | (glade.get_widget("summary_next_announce"), deluge.common.ftime, ("next_announce",)), |
89 | 102 | (glade.get_widget("summary_active_time"), deluge.common.ftime, ("active_time",)), |
90 | 103 | (glade.get_widget("summary_seed_time"), deluge.common.ftime, ("seeding_time",)), |
31 | 31 | # statement from all source files in the program, then also delete it here. |
32 | 32 | # |
33 | 33 | # |
34 | ||
35 | from __future__ import with_statement | |
34 | 36 | |
35 | 37 | import os |
36 | 38 | from HTMLParser import HTMLParser, HTMLParseError |
225 | 227 | if not url: |
226 | 228 | url = self.host_to_url(host) |
227 | 229 | log.debug("Downloading %s %s", host, url) |
228 | return download_file(url, mkstemp()[1], force_filename=True) | |
230 | fd, filename = mkstemp(prefix='deluge_ticon.') | |
231 | os.close(fd) | |
232 | return download_file(url, filename, force_filename=True) | |
229 | 233 | |
230 | 234 | def on_download_page_complete(self, page): |
231 | 235 | """ |
354 | 358 | |
355 | 359 | if PIL_INSTALLED: |
356 | 360 | try: |
357 | Image.open(icon_name) | |
361 | with Image.open(icon_name): | |
362 | pass | |
358 | 363 | except IOError, e: |
359 | 364 | raise InvalidIconError(e) |
360 | 365 | else: |
428 | 433 | """ |
429 | 434 | if icon: |
430 | 435 | filename = icon.get_filename() |
431 | img = Image.open(filename) | |
432 | if img.size > (16, 16): | |
433 | new_filename = filename.rpartition('.')[0]+".png" | |
434 | img = img.resize((16, 16), Image.ANTIALIAS) | |
435 | img.save(new_filename) | |
436 | if new_filename != filename: | |
437 | os.remove(filename) | |
438 | icon = TrackerIcon(new_filename) | |
436 | with Image.open(filename) as img: | |
437 | if img.size > (16, 16): | |
438 | new_filename = filename.rpartition('.')[0]+".png" | |
439 | img = img.resize((16, 16), Image.ANTIALIAS) | |
440 | img.save(new_filename) | |
441 | if new_filename != filename: | |
442 | os.remove(filename) | |
443 | icon = TrackerIcon(new_filename) | |
439 | 444 | return icon |
440 | 445 | |
441 | 446 | def store_icon(self, icon, host): |
118 | 118 | // InterfacePage.js:78 |
119 | 119 | GetText.add('Allow the use of multiple filters at once', '${escape(_("Allow the use of multiple filters at once"))}') |
120 | 120 | |
121 | // StatusTab.js:119 | |
122 | GetText.add('Announce OK', '${escape(_("Announce OK"))}') | |
123 | ||
124 | // StatusTab.js:120 | |
125 | GetText.add('Announce Sent', '${escape(_("Announce Sent"))}') | |
126 | ||
121 | 127 | // OptionsTab.js:347, PreferencesWindow.js:107 |
122 | 128 | GetText.add('Apply', '${escape(_("Apply"))}') |
123 | 129 | |
295 | 301 | // EncryptionPage.js:41 |
296 | 302 | GetText.add('Encryption', '${escape(_("Encryption"))}') |
297 | 303 | |
298 | // ConnectionManager.js:316, ConnectionManager.js:372, AddConnectionWindow.js:103, UrlWindow.js:116, FileWindow.js:103, AddWindow.js:211 | |
304 | // ConnectionManager.js:316, ConnectionManager.js:372, AddConnectionWindow.js:103, StatusTab.js:117, UrlWindow.js:116, FileWindow.js:103, AddWindow.js:211 | |
299 | 305 | GetText.add('Error', '${escape(_("Error"))}') |
300 | 306 | |
301 | 307 | // Menus.js:323 |
829 | 835 | // ConnectionManager.js:90 |
830 | 836 | GetText.add('Version', '${escape(_("Version"))}') |
831 | 837 | |
838 | // StatusTab.js:118 | |
839 | GetText.add('Warning', '${escape(_("Warning"))}') | |
840 | ||
832 | 841 | // ConnectionManager.js:285 |
833 | 842 | GetText.add('We recommend changing the default password.<br><br>Would you like to change it now?', '${escape(_("We recommend changing the default password.<br><br>Would you like to change it now?"))}') |
834 | 843 |
32 | 32 | # |
33 | 33 | # |
34 | 34 | |
35 | from __future__ import with_statement | |
36 | ||
35 | 37 | import os |
36 | 38 | import time |
37 | 39 | import base64 |
781 | 783 | client.core.add_torrent_magnet(torrent["path"], torrent["options"]) |
782 | 784 | else: |
783 | 785 | filename = os.path.basename(torrent["path"]) |
784 | fdump = base64.encodestring(open(torrent["path"], "rb").read()) | |
786 | with open(torrent["path"], "rb") as _file: | |
787 | fdump = base64.encodestring(_file.read()) | |
785 | 788 | log.info("Adding torrent from file `%s` with options `%r`", |
786 | 789 | filename, torrent["options"]) |
787 | 790 | client.core.add_torrent_file(filename, fdump, torrent["options"]) |
990 | 993 | client.core.rescan_plugins() |
991 | 994 | return True |
992 | 995 | |
993 | plugin_data = base64.encodestring(open(path, "rb").read()) | |
996 | with open(path, "rb") as _file: | |
997 | plugin_data = base64.encodestring(_file.read()) | |
994 | 998 | |
995 | 999 | def on_upload_complete(*args): |
996 | 1000 | client.core.rescan_plugins() |
233 | 233 | request.setHeader("cache-control", |
234 | 234 | "public, must-revalidate, max-age=86400") |
235 | 235 | request.setHeader("content-type", "image/png") |
236 | data = open(filename, "rb") | |
236 | with open(filename, "rb") as _file: | |
237 | data = _file.read() | |
237 | 238 | request.setResponseCode(http.OK) |
238 | return data.read() | |
239 | return data | |
239 | 240 | else: |
240 | 241 | request.setResponseCode(http.NOT_FOUND) |
241 | 242 | return "" |
281 | 282 | log.debug("Serving path: '%s'", path) |
282 | 283 | mime_type = mimetypes.guess_type(path) |
283 | 284 | request.setHeader("content-type", mime_type[0]) |
284 | return compress(open(path, "rb").read(), request) | |
285 | with open(path, "rb") as _file: | |
286 | data = _file.read() | |
287 | return compress(data, request) | |
285 | 288 | |
286 | 289 | request.setResponseCode(http.NOT_FOUND) |
287 | 290 | return "<h1>404 - Not Found</h1>" |
385 | 388 | |
386 | 389 | order_file = os.path.join(dirpath, '.order') |
387 | 390 | if os.path.isfile(order_file): |
388 | for line in open(order_file, 'rb'): | |
389 | line = line.strip() | |
390 | if not line or line[0] == '#': | |
391 | continue | |
392 | try: | |
393 | pos, filename = line.split() | |
394 | files.pop(files.index(filename)) | |
395 | if pos == '+': | |
396 | files.insert(0, filename) | |
397 | else: | |
398 | files.append(filename) | |
399 | except: | |
400 | pass | |
391 | with open(order_file, 'rb') as _file: | |
392 | for line in _file: | |
393 | line = line.strip() | |
394 | if not line or line[0] == '#': | |
395 | continue | |
396 | try: | |
397 | pos, filename = line.split() | |
398 | files.pop(files.index(filename)) | |
399 | if pos == '+': | |
400 | files.insert(0, filename) | |
401 | else: | |
402 | files.append(filename) | |
403 | except: | |
404 | pass | |
401 | 405 | |
402 | 406 | dirpath = dirpath[len(filepath)+1:] |
403 | 407 | if dirpath: |
438 | 442 | log.debug("Serving path: '%s'", path) |
439 | 443 | mime_type = mimetypes.guess_type(path) |
440 | 444 | request.setHeader("content-type", mime_type[0]) |
441 | return compress(open(path, "rb").read(), request) | |
445 | with open(path, "rb") as _file: | |
446 | data = _file.read() | |
447 | return compress(data, request) | |
442 | 448 | |
443 | 449 | request.setResponseCode(http.NOT_FOUND) |
444 | 450 | return "<h1>404 - Not Found</h1>" |