Compare commits
51 Commits
master
...
extjs4-por
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6892834d4d | ||
|
|
609f54a704 | ||
|
|
fa08f7de43 | ||
|
|
a91037843b | ||
|
|
4a43d6a635 | ||
|
|
1837d833c2 | ||
|
|
e3e20aa14f | ||
|
|
c865486f82 | ||
|
|
c06d4dfea5 | ||
|
|
c405425993 | ||
|
|
d10752fc1a | ||
|
|
ab665384d4 | ||
|
|
f5e6eabee4 | ||
|
|
717e66b836 | ||
|
|
fea0b41425 | ||
|
|
d37c3e0213 | ||
|
|
b724f74700 | ||
|
|
d44a357284 | ||
|
|
d6715fcbb9 | ||
|
|
2853d028fd | ||
|
|
4ab5c6d9de | ||
|
|
f53dc5faaf | ||
|
|
c46bc049d1 | ||
|
|
39d19b5afd | ||
|
|
e8506b925f | ||
|
|
eb9071fcb0 | ||
|
|
9362ec0103 | ||
|
|
fe0332bccf | ||
|
|
64bacbfbf4 | ||
|
|
280377ad6f | ||
|
|
0c3d2322cc | ||
|
|
07b6db0c98 | ||
|
|
713953ec03 | ||
|
|
6324737031 | ||
|
|
428681aca3 | ||
|
|
317e9ee423 | ||
|
|
08e774bbda | ||
|
|
43cb787b44 | ||
|
|
fb8f1e7ebc | ||
|
|
881bcee160 | ||
|
|
42b8af25aa | ||
|
|
bf4b826809 | ||
|
|
8ae14de208 | ||
|
|
5b45670a85 | ||
|
|
6cdf9940d3 | ||
|
|
8b69d66bae | ||
|
|
3ee434975c | ||
|
|
dda4620d98 | ||
|
|
7ac0083239 | ||
|
|
6ae58248a1 | ||
|
|
1c78bcbb29 |
8
.gitattributes
vendored
8
.gitattributes
vendored
@ -1,6 +1,10 @@
|
||||
/libtorrent export-ignore
|
||||
/win32 export-ignore
|
||||
docs/build export-ignore
|
||||
docs/source export-ignore
|
||||
/tests export-ignore
|
||||
deluge/scripts export-ignore
|
||||
.gitattributes export-ignore
|
||||
.gitmodules export-ignore
|
||||
.gitignore export-ignore
|
||||
*.py diff=python
|
||||
ext-all.js diff=minjs
|
||||
*.state -merge -text
|
||||
|
||||
100
.github/workflows/cd.yml
vendored
100
.github/workflows/cd.yml
vendored
@ -1,100 +0,0 @@
|
||||
name: Package
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "deluge-*"
|
||||
- "!deluge*-dev*"
|
||||
branches:
|
||||
- develop
|
||||
pull_request:
|
||||
types: [labeled, opened, synchronize, reopened]
|
||||
|
||||
# Allows you to run this workflow manually from the Actions tab
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
ref:
|
||||
description: "Enter a tag or commit to package"
|
||||
default: ""
|
||||
|
||||
jobs:
|
||||
windows_package:
|
||||
runs-on: windows-2019
|
||||
if: (github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'package'))
|
||||
strategy:
|
||||
matrix:
|
||||
arch: [x64, x86]
|
||||
python: ["3.9"]
|
||||
libtorrent: [2.0.6, 1.2.15]
|
||||
|
||||
steps:
|
||||
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
# Checkout Deluge source to subdir to enable packaging any tag/commit
|
||||
- name: Checkout Deluge source
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
ref: ${{ github.event.inputs.ref }}
|
||||
fetch-depth: 0
|
||||
path: deluge_src
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: ${{ matrix.python}}
|
||||
architecture: ${{ matrix.arch }}
|
||||
cache: pip
|
||||
|
||||
- name: Prepare pip
|
||||
run: python -m pip install wheel
|
||||
|
||||
- name: Install GTK
|
||||
run: |
|
||||
$WebClient = New-Object System.Net.WebClient
|
||||
$WebClient.DownloadFile("https://github.com/deluge-torrent/gvsbuild-release/releases/download/latest/gvsbuild-py${{ matrix.python }}-vs16-${{ matrix.arch }}.zip","C:\GTK.zip")
|
||||
7z x C:\GTK.zip -oc:\GTK
|
||||
echo "C:\GTK\release\lib" | Out-File -FilePath $env:GITHUB_PATH -Append
|
||||
echo "C:\GTK\release\bin" | Out-File -FilePath $env:GITHUB_PATH -Append
|
||||
echo "C:\GTK\release" | Out-File -FilePath $env:GITHUB_PATH -Append
|
||||
python -m pip install --no-index --find-links="C:\GTK\release\python" pycairo PyGObject
|
||||
|
||||
- name: Install Python dependencies
|
||||
run: >
|
||||
python -m pip install
|
||||
twisted[tls]==22.4.0
|
||||
libtorrent==${{ matrix.libtorrent }}
|
||||
pyinstaller==4.10
|
||||
pygame
|
||||
-r requirements.txt
|
||||
|
||||
- name: Install Deluge
|
||||
working-directory: deluge_src
|
||||
run: |
|
||||
python -m pip install .
|
||||
python setup.py install_scripts
|
||||
|
||||
- name: Freeze Deluge
|
||||
working-directory: packaging/win
|
||||
run: |
|
||||
pyinstaller --clean delugewin.spec --distpath freeze
|
||||
|
||||
- name: Fix OpenSSL for libtorrent x64
|
||||
if: ${{ matrix.arch == 'x64' }}
|
||||
working-directory: packaging/win/freeze/Deluge
|
||||
run: |
|
||||
cp libssl-1_1.dll libssl-1_1-x64.dll
|
||||
cp libcrypto-1_1.dll libcrypto-1_1-x64.dll
|
||||
|
||||
- name: Make Deluge Installer
|
||||
working-directory: ./packaging/win
|
||||
run: |
|
||||
python setup_nsis.py
|
||||
makensis /Darch=${{ matrix.arch }} deluge-win-installer.nsi
|
||||
|
||||
- uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: deluge-py${{ matrix.python }}-lt${{ matrix.libtorrent }}-${{ matrix.arch }}
|
||||
path: packaging/win/*.exe
|
||||
95
.github/workflows/ci.yml
vendored
95
.github/workflows/ci.yml
vendored
@ -1,95 +0,0 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
|
||||
# Allows you to run this workflow manually from the Actions tab
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
test-linux:
|
||||
runs-on: ubuntu-20.04
|
||||
strategy:
|
||||
matrix:
|
||||
python-version: ["3.7", "3.10"]
|
||||
|
||||
steps:
|
||||
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
cache: "pip"
|
||||
cache-dependency-path: "requirements*.txt"
|
||||
|
||||
- name: Sets env var for security
|
||||
if: (github.event_name == 'pull_request' && contains(github.event.pull_request.body, 'security_test')) || (github.event_name == 'push' && contains(github.event.head_commit.message, 'security_test'))
|
||||
run: echo "SECURITY_TESTS=True" >> $GITHUB_ENV
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
pip install --upgrade pip wheel
|
||||
pip install -r requirements.txt -r requirements-tests.txt
|
||||
pip install -e .
|
||||
|
||||
- name: Install security dependencies
|
||||
if: contains(env.SECURITY_TESTS, 'True')
|
||||
run: |
|
||||
wget -O- $TESTSSL_URL$TESTSSL_VER | tar xz
|
||||
mv -t deluge/tests/data testssl.sh-$TESTSSL_VER/testssl.sh testssl.sh-$TESTSSL_VER/etc/;
|
||||
env:
|
||||
TESTSSL_VER: 3.0.6
|
||||
TESTSSL_URL: https://codeload.github.com/drwetter/testssl.sh/tar.gz/refs/tags/v
|
||||
|
||||
- name: Setup core dump directory
|
||||
run: |
|
||||
sudo mkdir /cores/ && sudo chmod 777 /cores/
|
||||
echo "/cores/%E.%p" | sudo tee /proc/sys/kernel/core_pattern
|
||||
|
||||
- name: Test with pytest
|
||||
run: |
|
||||
ulimit -c unlimited # Enable core dumps to be captured
|
||||
python -c 'from deluge._libtorrent import lt; print(lt.__version__)';
|
||||
catchsegv python -X dev -m pytest -v -m "not (todo or gtkui)" deluge
|
||||
|
||||
- uses: actions/upload-artifact@v2
|
||||
# capture all crashes as build artifacts
|
||||
if: failure()
|
||||
with:
|
||||
name: crashes
|
||||
path: /cores
|
||||
|
||||
test-windows:
|
||||
runs-on: windows-2019
|
||||
strategy:
|
||||
matrix:
|
||||
python-version: ["3.7", "3.10"]
|
||||
|
||||
steps:
|
||||
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
cache: "pip"
|
||||
cache-dependency-path: "requirements*.txt"
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
pip install --upgrade pip wheel
|
||||
pip install -r requirements.txt -r requirements-tests.txt
|
||||
pip install -e .
|
||||
|
||||
- name: Test with pytest
|
||||
run: |
|
||||
python -c 'import libtorrent as lt; print(lt.__version__)';
|
||||
pytest -v -m "not (todo or gtkui or security)" deluge
|
||||
45
.github/workflows/docs.yml
vendored
45
.github/workflows/docs.yml
vendored
@ -1,45 +0,0 @@
|
||||
name: Docs
|
||||
|
||||
# Controls when the action will run.
|
||||
on:
|
||||
# Triggers the workflow on push or pull request events but only for the main branch
|
||||
push:
|
||||
pull_request:
|
||||
|
||||
# Allows you to run this workflow manually from the Actions tab
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: "3.8"
|
||||
- name: Cache pip
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
# This path is specific to Ubuntu
|
||||
path: ~/.cache/pip
|
||||
# Look to see if there is a cache hit for the corresponding requirements file
|
||||
key: ${{ runner.os }}-pip-${{ hashFiles('requirements*.txt') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-pip-
|
||||
${{ runner.os }}-
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
pip install --upgrade pip wheel
|
||||
pip install tox
|
||||
sudo apt-get install enchant
|
||||
|
||||
- name: Test with tox
|
||||
env:
|
||||
TOX_ENV: docs
|
||||
run: |
|
||||
tox -e $TOX_ENV
|
||||
17
.github/workflows/lint.yml
vendored
17
.github/workflows/lint.yml
vendored
@ -1,17 +0,0 @@
|
||||
name: Linting
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
|
||||
# Allows you to run this workflow manually from the Actions tab
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-python@v2
|
||||
- name: Run pre-commit linting
|
||||
uses: pre-commit/action@v2.0.2
|
||||
20
.gitignore
vendored
20
.gitignore
vendored
@ -1,25 +1,11 @@
|
||||
*~
|
||||
build
|
||||
.cache
|
||||
dist
|
||||
docs/source/modules/deluge*.rst
|
||||
*.egg-info/
|
||||
*.dist-info/
|
||||
*egg-info
|
||||
*.egg
|
||||
*.log
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*.pyc
|
||||
*.tar.*
|
||||
.tox/
|
||||
_trial_temp
|
||||
deluge/i18n/*/
|
||||
deluge.pot
|
||||
deluge/ui/web/js/*.js
|
||||
deluge/ui/web/js/extjs/ext-extensions*.js
|
||||
*.desktop
|
||||
*.appdata.xml
|
||||
.build_data*
|
||||
osx/app
|
||||
RELEASE-VERSION
|
||||
.venv*
|
||||
# used by setuptools to cache downloaded eggs
|
||||
/.eggs
|
||||
|
||||
@ -1,51 +0,0 @@
|
||||
default_language_version:
|
||||
python: python3
|
||||
exclude: >
|
||||
(?x)^(
|
||||
deluge/ui/web/docs/template/.*|
|
||||
deluge/tests/data/.*svg|
|
||||
)$
|
||||
repos:
|
||||
- repo: https://github.com/psf/black
|
||||
rev: 22.3.0
|
||||
hooks:
|
||||
- id: black
|
||||
name: Fmt Black
|
||||
- repo: https://github.com/pre-commit/mirrors-prettier
|
||||
rev: v2.5.1
|
||||
hooks:
|
||||
- id: prettier
|
||||
name: Fmt Prettier
|
||||
# Workaround to list modified files only.
|
||||
args: [--list-different]
|
||||
- repo: https://github.com/pycqa/isort
|
||||
rev: 5.10.1
|
||||
hooks:
|
||||
- id: isort
|
||||
name: Fmt isort
|
||||
- repo: https://github.com/pycqa/flake8
|
||||
rev: 4.0.1
|
||||
hooks:
|
||||
- id: flake8
|
||||
name: Chk Flake8
|
||||
additional_dependencies:
|
||||
- pep8-naming==0.12.1
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.1.0
|
||||
hooks:
|
||||
- id: double-quote-string-fixer
|
||||
name: Fix Double-quotes
|
||||
- id: end-of-file-fixer
|
||||
name: Fix End-of-files
|
||||
exclude_types: [javascript, css]
|
||||
- id: mixed-line-ending
|
||||
name: Fix Line endings
|
||||
args: [--fix=auto]
|
||||
- id: trailing-whitespace
|
||||
name: Fix Trailing whitespace
|
||||
- repo: https://github.com/asottile/pyupgrade
|
||||
rev: v2.31.0
|
||||
hooks:
|
||||
- id: pyupgrade
|
||||
args: [--py36-plus]
|
||||
stages: [manual]
|
||||
@ -1,6 +0,0 @@
|
||||
deluge/ui/web/css/ext-*.css
|
||||
deluge/ui/web/js/extjs/ext-*.js
|
||||
deluge/ui/web/docs/
|
||||
deluge/ui/web/themes/images/
|
||||
*.py*
|
||||
*.html
|
||||
@ -1,13 +0,0 @@
|
||||
trailingComma: "es5"
|
||||
tabWidth: 4
|
||||
singleQuote: true
|
||||
overrides:
|
||||
- files:
|
||||
- "*.yaml"
|
||||
- ".*.yaml"
|
||||
- "*.yml"
|
||||
- ".*.yml"
|
||||
- "*.md"
|
||||
options:
|
||||
tabWidth: 2
|
||||
singleQuote: false
|
||||
420
.pylintrc
420
.pylintrc
@ -1,420 +0,0 @@
|
||||
[MASTER]
|
||||
|
||||
# Specify a configuration file.
|
||||
#rcfile=
|
||||
|
||||
# Python code to execute, usually for sys.path manipulation such as
|
||||
# pygtk.require().
|
||||
#init-hook=
|
||||
|
||||
# Add files or directories to the blacklist. They should be base names, not
|
||||
# paths.
|
||||
ignore=CVS
|
||||
|
||||
# Add files or directories matching the regex patterns to the blacklist. The
|
||||
# regex matches against base names, not paths.
|
||||
ignore-patterns=
|
||||
|
||||
# Pickle collected data for later comparisons.
|
||||
persistent=yes
|
||||
|
||||
# List of plugins (as comma separated values of python modules names) to load,
|
||||
# usually to register additional checkers.
|
||||
load-plugins=
|
||||
|
||||
# Use multiple processes to speed up Pylint.
|
||||
jobs=2
|
||||
|
||||
# Allow loading of arbitrary C extensions. Extensions are imported into the
|
||||
# active Python interpreter and may run arbitrary code.
|
||||
unsafe-load-any-extension=no
|
||||
|
||||
# A comma-separated list of package or module names from where C extensions may
|
||||
# be loaded. Extensions are loading into the active Python interpreter and may
|
||||
# run arbitrary code
|
||||
extension-pkg-whitelist=
|
||||
|
||||
# Allow optimization of some AST trees. This will activate a peephole AST
|
||||
# optimizer, which will apply various small optimizations. For instance, it can
|
||||
# be used to obtain the result of joining multiple strings with the addition
|
||||
# operator. Joining a lot of strings can lead to a maximum recursion error in
|
||||
# Pylint and this flag can prevent that. It has one side effect, the resulting
|
||||
# AST will be different than the one from reality. This option is deprecated
|
||||
# and it will be removed in Pylint 2.0.
|
||||
optimize-ast=no
|
||||
|
||||
|
||||
[MESSAGES CONTROL]
|
||||
|
||||
# Only show warnings with the listed confidence levels. Leave empty to show
|
||||
# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED
|
||||
confidence=
|
||||
|
||||
# Enable the message, report, category or checker with the given id(s). You can
|
||||
# either give multiple identifier separated by comma (,) or put this option
|
||||
# multiple time (only on the command line, not in the configuration file where
|
||||
# it should appear only once). See also the "--disable" option for examples.
|
||||
#enable=
|
||||
|
||||
# Disable the message, report, category or checker with the given id(s). You
|
||||
# can either give multiple identifiers separated by comma (,) or put this
|
||||
# option multiple times (only on the command line, not in the configuration
|
||||
# file where it should appear only once).You can also use "--disable=all" to
|
||||
# disable everything first and then reenable specific checks. For example, if
|
||||
# you want to run only the similarities checker, you can use "--disable=all
|
||||
# --enable=similarities". If you want to run only the classes checker, but have
|
||||
# no Warning level messages displayed, use"--disable=all --enable=classes
|
||||
# --disable=W"
|
||||
#
|
||||
# Arranged by category and use symbolic names instead of ids.
|
||||
disable=
|
||||
# Convention
|
||||
missing-docstring, invalid-name, bad-continuation,
|
||||
# Error
|
||||
no-member, no-name-in-module,
|
||||
# Information
|
||||
locally-disabled,
|
||||
# Refactor
|
||||
no-self-use, too-many-arguments, too-many-branches, too-many-instance-attributes,
|
||||
too-many-locals, too-few-public-methods, too-many-public-methods, too-many-statements,
|
||||
# Refactor msgs that should eventually be enabled:
|
||||
redefined-variable-type, too-many-ancestors,
|
||||
too-many-nested-blocks, too-many-return-statements,
|
||||
# Warning
|
||||
unused-argument, protected-access, import-error, unused-variable,
|
||||
attribute-defined-outside-init,
|
||||
# Warning msgs that should eventually be enabled:
|
||||
arguments-differ, global-statement, fixme, broad-except
|
||||
|
||||
[REPORTS]
|
||||
|
||||
# Set the output format. Available formats are text, parseable, colorized, msvs
|
||||
# (visual studio) and html. You can also give a reporter class, eg
|
||||
# mypackage.mymodule.MyReporterClass.
|
||||
output-format=parseable
|
||||
|
||||
# Put messages in a separate file for each module / package specified on the
|
||||
# command line instead of printing them on stdout. Reports (if any) will be
|
||||
# written in a file name "pylint_global.[txt|html]". This option is deprecated
|
||||
# and it will be removed in Pylint 2.0.
|
||||
files-output=no
|
||||
|
||||
# Tells whether to display a full report or only the messages
|
||||
reports=no
|
||||
|
||||
# Python expression which should return a note less than 10 (10 is the highest
|
||||
# note). You have access to the variables errors warning, statement which
|
||||
# respectively contain the number of errors / warnings messages and the total
|
||||
# number of statements analyzed. This is used by the global evaluation report
|
||||
# (RP0004).
|
||||
evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
|
||||
|
||||
# Template used to display messages. This is a python new-style format string
|
||||
# used to format the message information. See doc for all details
|
||||
#msg-template=
|
||||
|
||||
|
||||
[SPELLING]
|
||||
|
||||
# Spelling dictionary name. Available dictionaries: none. To make it working
|
||||
# install python-enchant package.
|
||||
spelling-dict=
|
||||
|
||||
# List of comma separated words that should not be checked.
|
||||
spelling-ignore-words=
|
||||
|
||||
# A path to a file that contains private dictionary; one word per line.
|
||||
spelling-private-dict-file=
|
||||
|
||||
# Tells whether to store unknown words to indicated private dictionary in
|
||||
# --spelling-private-dict-file option instead of raising a message.
|
||||
spelling-store-unknown-words=no
|
||||
|
||||
|
||||
[BASIC]
|
||||
|
||||
# Good variable names which should always be accepted, separated by a comma
|
||||
good-names=d,i,j,k,ex,Run,_,log
|
||||
|
||||
# Bad variable names which should always be refused, separated by a comma
|
||||
bad-names=foo,bar,baz,toto,tutu,tata
|
||||
|
||||
# Colon-delimited sets of names that determine each other's naming style when
|
||||
# the name regexes allow several styles.
|
||||
name-group=
|
||||
|
||||
# Include a hint for the correct naming format with invalid-name
|
||||
include-naming-hint=no
|
||||
|
||||
# List of decorators that produce properties, such as abc.abstractproperty. Add
|
||||
# to this list to register other decorators that produce valid properties.
|
||||
property-classes=abc.abstractproperty
|
||||
|
||||
# Regular expression matching correct function names
|
||||
function-rgx=[a-z_][a-z0-9_]{2,30}$
|
||||
|
||||
# Naming hint for function names
|
||||
function-name-hint=[a-z_][a-z0-9_]{2,30}$
|
||||
|
||||
# Regular expression matching correct variable names
|
||||
variable-rgx=[a-z_][a-z0-9_]{2,30}$
|
||||
|
||||
# Naming hint for variable names
|
||||
variable-name-hint=[a-z_][a-z0-9_]{2,30}$
|
||||
|
||||
# Regular expression matching correct constant names
|
||||
const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$
|
||||
|
||||
# Naming hint for constant names
|
||||
const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$
|
||||
|
||||
# Regular expression matching correct attribute names
|
||||
attr-rgx=[a-z_][a-z0-9_]{2,30}$
|
||||
|
||||
# Naming hint for attribute names
|
||||
attr-name-hint=[a-z_][a-z0-9_]{2,30}$
|
||||
|
||||
# Regular expression matching correct argument names
|
||||
argument-rgx=[a-z_][a-z0-9_]{2,30}$
|
||||
|
||||
# Naming hint for argument names
|
||||
argument-name-hint=[a-z_][a-z0-9_]{2,30}$
|
||||
|
||||
# Regular expression matching correct class attribute names
|
||||
class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$
|
||||
|
||||
# Naming hint for class attribute names
|
||||
class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$
|
||||
|
||||
# Regular expression matching correct inline iteration names
|
||||
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
|
||||
|
||||
# Naming hint for inline iteration names
|
||||
inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$
|
||||
|
||||
# Regular expression matching correct class names
|
||||
class-rgx=[A-Z_][a-zA-Z0-9]+$
|
||||
|
||||
# Naming hint for class names
|
||||
class-name-hint=[A-Z_][a-zA-Z0-9]+$
|
||||
|
||||
# Regular expression matching correct module names
|
||||
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
|
||||
|
||||
# Naming hint for module names
|
||||
module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
|
||||
|
||||
# Regular expression matching correct method names
|
||||
method-rgx=[a-z_][a-z0-9_]{2,40}$
|
||||
|
||||
# Naming hint for method names
|
||||
method-name-hint=[a-z_][a-z0-9_]{2,30}$
|
||||
|
||||
# Regular expression which should only match function or class names that do
|
||||
# not require a docstring.
|
||||
no-docstring-rgx=__.*__
|
||||
|
||||
# Minimum line length for functions/classes that require docstrings, shorter
|
||||
# ones are exempt.
|
||||
docstring-min-length=-1
|
||||
|
||||
|
||||
[ELIF]
|
||||
|
||||
# Maximum number of nested blocks for function / method body
|
||||
max-nested-blocks=5
|
||||
|
||||
|
||||
[LOGGING]
|
||||
|
||||
# Logging modules to check that the string format arguments are in logging
|
||||
# function parameter format
|
||||
logging-modules=logging
|
||||
|
||||
|
||||
[FORMAT]
|
||||
|
||||
# Maximum number of characters on a single line.
|
||||
max-line-length=120
|
||||
|
||||
# Regexp for a line that is allowed to be longer than the limit.
|
||||
ignore-long-lines=^\s*(# )?<?https?://\S+>?$
|
||||
|
||||
# Allow the body of an if to be on the same line as the test if there is no
|
||||
# else.
|
||||
single-line-if-stmt=no
|
||||
|
||||
# List of optional constructs for which whitespace checking is disabled. `dict-
|
||||
# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}.
|
||||
# `trailing-comma` allows a space between comma and closing bracket: (a, ).
|
||||
# `empty-line` allows space-only lines.
|
||||
no-space-check=trailing-comma,dict-separator
|
||||
|
||||
# Maximum number of lines in a module
|
||||
max-module-lines=1550
|
||||
|
||||
# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
|
||||
# tab).
|
||||
indent-string=' '
|
||||
|
||||
# Number of spaces of indent required inside a hanging or continued line.
|
||||
indent-after-paren=4
|
||||
|
||||
# Expected format of line ending, e.g. empty (any line ending), LF or CRLF.
|
||||
expected-line-ending-format=LF
|
||||
|
||||
|
||||
[MISCELLANEOUS]
|
||||
|
||||
# List of note tags to take in consideration, separated by a comma.
|
||||
notes=FIXME,XXX,TODO
|
||||
|
||||
|
||||
[VARIABLES]
|
||||
|
||||
# Tells whether we should check for unused import in __init__ files.
|
||||
init-import=no
|
||||
|
||||
# A regular expression matching the name of dummy variables (i.e. expectedly
|
||||
# not used).
|
||||
dummy-variables-rgx=_$|dummy
|
||||
|
||||
# List of additional names supposed to be defined in builtins. Remember that
|
||||
# you should avoid to define new builtins when possible.
|
||||
additional-builtins=_,_n,__request__,WindowsError
|
||||
|
||||
# List of strings which can identify a callback function by name. A callback
|
||||
# name must start or end with one of those strings.
|
||||
callbacks=cb_,_cb
|
||||
|
||||
# List of qualified module names which can have objects that can redefine
|
||||
# builtins.
|
||||
redefining-builtins-modules=
|
||||
|
||||
|
||||
[TYPECHECK]
|
||||
|
||||
# Tells whether missing members accessed in mixin class should be ignored. A
|
||||
# mixin class is detected if its name ends with "mixin" (case insensitive).
|
||||
ignore-mixin-members=yes
|
||||
|
||||
# List of module names for which member attributes should not be checked
|
||||
# (useful for modules/projects where namespaces are manipulated during runtime
|
||||
# and thus existing member attributes cannot be deduced by static analysis. It
|
||||
# supports qualified module names, as well as Unix pattern matching.
|
||||
ignored-modules=
|
||||
|
||||
# List of class names for which member attributes should not be checked (useful
|
||||
# for classes with dynamically set attributes). This supports the use of
|
||||
# qualified names.
|
||||
ignored-classes=SQLObject,twisted.internet.reactor
|
||||
|
||||
# List of members which are set dynamically and missed by pylint inference
|
||||
# system, and so shouldn't trigger E1101 when accessed. Python regular
|
||||
# expressions are accepted.
|
||||
generated-members=REQUEST,acl_users,aq_parent
|
||||
|
||||
# List of decorators that produce context managers, such as
|
||||
# contextlib.contextmanager. Add to this list to register other decorators that
|
||||
# produce valid context managers.
|
||||
contextmanager-decorators=contextlib.contextmanager
|
||||
|
||||
|
||||
[SIMILARITIES]
|
||||
|
||||
# Minimum lines number of a similarity.
|
||||
min-similarity-lines=4
|
||||
|
||||
# Ignore comments when computing similarities.
|
||||
ignore-comments=yes
|
||||
|
||||
# Ignore docstrings when computing similarities.
|
||||
ignore-docstrings=yes
|
||||
|
||||
# Ignore imports when computing similarities.
|
||||
ignore-imports=no
|
||||
|
||||
|
||||
[IMPORTS]
|
||||
|
||||
# Deprecated modules which should not be used, separated by a comma
|
||||
deprecated-modules=regsub,TERMIOS,Bastion,rexec
|
||||
|
||||
# Create a graph of every (i.e. internal and external) dependencies in the
|
||||
# given file (report RP0402 must not be disabled)
|
||||
import-graph=
|
||||
|
||||
# Create a graph of external dependencies in the given file (report RP0402 must
|
||||
# not be disabled)
|
||||
ext-import-graph=
|
||||
|
||||
# Create a graph of internal dependencies in the given file (report RP0402 must
|
||||
# not be disabled)
|
||||
int-import-graph=
|
||||
|
||||
# Force import order to recognize a module as part of the standard
|
||||
# compatibility libraries.
|
||||
known-standard-library=
|
||||
|
||||
# Force import order to recognize a module as part of a third party library.
|
||||
known-third-party=enchant
|
||||
|
||||
|
||||
[DESIGN]
|
||||
|
||||
# Maximum number of arguments for function / method
|
||||
max-args=7
|
||||
|
||||
# Argument names that match this expression will be ignored. Default to name
|
||||
# with leading underscore
|
||||
ignored-argument-names=_.*
|
||||
|
||||
# Maximum number of locals for function / method body
|
||||
max-locals=15
|
||||
|
||||
# Maximum number of return / yield for function / method body
|
||||
max-returns=6
|
||||
|
||||
# Maximum number of branch for function / method body
|
||||
max-branches=12
|
||||
|
||||
# Maximum number of statements in function / method body
|
||||
max-statements=50
|
||||
|
||||
# Maximum number of parents for a class (see R0901).
|
||||
max-parents=7
|
||||
|
||||
# Maximum number of attributes for a class (see R0902).
|
||||
max-attributes=7
|
||||
|
||||
# Minimum number of public methods for a class (see R0903).
|
||||
min-public-methods=2
|
||||
|
||||
# Maximum number of public methods for a class (see R0904).
|
||||
max-public-methods=20
|
||||
|
||||
# Maximum number of boolean expressions in a if statement
|
||||
max-bool-expr=5
|
||||
|
||||
|
||||
[CLASSES]
|
||||
|
||||
# List of method names used to declare (i.e. assign) instance attributes.
|
||||
defining-attr-methods=__init__,__new__,setUp
|
||||
|
||||
# List of valid names for the first argument in a class method.
|
||||
valid-classmethod-first-arg=cls
|
||||
|
||||
# List of valid names for the first argument in a metaclass class method.
|
||||
valid-metaclass-classmethod-first-arg=mcs
|
||||
|
||||
# List of member names, which should be excluded from the protected access
|
||||
# warning.
|
||||
exclude-protected=_asdict,_fields,_replace,_source,_make
|
||||
|
||||
|
||||
[EXCEPTIONS]
|
||||
|
||||
# Exceptions that will emit a warning when being caught. Defaults to
|
||||
# "Exception"
|
||||
overgeneral-exceptions=Exception
|
||||
@ -1,22 +0,0 @@
|
||||
# .readthedocs.yml
|
||||
# Read the Docs configuration file
|
||||
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
|
||||
|
||||
# Required
|
||||
version: 2
|
||||
|
||||
# Build documentation in the docs/ directory with Sphinx
|
||||
sphinx:
|
||||
configuration: docs/source/conf.py
|
||||
|
||||
# Optionally build your docs in additional formats such as PDF and ePub
|
||||
formats: all
|
||||
|
||||
# Optionally set the version of Python and requirements required to build your docs
|
||||
python:
|
||||
version: 3.7
|
||||
install:
|
||||
- requirements: requirements.txt
|
||||
- requirements: docs/requirements.txt
|
||||
- method: setuptools
|
||||
path: .
|
||||
790
AUTHORS
790
AUTHORS
@ -1,790 +0,0 @@
|
||||
Authors:
|
||||
* Andrew Resch ('andar') <andrewresch@gmail.com>
|
||||
* Damien Churchill ('damoxc') <damoxc@gmail.com>
|
||||
|
||||
Main Developers:
|
||||
* Andrew Resch
|
||||
* Damien Churchill
|
||||
* John Garland ('johnnyg') <johnnybg+deluge@gmail.com>
|
||||
* Calum Lind ('cas') <calumlind+deluge@gmail.com>
|
||||
|
||||
libtorrent (http://www.libtorrent.org):
|
||||
* Arvid Norberg
|
||||
|
||||
Contributors (and Past Developers):
|
||||
* Zach Tibbitts <zach@collegegeek.org>
|
||||
* Alon Zakai ('Kripken') <kripkensteiner@gmail.com>
|
||||
* Marcos Mobley ('markybob') <markybob@gmail.com>
|
||||
* Alex Dedul
|
||||
* Sadrul Habib Chowdhury
|
||||
* Ido Abramovich <ido.deluge@gmail.com>
|
||||
* Martijn Voncken <mvoncken@gmail.com>
|
||||
* Mark Stahler ('kramed') <markstahler@gmail.com>
|
||||
* Pedro Algarvio ('s0undt3ch') <ufs@ufsoft.org>
|
||||
* Cristian Greco ('cgreco') <cristian@regolo.cc>
|
||||
* Chase Sterling ('gazpachoKing') <chase.sterling@gmail.com>
|
||||
|
||||
Plugin Developers:
|
||||
* Autoadd : Chase Sterling
|
||||
* Blocklist : John Garland
|
||||
* Execute : Damien Churchill
|
||||
* Extractor : Andrew Resch
|
||||
* Label : Martijn Voncken
|
||||
* Notifications : Pedro Algarvio
|
||||
* Scheduler : Andrew Resch
|
||||
* Webui : Damien Churchill
|
||||
|
||||
Images Authors:
|
||||
|
||||
* files: deluge/ui/data/pixmaps/*.svg, *.png
|
||||
deluge/ui/web/icons/active.png, alert.png, all.png, checking.png, dht.png,
|
||||
downloading.png, inactive.png, queued.png, seeding.png, traffic.png
|
||||
deluge/ui/web/images/deluge*.png
|
||||
deluge/ui/web/icons/apple-pre-*.png, deluge*.png
|
||||
copyright: Calum Lind
|
||||
license: GPLv3
|
||||
|
||||
* files: deluge/plugins/blocklist/blocklist/data/*.png
|
||||
deluge/ui/data/pixmaps/tracker_warning16.png, tracker_all16.png, lock48.png
|
||||
copyright: Gnome Icon Theme
|
||||
license: GPLv2
|
||||
url: http://ftp.acc.umu.se/pub/GNOME/sources/gnome-icon-theme
|
||||
|
||||
* files: deluge/ui/data/pixmaps/magnet*.svg, *.png
|
||||
copyright: Matias Wilkman
|
||||
license:
|
||||
|
||||
* files: deluge/ui/data/pixmaps/flags/*.png
|
||||
copyright: Mark James <mjames@gmail.com>
|
||||
license: Public Domain
|
||||
url: http://famfamfam.com/lab/icons/flags/
|
||||
|
||||
* files: deluge/ui/web/icons/*.png
|
||||
exceptions: apple-pre-*.png, active.png, alert.png, all.png, deluge.png, dht.png,
|
||||
downloading.png, inactive.png, queued.png, seeding.png, traffic.png
|
||||
copyright: Yusuke Kamiyamane <p@yusukekamiyamane.com>
|
||||
license: Creative Commons Attribution 3.0 License
|
||||
url: http://p.yusukekamiyamane.com/
|
||||
|
||||
* files: deluge/ui/web/images/spinner.gif, spinner-split.gif
|
||||
copyright: Steven Chim
|
||||
license: BSD license
|
||||
url: http://members.upc.nl/j.chim/ext/spinner2/ext-spinner.html
|
||||
|
||||
Translation Contributors:
|
||||
* files: deluge/i18n/*.po
|
||||
|
||||
Aaron Wang Shi
|
||||
abbigss
|
||||
ABCdatos
|
||||
Abcx
|
||||
Actam
|
||||
Adam
|
||||
adaminikisi
|
||||
adi_oporanu
|
||||
Adrian Goll
|
||||
afby
|
||||
Ahmades
|
||||
Ahmad Farghal
|
||||
Ahmad Gharbeia أحمد غربية
|
||||
akira
|
||||
Aki Sivula
|
||||
Alan Pepelko
|
||||
Alberto
|
||||
Alberto Ferrer
|
||||
alcatr4z
|
||||
AlckO
|
||||
Aleksej Korgenkov
|
||||
Alessio Treglia
|
||||
Alexander Ilyashov
|
||||
Alexander Matveev
|
||||
Alexander Saltykov
|
||||
Alexander Taubenkorb
|
||||
Alexander Telenga
|
||||
Alexander Yurtsev
|
||||
Alexandre Martani
|
||||
Alexandre Rosenfeld
|
||||
Alexandre Sapata Carbonell
|
||||
Alexey Osipov
|
||||
Alin Claudiu Radut
|
||||
allah
|
||||
AlSim
|
||||
Alvaro Carrillanca P.
|
||||
A.Matveev
|
||||
Andras Hipsag
|
||||
András Kárász
|
||||
Andrea Ratto
|
||||
Andreas Johansson
|
||||
Andreas Str
|
||||
André F. Oliveira
|
||||
AndreiF
|
||||
andrewh
|
||||
Angel Guzman Maeso
|
||||
Aníbal Deboni Neto
|
||||
animarval
|
||||
Antonio Cono
|
||||
antoniojreyes
|
||||
Anton Shestakov
|
||||
Anton Yakutovich
|
||||
antou
|
||||
Arkadiusz Kalinowski
|
||||
Artin
|
||||
artir
|
||||
Astur
|
||||
Athanasios Lefteris
|
||||
Athmane MOKRAOUI (ButterflyOfFire)
|
||||
Augusta Carla Klug
|
||||
Avoledo Marco
|
||||
axaard
|
||||
AxelRafn
|
||||
Axezium
|
||||
Ayont
|
||||
b3rx
|
||||
Bae Taegil
|
||||
Bajusz Tamás
|
||||
Balaam's Miracle
|
||||
Ballestein
|
||||
Bent Ole Fosse
|
||||
berto89
|
||||
bigx
|
||||
Bjorn Inge Berg
|
||||
blackbird
|
||||
Blackeyed
|
||||
blackmx
|
||||
BlueSky
|
||||
Blutheo
|
||||
bmhm
|
||||
bob00work
|
||||
boenki
|
||||
Bogdan Bădic-Spătariu
|
||||
bonpu
|
||||
Boone
|
||||
boss01
|
||||
Branislav Jovanović
|
||||
bronze
|
||||
brownie
|
||||
Brus46
|
||||
bumper
|
||||
butely
|
||||
BXCracer
|
||||
c0nfidencal
|
||||
Can Kaya
|
||||
Carlos Alexandro Becker
|
||||
cassianoleal
|
||||
Cédric.h
|
||||
César Rubén
|
||||
chaoswizard
|
||||
Chen Tao
|
||||
chicha
|
||||
Chien Cheng Wei
|
||||
Christian Kopac
|
||||
Christian Widell
|
||||
Christoffer Brodd-Reijer
|
||||
christooss
|
||||
CityAceE
|
||||
Clopy
|
||||
Clusty
|
||||
cnu
|
||||
Commandant
|
||||
Constantinos Koniaris
|
||||
Coolmax
|
||||
cosmix
|
||||
Costin Chirvasuta
|
||||
CoVaLiDiTy
|
||||
cow_2001
|
||||
Crispin Kirchner
|
||||
crom
|
||||
Cruster
|
||||
Cybolic
|
||||
Dan Bishop
|
||||
Danek
|
||||
Dani
|
||||
Daniel Demarco
|
||||
Daniel Ferreira
|
||||
Daniel Frank
|
||||
Daniel Holm
|
||||
Daniel Høyer Iversen
|
||||
Daniel Marynicz
|
||||
Daniel Nylander
|
||||
Daniel Patriche
|
||||
Daniel Schildt
|
||||
Daniil Sorokin
|
||||
Dante Díaz
|
||||
Daria Michalska
|
||||
DarkenCZ
|
||||
Darren
|
||||
Daspah
|
||||
David Eurenius
|
||||
davidhjelm
|
||||
David Machakhelidze
|
||||
Dawid Dziurdzia
|
||||
Daya Adianto
|
||||
dcruz
|
||||
Deady
|
||||
Dereck Wonnacott
|
||||
Devgru
|
||||
Devid Antonio FiloniDevilDogTG
|
||||
di0rz`
|
||||
Dialecti Valsamou
|
||||
Diego Medeiros
|
||||
Dkzoffy
|
||||
Dmitrij D. Czarkoff
|
||||
Dmitriy Geels
|
||||
Dmitry Olyenyov
|
||||
Dominik Kozaczko
|
||||
Dominik Lübben
|
||||
doomster
|
||||
Dorota Król
|
||||
Doyen Philippe
|
||||
Dread Knight
|
||||
DreamSonic
|
||||
duan
|
||||
Duong Thanh An
|
||||
DvoglavaZver
|
||||
dwori
|
||||
dylansmrjones
|
||||
Ebuntor
|
||||
Edgar Alejandro Jarquin Flores
|
||||
Eetu
|
||||
ekerazha
|
||||
Elias Julkunen
|
||||
elparia
|
||||
Emberke
|
||||
Emiliano Goday Caneda
|
||||
EndelWar
|
||||
eng.essam
|
||||
enubuntu
|
||||
ercangun
|
||||
Erdal Ronahi
|
||||
ergin üresin
|
||||
Eric
|
||||
Éric Lassauge
|
||||
Erlend Finvåg
|
||||
Errdil
|
||||
ethan shalev
|
||||
Evgeni Spasov
|
||||
ezekielnin
|
||||
Fabian Ordelmans
|
||||
Fabio Mazanatti
|
||||
Fábio Nogueira
|
||||
FaCuZ
|
||||
Felipe Lerena
|
||||
Fernando Pereira
|
||||
fjetland
|
||||
Florian Schäfer
|
||||
FoBoS
|
||||
Folke
|
||||
Force
|
||||
fosk
|
||||
fragarray
|
||||
freddeg
|
||||
Frédéric Perrin
|
||||
Fredrik Kilegran
|
||||
FreeAtMind
|
||||
Fulvio Ciucci
|
||||
Gabor Kelemen
|
||||
Galatsanos Panagiotis
|
||||
Gaussian
|
||||
gdevitis
|
||||
Georg Brzyk
|
||||
George Dumitrescu
|
||||
Georgi Arabadjiev
|
||||
Georg Sieber
|
||||
Gerd Radecke
|
||||
Germán Heusdens
|
||||
Gianni Vialetto
|
||||
Gigih Aji Ibrahim
|
||||
Giorgio Wicklein
|
||||
Giovanni Rapagnani
|
||||
Giuseppe
|
||||
gl
|
||||
glen
|
||||
granjerox
|
||||
Green Fish
|
||||
greentea
|
||||
Greyhound
|
||||
G. U.
|
||||
Guillaume BENOIT
|
||||
Guillaume Pelletier
|
||||
Gustavo Henrique Klug
|
||||
gutocarvalho
|
||||
Guybrush88
|
||||
Hans Rødtang
|
||||
HardDisk
|
||||
Hargas Gábor
|
||||
Heitor Thury Barreiros Barbosa
|
||||
helios91940
|
||||
helix84
|
||||
Helton Rodrigues
|
||||
Hendrik Luup
|
||||
Henrique Ferreiro
|
||||
Henry Goury-Laffont
|
||||
Hezy Amiel
|
||||
hidro
|
||||
hoball
|
||||
hokten
|
||||
Holmsss
|
||||
hristo.num
|
||||
Hubert Życiński
|
||||
Hyo
|
||||
Iarwain
|
||||
ibe
|
||||
ibear
|
||||
Id2ndR
|
||||
Igor Zubarev
|
||||
IKON (Ion)
|
||||
imen
|
||||
Ionuț Jula
|
||||
Isabelle STEVANT
|
||||
István Nyitrai
|
||||
Ivan Petrovic
|
||||
Ivan Prignano
|
||||
IvaSerge
|
||||
jackmc
|
||||
Jacks0nxD
|
||||
Jack Shen
|
||||
Jacky Yeung
|
||||
Jacques Stadler
|
||||
Janek Thomaschewski
|
||||
Jan Kaláb
|
||||
Jan Niklas Hasse
|
||||
Jasper Groenewegen
|
||||
Javi Rodríguez
|
||||
Jayasimha (ಜಯಸಿಂಹ)
|
||||
jeannich
|
||||
Jeff Bailes
|
||||
Jesse Zilstorff
|
||||
Joan Duran
|
||||
João Santos
|
||||
Joar Bagge
|
||||
Joe Anderson
|
||||
Joel Calado
|
||||
Johan Linde
|
||||
John Garland
|
||||
Jojan
|
||||
jollyr0ger
|
||||
Jonas Bo Grimsgaard
|
||||
Jonas Granqvist
|
||||
Jonas Slivka
|
||||
Jonathan Zeppettini
|
||||
Jørgen
|
||||
Jørgen Tellnes
|
||||
josé
|
||||
José Geraldo Gouvêa
|
||||
José Iván León Islas
|
||||
José Lou C.
|
||||
Jose Sun
|
||||
Jr.
|
||||
Jukka Kauppinen
|
||||
Julián Alarcón
|
||||
julietgolf
|
||||
Jusic
|
||||
Justzupi
|
||||
Kaarel
|
||||
Kai Thomsen
|
||||
Kalman Tarnay
|
||||
Kamil Páral
|
||||
Kane_F
|
||||
kaotiks@gmail.com
|
||||
Kateikyoushii
|
||||
kaxhinaz
|
||||
Kazuhiro NISHIYAMA
|
||||
Kerberos
|
||||
Keresztes Ákos
|
||||
kevintyk
|
||||
kiersie
|
||||
Kimbo^
|
||||
Kim Lübbe
|
||||
kitzOgen
|
||||
Kjetil Rydland
|
||||
kluon
|
||||
kmikz
|
||||
Knedlyk
|
||||
koleoptero
|
||||
Kőrösi Krisztián
|
||||
Kouta
|
||||
Krakatos
|
||||
Krešo Kunjas
|
||||
kripken
|
||||
Kristaps
|
||||
Kristian Øllegaard
|
||||
Kristoffer Egil Bonarjee
|
||||
Krzysztof Janowski
|
||||
Krzysztof Zawada
|
||||
Larry Wei Liu
|
||||
laughterwym
|
||||
Laur Mõtus
|
||||
lazka
|
||||
leandrud
|
||||
lê bình
|
||||
Le Coz Florent
|
||||
Leo
|
||||
liorda
|
||||
LKRaider
|
||||
LoLo_SaG
|
||||
Long Tran
|
||||
Lorenz
|
||||
Low Kian Seong
|
||||
Luca Andrea Rossi
|
||||
Luca Ferretti
|
||||
Lucky LIX
|
||||
Luis Gomes
|
||||
Luis Reis
|
||||
Łukasz Wyszyński
|
||||
luojie-dune
|
||||
maaark
|
||||
Maciej Chojnacki
|
||||
Maciej Meller
|
||||
Mads Peter Rommedahl
|
||||
Major Kong
|
||||
Malaki
|
||||
malde
|
||||
Malte Lenz
|
||||
Mantas Kriaučiūnas
|
||||
Mara Sorella
|
||||
Marcin
|
||||
Marcin Falkiewicz
|
||||
marcobra
|
||||
Marco da Silva
|
||||
Marco de Moulin
|
||||
Marco Rodrigues
|
||||
Marcos
|
||||
Marcos Escalier
|
||||
Marcos Mobley
|
||||
Marcus Ekstrom
|
||||
Marek Dębowski
|
||||
Mário Buči
|
||||
Mario Munda
|
||||
Marius Andersen
|
||||
Marius Hudea
|
||||
Marius Mihai
|
||||
Mariusz Cielecki
|
||||
Mark Krapivner
|
||||
marko-markovic
|
||||
Markus Brummer
|
||||
Markus Sutter
|
||||
Martin
|
||||
Martin Dybdal
|
||||
Martin Iglesias
|
||||
Martin Lettner
|
||||
Martin Pihl
|
||||
Masoud Kalali
|
||||
mat02
|
||||
Matej Urbančič
|
||||
Mathias-K
|
||||
Mathieu Arès
|
||||
Mathieu D. (MatToufoutu)
|
||||
Mathijs
|
||||
Matrik
|
||||
Matteo Renzulli
|
||||
Matteo Settenvini
|
||||
Matthew Gadd
|
||||
Matthias Benkard
|
||||
Matthias Mailänder
|
||||
Mattias Ohlsson
|
||||
Mauro de Carvalho
|
||||
Max Molchanov
|
||||
Me
|
||||
MercuryCC
|
||||
Mert Bozkurt
|
||||
Mert Dirik
|
||||
MFX
|
||||
mhietar
|
||||
mibtha
|
||||
Michael Budde
|
||||
Michael Kaliszka
|
||||
Michalis Makaronides
|
||||
Michał Tokarczyk
|
||||
Miguel Pires da Rosa
|
||||
Mihai Capotă
|
||||
Miika Metsälä
|
||||
Mikael Fernblad
|
||||
Mike Sierra
|
||||
mikhalek
|
||||
Milan Prvulović
|
||||
Milo Casagrande
|
||||
Mindaugas
|
||||
Miroslav Matejaš
|
||||
misel
|
||||
mithras
|
||||
Mitja Pagon
|
||||
M.Kitchen
|
||||
Mohamed Magdy
|
||||
moonkey
|
||||
MrBlonde
|
||||
muczy
|
||||
Münir Ekinci
|
||||
Mustafa Temizel
|
||||
mvoncken
|
||||
Mytonn
|
||||
NagyMarton
|
||||
neaion
|
||||
Neil Lin
|
||||
Nemo
|
||||
Nerijus Arlauskas
|
||||
Nicklas Larsson
|
||||
Nicolaj Wyke
|
||||
Nicola Piovesan
|
||||
Nicolas Sabatier
|
||||
Nicolas Velin
|
||||
Nightfall
|
||||
NiKoB
|
||||
Nikolai M. Riabov
|
||||
Niko_Thien
|
||||
niska
|
||||
Nithir
|
||||
noisemonkey
|
||||
nomemohes
|
||||
nosense
|
||||
null
|
||||
Nuno Estêvão
|
||||
Nuno Santos
|
||||
nxxs
|
||||
nyo
|
||||
obo
|
||||
Ojan
|
||||
Olav Andreas Lindekleiv
|
||||
oldbeggar
|
||||
Olivier FAURAX
|
||||
orphe
|
||||
osantana
|
||||
Osman Tosun
|
||||
OssiR
|
||||
otypoks
|
||||
ounn
|
||||
Oz123
|
||||
Özgür BASKIN
|
||||
Pablo Carmona A.
|
||||
Pablo Ledesma
|
||||
Pablo Navarro Castillo
|
||||
Paco Molinero
|
||||
Pål-Eivind Johnsen
|
||||
pano
|
||||
Paolo Naldini
|
||||
Paracelsus
|
||||
Patryk13_03
|
||||
Patryk Skorupa
|
||||
PattogoTehen
|
||||
Paul Lange
|
||||
Pavcio
|
||||
Paweł Wysocki
|
||||
Pedro Brites Moita
|
||||
Pedro Clemente Pereira Neto
|
||||
Pekka "PEXI" Niemistö
|
||||
Penegal
|
||||
Penzo
|
||||
perdido
|
||||
Peter Kotrcka
|
||||
Peter Skov
|
||||
Peter Van den Bosch
|
||||
Petter Eklund
|
||||
Petter Viklund
|
||||
phatsphere
|
||||
Phenomen
|
||||
Philipi
|
||||
Philippides Homer
|
||||
phoenix
|
||||
pidi
|
||||
Pierre Quillery
|
||||
Pierre Rudloff
|
||||
Pierre Slamich
|
||||
Pietrao
|
||||
Piotr Strębski
|
||||
Piotr Wicijowski
|
||||
Pittmann Tamás
|
||||
Playmolas
|
||||
Prescott
|
||||
Prescott_SK
|
||||
pronull
|
||||
Przemysław Kulczycki
|
||||
Pumy
|
||||
pushpika
|
||||
PY
|
||||
qubicllj
|
||||
r21vo
|
||||
Rafał Barański
|
||||
rainofchaos
|
||||
Rajbir
|
||||
ras0ir
|
||||
Rat
|
||||
rd1381
|
||||
Renato
|
||||
Rene Hennig
|
||||
Rene Pärts
|
||||
Ricardo Duarte
|
||||
Richard
|
||||
Robert Hrovat
|
||||
Roberth Sjonøy
|
||||
Robert Lundmark
|
||||
Robin Jakobsson
|
||||
Robin Kåveland
|
||||
Rodrigo Donado
|
||||
Roel Groeneveld
|
||||
rohmaru
|
||||
Rolf Christensen
|
||||
Rolf Leggewie
|
||||
Roni Kantis
|
||||
Ronmi
|
||||
Rostislav Raykov
|
||||
royto
|
||||
RuiAmaro
|
||||
Rui Araújo
|
||||
Rui Moura
|
||||
Rune Svendsen
|
||||
Rusna
|
||||
Rytis
|
||||
Sabirov Mikhail
|
||||
salseeg
|
||||
Sami Koskinen
|
||||
Samir van de Sand
|
||||
Samuel Arroyo Acuña
|
||||
Samuel R. C. Vale
|
||||
Sanel
|
||||
Santi
|
||||
Santi Martínez Cantelli
|
||||
Sardan
|
||||
Sargate Kanogan
|
||||
Sarmad Jari
|
||||
Saša Bodiroža
|
||||
sat0shi
|
||||
Saulius Pranckevičius
|
||||
Savvas Radevic
|
||||
Sebastian Krauß
|
||||
Sebastián Porta
|
||||
Sedir
|
||||
Sefa Denizoğlu
|
||||
sekolands
|
||||
Selim Suerkan
|
||||
semsomi
|
||||
Sergii Golovatiuk
|
||||
setarcos
|
||||
Sheki
|
||||
Shironeko
|
||||
Shlomil
|
||||
silfiriel
|
||||
Simone Tolotti
|
||||
Simone Vendemia
|
||||
sirkubador
|
||||
Sławomir Więch
|
||||
slip
|
||||
slyon
|
||||
smoke
|
||||
Sonja
|
||||
spectral
|
||||
spin_555
|
||||
spitf1r3
|
||||
Spiziuz
|
||||
Spyros Theodoritsis
|
||||
SqUe
|
||||
Squigly
|
||||
srtck
|
||||
Stefan Horning
|
||||
Stefano Maggiolo
|
||||
Stefano Roberto Soleti
|
||||
steinberger
|
||||
Stéphane Travostino
|
||||
Stephan Klein
|
||||
Steven De Winter
|
||||
Stevie
|
||||
Stian24
|
||||
stylius
|
||||
Sukarn Maini
|
||||
Sunjae Park
|
||||
Susana Pereira
|
||||
szymon siglowy
|
||||
takercena
|
||||
TAS
|
||||
Taygeto
|
||||
temy4
|
||||
texxxxxx
|
||||
thamood
|
||||
Thanos Chatziathanassiou
|
||||
Tharawut Paripaiboon
|
||||
Theodoor
|
||||
Théophane Anestis
|
||||
Thor Marius K. Høgås
|
||||
Tiago Silva
|
||||
Tiago Sousa
|
||||
Tikkel
|
||||
tim__b
|
||||
Tim Bordemann
|
||||
Tim Fuchs
|
||||
Tim Kornhammar
|
||||
Timo
|
||||
Timo Jyrinki
|
||||
Timothy Babych
|
||||
TitkosRejtozo
|
||||
Tom
|
||||
Tomas Gustavsson
|
||||
Tomas Valentukevičius
|
||||
Tomasz Dominikowski
|
||||
Tomislav Plavčić
|
||||
Tom Mannerhagen
|
||||
Tommy Mikkelsen
|
||||
Tom Verdaat
|
||||
Tony Manco
|
||||
Tor Erling H. Opsahl
|
||||
Toudi
|
||||
tqm_z
|
||||
Trapanator
|
||||
Tribaal
|
||||
Triton
|
||||
TuniX12
|
||||
Tuomo Sipola
|
||||
turbojugend_gr
|
||||
Turtle.net
|
||||
twilight
|
||||
tymmej
|
||||
Ulrik
|
||||
Umarzuki Mochlis
|
||||
unikob
|
||||
Vadim Gusev
|
||||
Vagi
|
||||
Valentin Bora
|
||||
Valmantas Palikša
|
||||
VASKITTU
|
||||
Vassilis Skoullis
|
||||
vetal17
|
||||
vicedo
|
||||
viki
|
||||
villads hamann
|
||||
Vincent Garibal
|
||||
Vincent Ortalda
|
||||
vinchi007
|
||||
Vinícius de Figueiredo Silva
|
||||
Vinzenz Vietzke
|
||||
virtoo
|
||||
virtual_spirit
|
||||
Vitor Caike
|
||||
Vitor Lamas Gatti
|
||||
Vladimir Lazic
|
||||
Vladimir Sharshov
|
||||
Wanderlust
|
||||
Wander Nauta
|
||||
Ward De Ridder
|
||||
WebCrusader
|
||||
webdr
|
||||
Wentao Tang
|
||||
wilana
|
||||
Wilfredo Ernesto Guerrero Campos
|
||||
Wim Champagne
|
||||
World Sucks
|
||||
Xabi Ezpeleta
|
||||
Xavi de Moner
|
||||
XavierToo
|
||||
XChesser
|
||||
Xiaodong Xu
|
||||
xyb
|
||||
Yaron
|
||||
Yasen Pramatarov
|
||||
YesPoX
|
||||
Yuren Ju
|
||||
Yves MATHIEU
|
||||
zekopeko
|
||||
zhuqin
|
||||
Zissan
|
||||
Γιάννης Κατσαμπίρης
|
||||
Артём Попов
|
||||
Миша
|
||||
Шаймарданов Максим
|
||||
蔡查理
|
||||
259
CHANGELOG.md
259
CHANGELOG.md
@ -1,259 +0,0 @@
|
||||
# Changelog
|
||||
|
||||
## 2.1.1 (2022-07-10)
|
||||
|
||||
### Core
|
||||
|
||||
- Fix missing trackers added via magnet
|
||||
- Fix handling magnets with tracker tiers
|
||||
|
||||
## 2.1.0 (2022-06-28)
|
||||
|
||||
### Breaking changes
|
||||
|
||||
- Python 2 support removed (Python >= 3.6)
|
||||
- libtorrent minimum requirement increased (>= 1.2).
|
||||
|
||||
### Core
|
||||
|
||||
- Add support for SVG tracker icons.
|
||||
- Fix tracker icon error handling.
|
||||
- Fix cleaning-up tracker icon temp files.
|
||||
- Fix Plugin manager to handle new metadata 2.1.
|
||||
- Hide passwords in config logs.
|
||||
- Fix cleaning-up temp files in add_torrent_url.
|
||||
- Fix KeyError in sessionproxy after torrent delete.
|
||||
- Remove libtorrent deprecated functions.
|
||||
- Fix file_completed_alert handling.
|
||||
- Add plugin keys to get_torrents_status.
|
||||
- Add support for pygeoip dependency.
|
||||
- Fix crash logging to Windows protected folder.
|
||||
- Add is_interface and is_interface_name to validate network interfaces.
|
||||
- Fix is_url and is_infohash error with None value.
|
||||
- Fix load_libintl error.
|
||||
- Add support for IPv6 in host lists.
|
||||
- Add systemd user services.
|
||||
- Fix refresh and expire the torrent status cache.
|
||||
- Fix crash when logging errors initializing gettext.
|
||||
|
||||
### Web UI
|
||||
|
||||
- Fix ETA column sorting in correct order (#3413).
|
||||
- Fix defining foreground and background colors.
|
||||
- Accept charset in content-type for json messages.
|
||||
- Fix 'Complete Seen' and 'Completed' sorting.
|
||||
- Fix encoding HTML entities for torrent attributes to prevent XSS.
|
||||
|
||||
### Gtk UI
|
||||
|
||||
- Fix download location textbox width.
|
||||
- Fix obscured port number in Connection Manager.
|
||||
- Increase connection manager default height.
|
||||
- Fix bug with setting move completed in Options tab.
|
||||
- Fix adding daemon accounts.
|
||||
- Add workaround for crash on Windows with ico or gif icons.
|
||||
- Hide account password length in log.
|
||||
- Added a torrent menu option for magnet copy.
|
||||
- Fix unable to prefetch magnet in thinclient mode.
|
||||
- Use GtkSpinner when testing open port.
|
||||
- Update About Dialog year.
|
||||
- Fix Edit Torrents dialogs close issues.
|
||||
- Fix ETA being copied to neighboring empty cells.
|
||||
- Disable GTK CSD by default on Windows.
|
||||
|
||||
### Console UI
|
||||
|
||||
- Fix curses.init_pair raise ValueError on Py3.10.
|
||||
- Swap j and k key's behavior to fit vim mode.
|
||||
- Fix torrent details status error.
|
||||
- Fix incorrect test for when a host is online.
|
||||
- Add the torrent label to info command.
|
||||
|
||||
### AutoAdd
|
||||
|
||||
- Fix handling torrent decode errors.
|
||||
- Fix error dialog not being shown on error.
|
||||
|
||||
### Blocklist
|
||||
|
||||
- Add frequency unit to interval label.
|
||||
|
||||
### Notifications
|
||||
|
||||
- Fix UnicodeEncodeError upon non-ascii torrent name.
|
||||
|
||||
## 2.0.5 (2021-12-15)
|
||||
|
||||
### WebUI
|
||||
|
||||
- Fix js minifying error resulting in WebUI blank screen.
|
||||
- Silence erronous missing translations warning.
|
||||
|
||||
## 2.0.4 (2021-12-12)
|
||||
|
||||
### Packaging
|
||||
|
||||
- Fix python optional setup.py requirements
|
||||
|
||||
### Gtk UI
|
||||
|
||||
- Add detection of torrent URL on GTK UI focus
|
||||
- Fix piecesbar crashing when enabled
|
||||
- Remove num_blocks_cache_hits in stats
|
||||
- Fix unhandled error with empty clipboard
|
||||
- Add torrentdetails tabs position menu (#3441)
|
||||
- Hide pygame community banner in console
|
||||
- Fix cmp function for None types (#3309)
|
||||
- Fix loading config with double-quotes in string
|
||||
- Fix Status tab download speed and uploaded
|
||||
|
||||
### Web UI
|
||||
|
||||
- Handle torrent add failures
|
||||
- Add menu option to copy magnet URI
|
||||
- Fix md5sums in torrent files breaking file listing (#3388)
|
||||
- Add country flag alt/title for accessibility
|
||||
|
||||
### Console UI
|
||||
|
||||
- Fix allowing use of windows-curses on Windows
|
||||
- Fix hostlist status lookup errors
|
||||
- Fix AttributeError setting config values
|
||||
- Fix setting 'Skip' priority
|
||||
|
||||
### Core
|
||||
|
||||
- Add workaround libtorrent 2.0 file_progress error
|
||||
- Fix allow enabling any plugin Python version
|
||||
- Export torrent get_magnet_uri method
|
||||
- Fix loading magnet with resume_data and no metadata (#3478)
|
||||
- Fix httpdownloader reencoding torrent file downloads (#3440)
|
||||
- Fix lt listen_interfaces not comma-separated (#3337)
|
||||
- Fix unable to remove magnet with delete_copies enabled (#3325)
|
||||
- Fix Python 3.8 compatibility
|
||||
- Fix loading config with double-quotes in string
|
||||
- Fix pickle loading non-ascii state error (#3298)
|
||||
- Fix creation of pidfile via command option
|
||||
- Fix for peer.client UnicodeDecodeError
|
||||
- Fix show_file unhandled dbus error
|
||||
|
||||
### Documentation
|
||||
|
||||
- Add How-to guides about services.
|
||||
|
||||
### Stats plugin
|
||||
|
||||
- Fix constant session status key warnings
|
||||
- Fix cairo error
|
||||
|
||||
### Notifications plugin
|
||||
|
||||
- Fix email KeyError with status name
|
||||
- Fix unhandled TypeErrors on Python 3
|
||||
|
||||
### Autoadd plugin
|
||||
|
||||
- Fix magnet missing applied labels
|
||||
|
||||
### Execute plugin
|
||||
|
||||
- Fix failing to run on Windows (#3439)
|
||||
|
||||
## 2.0.3 (2019-06-12)
|
||||
|
||||
### Gtk UI
|
||||
|
||||
- Fix errors running on Wayland (#3265).
|
||||
- Fix Peers Tab tooltip and context menu errors (#3266).
|
||||
|
||||
### Web UI
|
||||
|
||||
- Fix TypeError in Peers Tab setting country flag.
|
||||
- Fix reverse proxy header TypeError (#3260).
|
||||
- Fix request.base 'idna' codec error (#3261).
|
||||
- Fix unable to change password (#3262).
|
||||
|
||||
### Extractor plugin
|
||||
|
||||
- Fix potential error starting plugin.
|
||||
|
||||
### Documentation
|
||||
|
||||
- Fix macOS install typo.
|
||||
- Fix Windows install instructions.
|
||||
|
||||
## 2.0.2 (2019-06-08)
|
||||
|
||||
### Packaging
|
||||
|
||||
- Add systemd deluged and deluge-web service files to package tarball (#2034)
|
||||
|
||||
### Core
|
||||
|
||||
- Fix Python 2 compatibility issue with SimpleNamespace.
|
||||
|
||||
## 2.0.1 (2019-06-07)
|
||||
|
||||
### Packaging
|
||||
|
||||
- Fix `setup.py` build error without git installed.
|
||||
|
||||
## 2.0.0 (2019-06-06)
|
||||
|
||||
### Codebase
|
||||
|
||||
- Ported to Python 3
|
||||
|
||||
### Core
|
||||
|
||||
- Improved Logging
|
||||
- Removed the AutoAdd feature on the core. It's now handled with the AutoAdd
|
||||
plugin, which is also shipped with Deluge, and it does a better job and
|
||||
now, it even supports multiple users perfectly.
|
||||
- Authentication/Permission exceptions are now sent to clients and recreated
|
||||
there to allow acting upon them.
|
||||
- Updated SSL/TLS Protocol parameters for better security.
|
||||
- Make the distinction between adding to the session new unmanaged torrents
|
||||
and torrents loaded from state. This will break backwards compatibility.
|
||||
- Pass a copy of an event instead of passing the event arguments to the
|
||||
event handlers. This will break backwards compatibility.
|
||||
- Allow changing ownership of torrents.
|
||||
- File modifications on the auth file are now detected and when they happen,
|
||||
the file is reloaded. Upon finding an old auth file with an old format, an
|
||||
upgrade to the new format is made, file saved, and reloaded.
|
||||
- Authentication no longer requires a username/password. If one or both of
|
||||
these is missing, an authentication error will be sent to the client
|
||||
which should then ask the username/password to the user.
|
||||
- Implemented sequential downloads.
|
||||
- Provide information about a torrent's pieces states
|
||||
- Add Option To Specify Outgoing Connection Interface.
|
||||
- Fix potential for host_id collision when creating hostlist entries.
|
||||
|
||||
### Gtk UI
|
||||
|
||||
- Ported to GTK3 (3rd-party plugins will need updated).
|
||||
- Allow changing ownership of torrents.
|
||||
- Host entries in the Connection Manager UI are now editable.
|
||||
- Implemented sequential downloads UI handling.
|
||||
- Add optional pieces bar instead of a regular progress bar in torrent status tab.
|
||||
- Make torrent opening compatible with all Unicode paths.
|
||||
- Fix magnet association button on Windows.
|
||||
- Add keyboard shortcuts for changing queue position:
|
||||
- Up: `Ctrl+Alt+Up`
|
||||
- Down: `Ctrl+Alt+Down`
|
||||
- Top: `Ctrl+Alt+Shift+Up`
|
||||
- Bottom: `Ctrl+Alt+Shift+Down`
|
||||
|
||||
### Web UI
|
||||
|
||||
- Server (deluge-web) now daemonizes by default, use '-d' or '--do-not-daemonize' to disable.
|
||||
- Fixed the '--base' option to work for regular use, not just with reverse proxies.
|
||||
|
||||
### Blocklist Plugin
|
||||
|
||||
- Implemented whitelist support to both core and GTK UI.
|
||||
- Implemented IP filter cleaning before each update. Restarting the deluge
|
||||
daemon is no longer needed.
|
||||
- If "check_after_days" is 0(zero), the timer is not started anymore. It
|
||||
would keep updating one call after the other. If the value changed, the
|
||||
timer is now stopped and restarted using the new value.
|
||||
149
ChangeLog
Normal file
149
ChangeLog
Normal file
@ -0,0 +1,149 @@
|
||||
=== Deluge 1.3.0 (In Development) ===
|
||||
* Improved Logging
|
||||
* Removed the AutoAdd feature on the core. It's now handled with the AutoAdd
|
||||
plugin, which is also shipped with Deluge, and it does a better job and
|
||||
now, it even supports multiple users perfectly.
|
||||
* Authentication/Permission exceptions are now sent to clients and recreated
|
||||
there to allow acting upon them.
|
||||
* Enforced the use of the "deluge.plugins" namespace to reduce package
|
||||
names clashing beetween regular packages and deluge plugins.
|
||||
|
||||
==== Core ====
|
||||
* Implement #1063 option to delete torrent file copy on torrent removal - patch from Ghent
|
||||
* Implement #457 progress bars for folders
|
||||
* Implement #1012 httpdownloader supports gzip decoding
|
||||
* #496: Remove deprecated functions in favour of get_session_status()
|
||||
* #1112: Fix renaming files in add torrent dialog
|
||||
* #1247: Fix deluge-gtk from hanging on shutdown
|
||||
* #995: Rewrote tracker_icons
|
||||
* Make the distinction between adding to the session new unmanaged torrents
|
||||
and torrents loaded from state. This will break backwards compatability.
|
||||
* Pass a copy of an event instead of passing the event arguments to the
|
||||
event handlers. This will break backwards compatability.
|
||||
* Allow changing ownership of torrents.
|
||||
* File modifications on the auth file are now detected and when they happen,
|
||||
the file is reloaded. Upon finding an old auth file with an old format, an
|
||||
upgrade to the new format is made, file saved, and reloaded.
|
||||
* Authentication no longer requires a username/password. If one or both of
|
||||
these is missing, an authentication error will be sent to the client
|
||||
which sould then ask the username/password to the user.
|
||||
* Implemented sequential downloads.
|
||||
* #378: Provide information about a torrent's pieces states
|
||||
|
||||
==== GtkUI ====
|
||||
* Fix uncaught exception when closing deluge in classic mode
|
||||
* Allow changing ownership of torrents
|
||||
* Host entries in the Connection Manager UI are now editable. They're
|
||||
now also migrated from the old format were automatic localhost logins were
|
||||
possible, which no longer is, this fixes #1814.
|
||||
* Implemented sequential downloads UI handling.
|
||||
* #378: Allow showing a pieces bar instead of a regular progress bar in a
|
||||
torrent's status tab.
|
||||
|
||||
==== WebUI ====
|
||||
* Migrate to ExtJS 3.1
|
||||
* Add gzip compression of HTTP data to the server
|
||||
* Improve the efficiency of the TorrentGrid
|
||||
|
||||
==== Blocklist ====
|
||||
* Implement local blocklist support
|
||||
* #861: Pause transfers until blocklist is imported
|
||||
|
||||
=== Deluge 1.2.0 - "Bursting like an infected kidney" (10 January 2010) ===
|
||||
==== Core ====
|
||||
* Implement new RPC protocol DelugeRPC replacing XMLRPC
|
||||
* Move to a twisted framework
|
||||
* Add an 'Error' filter for Trackers to show trackers that currently have a tracker error
|
||||
* Use system GeoIP database if available, this is now an optional dependency
|
||||
|
||||
==== GtkUI ====
|
||||
* Remove SignalReceiver
|
||||
* Implemented a cross-platform IPC method thus removing the DBUS dependency
|
||||
* Implement a "True" Classic Mode where there is no longer a separate daemon process
|
||||
* Add preferences option "Add torrent in paused state"
|
||||
* Add tracker icons to the Tracker column
|
||||
* Implement #259 show tooltip with country name in the peers tab
|
||||
* Add an error category to the tracker sidebar list
|
||||
* Add Find More Plugins button to Plugins preference page
|
||||
* Fix #518 remove header in add torrent dialog to save vertical space
|
||||
* Add a Cache preferences page to adjust cache settings and examine cache status
|
||||
* Add ability to rename files prior to adding them
|
||||
* Fix shutdown handler with GNOME session manager
|
||||
* Allow 4 MiB piece sizes when creating a torrent
|
||||
|
||||
==== ConsoleUI ====
|
||||
* Changed to use curses for a more interactive client
|
||||
|
||||
==== WebUI ====
|
||||
* Move over to using Twisted-Web for the webserver.
|
||||
* Move to only AJAX interface built upon Ext-JS.
|
||||
|
||||
==== Plugins ====
|
||||
* Add Scheduler plugin
|
||||
* Add Extractor plugin
|
||||
|
||||
==== Misc ====
|
||||
* PyGTK dependency bumped to => 2.12 to use new tooltip system
|
||||
* Add new scripts for invoking UIs: deluge-gtk, deluge-web, deluge-console
|
||||
* Remove GeoIP database from the source tree
|
||||
|
||||
=== Deluge 1.1.0 - "Time gas!" (10 January 2009) ===
|
||||
==== Core ====
|
||||
* Implement #79 ability to change outgoing port range
|
||||
* Implement #296 ability to change peer TOS byte
|
||||
* Add per-torrent move on completed settings
|
||||
* Implement #414 use async save_resume_data method
|
||||
* Filter Manager with torrent filtering in get_torrents_status , for sidebar and plugins.
|
||||
* Implement #368 add torrents by infohash/magnet uri (trackerless torrents)
|
||||
* Remove remaining gtk functions in common
|
||||
* Tracker icons.
|
||||
* Add ETA for torrents with stop at seed ratio set
|
||||
* Fix #47 the state and config files are no longer invalidated when there is no diskspace
|
||||
* Fix #619 return "" instead of "Infinity" if seconds == 0 in ftime
|
||||
* Add -P, --pidfile option to deluged
|
||||
|
||||
==== GtkUI ====
|
||||
* Add peer progress to the peers tab
|
||||
* Add ability to manually add peers
|
||||
* Sorting # column will place downloaders above seeds
|
||||
* Remove dependency on libtorrent for add torrent dialog
|
||||
* Allow adding multiple trackers at once in the edit tracker dialog
|
||||
* Implement #28 Create Torrent Dialog
|
||||
* Redesiged sidebar with filters for Active and Tracker (see Filter Manager)
|
||||
* Implement #428 the ability to rename files and directories
|
||||
* Implement #229 add date added column
|
||||
* Implement #596 show speeds in title
|
||||
* Fix #636 not setting the daemon's config directory when using --config= with the UI in classic mode.
|
||||
* Fix #624 do not allow changing file priorities when using compact allocation
|
||||
* Fix #602 re-did files/peers tab state saving/loading
|
||||
* Fix gtk warnings
|
||||
* Add protocol traffic statusbar item
|
||||
* Rework the Remove Torrent Dialog to only have 2 options, remove data and remove from session.
|
||||
* Add "Install Plugin" and "Rescan Plugins" buttons to the Plugins preferences
|
||||
* Make active port test use internal graphic instead of launching browser
|
||||
|
||||
==== WebUI ====
|
||||
* Lots of smaller tweaks.
|
||||
* All details tabs have the same features as in gtk-ui 1.0.x
|
||||
* Persistent sessions #486
|
||||
* Plugin improvements for easy use of templates and images in eggs. #497
|
||||
* Classic template takes over some style elements from white template.
|
||||
* https (for users that know how to create certificates)
|
||||
* Easier apache mod_proxy use.
|
||||
* Redesigned sidebar
|
||||
|
||||
==== AjaxUI ====
|
||||
* Hosted in a webui template.
|
||||
|
||||
==== ConsoleUI ====
|
||||
* New ConsoleUI written by Idoa01
|
||||
* Callable from command-line for scripts.
|
||||
|
||||
==== Plugins ====
|
||||
* Stats plugin for graphs.
|
||||
* Label plugin for grouping torrents and per torrent settings.
|
||||
|
||||
==== Misc ====
|
||||
* Implement #478 display UI options in usage help
|
||||
* Fix #547 add description to name field per HIG entry 2.1.1.1
|
||||
* Fix #531 set default log level to ERROR and add 2 command-line options, "-L, --loglevel" and "-q, --quiet".
|
||||
29
DEPENDS
Normal file
29
DEPENDS
Normal file
@ -0,0 +1,29 @@
|
||||
=== Core ===
|
||||
* python >= 2.5
|
||||
* twisted >= 8.1
|
||||
* twisted-web >= 8.1
|
||||
* pyopenssl
|
||||
* simplejson (if python < 2.6)
|
||||
* setuptools
|
||||
* gettext
|
||||
* intltool
|
||||
* pyxdg
|
||||
* chardet
|
||||
* geoip-database (optional)
|
||||
|
||||
* libtorrent >= 0.14, or build the included version
|
||||
|
||||
* If building included libtorrent::
|
||||
* boost >= 1.34.1
|
||||
* openssl
|
||||
* zlib
|
||||
|
||||
=== Gtk ===
|
||||
* python-notify (libnotify python wrapper)
|
||||
* pygame
|
||||
* pygtk >= 2.12
|
||||
* librsvg
|
||||
* xdg-utils
|
||||
|
||||
=== Web ===
|
||||
* mako
|
||||
100
DEPENDS.md
100
DEPENDS.md
@ -1,100 +0,0 @@
|
||||
# Deluge dependencies
|
||||
|
||||
The following are required to install and run Deluge. They are separated into
|
||||
sections to distinguish the precise requirements for each module.
|
||||
|
||||
All modules will require the [common](#common) section dependencies.
|
||||
|
||||
## Prerequisite
|
||||
|
||||
- [Python] _>= 3.6_
|
||||
|
||||
## Build
|
||||
|
||||
- [setuptools]
|
||||
- [intltool] - Optional: Desktop file translation for \*nix.
|
||||
- [closure-compiler] - Minify javascript (alternative is [rjsmin])
|
||||
|
||||
## Common
|
||||
|
||||
- [Twisted] _>= 17.1_ - Use `TLS` extras for `service_identity` and `idna`.
|
||||
- [OpenSSL] _>= 1.0.1_
|
||||
- [pyOpenSSL]
|
||||
- [rencode] _>= 1.0.2_ - Encoding library.
|
||||
- [PyXDG] - Access freedesktop.org standards for \*nix.
|
||||
- [xdg-utils] - Provides xdg-open for \*nix.
|
||||
- [zope.interface]
|
||||
- [chardet] - Optional: Encoding detection.
|
||||
- [setproctitle] - Optional: Renaming processes.
|
||||
- [Pillow] - Optional: Support for resizing tracker icons.
|
||||
- [dbus-python] - Optional: Show item location in filemanager.
|
||||
- [ifaddr] - Optional: Verify network interfaces.
|
||||
|
||||
### Linux and BSD
|
||||
|
||||
- [distro] - Optional: OS platform information.
|
||||
|
||||
### Windows OS
|
||||
|
||||
- [pywin32]
|
||||
- [certifi]
|
||||
|
||||
## Core (deluged daemon)
|
||||
|
||||
- [libtorrent] _>= 1.2.0_
|
||||
- [GeoIP] or [pygeoip] - Optional: IP address country lookup. (_Debian: `python-geoip`_)
|
||||
|
||||
## GTK UI
|
||||
|
||||
- [GTK+] >= 3.10
|
||||
- [PyGObject]
|
||||
- [Pycairo]
|
||||
- [librsvg] _>= 2_
|
||||
- [libappindicator3] w/GIR - Optional: Ubuntu system tray icon.
|
||||
|
||||
### MacOS
|
||||
|
||||
- [GtkOSXApplication]
|
||||
|
||||
## Web UI
|
||||
|
||||
- [mako]
|
||||
|
||||
## Plugins
|
||||
|
||||
### Notifications
|
||||
|
||||
- [pygame] - Optional: Play sounds
|
||||
- [libnotify] w/GIR - Optional: Desktop popups.
|
||||
|
||||
[python]: https://www.python.org/
|
||||
[setuptools]: https://setuptools.readthedocs.io/en/latest/
|
||||
[intltool]: https://freedesktop.org/wiki/Software/intltool/
|
||||
[closure-compiler]: https://developers.google.com/closure/compiler/
|
||||
[rjsmin]: https://pypi.org/project/rjsmin/
|
||||
[openssl]: https://www.openssl.org/
|
||||
[pyopenssl]: https://pyopenssl.org
|
||||
[twisted]: https://twistedmatrix.com
|
||||
[pillow]: https://pypi.org/project/Pillow/
|
||||
[libtorrent]: https://libtorrent.org/
|
||||
[zope.interface]: https://pypi.org/project/zope.interface/
|
||||
[distro]: https://github.com/nir0s/distro
|
||||
[pywin32]: https://github.com/mhammond/pywin32
|
||||
[certifi]: https://pypi.org/project/certifi/
|
||||
[dbus-python]: https://pypi.org/project/dbus-python/
|
||||
[setproctitle]: https://pypi.org/project/setproctitle/
|
||||
[gtkosxapplication]: https://github.com/jralls/gtk-mac-integration
|
||||
[chardet]: https://chardet.github.io/
|
||||
[rencode]: https://github.com/aresch/rencode
|
||||
[pyxdg]: https://www.freedesktop.org/wiki/Software/pyxdg/
|
||||
[xdg-utils]: https://www.freedesktop.org/wiki/Software/xdg-utils/
|
||||
[gtk+]: https://www.gtk.org/
|
||||
[pycairo]: https://cairographics.org/pycairo/
|
||||
[pygobject]: https://pygobject.readthedocs.io/en/latest/
|
||||
[geoip]: https://pypi.org/project/GeoIP/
|
||||
[mako]: https://www.makotemplates.org/
|
||||
[pygame]: https://www.pygame.org/
|
||||
[libnotify]: https://developer.gnome.org/libnotify/
|
||||
[python-appindicator]: https://packages.ubuntu.com/xenial/python-appindicator
|
||||
[librsvg]: https://wiki.gnome.org/action/show/Projects/LibRsvg
|
||||
[ifaddr]: https://pypi.org/project/ifaddr/
|
||||
46
MANIFEST.in
46
MANIFEST.in
@ -1,36 +1,12 @@
|
||||
include *.md
|
||||
include AUTHORS
|
||||
include LICENSE
|
||||
include RELEASE-VERSION
|
||||
include msgfmt.py
|
||||
include minify_web_js.py
|
||||
include version.py
|
||||
include gen_web_gettext.py
|
||||
recursive-include docs/man *
|
||||
recursive-include deluge *
|
||||
recursive-include win32 *
|
||||
|
||||
graft docs/man
|
||||
graft packaging/systemd
|
||||
|
||||
include deluge/i18n/*.po
|
||||
recursive-exclude deluge/i18n *.mo
|
||||
|
||||
graft deluge/plugins
|
||||
recursive-exclude deluge/plugins create_dev_link.sh *.pyc *.egg
|
||||
prune deluge/plugins/*/build
|
||||
prune deluge/plugins/*/*.egg-info
|
||||
|
||||
graft deluge/tests/
|
||||
recursive-exclude deluge/tests *.pyc
|
||||
|
||||
graft deluge/ui/data
|
||||
recursive-exclude deluge/ui/data *.desktop *.xml
|
||||
graft deluge/ui/gtk3/glade
|
||||
|
||||
include deluge/ui/web/index.html
|
||||
include deluge/ui/web/css/*.css
|
||||
include deluge/ui/web/js/*.js
|
||||
graft deluge/ui/web/js/deluge-all/
|
||||
graft deluge/ui/web/js/extjs/
|
||||
graft deluge/ui/web/themes
|
||||
graft deluge/ui/web/render
|
||||
graft deluge/ui/web/icons
|
||||
graft deluge/ui/web/images
|
||||
recursive-exclude deluge *.egg-link
|
||||
exclude deluge/ui/web/gen_gettext.py
|
||||
exclude deluge/ui/web/css/*-debug.css
|
||||
exclude deluge/ui/web/js/build.sh
|
||||
exclude deluge/ui/web/js/Deluge*.js
|
||||
exclude deluge/ui/web/js/*-debug.js
|
||||
prune deluge/ui/web/docs
|
||||
prune deluge/scripts
|
||||
|
||||
94
README
Normal file
94
README
Normal file
@ -0,0 +1,94 @@
|
||||
|
||||
==========================
|
||||
Deluge BitTorrent Client
|
||||
==========================
|
||||
|
||||
Homepage: http://deluge-torrent.org
|
||||
|
||||
Authors:
|
||||
Andrew Resch
|
||||
Damien Churchill
|
||||
|
||||
For past developers and contributers see: http://dev.deluge-torrent.org/wiki/About
|
||||
|
||||
==========================
|
||||
License
|
||||
==========================
|
||||
Deluge is under the GNU GPLv3 license.
|
||||
Icon ui/data/pixmaps/deluge.svg and derivatives in ui/data/icons are copyright
|
||||
Andrew Wedderburn and are under the GNU GPLv3.
|
||||
All other icons in ui/data/pixmaps are copyright Andrew Resch and are under
|
||||
the GNU GPLv3.
|
||||
|
||||
==========================
|
||||
Contact/Support:
|
||||
==========================
|
||||
|
||||
We have two options available for support:
|
||||
|
||||
Our Forum, at: http://forum.deluge-torrent.org
|
||||
or
|
||||
Our IRC Channel, at #deluge on Freenode: http://freenode.net
|
||||
|
||||
==========================
|
||||
Installation Instructions:
|
||||
==========================
|
||||
|
||||
For more detailed instructions see: http://dev.deluge-torrent.org/wiki/Installing/Source
|
||||
|
||||
See: DEPENDS for a full list of dependencies.
|
||||
|
||||
First, make sure you have the proper build dependencies installed. On a normal
|
||||
Debian or Ubuntu system:
|
||||
|
||||
sudo apt-get install g++ make python-all-dev python-all python-dbus \
|
||||
python-gtk2 python-notify librsvg2-common python-xdg python-support \
|
||||
subversion libboost-dev libboost-python-dev \
|
||||
libboost-thread-dev libboost-date-time-dev libboost-filesystem-dev \
|
||||
libssl-dev zlib1g-dev python-setuptools \
|
||||
python-mako python-twisted-web python-chardet python-simplejson
|
||||
|
||||
The names of the packages may vary depending on your OS / distro.
|
||||
|
||||
Once you have the needed libraries installed, build and install by running:
|
||||
|
||||
$ python setup.py build
|
||||
$ sudo python setup.py install
|
||||
|
||||
==========================
|
||||
FAQ
|
||||
==========================
|
||||
|
||||
How to start the various user-interfaces
|
||||
|
||||
Gtk:
|
||||
deluge-gtk
|
||||
Console:
|
||||
deluge-console
|
||||
Web:
|
||||
deluge-web
|
||||
Go to http://localhost:8112/ default-password = "deluge"
|
||||
|
||||
Why is deluge still listed in my system tray even after I close it ?
|
||||
|
||||
You closed the gtk user-interface but you did not close the daemon. Choose "Quit & Shutdown Daemon" to close both Daemon and gtk-ui.
|
||||
|
||||
How do I start the daemon?
|
||||
|
||||
deluged
|
||||
|
||||
How do I start the daemon with logging to console?
|
||||
|
||||
deluged -d -L <log level>
|
||||
|
||||
I can't connect to the daemon from another machine
|
||||
|
||||
* Configure the daemon to allow remote connections
|
||||
* Add a user to the auth file located in the config folder: ~/.config/deluge/auth
|
||||
* Restart the daemon.
|
||||
|
||||
I upgraded from 0.5 and plugin x is missing
|
||||
|
||||
1.0 is a rewrite, all old 0.5 plugins have to be rewritten.
|
||||
|
||||
For the full FAQ see: http://dev.deluge-torrent.org/wiki/Faq
|
||||
71
README.md
71
README.md
@ -1,71 +0,0 @@
|
||||
# Deluge BitTorrent Client
|
||||
|
||||
[![build-status]][github-ci] [![docs-status]][rtd-deluge]
|
||||
|
||||
Deluge is a BitTorrent client that utilizes a daemon/client model.
|
||||
It has various user interfaces available such as the GTK-UI, Web-UI and
|
||||
Console-UI. It uses [libtorrent][lt] at its core to handle the BitTorrent
|
||||
protocol.
|
||||
|
||||
## Install
|
||||
|
||||
From [PyPi](https://pypi.org/project/deluge):
|
||||
|
||||
pip install deluge
|
||||
|
||||
with all optional dependencies:
|
||||
|
||||
pip install deluge[all]
|
||||
|
||||
From source code:
|
||||
|
||||
pip install .
|
||||
|
||||
with all optional dependencies:
|
||||
|
||||
pip install .[all]
|
||||
|
||||
See [DEPENDS](DEPENDS.md) and [Installing/Source] for dependency details.
|
||||
|
||||
## Usage
|
||||
|
||||
The various user-interfaces and Deluge daemon can be started with the following commands.
|
||||
|
||||
Use the `--help` option for further command options.
|
||||
|
||||
### Gtk UI
|
||||
|
||||
`deluge` or `deluge-gtk`
|
||||
|
||||
### Console UI
|
||||
|
||||
`deluge-console`
|
||||
|
||||
### Web UI
|
||||
|
||||
`deluge-web`
|
||||
|
||||
Open http://localhost:8112 with default password `deluge`.
|
||||
|
||||
### Daemon
|
||||
|
||||
`deluged`
|
||||
|
||||
See the [Thinclient guide] to connect to the daemon from another computer.
|
||||
|
||||
## Contact
|
||||
|
||||
- [Homepage](https://deluge-torrent.org)
|
||||
- [User guide][user guide]
|
||||
- [Forum](https://forum.deluge-torrent.org)
|
||||
- [IRC Libera.Chat #deluge](irc://irc.libera.chat/deluge)
|
||||
- [Discord](https://discord.gg/nwaHSE6tqn)
|
||||
|
||||
[user guide]: https://dev.deluge-torrent.org/wiki/UserGuide
|
||||
[thinclient guide]: https://dev.deluge-torrent.org/wiki/UserGuide/ThinClient
|
||||
[installing/source]: https://dev.deluge-torrent.org/wiki/Installing/Source
|
||||
[build-status]: https://github.com/deluge-torrent/deluge/actions/workflows/ci.yml/badge.svg?branch=develop "CI"
|
||||
[github-ci]: https://github.com/deluge-torrent/deluge/actions/workflows/ci.yml
|
||||
[docs-status]: https://readthedocs.org/projects/deluge/badge/?version=latest
|
||||
[rtd-deluge]: https://deluge.readthedocs.io/en/latest/?badge=latest "Documentation Status"
|
||||
[lt]: https://libtorrent.org
|
||||
21
check_glade.sh
Executable file
21
check_glade.sh
Executable file
@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Fixes glade files which may have set gtk stock labels set to translatable
|
||||
for x in `find . -name '*.glade' |grep -v '.git\|build'` ; do \
|
||||
for y in gtk-add gtk-apply gtk-bold gtk-cancel gtk-cdrom gtk-clear \
|
||||
gtk-close gtk-color-picker gtk-connect gtk-convert gtk-copy gtk-cut \
|
||||
gtk-delete gtk-dialog-error gtk-dialog-info gtk-dialog-question \
|
||||
gtk-dialog-warning gtk-dnd gtk-dnd-multiple gtk-edit gtk-execute gtk-find \
|
||||
gtk-find-and-replace gtk-floppy gtk-goto-bottom gtk-goto-first \
|
||||
gtk-goto-last gtk-goto-top gtk-go-back gtk-go-down gtk-go-forward \
|
||||
gtk-go-up gtk-help gtk-home gtk-index gtk-italic gtk-jump-to \
|
||||
gtk-justify-center gtk-justify-fill gtk-justify-left gtk-missing-image \
|
||||
gtk-new gtk-no gtk-ok gtk-open gtk-paste gtk-preferences gtk-print \
|
||||
gtk-print-preview gtk-properties gtk-quit gtk-redo gtk-refresh \
|
||||
gtk-remove gtk-revert-to-saved gtk-save gtk-save-as gtk-select-color \
|
||||
gtk-select-font gtk-sort-descending gtk-spell-check gtk-stop \
|
||||
gtk-strikethrough gtk-undelete gtk-underline gtk-undo gtk-yes \
|
||||
gtk-zoom-100 gtk-zoom-fit gtk-zoom-in gtk-zoom-out; do \
|
||||
sed -i "s/<property\ name\=\"label\"\ translatable\=\"yes\">$y<\/property>/<property\ name\=\"label\"\ translatable\=\"no\">$y<\/property>/g" $x; \
|
||||
done;\
|
||||
done
|
||||
32
create_potfiles_in.py
Executable file
32
create_potfiles_in.py
Executable file
@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env python
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
# Paths to exclude
|
||||
EXCLUSIONS = [
|
||||
"deluge/scripts",
|
||||
"deluge/i18n",
|
||||
]
|
||||
|
||||
POTFILE_IN = "deluge/i18n/POTFILES.in"
|
||||
|
||||
pattern = "deluge\/plugins\/.*\/build"
|
||||
compiled = re.compile(pattern)
|
||||
|
||||
sys.stdout.write("Creating " + POTFILE_IN + " ... ")
|
||||
sys.stdout.flush()
|
||||
to_translate = []
|
||||
for (dirpath, dirnames, filenames) in os.walk("deluge"):
|
||||
for filename in filenames:
|
||||
if os.path.splitext(filename)[1] in (".py", ".glade", ".in") \
|
||||
and dirpath not in EXCLUSIONS \
|
||||
and not compiled.match(dirpath):
|
||||
to_translate.append(os.path.join(dirpath, filename))
|
||||
|
||||
f = open(POTFILE_IN, "wb")
|
||||
for line in to_translate:
|
||||
f.write(line + "\n")
|
||||
|
||||
f.close()
|
||||
|
||||
print "Done"
|
||||
6
createicons.sh
Executable file
6
createicons.sh
Executable file
@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
for size in 16 22 24 32 36 48 64 72 96 128 192 256; do mkdir -p deluge/ui/data/\
|
||||
icons/hicolor/${size}x${size}/apps; rsvg-convert -w ${size} -h ${size} \
|
||||
-o deluge/ui/data/icons/hicolor/${size}x${size}/apps/deluge.png deluge/ui/data/pixmaps\
|
||||
/deluge.svg; mkdir -p deluge/ui/data/icons/scalable/apps/; cp deluge/ui/data/pixmaps/\
|
||||
deluge.svg deluge/ui/data/icons/scalable/apps/deluge.svg; done
|
||||
@ -1 +1,4 @@
|
||||
"""Deluge"""
|
||||
# this is a namespace package
|
||||
import pkg_resources
|
||||
pkg_resources.declare_namespace(__name__)
|
||||
|
||||
20
deluge/__rpcapi.py
Normal file
20
deluge/__rpcapi.py
Normal file
@ -0,0 +1,20 @@
|
||||
from new import classobj
|
||||
from deluge.core.core import Core
|
||||
from deluge.core.daemon import Daemon
|
||||
|
||||
class RpcApi:
|
||||
pass
|
||||
|
||||
def scan_for_methods(obj):
|
||||
methods = {
|
||||
'__doc__': 'Methods available in %s' % obj.__name__.lower()
|
||||
}
|
||||
for d in dir(obj):
|
||||
if not hasattr(getattr(obj,d), '_rpcserver_export'):
|
||||
continue
|
||||
methods[d] = getattr(obj, d)
|
||||
cobj = classobj(obj.__name__.lower(), (object,), methods)
|
||||
setattr(RpcApi, obj.__name__.lower(), cobj)
|
||||
|
||||
scan_for_methods(Core)
|
||||
scan_for_methods(Daemon)
|
||||
@ -1,35 +1,60 @@
|
||||
#
|
||||
# _libtorrent.py
|
||||
#
|
||||
# Copyright (C) 2009 Andrew Resch <andrewresch@gmail.com>
|
||||
#
|
||||
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
|
||||
# the additional special exception to link portions of this program with the OpenSSL library.
|
||||
# See LICENSE for more details.
|
||||
# Deluge is free software.
|
||||
#
|
||||
# You may redistribute it and/or modify it under the terms of the
|
||||
# GNU General Public License, as published by the Free Software
|
||||
# Foundation; either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# deluge is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with deluge. If not, write to:
|
||||
# The Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor
|
||||
# Boston, MA 02110-1301, USA.
|
||||
#
|
||||
# In addition, as a special exception, the copyright holders give
|
||||
# permission to link the code of portions of this program with the OpenSSL
|
||||
# library.
|
||||
# You must obey the GNU General Public License in all respects for all of
|
||||
# the code used other than OpenSSL. If you modify file(s) with this
|
||||
# exception, you may extend this exception to your version of the file(s),
|
||||
# but you are not obligated to do so. If you do not wish to do so, delete
|
||||
# this exception statement from your version. If you delete this exception
|
||||
# statement from all source files in the program, then also delete it here.
|
||||
#
|
||||
#
|
||||
|
||||
"""
|
||||
This module is used to handle the importing of libtorrent and also controls
|
||||
the minimum versions of libtorrent that this version of Deluge supports.
|
||||
This module is used to handle the importing of libtorrent.
|
||||
|
||||
Example:
|
||||
>>> from deluge._libtorrent import lt
|
||||
We use this module to control what versions of libtorrent this version of Deluge
|
||||
supports.
|
||||
|
||||
** Usage **
|
||||
|
||||
>>> from deluge._libtorrent import lt
|
||||
|
||||
"""
|
||||
from deluge.common import VersionSplit, get_version
|
||||
from deluge.error import LibtorrentImportError
|
||||
|
||||
REQUIRED_VERSION = "0.14.9.0"
|
||||
|
||||
def check_version(LT):
|
||||
from deluge.common import VersionSplit
|
||||
if VersionSplit(lt.version) < VersionSplit(REQUIRED_VERSION):
|
||||
raise ImportError("This version of Deluge requires libtorrent >=%s!" % REQUIRED_VERSION)
|
||||
|
||||
try:
|
||||
import deluge.libtorrent as lt
|
||||
check_version(lt)
|
||||
except ImportError:
|
||||
try:
|
||||
import libtorrent as lt
|
||||
except ImportError as ex:
|
||||
raise LibtorrentImportError('No libtorrent library found: %s' % (ex))
|
||||
|
||||
|
||||
REQUIRED_VERSION = '1.2.0.0'
|
||||
LT_VERSION = lt.__version__
|
||||
|
||||
if VersionSplit(LT_VERSION) < VersionSplit(REQUIRED_VERSION):
|
||||
raise LibtorrentImportError(
|
||||
f'Deluge {get_version()} requires libtorrent >= {REQUIRED_VERSION}'
|
||||
)
|
||||
import libtorrent as lt
|
||||
check_version(lt)
|
||||
|
||||
@ -1,384 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2007 Andrew Resch <andrewresch@gmail.com>
|
||||
#
|
||||
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
|
||||
# the additional special exception to link portions of this program with the OpenSSL library.
|
||||
# See LICENSE for more details.
|
||||
#
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
import os
|
||||
import platform
|
||||
import sys
|
||||
import textwrap
|
||||
|
||||
import deluge.log
|
||||
from deluge import common
|
||||
from deluge.configmanager import get_config_dir, set_config_dir
|
||||
|
||||
|
||||
def find_subcommand(self, args=None, sys_argv=True):
|
||||
"""Find if a subcommand has been supplied.
|
||||
|
||||
Args:
|
||||
args (list, optional): The argument list to search through.
|
||||
sys_argv (bool): Use sys.argv[1:] if args is None.
|
||||
|
||||
Returns:
|
||||
int: Index of the subcommand or '-1' if none found.
|
||||
|
||||
"""
|
||||
subcommand_found = -1
|
||||
if args is None:
|
||||
args = sys.argv[1:] if sys_argv is None else []
|
||||
|
||||
for x in self._subparsers._actions:
|
||||
if not isinstance(x, argparse._SubParsersAction):
|
||||
continue
|
||||
for sp_name in x._name_parser_map:
|
||||
if sp_name in args:
|
||||
subcommand_found = args.index(sp_name)
|
||||
|
||||
return subcommand_found
|
||||
|
||||
|
||||
def set_default_subparser(self, name, abort_opts=None):
|
||||
"""Sets the default argparse subparser.
|
||||
|
||||
Args:
|
||||
name (str): The name of the default subparser.
|
||||
abort_opts (list): The arguments to test for in case no subcommand is found.
|
||||
If any of the values are found, the default subparser will
|
||||
not be inserted into sys.argv.
|
||||
|
||||
Returns:
|
||||
list: The arguments found in sys.argv if no subcommand found, else None
|
||||
|
||||
"""
|
||||
found_abort_opts = []
|
||||
abort_opts = [] if abort_opts is None else abort_opts
|
||||
test_args = sys.argv[1:]
|
||||
subparser_found = self.find_subcommand(args=test_args)
|
||||
|
||||
for i, arg in enumerate(test_args):
|
||||
if subparser_found == i:
|
||||
break
|
||||
if arg in abort_opts:
|
||||
found_abort_opts.append(arg)
|
||||
|
||||
if subparser_found == -1:
|
||||
if found_abort_opts:
|
||||
# Found one or more of arguments in abort_opts
|
||||
return found_abort_opts
|
||||
|
||||
# insert default in first position, this implies no
|
||||
# global options without a sub_parsers specified
|
||||
sys.argv.insert(1, name)
|
||||
|
||||
return None
|
||||
|
||||
|
||||
argparse.ArgumentParser.find_subcommand = find_subcommand
|
||||
argparse.ArgumentParser.set_default_subparser = set_default_subparser
|
||||
|
||||
|
||||
def _get_version_detail():
|
||||
version_str = '%s\n' % (common.get_version())
|
||||
try:
|
||||
from deluge._libtorrent import LT_VERSION
|
||||
|
||||
version_str += 'libtorrent: %s\n' % LT_VERSION
|
||||
except ImportError:
|
||||
pass
|
||||
version_str += 'Python: %s\n' % platform.python_version()
|
||||
version_str += f'OS: {platform.system()} {common.get_os_version()}\n'
|
||||
return version_str
|
||||
|
||||
|
||||
class DelugeTextHelpFormatter(argparse.RawDescriptionHelpFormatter):
|
||||
"""Help message formatter which retains formatting of all help text."""
|
||||
|
||||
def _split_lines(self, text, width):
|
||||
"""
|
||||
Do not remove whitespaces in string but still wrap text to max width.
|
||||
Instead of passing the entire text to textwrap.wrap, split and pass each
|
||||
line instead. This way list formatting is not mangled by textwrap.wrap.
|
||||
"""
|
||||
wrapped_lines = []
|
||||
for line in text.splitlines():
|
||||
wrapped_lines.extend(textwrap.wrap(line, width, subsequent_indent=' '))
|
||||
return wrapped_lines
|
||||
|
||||
def _format_action_invocation(self, action):
|
||||
"""
|
||||
Combines the options with comma and displays the argument
|
||||
value only once instead of after both options.
|
||||
Instead of: -s <arg>, --long-opt <arg>
|
||||
Show : -s, --long-opt <arg>
|
||||
|
||||
"""
|
||||
if not action.option_strings:
|
||||
(metavar,) = self._metavar_formatter(action, action.dest)(1)
|
||||
return metavar
|
||||
else:
|
||||
parts = []
|
||||
# if the Optional doesn't take a value, format is:
|
||||
# -s, --long
|
||||
if action.nargs == 0:
|
||||
parts.extend(action.option_strings)
|
||||
|
||||
# if the Optional takes a value, format is:
|
||||
# -s, --long ARGS
|
||||
else:
|
||||
default = action.dest.upper()
|
||||
args_string = self._format_args(action, default)
|
||||
opt = ', '.join(action.option_strings)
|
||||
parts.append(f'{opt} {args_string}')
|
||||
return ', '.join(parts)
|
||||
|
||||
|
||||
class HelpAction(argparse._HelpAction):
|
||||
def __call__(self, parser, namespace, values, option_string=None):
|
||||
if hasattr(parser, 'subparser'):
|
||||
subparser = getattr(parser, 'subparser')
|
||||
subparser.print_help()
|
||||
else:
|
||||
parser.print_help()
|
||||
parser.exit()
|
||||
|
||||
|
||||
class ArgParserBase(argparse.ArgumentParser):
|
||||
def __init__(self, *args, **kwargs):
|
||||
if 'formatter_class' not in kwargs:
|
||||
kwargs['formatter_class'] = lambda prog: DelugeTextHelpFormatter(
|
||||
prog, max_help_position=33, width=90
|
||||
)
|
||||
|
||||
kwargs['add_help'] = kwargs.get('add_help', False)
|
||||
common_help = kwargs.pop('common_help', True)
|
||||
self.log_stream = sys.stdout
|
||||
if 'log_stream' in kwargs:
|
||||
self.log_stream = kwargs['log_stream']
|
||||
del kwargs['log_stream']
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self.common_setup = False
|
||||
self.process_arg_group = False
|
||||
self.group = self.add_argument_group(_('Common Options'))
|
||||
if common_help:
|
||||
self.group.add_argument(
|
||||
'-h', '--help', action=HelpAction, help=_('Print this help message')
|
||||
)
|
||||
self.group.add_argument(
|
||||
'-V',
|
||||
'--version',
|
||||
action='version',
|
||||
version='%(prog)s ' + _get_version_detail(),
|
||||
help=_('Print version information'),
|
||||
)
|
||||
self.group.add_argument(
|
||||
'-v',
|
||||
action='version',
|
||||
version='%(prog)s ' + _get_version_detail(),
|
||||
help=argparse.SUPPRESS,
|
||||
) # Deprecated arg
|
||||
self.group.add_argument(
|
||||
'-c',
|
||||
'--config',
|
||||
metavar='<config>',
|
||||
help=_('Set the config directory path'),
|
||||
)
|
||||
self.group.add_argument(
|
||||
'-l',
|
||||
'--logfile',
|
||||
metavar='<logfile>',
|
||||
help=_('Output to specified logfile instead of stdout'),
|
||||
)
|
||||
self.group.add_argument(
|
||||
'-L',
|
||||
'--loglevel',
|
||||
choices=[level for k in deluge.log.levels for level in (k, k.upper())],
|
||||
help=_('Set the log level (none, error, warning, info, debug)'),
|
||||
metavar='<level>',
|
||||
)
|
||||
self.group.add_argument(
|
||||
'--logrotate',
|
||||
nargs='?',
|
||||
const='2M',
|
||||
metavar='<max-size>',
|
||||
help=_(
|
||||
'Enable logfile rotation, with optional maximum logfile size, '
|
||||
'default: %(const)s (Logfile rotation count is 5)'
|
||||
),
|
||||
)
|
||||
self.group.add_argument(
|
||||
'-q',
|
||||
'--quiet',
|
||||
action='store_true',
|
||||
help=_('Quieten logging output (Same as `--loglevel none`)'),
|
||||
)
|
||||
self.group.add_argument(
|
||||
'--profile',
|
||||
metavar='<profile-file>',
|
||||
nargs='?',
|
||||
default=False,
|
||||
help=_(
|
||||
'Profile %(prog)s with cProfile. Outputs to stdout '
|
||||
'unless a filename is specified'
|
||||
),
|
||||
)
|
||||
|
||||
def parse_args(self, args=None):
|
||||
"""Parse UI arguments and handle common and process group options.
|
||||
|
||||
Notes:
|
||||
Unknown arguments results in usage text printed and system exit.
|
||||
|
||||
Args:
|
||||
args (list, optional): The arguments to parse.
|
||||
|
||||
Returns:
|
||||
argparse.Namespace: The parsed arguments.
|
||||
|
||||
"""
|
||||
options = super().parse_args(args=args)
|
||||
return self._handle_ui_options(options)
|
||||
|
||||
def parse_known_ui_args(self, args, withhold=None):
|
||||
"""Parse UI arguments and handle common and process group options without error.
|
||||
|
||||
Args:
|
||||
args (list): The arguments to parse.
|
||||
withhold (list): Values to ignore in the args list.
|
||||
|
||||
Returns:
|
||||
argparse.Namespace: The parsed arguments.
|
||||
|
||||
"""
|
||||
if withhold:
|
||||
args = [a for a in args if a not in withhold]
|
||||
options, remaining = super().parse_known_args(args=args)
|
||||
options.remaining = remaining
|
||||
# Handle common and process group options
|
||||
return self._handle_ui_options(options)
|
||||
|
||||
def _handle_ui_options(self, options):
|
||||
"""Handle UI common and process group options.
|
||||
|
||||
Args:
|
||||
options (argparse.Namespace): The parsed options.
|
||||
|
||||
Returns:
|
||||
argparse.Namespace: The parsed options.
|
||||
|
||||
"""
|
||||
if not self.common_setup:
|
||||
self.common_setup = True
|
||||
|
||||
# Setup the logger
|
||||
if options.quiet:
|
||||
options.loglevel = 'none'
|
||||
if options.loglevel:
|
||||
options.loglevel = options.loglevel.lower()
|
||||
|
||||
logfile_mode = 'w'
|
||||
logrotate = options.logrotate
|
||||
if options.logrotate:
|
||||
logfile_mode = 'a'
|
||||
logrotate = common.parse_human_size(options.logrotate)
|
||||
|
||||
# Setup the logger
|
||||
deluge.log.setup_logger(
|
||||
level=options.loglevel,
|
||||
filename=options.logfile,
|
||||
filemode=logfile_mode,
|
||||
logrotate=logrotate,
|
||||
output_stream=self.log_stream,
|
||||
)
|
||||
|
||||
if options.config:
|
||||
if not set_config_dir(options.config):
|
||||
log = logging.getLogger(__name__)
|
||||
log.error('There was an error setting the config dir! Exiting..')
|
||||
sys.exit(1)
|
||||
else:
|
||||
if not os.path.exists(common.get_default_config_dir()):
|
||||
os.makedirs(common.get_default_config_dir())
|
||||
|
||||
if self.process_arg_group:
|
||||
self.process_arg_group = False
|
||||
# If donotdaemonize is set, skip process forking.
|
||||
if not (common.windows_check() or options.donotdaemonize):
|
||||
if os.fork():
|
||||
os._exit(0)
|
||||
os.setsid()
|
||||
# Do second fork
|
||||
if os.fork():
|
||||
os._exit(0)
|
||||
# Ensure process doesn't keep any directory in use that may prevent a filesystem unmount.
|
||||
os.chdir(get_config_dir())
|
||||
|
||||
# Write pid file before chuid
|
||||
if options.pidfile:
|
||||
with open(options.pidfile, 'w') as _file:
|
||||
_file.write('%d\n' % os.getpid())
|
||||
|
||||
if not common.windows_check():
|
||||
if options.group:
|
||||
if not options.group.isdigit():
|
||||
import grp
|
||||
|
||||
options.group = grp.getgrnam(options.group)[2]
|
||||
os.setgid(options.group)
|
||||
if options.user:
|
||||
if not options.user.isdigit():
|
||||
import pwd
|
||||
|
||||
options.user = pwd.getpwnam(options.user)[2]
|
||||
os.setuid(options.user)
|
||||
|
||||
return options
|
||||
|
||||
def add_process_arg_group(self):
|
||||
"""Adds a grouping of common process args to control a daemon to the parser"""
|
||||
|
||||
self.process_arg_group = True
|
||||
self.group = self.add_argument_group(_('Process Control Options'))
|
||||
self.group.add_argument(
|
||||
'-P',
|
||||
'--pidfile',
|
||||
metavar='<pidfile>',
|
||||
action='store',
|
||||
help=_('Pidfile to store the process id'),
|
||||
)
|
||||
if not common.windows_check():
|
||||
self.group.add_argument(
|
||||
'-d',
|
||||
'--do-not-daemonize',
|
||||
dest='donotdaemonize',
|
||||
action='store_true',
|
||||
help=_('Do not daemonize (fork) this process'),
|
||||
)
|
||||
self.group.add_argument(
|
||||
'-f',
|
||||
'--fork',
|
||||
dest='donotdaemonize',
|
||||
action='store_false',
|
||||
help=argparse.SUPPRESS,
|
||||
) # Deprecated arg
|
||||
self.group.add_argument(
|
||||
'-U',
|
||||
'--user',
|
||||
metavar='<user>',
|
||||
action='store',
|
||||
help=_('Change to this user on startup (Requires root)'),
|
||||
)
|
||||
self.group.add_argument(
|
||||
'-g',
|
||||
'--group',
|
||||
metavar='<group>',
|
||||
action='store',
|
||||
help=_('Change to this group on startup (Requires root)'),
|
||||
)
|
||||
@ -9,140 +9,121 @@
|
||||
# License.
|
||||
|
||||
# Written by Petru Paler
|
||||
# Updated by Calum Lind to support Python 3.
|
||||
|
||||
|
||||
class BTFailure(Exception):
|
||||
pass
|
||||
|
||||
|
||||
DICT_DELIM = b'd'
|
||||
END_DELIM = b'e'
|
||||
INT_DELIM = b'i'
|
||||
LIST_DELIM = b'l'
|
||||
BYTE_SEP = b':'
|
||||
|
||||
# Minor modifications made by Andrew Resch to replace the BTFailure errors with Exceptions
|
||||
|
||||
def decode_int(x, f):
|
||||
f += 1
|
||||
newf = x.index(END_DELIM, f)
|
||||
newf = x.index('e', f)
|
||||
n = int(x[f:newf])
|
||||
if x[f : f + 1] == b'-' and x[f + 1 : f + 2] == b'0':
|
||||
if x[f] == '-':
|
||||
if x[f + 1] == '0':
|
||||
raise ValueError
|
||||
elif x[f] == '0' and newf != f+1:
|
||||
raise ValueError
|
||||
elif x[f : f + 1] == b'0' and newf != f + 1:
|
||||
raise ValueError
|
||||
return (n, newf + 1)
|
||||
|
||||
return (n, newf+1)
|
||||
|
||||
def decode_string(x, f):
|
||||
colon = x.index(BYTE_SEP, f)
|
||||
colon = x.index(':', f)
|
||||
n = int(x[f:colon])
|
||||
if x[f : f + 1] == b'0' and colon != f + 1:
|
||||
if x[f] == '0' and colon != f+1:
|
||||
raise ValueError
|
||||
colon += 1
|
||||
return (x[colon : colon + n], colon + n)
|
||||
|
||||
return (x[colon:colon+n], colon+n)
|
||||
|
||||
def decode_list(x, f):
|
||||
r, f = [], f + 1
|
||||
while x[f : f + 1] != END_DELIM:
|
||||
v, f = decode_func[x[f : f + 1]](x, f)
|
||||
r, f = [], f+1
|
||||
while x[f] != 'e':
|
||||
v, f = decode_func[x[f]](x, f)
|
||||
r.append(v)
|
||||
return (r, f + 1)
|
||||
|
||||
|
||||
def decode_dict(x, f):
|
||||
r, f = {}, f + 1
|
||||
while x[f : f + 1] != END_DELIM:
|
||||
r, f = {}, f+1
|
||||
while x[f] != 'e':
|
||||
k, f = decode_string(x, f)
|
||||
r[k], f = decode_func[x[f : f + 1]](x, f)
|
||||
r[k], f = decode_func[x[f]](x, f)
|
||||
return (r, f + 1)
|
||||
|
||||
|
||||
decode_func = {}
|
||||
decode_func[LIST_DELIM] = decode_list
|
||||
decode_func[DICT_DELIM] = decode_dict
|
||||
decode_func[INT_DELIM] = decode_int
|
||||
decode_func[b'0'] = decode_string
|
||||
decode_func[b'1'] = decode_string
|
||||
decode_func[b'2'] = decode_string
|
||||
decode_func[b'3'] = decode_string
|
||||
decode_func[b'4'] = decode_string
|
||||
decode_func[b'5'] = decode_string
|
||||
decode_func[b'6'] = decode_string
|
||||
decode_func[b'7'] = decode_string
|
||||
decode_func[b'8'] = decode_string
|
||||
decode_func[b'9'] = decode_string
|
||||
|
||||
decode_func['l'] = decode_list
|
||||
decode_func['d'] = decode_dict
|
||||
decode_func['i'] = decode_int
|
||||
decode_func['0'] = decode_string
|
||||
decode_func['1'] = decode_string
|
||||
decode_func['2'] = decode_string
|
||||
decode_func['3'] = decode_string
|
||||
decode_func['4'] = decode_string
|
||||
decode_func['5'] = decode_string
|
||||
decode_func['6'] = decode_string
|
||||
decode_func['7'] = decode_string
|
||||
decode_func['8'] = decode_string
|
||||
decode_func['9'] = decode_string
|
||||
|
||||
def bdecode(x):
|
||||
try:
|
||||
r, __ = decode_func[x[0:1]](x, 0)
|
||||
except (LookupError, TypeError, ValueError):
|
||||
raise BTFailure('Not a valid bencoded string')
|
||||
else:
|
||||
return r
|
||||
r, l = decode_func[x[0]](x, 0)
|
||||
except (IndexError, KeyError, ValueError):
|
||||
raise Exception("not a valid bencoded string")
|
||||
|
||||
return r
|
||||
|
||||
from types import StringType, IntType, LongType, DictType, ListType, TupleType
|
||||
|
||||
|
||||
class Bencached:
|
||||
class Bencached(object):
|
||||
|
||||
__slots__ = ['bencoded']
|
||||
|
||||
def __init__(self, s):
|
||||
self.bencoded = s
|
||||
|
||||
|
||||
def encode_bencached(x, r):
|
||||
def encode_bencached(x,r):
|
||||
r.append(x.bencoded)
|
||||
|
||||
|
||||
def encode_int(x, r):
|
||||
r.extend((INT_DELIM, str(x).encode('utf8'), END_DELIM))
|
||||
|
||||
r.extend(('i', str(x), 'e'))
|
||||
|
||||
def encode_bool(x, r):
|
||||
encode_int(1 if x else 0, r)
|
||||
|
||||
if x:
|
||||
encode_int(1, r)
|
||||
else:
|
||||
encode_int(0, r)
|
||||
|
||||
def encode_string(x, r):
|
||||
encode_bytes(x.encode('utf8'), r)
|
||||
|
||||
|
||||
def encode_bytes(x, r):
|
||||
r.extend((str(len(x)).encode('utf8'), BYTE_SEP, x))
|
||||
|
||||
r.extend((str(len(x)), ':', x))
|
||||
|
||||
def encode_list(x, r):
|
||||
r.append(LIST_DELIM)
|
||||
r.append('l')
|
||||
for i in x:
|
||||
encode_func[type(i)](i, r)
|
||||
r.append(END_DELIM)
|
||||
r.append('e')
|
||||
|
||||
|
||||
def encode_dict(x, r):
|
||||
r.append(DICT_DELIM)
|
||||
for k, v in sorted(x.items()):
|
||||
try:
|
||||
k = k.encode('utf8')
|
||||
except AttributeError:
|
||||
pass
|
||||
r.extend((str(len(k)).encode('utf8'), BYTE_SEP, k))
|
||||
def encode_dict(x,r):
|
||||
r.append('d')
|
||||
ilist = x.items()
|
||||
ilist.sort()
|
||||
for k, v in ilist:
|
||||
r.extend((str(len(k)), ':', k))
|
||||
encode_func[type(v)](v, r)
|
||||
r.append(END_DELIM)
|
||||
|
||||
r.append('e')
|
||||
|
||||
encode_func = {}
|
||||
encode_func[Bencached] = encode_bencached
|
||||
encode_func[int] = encode_int
|
||||
encode_func[list] = encode_list
|
||||
encode_func[tuple] = encode_list
|
||||
encode_func[dict] = encode_dict
|
||||
encode_func[bool] = encode_bool
|
||||
encode_func[str] = encode_string
|
||||
encode_func[bytes] = encode_bytes
|
||||
encode_func[IntType] = encode_int
|
||||
encode_func[LongType] = encode_int
|
||||
encode_func[StringType] = encode_string
|
||||
encode_func[ListType] = encode_list
|
||||
encode_func[TupleType] = encode_list
|
||||
encode_func[DictType] = encode_dict
|
||||
|
||||
try:
|
||||
from types import BooleanType
|
||||
encode_func[BooleanType] = encode_bool
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
def bencode(x):
|
||||
r = []
|
||||
encode_func[type(x)](x, r)
|
||||
return b''.join(r)
|
||||
return ''.join(r)
|
||||
|
||||
1558
deluge/common.py
1558
deluge/common.py
File diff suppressed because it is too large
Load Diff
@ -1,49 +1,50 @@
|
||||
#
|
||||
# component.py
|
||||
#
|
||||
# Copyright (C) 2007-2010 Andrew Resch <andrewresch@gmail.com>
|
||||
#
|
||||
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
|
||||
# the additional special exception to link portions of this program with the OpenSSL library.
|
||||
# See LICENSE for more details.
|
||||
# Deluge is free software.
|
||||
#
|
||||
# You may redistribute it and/or modify it under the terms of the
|
||||
# GNU General Public License, as published by the Free Software
|
||||
# Foundation; either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# deluge is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with deluge. If not, write to:
|
||||
# The Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor
|
||||
# Boston, MA 02110-1301, USA.
|
||||
#
|
||||
# In addition, as a special exception, the copyright holders give
|
||||
# permission to link the code of portions of this program with the OpenSSL
|
||||
# library.
|
||||
# You must obey the GNU General Public License in all respects for all of
|
||||
# the code used other than OpenSSL. If you modify file(s) with this
|
||||
# exception, you may extend this exception to your version of the file(s),
|
||||
# but you are not obligated to do so. If you do not wish to do so, delete
|
||||
# this exception statement from your version. If you delete this exception
|
||||
# statement from all source files in the program, then also delete it here.
|
||||
#
|
||||
#
|
||||
|
||||
import logging
|
||||
import traceback
|
||||
from collections import defaultdict
|
||||
|
||||
from twisted.internet import reactor
|
||||
from twisted.internet.defer import DeferredList, fail, maybeDeferred, succeed
|
||||
from twisted.internet.task import LoopingCall, deferLater
|
||||
from twisted.internet.defer import maybeDeferred, succeed, DeferredList, fail
|
||||
from twisted.internet.task import LoopingCall
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ComponentAlreadyRegistered(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class ComponentException(Exception):
|
||||
def __init__(self, message, tb):
|
||||
super().__init__(message)
|
||||
self.message = message
|
||||
self.tb = tb
|
||||
|
||||
def __str__(self):
|
||||
s = super().__str__()
|
||||
return '{}\n{}'.format(s, ''.join(self.tb))
|
||||
|
||||
def __eq__(self, other):
|
||||
if isinstance(other, self.__class__):
|
||||
return self.message == other.message
|
||||
else:
|
||||
return False
|
||||
|
||||
def __ne__(self, other):
|
||||
return not self.__eq__(other)
|
||||
|
||||
|
||||
class Component:
|
||||
"""Component objects are singletons managed by the :class:`ComponentRegistry`.
|
||||
|
||||
class Component(object):
|
||||
"""
|
||||
Component objects are singletons managed by the :class:`ComponentRegistry`.
|
||||
When a new Component object is instantiated, it will be automatically
|
||||
registered with the :class:`ComponentRegistry`.
|
||||
|
||||
@ -87,20 +88,11 @@ class Component:
|
||||
still be considered in a Started state.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, name, interval=1, depend=None):
|
||||
"""Initialize component.
|
||||
|
||||
Args:
|
||||
name (str): Name of component.
|
||||
interval (int, optional): The interval in seconds to call the update function.
|
||||
depend (list, optional): The names of components this component depends on.
|
||||
|
||||
"""
|
||||
self._component_name = name
|
||||
self._component_interval = interval
|
||||
self._component_depend = depend
|
||||
self._component_state = 'Stopped'
|
||||
self._component_state = "Stopped"
|
||||
self._component_timer = None
|
||||
self._component_starting_deferred = None
|
||||
self._component_stopping_deferred = None
|
||||
@ -109,64 +101,59 @@ class Component:
|
||||
def __del__(self):
|
||||
if _ComponentRegistry:
|
||||
_ComponentRegistry.deregister(self)
|
||||
|
||||
|
||||
def _component_start_timer(self):
|
||||
if hasattr(self, 'update'):
|
||||
if hasattr(self, "update"):
|
||||
self._component_timer = LoopingCall(self.update)
|
||||
self._component_timer.start(self._component_interval)
|
||||
|
||||
def _component_start(self):
|
||||
def on_start(result):
|
||||
self._component_state = 'Started'
|
||||
self._component_state = "Started"
|
||||
self._component_starting_deferred = None
|
||||
self._component_start_timer()
|
||||
return True
|
||||
|
||||
def on_start_fail(result):
|
||||
self._component_state = 'Stopped'
|
||||
self._component_state = "Stopped"
|
||||
self._component_starting_deferred = None
|
||||
log.error(result)
|
||||
return fail(result)
|
||||
return result
|
||||
|
||||
if self._component_state == 'Stopped':
|
||||
if hasattr(self, 'start'):
|
||||
self._component_state = 'Starting'
|
||||
d = deferLater(reactor, 0, self.start)
|
||||
d.addCallbacks(on_start, on_start_fail)
|
||||
if self._component_state == "Stopped":
|
||||
if hasattr(self, "start"):
|
||||
self._component_state = "Starting"
|
||||
d = maybeDeferred(self.start)
|
||||
d.addCallback(on_start)
|
||||
d.addErrback(on_start_fail)
|
||||
self._component_starting_deferred = d
|
||||
else:
|
||||
d = maybeDeferred(on_start, None)
|
||||
elif self._component_state == 'Starting':
|
||||
elif self._component_state == "Starting":
|
||||
return self._component_starting_deferred
|
||||
elif self._component_state == 'Started':
|
||||
elif self._component_state == "Started":
|
||||
d = succeed(True)
|
||||
else:
|
||||
d = fail(
|
||||
ComponentException(
|
||||
'Trying to start component "%s" but it is '
|
||||
'not in a stopped state. Current state: %s'
|
||||
% (self._component_name, self._component_state),
|
||||
traceback.format_stack(limit=4),
|
||||
)
|
||||
)
|
||||
d = fail("Cannot start a component not in a Stopped state!")
|
||||
|
||||
return d
|
||||
|
||||
def _component_stop(self):
|
||||
def on_stop(result):
|
||||
self._component_state = 'Stopped'
|
||||
self._component_state = "Stopped"
|
||||
if self._component_timer and self._component_timer.running:
|
||||
self._component_timer.stop()
|
||||
return True
|
||||
|
||||
def on_stop_fail(result):
|
||||
self._component_state = 'Started'
|
||||
self._component_state = "Started"
|
||||
self._component_stopping_deferred = None
|
||||
log.error(result)
|
||||
return result
|
||||
|
||||
if self._component_state != 'Stopped' and self._component_state != 'Stopping':
|
||||
if hasattr(self, 'stop'):
|
||||
self._component_state = 'Stopping'
|
||||
|
||||
if self._component_state != "Stopped" and self._component_state != "Stopping":
|
||||
if hasattr(self, "stop"):
|
||||
self._component_state = "Stopping"
|
||||
d = maybeDeferred(self.stop)
|
||||
d.addCallback(on_stop)
|
||||
d.addErrback(on_stop_fail)
|
||||
@ -174,55 +161,43 @@ class Component:
|
||||
else:
|
||||
d = maybeDeferred(on_stop, None)
|
||||
|
||||
if self._component_state == 'Stopping':
|
||||
if self._component_state == "Stopping":
|
||||
return self._component_stopping_deferred
|
||||
|
||||
return succeed(None)
|
||||
|
||||
def _component_pause(self):
|
||||
def on_pause(result):
|
||||
self._component_state = 'Paused'
|
||||
self._component_state = "Paused"
|
||||
|
||||
if self._component_state == 'Started':
|
||||
if self._component_state == "Started":
|
||||
if self._component_timer and self._component_timer.running:
|
||||
d = maybeDeferred(self._component_timer.stop)
|
||||
d.addCallback(on_pause)
|
||||
else:
|
||||
d = succeed(None)
|
||||
elif self._component_state == 'Paused':
|
||||
elif self._component_state == "Paused":
|
||||
d = succeed(None)
|
||||
else:
|
||||
d = fail(
|
||||
ComponentException(
|
||||
'Trying to pause component "%s" but it is '
|
||||
'not in a started state. Current state: %s'
|
||||
% (self._component_name, self._component_state),
|
||||
traceback.format_stack(limit=4),
|
||||
)
|
||||
)
|
||||
d = fail("Cannot pause a component in a non-Started state!")
|
||||
|
||||
return d
|
||||
|
||||
def _component_resume(self):
|
||||
def on_resume(result):
|
||||
self._component_state = 'Started'
|
||||
self._component_state = "Started"
|
||||
|
||||
if self._component_state == 'Paused':
|
||||
if self._component_state == "Paused":
|
||||
d = maybeDeferred(self._component_start_timer)
|
||||
d.addCallback(on_resume)
|
||||
else:
|
||||
d = fail(
|
||||
ComponentException(
|
||||
'Trying to resume component "%s" but it is '
|
||||
'not in a paused state. Current state: %s'
|
||||
% (self._component_name, self._component_state),
|
||||
traceback.format_stack(limit=4),
|
||||
)
|
||||
)
|
||||
d = fail("Component cannot be resumed from a non-Paused state!")
|
||||
|
||||
return d
|
||||
|
||||
def _component_shutdown(self):
|
||||
def on_stop(result):
|
||||
if hasattr(self, 'shutdown'):
|
||||
if hasattr(self, "shutdown"):
|
||||
return maybeDeferred(self.shutdown)
|
||||
return succeed(None)
|
||||
|
||||
@ -230,97 +205,69 @@ class Component:
|
||||
d.addCallback(on_stop)
|
||||
return d
|
||||
|
||||
def get_state(self):
|
||||
return self._component_state
|
||||
|
||||
def start(self):
|
||||
pass
|
||||
|
||||
def stop(self):
|
||||
pass
|
||||
|
||||
def update(self):
|
||||
pass
|
||||
|
||||
def shutdown(self):
|
||||
pass
|
||||
|
||||
|
||||
class ComponentRegistry:
|
||||
"""The ComponentRegistry holds a list of currently registered :class:`Component` objects.
|
||||
|
||||
It is used to manage the Components by starting, stopping, pausing and shutting them down.
|
||||
class ComponentRegistry(object):
|
||||
"""
|
||||
The ComponentRegistry holds a list of currently registered
|
||||
:class:`Component` objects. It is used to manage the Components by
|
||||
starting, stopping, pausing and shutting them down.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self.components = {}
|
||||
# Stores all of the components that are dependent on a particular component
|
||||
self.dependents = defaultdict(list)
|
||||
|
||||
def register(self, obj):
|
||||
"""Register a component object with the registry.
|
||||
"""
|
||||
Registers a component object with the registry. This is done
|
||||
automatically when a Component object is instantiated.
|
||||
|
||||
Note:
|
||||
This is done automatically when a Component object is instantiated.
|
||||
:param obj: the Component object
|
||||
:type obj: object
|
||||
|
||||
Args:
|
||||
obj (Component): A component object to register.
|
||||
|
||||
Raises:
|
||||
ComponentAlreadyRegistered: If a component with the same name is already registered.
|
||||
:raises ComponentAlreadyRegistered: if a component with the same name is already registered.
|
||||
|
||||
"""
|
||||
name = obj._component_name
|
||||
if name in self.components:
|
||||
raise ComponentAlreadyRegistered(
|
||||
'Component already registered with name %s' % name
|
||||
)
|
||||
"Component already registered with name %s" % name)
|
||||
|
||||
self.components[obj._component_name] = obj
|
||||
if obj._component_depend:
|
||||
for depend in obj._component_depend:
|
||||
self.dependents[depend].append(name)
|
||||
|
||||
def deregister(self, obj):
|
||||
"""Deregister a component from the registry. A stop will be
|
||||
"""
|
||||
Deregisters a component from the registry. A stop will be
|
||||
issued to the component prior to deregistering it.
|
||||
|
||||
Args:
|
||||
obj (Component): a component object to deregister
|
||||
|
||||
Returns:
|
||||
Deferred: a deferred object that will fire once the Component has been
|
||||
successfully deregistered
|
||||
:param obj: the Component object
|
||||
:type obj: object
|
||||
|
||||
"""
|
||||
|
||||
if obj in self.components.values():
|
||||
log.debug('Deregistering Component: %s', obj._component_name)
|
||||
log.debug("Deregistering Component: %s", obj._component_name)
|
||||
d = self.stop([obj._component_name])
|
||||
|
||||
def on_stop(result, name):
|
||||
# Component may have been removed, so pop to ensure it doesn't fail
|
||||
self.components.pop(name, None)
|
||||
|
||||
del self.components[name]
|
||||
return d.addCallback(on_stop, obj._component_name)
|
||||
else:
|
||||
return succeed(None)
|
||||
|
||||
def start(self, names=None):
|
||||
"""Start Components, and their dependencies, that are currently in a Stopped state.
|
||||
def start(self, names=[]):
|
||||
"""
|
||||
Starts Components that are currently in a Stopped state and their
|
||||
dependencies. If *names* is specified, will only start those
|
||||
Components and their dependencies and if not it will start all
|
||||
registered components.
|
||||
|
||||
Note:
|
||||
If no names are specified then all registered components will be started.
|
||||
:param names: a list of Components to start
|
||||
:type names: list
|
||||
|
||||
Args:
|
||||
names (list): A list of Components to start and their dependencies.
|
||||
|
||||
Returns:
|
||||
Deferred: Fired once all Components have been successfully started.
|
||||
:returns: a Deferred object that will fire once all Components have been sucessfully started
|
||||
:rtype: twisted.internet.defer.Deferred
|
||||
|
||||
"""
|
||||
# Start all the components if names is empty
|
||||
if not names:
|
||||
names = list(self.components)
|
||||
names = self.components.keys()
|
||||
elif isinstance(names, str):
|
||||
names = [names]
|
||||
|
||||
@ -340,124 +287,109 @@ class ComponentRegistry:
|
||||
|
||||
return DeferredList(deferreds)
|
||||
|
||||
def stop(self, names=None):
|
||||
"""Stop Components that are currently not in a Stopped state.
|
||||
def stop(self, names=[]):
|
||||
"""
|
||||
Stops Components that are currently not in a Stopped state. If
|
||||
*names* is specified, then it will only stop those Components,
|
||||
and if not it will stop all the registered Components.
|
||||
|
||||
Note:
|
||||
If no names are specified then all registered components will be stopped.
|
||||
:param names: a list of Components to start
|
||||
:type names: list
|
||||
|
||||
Args:
|
||||
names (list): A list of Components to stop.
|
||||
|
||||
Returns:
|
||||
Deferred: Fired once all Components have been successfully stopped.
|
||||
:returns: a Deferred object that will fire once all Components have been sucessfully stopped
|
||||
:rtype: twisted.internet.defer.Deferred
|
||||
|
||||
"""
|
||||
if not names:
|
||||
names = list(self.components)
|
||||
names = self.components.keys()
|
||||
elif isinstance(names, str):
|
||||
names = [names]
|
||||
|
||||
def on_dependents_stopped(result, name):
|
||||
return self.components[name]._component_stop()
|
||||
|
||||
stopped_in_deferred = set()
|
||||
deferreds = []
|
||||
|
||||
for name in names:
|
||||
if name in stopped_in_deferred:
|
||||
continue
|
||||
if name in self.components:
|
||||
if name in self.dependents:
|
||||
# If other components depend on this component, stop them first
|
||||
d = self.stop(self.dependents[name]).addCallback(
|
||||
on_dependents_stopped, name
|
||||
)
|
||||
deferreds.append(d)
|
||||
stopped_in_deferred.update(self.dependents[name])
|
||||
else:
|
||||
deferreds.append(self.components[name]._component_stop())
|
||||
deferreds.append(self.components[name]._component_stop())
|
||||
|
||||
return DeferredList(deferreds)
|
||||
|
||||
def pause(self, names=None):
|
||||
"""Pause Components that are currently in a Started state.
|
||||
def pause(self, names=[]):
|
||||
"""
|
||||
Pauses Components that are currently in a Started state. If
|
||||
*names* is specified, then it will only pause those Components,
|
||||
and if not it will pause all the registered Components.
|
||||
|
||||
Note:
|
||||
If no names are specified then all registered components will be paused.
|
||||
:param names: a list of Components to pause
|
||||
:type names: list
|
||||
|
||||
Args:
|
||||
names (list): A list of Components to pause.
|
||||
|
||||
Returns:
|
||||
Deferred: Fired once all Components have been successfully paused.
|
||||
:returns: a Deferred object that will fire once all Components have been sucessfully paused
|
||||
:rtype: twisted.internet.defer.Deferred
|
||||
|
||||
"""
|
||||
if not names:
|
||||
names = list(self.components)
|
||||
names = self.components.keys()
|
||||
elif isinstance(names, str):
|
||||
names = [names]
|
||||
|
||||
deferreds = []
|
||||
|
||||
for name in names:
|
||||
if self.components[name]._component_state == 'Started':
|
||||
if self.components[name]._component_state == "Started":
|
||||
deferreds.append(self.components[name]._component_pause())
|
||||
|
||||
return DeferredList(deferreds)
|
||||
|
||||
def resume(self, names=None):
|
||||
"""Resume Components that are currently in a Paused state.
|
||||
def resume(self, names=[]):
|
||||
"""
|
||||
Resumes Components that are currently in a Paused state. If
|
||||
*names* is specified, then it will only resume those Components,
|
||||
and if not it will resume all the registered Components.
|
||||
|
||||
Note:
|
||||
If no names are specified then all registered components will be resumed.
|
||||
:param names: a list of Components to resume
|
||||
:type names: list
|
||||
|
||||
Args:
|
||||
names (list): A list of Components to to resume.
|
||||
|
||||
Returns:
|
||||
Deferred: Fired once all Components have been successfully resumed.
|
||||
:returns: a Deferred object that will fire once all Components have been sucessfully resumed
|
||||
:rtype: twisted.internet.defer.Deferred
|
||||
|
||||
"""
|
||||
if not names:
|
||||
names = list(self.components)
|
||||
names = self.components.keys()
|
||||
elif isinstance(names, str):
|
||||
names = [names]
|
||||
|
||||
deferreds = []
|
||||
|
||||
for name in names:
|
||||
if self.components[name]._component_state == 'Paused':
|
||||
if self.components[name]._component_state == "Paused":
|
||||
deferreds.append(self.components[name]._component_resume())
|
||||
|
||||
return DeferredList(deferreds)
|
||||
|
||||
def shutdown(self):
|
||||
"""Shutdown all Components regardless of state.
|
||||
"""
|
||||
Shutdowns all Components regardless of state. This will call
|
||||
:meth:`stop` on call the components prior to shutting down. This should
|
||||
be called when the program is exiting to ensure all Components have a
|
||||
chance to properly shutdown.
|
||||
|
||||
This will call stop() on all the components prior to shutting down. This should be called
|
||||
when the program is exiting to ensure all Components have a chance to properly shutdown.
|
||||
|
||||
Returns:
|
||||
Deferred: Fired once all Components have been successfully shut down.
|
||||
:returns: a Deferred object that will fire once all Components have been sucessfully resumed
|
||||
:rtype: twisted.internet.defer.Deferred
|
||||
|
||||
"""
|
||||
deferreds = []
|
||||
|
||||
def on_stopped(result):
|
||||
return DeferredList(
|
||||
[comp._component_shutdown() for comp in list(self.components.values())]
|
||||
)
|
||||
for component in self.components.values():
|
||||
deferreds.append(component._component_shutdown())
|
||||
|
||||
return self.stop(list(self.components)).addCallback(on_stopped)
|
||||
return DeferredList(deferreds)
|
||||
|
||||
def update(self):
|
||||
"""Update all Components that are in a Started state."""
|
||||
for component in self.components.items():
|
||||
try:
|
||||
component.update()
|
||||
except BaseException as ex:
|
||||
log.exception(ex)
|
||||
"""
|
||||
Updates all Components that are in a Started state.
|
||||
|
||||
"""
|
||||
for component in self.components.items():
|
||||
component.update()
|
||||
|
||||
_ComponentRegistry = ComponentRegistry()
|
||||
|
||||
@ -469,18 +401,17 @@ resume = _ComponentRegistry.resume
|
||||
update = _ComponentRegistry.update
|
||||
shutdown = _ComponentRegistry.shutdown
|
||||
|
||||
|
||||
def get(name):
|
||||
"""Return a reference to a component.
|
||||
"""
|
||||
Return a reference to a component.
|
||||
|
||||
Args:
|
||||
name (str): The Component name to get.
|
||||
:param name: the Component name to get
|
||||
:type name: string
|
||||
|
||||
Returns:
|
||||
Component: The Component object.
|
||||
:returns: the Component object
|
||||
:rtype: object
|
||||
|
||||
Raises:
|
||||
KeyError: If the Component does not exist.
|
||||
:raises KeyError: if the Component does not exist
|
||||
|
||||
"""
|
||||
return _ComponentRegistry.components[name]
|
||||
|
||||
598
deluge/config.py
598
deluge/config.py
@ -1,10 +1,38 @@
|
||||
#
|
||||
# config.py
|
||||
#
|
||||
# Copyright (C) 2008 Andrew Resch <andrewresch@gmail.com>
|
||||
#
|
||||
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
|
||||
# the additional special exception to link portions of this program with the OpenSSL library.
|
||||
# See LICENSE for more details.
|
||||
# Deluge is free software.
|
||||
#
|
||||
# You may redistribute it and/or modify it under the terms of the
|
||||
# GNU General Public License, as published by the Free Software
|
||||
# Foundation; either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# deluge is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with deluge. If not, write to:
|
||||
# The Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor
|
||||
# Boston, MA 02110-1301, USA.
|
||||
#
|
||||
# In addition, as a special exception, the copyright holders give
|
||||
# permission to link the code of portions of this program with the OpenSSL
|
||||
# library.
|
||||
# You must obey the GNU General Public License in all respects for all of
|
||||
# the code used other than OpenSSL. If you modify file(s) with this
|
||||
# exception, you may extend this exception to your version of the file(s),
|
||||
# but you are not obligated to do so. If you do not wish to do so, delete
|
||||
# this exception statement from your version. If you delete this exception
|
||||
# statement from all source files in the program, then also delete it here.
|
||||
#
|
||||
#
|
||||
|
||||
|
||||
"""
|
||||
Deluge Config Module
|
||||
@ -38,247 +66,207 @@ this can only be done for the 'config file version' and not for the 'format'
|
||||
version as this will be done internally.
|
||||
|
||||
"""
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import pickle
|
||||
import shutil
|
||||
from codecs import getwriter
|
||||
from tempfile import NamedTemporaryFile
|
||||
|
||||
from deluge.common import JSON_FORMAT, get_default_config_dir
|
||||
import cPickle as pickle
|
||||
import logging
|
||||
import shutil
|
||||
import os
|
||||
|
||||
import deluge.common
|
||||
|
||||
json = deluge.common.json
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
def prop(func):
|
||||
"""Function decorator for defining property attributes
|
||||
|
||||
def find_json_objects(text, decoder=json.JSONDecoder()):
|
||||
"""Find json objects in text.
|
||||
The decorated function is expected to return a dictionary
|
||||
containing one or more of the following pairs:
|
||||
fget - function for getting attribute value
|
||||
fset - function for setting attribute value
|
||||
fdel - function for deleting attribute
|
||||
This can be conveniently constructed by the locals() builtin
|
||||
function; see:
|
||||
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/205183
|
||||
"""
|
||||
return property(doc=func.__doc__, **func())
|
||||
|
||||
Args:
|
||||
text (str): The text to find json objects within.
|
||||
def find_json_objects(s):
|
||||
"""
|
||||
Find json objects in a string.
|
||||
|
||||
Returns:
|
||||
list: A list of tuples containing start and end locations of json
|
||||
objects in the text. e.g. [(start, end), ...]
|
||||
:param s: the string to find json objects in
|
||||
:type s: string
|
||||
|
||||
:returns: a list of tuples containing start and end locations of json objects in the string `s`
|
||||
:rtype: [(start, end), ...]
|
||||
|
||||
"""
|
||||
objects = []
|
||||
offset = 0
|
||||
while True:
|
||||
try:
|
||||
start = text.index('{', offset)
|
||||
except ValueError:
|
||||
break
|
||||
opens = 0
|
||||
start = s.find("{")
|
||||
offset = start
|
||||
|
||||
try:
|
||||
__, index = decoder.raw_decode(text[start:])
|
||||
except json.decoder.JSONDecodeError:
|
||||
offset = start + 1
|
||||
else:
|
||||
offset = start + index
|
||||
objects.append((start, offset))
|
||||
if start < 0:
|
||||
return []
|
||||
|
||||
for index, c in enumerate(s[offset:]):
|
||||
if c == "{":
|
||||
opens += 1
|
||||
elif c == "}":
|
||||
opens -= 1
|
||||
if opens == 0:
|
||||
objects.append((start, index+offset+1))
|
||||
start = index + offset + 1
|
||||
|
||||
return objects
|
||||
|
||||
|
||||
def cast_to_existing_type(value, old_value):
|
||||
"""Attempt to convert new value type to match old value type"""
|
||||
types_match = isinstance(old_value, (type(None), type(value)))
|
||||
if value is not None and not types_match:
|
||||
old_type = type(old_value)
|
||||
# Skip convert to bytes since requires knowledge of encoding and value should
|
||||
# be unicode anyway.
|
||||
if old_type is bytes:
|
||||
return value
|
||||
class Config(object):
|
||||
"""
|
||||
This class is used to access/create/modify config files
|
||||
|
||||
return old_type(value)
|
||||
|
||||
return value
|
||||
|
||||
|
||||
class Config:
|
||||
"""This class is used to access/create/modify config files.
|
||||
|
||||
Args:
|
||||
filename (str): The config filename.
|
||||
defaults (dict): The default config values to insert before loading the config file.
|
||||
config_dir (str): the path to the config directory.
|
||||
file_version (int): The file format for the default config values when creating
|
||||
a fresh config. This value should be increased whenever a new migration function is
|
||||
setup to convert old config files. (default: 1)
|
||||
log_mask_funcs (dict): A dict of key:function, used to mask sensitive
|
||||
key values (e.g. passwords) when logging is enabled.
|
||||
:param filename: the name of the config file
|
||||
:param defaults: dictionary of default values
|
||||
:param config_dir: the path to the config directory
|
||||
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
filename,
|
||||
defaults=None,
|
||||
config_dir=None,
|
||||
file_version=1,
|
||||
log_mask_funcs=None,
|
||||
):
|
||||
def __init__(self, filename, defaults=None, config_dir=None):
|
||||
self.__config = {}
|
||||
self.__set_functions = {}
|
||||
self.__change_callbacks = []
|
||||
self.__log_mask_funcs = log_mask_funcs if log_mask_funcs else {}
|
||||
|
||||
# These hold the version numbers and they will be set when loaded
|
||||
self.__version = {'format': 1, 'file': file_version}
|
||||
self.__version = {
|
||||
"format": 1,
|
||||
"file": 1
|
||||
}
|
||||
|
||||
# This will get set with a reactor.callLater whenever a config option
|
||||
# is set.
|
||||
self._save_timer = None
|
||||
|
||||
if defaults:
|
||||
for key, value in defaults.items():
|
||||
self.set_item(key, value, default=True)
|
||||
for key, value in defaults.iteritems():
|
||||
self.set_item(key, value)
|
||||
|
||||
# Load the config from file in the config_dir
|
||||
if config_dir:
|
||||
self.__config_file = os.path.join(config_dir, filename)
|
||||
else:
|
||||
self.__config_file = get_default_config_dir(filename)
|
||||
self.__config_file = deluge.common.get_default_config_dir(filename)
|
||||
|
||||
self.load()
|
||||
|
||||
def callLater(self, period, func, *args, **kwargs): # noqa: N802 ignore camelCase
|
||||
"""Wrapper around reactor.callLater for test purpose."""
|
||||
from twisted.internet import reactor
|
||||
|
||||
return reactor.callLater(period, func, *args, **kwargs)
|
||||
|
||||
def __contains__(self, item):
|
||||
return item in self.__config
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
"""See set_item"""
|
||||
"""
|
||||
See
|
||||
:meth:`set_item`
|
||||
"""
|
||||
|
||||
return self.set_item(key, value)
|
||||
|
||||
def set_item(self, key, value, default=False):
|
||||
"""Sets item 'key' to 'value' in the config dictionary.
|
||||
def set_item(self, key, value):
|
||||
"""
|
||||
Sets item 'key' to 'value' in the config dictionary, but does not allow
|
||||
changing the item's type unless it is None. If the types do not match,
|
||||
it will attempt to convert it to the set type before raising a ValueError.
|
||||
|
||||
Does not allow changing the item's type unless it is None.
|
||||
:param key: string, item to change to change
|
||||
:param value: the value to change item to, must be same type as what is currently in the config
|
||||
|
||||
If the types do not match, it will attempt to convert it to the
|
||||
set type before raising a ValueError.
|
||||
:raises ValueError: raised when the type of value is not the same as\
|
||||
what is currently in the config and it could not convert the value
|
||||
|
||||
Args:
|
||||
key (str): Item to change to change.
|
||||
value (any): The value to change item to, must be same type as what is
|
||||
currently in the config.
|
||||
default (optional, bool): When setting a default value skip func or save
|
||||
callbacks.
|
||||
**Usage**
|
||||
|
||||
Raises:
|
||||
ValueError: Raised when the type of value is not the same as what is
|
||||
currently in the config and it could not convert the value.
|
||||
|
||||
Examples:
|
||||
>>> config = Config('test.conf')
|
||||
>>> config['test'] = 5
|
||||
>>> config['test']
|
||||
5
|
||||
>>> config = Config("test.conf")
|
||||
>>> config["test"] = 5
|
||||
>>> config["test"]
|
||||
5
|
||||
|
||||
"""
|
||||
if isinstance(value, bytes):
|
||||
value = value.decode()
|
||||
if isinstance(value, basestring):
|
||||
value = deluge.common.utf8_encoded(value)
|
||||
|
||||
if key in self.__config:
|
||||
try:
|
||||
value = cast_to_existing_type(value, self.__config[key])
|
||||
except ValueError:
|
||||
log.warning('Value Type "%s" invalid for key: %s', type(value), key)
|
||||
raise
|
||||
else:
|
||||
if self.__config[key] == value:
|
||||
return
|
||||
|
||||
if log.isEnabledFor(logging.DEBUG):
|
||||
if key in self.__log_mask_funcs:
|
||||
value = self.__log_mask_funcs[key](value)
|
||||
log.debug(
|
||||
'Setting key "%s" to: %s (of type: %s)',
|
||||
key,
|
||||
value,
|
||||
type(value),
|
||||
)
|
||||
self.__config[key] = value
|
||||
|
||||
# Skip save or func callbacks if setting default value for keys
|
||||
if default:
|
||||
if not self.__config.has_key(key):
|
||||
self.__config[key] = value
|
||||
log.debug("Setting '%s' to %s of %s", key, value, type(value))
|
||||
return
|
||||
|
||||
if self.__config[key] == value:
|
||||
return
|
||||
|
||||
# Do not allow the type to change unless it is None
|
||||
oldtype, newtype = type(self.__config[key]), type(value)
|
||||
|
||||
if value is not None and oldtype != type(None) and oldtype != newtype:
|
||||
try:
|
||||
if oldtype == unicode:
|
||||
value = oldtype(value, "utf8")
|
||||
else:
|
||||
value = oldtype(value)
|
||||
except ValueError:
|
||||
log.warning("Type '%s' invalid for '%s'", newtype, key)
|
||||
raise
|
||||
|
||||
log.debug("Setting '%s' to %s of %s", key, value, type(value))
|
||||
|
||||
self.__config[key] = value
|
||||
# Run the set_function for this key if any
|
||||
for func in self.__set_functions.get(key, []):
|
||||
self.callLater(0, func, key, value)
|
||||
|
||||
from twisted.internet import reactor
|
||||
try:
|
||||
for func in self.__set_functions[key]:
|
||||
reactor.callLater(0, func, key, value)
|
||||
except KeyError:
|
||||
pass
|
||||
try:
|
||||
|
||||
def do_change_callbacks(key, value):
|
||||
for func in self.__change_callbacks:
|
||||
func(key, value)
|
||||
|
||||
self.callLater(0, do_change_callbacks, key, value)
|
||||
except Exception:
|
||||
reactor.callLater(0, do_change_callbacks, key, value)
|
||||
except:
|
||||
pass
|
||||
|
||||
# We set the save_timer for 5 seconds if not already set
|
||||
if not self._save_timer or not self._save_timer.active():
|
||||
self._save_timer = self.callLater(5, self.save)
|
||||
self._save_timer = reactor.callLater(5, self.save)
|
||||
|
||||
def __getitem__(self, key):
|
||||
"""See get_item"""
|
||||
"""
|
||||
See
|
||||
:meth:`get_item`
|
||||
"""
|
||||
return self.get_item(key)
|
||||
|
||||
def get_item(self, key):
|
||||
"""Gets the value of item 'key'.
|
||||
"""
|
||||
Gets the value of item 'key'
|
||||
|
||||
Args:
|
||||
key (str): The item for which you want it's value.
|
||||
:param key: the item for which you want it's value
|
||||
:return: the value of item 'key'
|
||||
|
||||
Returns:
|
||||
any: The value of item 'key'.
|
||||
:raises KeyError: if 'key' is not in the config dictionary
|
||||
|
||||
Raises:
|
||||
ValueError: If 'key' is not in the config dictionary.
|
||||
**Usage**
|
||||
|
||||
Examples:
|
||||
>>> config = Config('test.conf', defaults={'test': 5})
|
||||
>>> config['test']
|
||||
5
|
||||
>>> config = Config("test.conf", defaults={"test": 5})
|
||||
>>> config["test"]
|
||||
5
|
||||
|
||||
"""
|
||||
return self.__config[key]
|
||||
|
||||
def get(self, key, default=None):
|
||||
"""Gets the value of item 'key' if key is in the config, else default.
|
||||
|
||||
If default is not given, it defaults to None, so that this method
|
||||
never raises a KeyError.
|
||||
|
||||
Args:
|
||||
key (str): the item for which you want it's value
|
||||
default (any): the default value if key is missing
|
||||
|
||||
Returns:
|
||||
any: The value of item 'key' or default.
|
||||
|
||||
Examples:
|
||||
>>> config = Config('test.conf', defaults={'test': 5})
|
||||
>>> config.get('test', 10)
|
||||
5
|
||||
>>> config.get('bad_key', 10)
|
||||
10
|
||||
|
||||
"""
|
||||
try:
|
||||
return self.get_item(key)
|
||||
except KeyError:
|
||||
return default
|
||||
if isinstance(self.__config[key], str):
|
||||
try:
|
||||
return self.__config[key].decode("utf8")
|
||||
except UnicodeDecodeError:
|
||||
return self.__config[key]
|
||||
else:
|
||||
return self.__config[key]
|
||||
|
||||
def __delitem__(self, key):
|
||||
"""
|
||||
@ -288,62 +276,59 @@ class Config:
|
||||
self.del_item(key)
|
||||
|
||||
def del_item(self, key):
|
||||
"""Deletes item with a specific key from the configuration.
|
||||
|
||||
Args:
|
||||
key (str): The item which you wish to delete.
|
||||
|
||||
Raises:
|
||||
ValueError: If 'key' is not in the config dictionary.
|
||||
|
||||
Examples:
|
||||
>>> config = Config('test.conf', defaults={'test': 5})
|
||||
>>> del config['test']
|
||||
|
||||
"""
|
||||
Deletes item with a specific key from the configuration.
|
||||
|
||||
:param key: the item which you wish to delete.
|
||||
:raises KeyError: if 'key' is not in the config dictionary
|
||||
|
||||
**Usage**
|
||||
>>> config = Config("test.conf", defaults={"test": 5})
|
||||
>>> del config["test"]
|
||||
"""
|
||||
del self.__config[key]
|
||||
|
||||
# We set the save_timer for 5 seconds if not already set
|
||||
from twisted.internet import reactor
|
||||
if not self._save_timer or not self._save_timer.active():
|
||||
self._save_timer = self.callLater(5, self.save)
|
||||
self._save_timer = reactor.callLater(5, self.save)
|
||||
|
||||
|
||||
def register_change_callback(self, callback):
|
||||
"""Registers a callback function for any changed value.
|
||||
"""
|
||||
Registers a callback function that will be called when a value is changed in the config dictionary
|
||||
|
||||
Will be called when any value is changed in the config dictionary.
|
||||
:param callback: the function, callback(key, value)
|
||||
|
||||
Args:
|
||||
callback (func): The function to call with parameters: f(key, value).
|
||||
**Usage**
|
||||
|
||||
Examples:
|
||||
>>> config = Config('test.conf', defaults={'test': 5})
|
||||
>>> def cb(key, value):
|
||||
... print key, value
|
||||
...
|
||||
>>> config.register_change_callback(cb)
|
||||
>>> config = Config("test.conf", defaults={"test": 5})
|
||||
>>> def cb(key, value):
|
||||
... print key, value
|
||||
...
|
||||
>>> config.register_change_callback(cb)
|
||||
|
||||
"""
|
||||
self.__change_callbacks.append(callback)
|
||||
|
||||
def register_set_function(self, key, function, apply_now=True):
|
||||
"""Register a function to be called when a config value changes.
|
||||
"""
|
||||
Register a function to be called when a config value changes
|
||||
|
||||
Args:
|
||||
key (str): The item to monitor for change.
|
||||
function (func): The function to call when the value changes, f(key, value).
|
||||
apply_now (bool): If True, the function will be called immediately after it's registered.
|
||||
:param key: the item to monitor for change
|
||||
:param function: the function to call when the value changes, f(key, value)
|
||||
:keyword apply_now: if True, the function will be called after it's registered
|
||||
|
||||
Examples:
|
||||
>>> config = Config('test.conf', defaults={'test': 5})
|
||||
>>> def cb(key, value):
|
||||
... print key, value
|
||||
...
|
||||
>>> config.register_set_function('test', cb, apply_now=True)
|
||||
test 5
|
||||
**Usage**
|
||||
|
||||
>>> config = Config("test.conf", defaults={"test": 5})
|
||||
>>> def cb(key, value):
|
||||
... print key, value
|
||||
...
|
||||
>>> config.register_set_function("test", cb, apply_now=True)
|
||||
test 5
|
||||
|
||||
"""
|
||||
log.debug('Registering function for %s key..', key)
|
||||
log.debug("Registering function for %s key..", key)
|
||||
if key not in self.__set_functions:
|
||||
self.__set_functions[key] = []
|
||||
|
||||
@ -352,52 +337,55 @@ class Config:
|
||||
# Run the function now if apply_now is set
|
||||
if apply_now:
|
||||
function(key, self.__config[key])
|
||||
return
|
||||
|
||||
def apply_all(self):
|
||||
"""Calls all set functions.
|
||||
"""
|
||||
Calls all set functions
|
||||
|
||||
Examples:
|
||||
>>> config = Config('test.conf', defaults={'test': 5})
|
||||
>>> def cb(key, value):
|
||||
... print key, value
|
||||
...
|
||||
>>> config.register_set_function('test', cb, apply_now=False)
|
||||
>>> config.apply_all()
|
||||
test 5
|
||||
**Usage**
|
||||
|
||||
>>> config = Config("test.conf", defaults={"test": 5})
|
||||
>>> def cb(key, value):
|
||||
... print key, value
|
||||
...
|
||||
>>> config.register_set_function("test", cb, apply_now=False)
|
||||
>>> config.apply_all()
|
||||
test 5
|
||||
|
||||
"""
|
||||
log.debug('Calling all set functions..')
|
||||
for key, value in self.__set_functions.items():
|
||||
log.debug("Calling all set functions..")
|
||||
for key, value in self.__set_functions.iteritems():
|
||||
for func in value:
|
||||
func(key, self.__config[key])
|
||||
|
||||
def apply_set_functions(self, key):
|
||||
"""Calls set functions for `:param:key`.
|
||||
"""
|
||||
Calls set functions for `:param:key`.
|
||||
|
||||
Args:
|
||||
key (str): the config key
|
||||
:param key: str, the config key
|
||||
|
||||
"""
|
||||
log.debug('Calling set functions for key %s..', key)
|
||||
log.debug("Calling set functions for key %s..", key)
|
||||
if key in self.__set_functions:
|
||||
for func in self.__set_functions[key]:
|
||||
func(key, self.__config[key])
|
||||
|
||||
def load(self, filename=None):
|
||||
"""Load a config file.
|
||||
"""
|
||||
Load a config file
|
||||
|
||||
:param filename: if None, uses filename set in object initialization
|
||||
|
||||
Args:
|
||||
filename (str): If None, uses filename set in object initialization
|
||||
|
||||
"""
|
||||
if not filename:
|
||||
filename = self.__config_file
|
||||
|
||||
try:
|
||||
with open(filename, encoding='utf8') as _file:
|
||||
data = _file.read()
|
||||
except OSError as ex:
|
||||
log.warning('Unable to open config file %s: %s', filename, ex)
|
||||
data = open(filename, "rb").read()
|
||||
except IOError, e:
|
||||
log.warning("Unable to open config file %s: %s", filename, e)
|
||||
return
|
||||
|
||||
objects = find_json_objects(data)
|
||||
@ -406,54 +394,36 @@ class Config:
|
||||
# No json objects found, try depickling it
|
||||
try:
|
||||
self.__config.update(pickle.loads(data))
|
||||
except Exception as ex:
|
||||
log.exception(ex)
|
||||
log.warning('Unable to load config file: %s', filename)
|
||||
except Exception, e:
|
||||
log.exception(e)
|
||||
log.warning("Unable to load config file: %s", filename)
|
||||
elif len(objects) == 1:
|
||||
start, end = objects[0]
|
||||
try:
|
||||
self.__config.update(json.loads(data[start:end]))
|
||||
except Exception as ex:
|
||||
log.exception(ex)
|
||||
log.warning('Unable to load config file: %s', filename)
|
||||
except Exception, e:
|
||||
log.exception(e)
|
||||
log.warning("Unable to load config file: %s", filename)
|
||||
elif len(objects) == 2:
|
||||
try:
|
||||
start, end = objects[0]
|
||||
self.__version.update(json.loads(data[start:end]))
|
||||
start, end = objects[1]
|
||||
self.__config.update(json.loads(data[start:end]))
|
||||
except Exception as ex:
|
||||
log.exception(ex)
|
||||
log.warning('Unable to load config file: %s', filename)
|
||||
except Exception, e:
|
||||
log.exception(e)
|
||||
log.warning("Unable to load config file: %s", filename)
|
||||
|
||||
if not log.isEnabledFor(logging.DEBUG):
|
||||
return
|
||||
|
||||
config = self.__config
|
||||
if self.__log_mask_funcs:
|
||||
config = {
|
||||
key: self.__log_mask_funcs[key](config[key])
|
||||
if key in self.__log_mask_funcs
|
||||
else config[key]
|
||||
for key in config
|
||||
}
|
||||
|
||||
log.debug(
|
||||
'Config %s version: %s.%s loaded: %s',
|
||||
filename,
|
||||
self.__version['format'],
|
||||
self.__version['file'],
|
||||
config,
|
||||
)
|
||||
log.debug("Config %s version: %s.%s loaded: %s", filename,
|
||||
self.__version["format"], self.__version["file"], self.__config)
|
||||
|
||||
def save(self, filename=None):
|
||||
"""Save configuration to disk.
|
||||
"""
|
||||
Save configuration to disk
|
||||
|
||||
Args:
|
||||
filename (str): If None, uses filename set in object initialization
|
||||
|
||||
Returns:
|
||||
bool: Whether or not the save succeeded.
|
||||
:param filename: if None, uses filename set in object initiliazation
|
||||
:rtype bool:
|
||||
:return: whether or not the save succeeded.
|
||||
|
||||
"""
|
||||
if not filename:
|
||||
@ -461,8 +431,7 @@ class Config:
|
||||
# Check to see if the current config differs from the one on disk
|
||||
# We will only write a new config file if there is a difference
|
||||
try:
|
||||
with open(filename, encoding='utf8') as _file:
|
||||
data = _file.read()
|
||||
data = open(filename, "rb").read()
|
||||
objects = find_json_objects(data)
|
||||
start, end = objects[0]
|
||||
version = json.loads(data[start:end])
|
||||
@ -473,41 +442,36 @@ class Config:
|
||||
if self._save_timer and self._save_timer.active():
|
||||
self._save_timer.cancel()
|
||||
return True
|
||||
except (OSError, IndexError) as ex:
|
||||
log.warning('Unable to open config file: %s because: %s', filename, ex)
|
||||
except IOError, e:
|
||||
log.warning("Unable to open config file: %s because: %s", filename, e)
|
||||
|
||||
# Save the new config and make sure it's written to disk
|
||||
try:
|
||||
with NamedTemporaryFile(
|
||||
prefix=os.path.basename(filename) + '.', delete=False
|
||||
) as _file:
|
||||
filename_tmp = _file.name
|
||||
log.debug('Saving new config file %s', filename_tmp)
|
||||
json.dump(self.__version, getwriter('utf8')(_file), **JSON_FORMAT)
|
||||
json.dump(self.__config, getwriter('utf8')(_file), **JSON_FORMAT)
|
||||
_file.flush()
|
||||
os.fsync(_file.fileno())
|
||||
except OSError as ex:
|
||||
log.error('Error writing new config file: %s', ex)
|
||||
log.debug("Saving new config file %s", filename + ".new")
|
||||
f = open(filename + ".new", "wb")
|
||||
json.dump(self.__version, f, indent=2)
|
||||
json.dump(self.__config, f, indent=2)
|
||||
f.flush()
|
||||
os.fsync(f.fileno())
|
||||
f.close()
|
||||
except IOError, e:
|
||||
log.error("Error writing new config file: %s", e)
|
||||
return False
|
||||
|
||||
# Resolve symlinked config files before backing up and saving.
|
||||
filename = os.path.realpath(filename)
|
||||
|
||||
# Make a backup of the old config
|
||||
try:
|
||||
log.debug('Backing up old config file to %s.bak', filename)
|
||||
shutil.move(filename, filename + '.bak')
|
||||
except OSError as ex:
|
||||
log.warning('Unable to backup old config: %s', ex)
|
||||
log.debug("Backing up old config file to %s~", filename)
|
||||
shutil.move(filename, filename + "~")
|
||||
except Exception, e:
|
||||
log.error("Error backing up old config..")
|
||||
|
||||
# The new config file has been written successfully, so let's move it over
|
||||
# the existing one.
|
||||
try:
|
||||
log.debug('Moving new config file %s to %s', filename_tmp, filename)
|
||||
shutil.move(filename_tmp, filename)
|
||||
except OSError as ex:
|
||||
log.error('Error moving new config file: %s', ex)
|
||||
log.debug("Moving new config file %s to %s..", filename + ".new", filename)
|
||||
shutil.move(filename + ".new", filename)
|
||||
except Exception, e:
|
||||
log.error("Error moving new config file: %s", e)
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
@ -516,53 +480,47 @@ class Config:
|
||||
self._save_timer.cancel()
|
||||
|
||||
def run_converter(self, input_range, output_version, func):
|
||||
"""Runs a function that will convert file versions.
|
||||
"""
|
||||
Runs a function that will convert file versions in the `:param:input_range`
|
||||
to the `:param:output_version`.
|
||||
|
||||
Args:
|
||||
input_range (tuple): (int, int) The range of input versions this function will accept.
|
||||
output_version (int): The version this function will convert to.
|
||||
func (func): The function that will do the conversion, it will take the config
|
||||
dict as an argument and return the augmented dict.
|
||||
:param input_range: tuple, (int, int) the range of input versions this
|
||||
function will accept
|
||||
:param output_version: int, the version this function will return
|
||||
:param func: func, the function that will do the conversion, it will take
|
||||
the config dict as an argument and return the augmented dict
|
||||
|
||||
Raises:
|
||||
ValueError: If output_version is less than the input_range.
|
||||
:raises ValueError: if the output_version is less than the input_range
|
||||
|
||||
"""
|
||||
if output_version in input_range or output_version <= max(input_range):
|
||||
raise ValueError('output_version needs to be greater than input_range')
|
||||
raise ValueError("output_version needs to be greater than input_range")
|
||||
|
||||
if self.__version['file'] not in input_range:
|
||||
log.debug(
|
||||
'File version %s is not in input_range %s, ignoring converter function..',
|
||||
self.__version['file'],
|
||||
input_range,
|
||||
)
|
||||
if self.__version["file"] not in input_range:
|
||||
log.debug("File version %s is not in input_range %s, ignoring converter function..",
|
||||
self.__version["file"], input_range)
|
||||
return
|
||||
|
||||
try:
|
||||
self.__config = func(self.__config)
|
||||
except Exception as ex:
|
||||
log.exception(ex)
|
||||
log.error(
|
||||
'There was an exception try to convert config file %s %s to %s',
|
||||
self.__config_file,
|
||||
self.__version['file'],
|
||||
output_version,
|
||||
)
|
||||
raise ex
|
||||
except Exception, e:
|
||||
log.exception(e)
|
||||
log.error("There was an exception try to convert config file %s %s to %s",
|
||||
self.__config_file, self.__version["file"], output_version)
|
||||
raise e
|
||||
else:
|
||||
self.__version['file'] = output_version
|
||||
self.__version["file"] = output_version
|
||||
self.save()
|
||||
|
||||
@property
|
||||
def config_file(self):
|
||||
return self.__config_file
|
||||
|
||||
@property
|
||||
def config(self):
|
||||
@prop
|
||||
def config():
|
||||
"""The config dictionary"""
|
||||
return self.__config
|
||||
|
||||
@config.deleter
|
||||
def config(self):
|
||||
return self.save()
|
||||
def fget(self):
|
||||
return self.__config
|
||||
def fdel(self):
|
||||
return self.save()
|
||||
return locals()
|
||||
|
||||
@ -1,13 +1,40 @@
|
||||
#
|
||||
# configmanager.py
|
||||
#
|
||||
# Copyright (C) 2007 Andrew Resch <andrewresch@gmail.com>
|
||||
#
|
||||
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
|
||||
# the additional special exception to link portions of this program with the OpenSSL library.
|
||||
# See LICENSE for more details.
|
||||
# Deluge is free software.
|
||||
#
|
||||
# You may redistribute it and/or modify it under the terms of the
|
||||
# GNU General Public License, as published by the Free Software
|
||||
# Foundation; either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# deluge is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with deluge. If not, write to:
|
||||
# The Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor
|
||||
# Boston, MA 02110-1301, USA.
|
||||
#
|
||||
# In addition, as a special exception, the copyright holders give
|
||||
# permission to link the code of portions of this program with the OpenSSL
|
||||
# library.
|
||||
# You must obey the GNU General Public License in all respects for all of
|
||||
# the code used other than OpenSSL. If you modify file(s) with this
|
||||
# exception, you may extend this exception to your version of the file(s),
|
||||
# but you are not obligated to do so. If you do not wish to do so, delete
|
||||
# this exception statement from your version. If you delete this exception
|
||||
# statement from all source files in the program, then also delete it here.
|
||||
#
|
||||
#
|
||||
|
||||
import logging
|
||||
import os
|
||||
import logging
|
||||
|
||||
import deluge.common
|
||||
import deluge.log
|
||||
@ -15,10 +42,9 @@ from deluge.config import Config
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class _ConfigManager:
|
||||
def __init__(self):
|
||||
log.debug('ConfigManager started..')
|
||||
log.debug("ConfigManager started..")
|
||||
self.config_files = {}
|
||||
self.__config_directory = None
|
||||
|
||||
@ -43,19 +69,16 @@ class _ConfigManager:
|
||||
if not directory:
|
||||
return False
|
||||
|
||||
# Ensure absolute dirpath
|
||||
directory = os.path.abspath(directory)
|
||||
|
||||
log.info('Setting config directory to: %s', directory)
|
||||
log.info("Setting config directory to: %s", directory)
|
||||
if not os.path.exists(directory):
|
||||
# Try to create the config folder if it doesn't exist
|
||||
try:
|
||||
os.makedirs(directory)
|
||||
except OSError as ex:
|
||||
log.error('Unable to make config directory: %s', ex)
|
||||
except Exception, e:
|
||||
log.error("Unable to make config directory: %s", e)
|
||||
return False
|
||||
elif not os.path.isdir(directory):
|
||||
log.error('Config directory needs to be a directory!')
|
||||
log.error("Config directory needs to be a directory!")
|
||||
return False
|
||||
|
||||
self.__config_directory = directory
|
||||
@ -86,42 +109,30 @@ class _ConfigManager:
|
||||
# We need to return True to keep the timer active
|
||||
return True
|
||||
|
||||
def get_config(self, config_file, defaults=None, file_version=1):
|
||||
def get_config(self, config_file, defaults=None):
|
||||
"""Get a reference to the Config object for this filename"""
|
||||
log.debug('Getting config: %s', config_file)
|
||||
log.debug("Getting config '%s'", config_file)
|
||||
# Create the config object if not already created
|
||||
if config_file not in self.config_files:
|
||||
self.config_files[config_file] = Config(
|
||||
config_file,
|
||||
defaults,
|
||||
config_dir=self.config_directory,
|
||||
file_version=file_version,
|
||||
)
|
||||
if config_file not in self.config_files.keys():
|
||||
self.config_files[config_file] = Config(config_file, defaults, self.config_directory)
|
||||
|
||||
return self.config_files[config_file]
|
||||
|
||||
|
||||
# Singleton functions
|
||||
_configmanager = _ConfigManager()
|
||||
|
||||
|
||||
def ConfigManager(config, defaults=None, file_version=1): # NOQA: N802
|
||||
return _configmanager.get_config(
|
||||
config, defaults=defaults, file_version=file_version
|
||||
)
|
||||
|
||||
def ConfigManager(config, defaults=None):
|
||||
return _configmanager.get_config(config, defaults)
|
||||
|
||||
def set_config_dir(directory):
|
||||
"""Sets the config directory, else just uses default"""
|
||||
return _configmanager.set_config_dir(deluge.common.decode_bytes(directory))
|
||||
|
||||
return _configmanager.set_config_dir(directory)
|
||||
|
||||
def get_config_dir(filename=None):
|
||||
if filename is not None:
|
||||
if filename != None:
|
||||
return os.path.join(_configmanager.get_config_dir(), filename)
|
||||
else:
|
||||
return _configmanager.get_config_dir()
|
||||
|
||||
|
||||
def close(config):
|
||||
return _configmanager.close(config)
|
||||
|
||||
@ -1,192 +0,0 @@
|
||||
#
|
||||
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
|
||||
# the additional special exception to link portions of this program with the OpenSSL library.
|
||||
# See LICENSE for more details.
|
||||
#
|
||||
|
||||
import tempfile
|
||||
import warnings
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
import pytest
|
||||
import pytest_twisted
|
||||
from twisted.internet import reactor
|
||||
from twisted.internet.defer import Deferred, maybeDeferred
|
||||
from twisted.internet.error import CannotListenError
|
||||
from twisted.python.failure import Failure
|
||||
|
||||
import deluge.component as _component
|
||||
import deluge.configmanager
|
||||
from deluge.common import get_localhost_auth
|
||||
from deluge.tests import common
|
||||
from deluge.ui.client import client as _client
|
||||
|
||||
DEFAULT_LISTEN_PORT = 58900
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def listen_port(request):
|
||||
if request and 'daemon' in request.fixturenames:
|
||||
try:
|
||||
return request.getfixturevalue('daemon').listen_port
|
||||
except Exception:
|
||||
pass
|
||||
return DEFAULT_LISTEN_PORT
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_callback():
|
||||
"""Returns a `Mock` object which can be registered as a callback to test against.
|
||||
|
||||
If callback was not called within `timeout` seconds, it will raise a TimeoutError.
|
||||
The returned Mock instance will have a `deferred` attribute which will complete when the callback has been called.
|
||||
"""
|
||||
|
||||
def reset():
|
||||
if mock.called:
|
||||
original_reset_mock()
|
||||
deferred = Deferred()
|
||||
deferred.addTimeout(0.5, reactor)
|
||||
mock.side_effect = lambda *args, **kw: deferred.callback((args, kw))
|
||||
mock.deferred = deferred
|
||||
|
||||
mock = Mock()
|
||||
original_reset_mock = mock.reset_mock
|
||||
mock.reset_mock = reset
|
||||
mock.reset_mock()
|
||||
return mock
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def config_dir(tmp_path):
|
||||
deluge.configmanager.set_config_dir(tmp_path)
|
||||
yield tmp_path
|
||||
|
||||
|
||||
@pytest_twisted.async_yield_fixture()
|
||||
async def client(request, config_dir, monkeypatch, listen_port):
|
||||
# monkeypatch.setattr(
|
||||
# _client, 'connect', functools.partial(_client.connect, port=listen_port)
|
||||
# )
|
||||
try:
|
||||
username, password = get_localhost_auth()
|
||||
except Exception:
|
||||
username, password = '', ''
|
||||
await _client.connect(
|
||||
'localhost',
|
||||
port=listen_port,
|
||||
username=username,
|
||||
password=password,
|
||||
)
|
||||
yield _client
|
||||
if _client.connected():
|
||||
await _client.disconnect()
|
||||
|
||||
|
||||
@pytest_twisted.async_yield_fixture
|
||||
async def daemon(request, config_dir):
|
||||
listen_port = DEFAULT_LISTEN_PORT
|
||||
logfile = f'daemon_{request.node.name}.log'
|
||||
if hasattr(request.cls, 'daemon_custom_script'):
|
||||
custom_script = request.cls.daemon_custom_script
|
||||
else:
|
||||
custom_script = ''
|
||||
|
||||
for dummy in range(10):
|
||||
try:
|
||||
d, daemon = common.start_core(
|
||||
listen_port=listen_port,
|
||||
logfile=logfile,
|
||||
timeout=5,
|
||||
timeout_msg='Timeout!',
|
||||
custom_script=custom_script,
|
||||
print_stdout=True,
|
||||
print_stderr=True,
|
||||
config_directory=config_dir,
|
||||
)
|
||||
await d
|
||||
except CannotListenError as ex:
|
||||
exception_error = ex
|
||||
listen_port += 1
|
||||
except (KeyboardInterrupt, SystemExit):
|
||||
raise
|
||||
else:
|
||||
break
|
||||
else:
|
||||
raise exception_error
|
||||
daemon.listen_port = listen_port
|
||||
yield daemon
|
||||
await daemon.kill()
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def common_fixture(config_dir, request, monkeypatch, listen_port):
|
||||
"""Adds some instance attributes to test classes for backwards compatibility with old testing."""
|
||||
|
||||
def fail(self, reason):
|
||||
if isinstance(reason, Failure):
|
||||
reason = reason.value
|
||||
return pytest.fail(str(reason))
|
||||
|
||||
if request.instance:
|
||||
request.instance.patch = monkeypatch.setattr
|
||||
request.instance.config_dir = config_dir
|
||||
request.instance.listen_port = listen_port
|
||||
request.instance.id = lambda: request.node.name
|
||||
request.cls.fail = fail
|
||||
|
||||
|
||||
@pytest_twisted.async_yield_fixture(scope='function')
|
||||
async def component(request):
|
||||
"""Verify component registry is clean, and clean up after test."""
|
||||
if len(_component._ComponentRegistry.components) != 0:
|
||||
warnings.warn(
|
||||
'The component._ComponentRegistry.components is not empty on test setup.\n'
|
||||
'This is probably caused by another test that did not clean up after finishing!: %s'
|
||||
% _component._ComponentRegistry.components
|
||||
)
|
||||
|
||||
yield _component
|
||||
|
||||
await _component.shutdown()
|
||||
_component._ComponentRegistry.components.clear()
|
||||
_component._ComponentRegistry.dependents.clear()
|
||||
|
||||
|
||||
@pytest_twisted.async_yield_fixture(scope='function')
|
||||
async def base_fixture(common_fixture, component, request):
|
||||
"""This fixture is autoused on all tests that subclass BaseTestCase"""
|
||||
self = request.instance
|
||||
|
||||
if hasattr(self, 'set_up'):
|
||||
try:
|
||||
await maybeDeferred(self.set_up)
|
||||
except Exception as exc:
|
||||
warnings.warn('Error caught in test setup!\n%s' % exc)
|
||||
pytest.fail('Error caught in test setup!\n%s' % exc)
|
||||
|
||||
yield
|
||||
|
||||
if hasattr(self, 'tear_down'):
|
||||
try:
|
||||
await maybeDeferred(self.tear_down)
|
||||
except Exception as exc:
|
||||
pytest.fail('Error caught in test teardown!\n%s' % exc)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('base_fixture')
|
||||
class BaseTestCase:
|
||||
"""This is the base class that should be used for all test classes
|
||||
that create classes that inherit from deluge.component.Component. It
|
||||
ensures that the component registry has been cleaned up when tests
|
||||
have finished.
|
||||
|
||||
"""
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_mkstemp(tmp_path):
|
||||
"""Return known tempfile location to verify file deleted"""
|
||||
tmp_file = tempfile.mkstemp(dir=tmp_path)
|
||||
with patch('tempfile.mkstemp', return_value=tmp_file):
|
||||
yield tmp_file
|
||||
@ -1,58 +1,72 @@
|
||||
#
|
||||
# alertmanager.py
|
||||
#
|
||||
# Copyright (C) 2007-2009 Andrew Resch <andrewresch@gmail.com>
|
||||
#
|
||||
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
|
||||
# the additional special exception to link portions of this program with the OpenSSL library.
|
||||
# See LICENSE for more details.
|
||||
# Deluge is free software.
|
||||
#
|
||||
# You may redistribute it and/or modify it under the terms of the
|
||||
# GNU General Public License, as published by the Free Software
|
||||
# Foundation; either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# deluge is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with deluge. If not, write to:
|
||||
# The Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor
|
||||
# Boston, MA 02110-1301, USA.
|
||||
#
|
||||
# In addition, as a special exception, the copyright holders give
|
||||
# permission to link the code of portions of this program with the OpenSSL
|
||||
# library.
|
||||
# You must obey the GNU General Public License in all respects for all of
|
||||
# the code used other than OpenSSL. If you modify file(s) with this
|
||||
# exception, you may extend this exception to your version of the file(s),
|
||||
# but you are not obligated to do so. If you do not wish to do so, delete
|
||||
# this exception statement from your version. If you delete this exception
|
||||
# statement from all source files in the program, then also delete it here.
|
||||
#
|
||||
|
||||
"""
|
||||
|
||||
The AlertManager handles all the libtorrent alerts.
|
||||
|
||||
This should typically only be used by the Core. Plugins should utilize the
|
||||
This should typically only be used by the Core. Plugins should utilize the
|
||||
`:mod:EventManager` for similar functionality.
|
||||
|
||||
"""
|
||||
import logging
|
||||
from types import SimpleNamespace
|
||||
|
||||
import logging
|
||||
from twisted.internet import reactor
|
||||
|
||||
import deluge.component as component
|
||||
from deluge._libtorrent import lt
|
||||
from deluge.common import decode_bytes
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class AlertManager(component.Component):
|
||||
"""AlertManager fetches and processes libtorrent alerts"""
|
||||
|
||||
def __init__(self):
|
||||
log.debug('AlertManager init...')
|
||||
component.Component.__init__(self, 'AlertManager', interval=0.3)
|
||||
self.session = component.get('Core').session
|
||||
log.debug("AlertManager initialized..")
|
||||
component.Component.__init__(self, "AlertManager", interval=0.05)
|
||||
self.session = component.get("Core").session
|
||||
|
||||
# Increase the alert queue size so that alerts don't get lost.
|
||||
self.alert_queue_size = 10000
|
||||
self.set_alert_queue_size(self.alert_queue_size)
|
||||
|
||||
alert_mask = (
|
||||
lt.alert.category_t.error_notification
|
||||
| lt.alert.category_t.port_mapping_notification
|
||||
| lt.alert.category_t.storage_notification
|
||||
| lt.alert.category_t.tracker_notification
|
||||
| lt.alert.category_t.status_notification
|
||||
| lt.alert.category_t.ip_block_notification
|
||||
| lt.alert.category_t.performance_warning
|
||||
| lt.alert.category_t.file_progress_notification
|
||||
)
|
||||
|
||||
self.session.apply_settings({'alert_mask': alert_mask})
|
||||
self.session.set_alert_mask(
|
||||
lt.alert.category_t.error_notification |
|
||||
lt.alert.category_t.port_mapping_notification |
|
||||
lt.alert.category_t.storage_notification |
|
||||
lt.alert.category_t.tracker_notification |
|
||||
lt.alert.category_t.status_notification |
|
||||
lt.alert.category_t.ip_block_notification |
|
||||
lt.alert.category_t.performance_warning)
|
||||
|
||||
# handlers is a dictionary of lists {"alert_type": [handler1,h2,..]}
|
||||
self.handlers = {}
|
||||
|
||||
self.delayed_calls = []
|
||||
|
||||
def update(self):
|
||||
@ -60,9 +74,8 @@ class AlertManager(component.Component):
|
||||
self.handle_alerts()
|
||||
|
||||
def stop(self):
|
||||
for delayed_call in self.delayed_calls:
|
||||
if delayed_call.active():
|
||||
delayed_call.cancel()
|
||||
for dc in self.delayed_calls:
|
||||
dc.cancel()
|
||||
self.delayed_calls = []
|
||||
|
||||
def register_handler(self, alert_type, handler):
|
||||
@ -81,7 +94,7 @@ class AlertManager(component.Component):
|
||||
|
||||
# Append the handler to the list in the handlers dictionary
|
||||
self.handlers[alert_type].append(handler)
|
||||
log.debug('Registered handler for alert %s', alert_type)
|
||||
log.debug("Registered handler for alert %s", alert_type)
|
||||
|
||||
def deregister_handler(self, handler):
|
||||
"""
|
||||
@ -90,53 +103,31 @@ class AlertManager(component.Component):
|
||||
:param handler: func, the handler function to deregister
|
||||
"""
|
||||
# Iterate through all handlers and remove 'handler' where found
|
||||
for (dummy_key, value) in self.handlers.items():
|
||||
for (key, value) in self.handlers.items():
|
||||
if handler in value:
|
||||
# Handler is in this alert type list
|
||||
value.remove(handler)
|
||||
|
||||
def handle_alerts(self):
|
||||
def handle_alerts(self, wait=False):
|
||||
"""
|
||||
Pops all libtorrent alerts in the session queue and handles them appropriately.
|
||||
Pops all libtorrent alerts in the session queue and handles them
|
||||
appropriately.
|
||||
|
||||
:param wait: bool, if True then the handler functions will be run right
|
||||
away and waited to return before processing the next alert
|
||||
"""
|
||||
alerts = self.session.pop_alerts()
|
||||
if not alerts:
|
||||
return
|
||||
|
||||
num_alerts = len(alerts)
|
||||
if log.isEnabledFor(logging.DEBUG):
|
||||
log.debug('Alerts queued: %s', num_alerts)
|
||||
if num_alerts > 0.9 * self.alert_queue_size:
|
||||
log.warning(
|
||||
'Warning total alerts queued, %s, passes 90%% of queue size.',
|
||||
num_alerts,
|
||||
)
|
||||
|
||||
alert = self.session.pop_alert()
|
||||
# Loop through all alerts in the queue
|
||||
for alert in alerts:
|
||||
while alert is not None:
|
||||
alert_type = type(alert).__name__
|
||||
# Display the alert message
|
||||
if log.isEnabledFor(logging.DEBUG):
|
||||
log.debug('%s: %s', alert_type, decode_bytes(alert.message()))
|
||||
log.debug("%s: %s", alert_type, alert.message())
|
||||
# Call any handlers for this alert type
|
||||
if alert_type in self.handlers:
|
||||
for handler in self.handlers[alert_type]:
|
||||
if log.isEnabledFor(logging.DEBUG):
|
||||
log.debug('Handling alert: %s', alert_type)
|
||||
# Copy alert attributes
|
||||
alert_copy = SimpleNamespace(
|
||||
**{
|
||||
attr: getattr(alert, attr)
|
||||
for attr in dir(alert)
|
||||
if not attr.startswith('__')
|
||||
}
|
||||
)
|
||||
self.delayed_calls.append(reactor.callLater(0, handler, alert_copy))
|
||||
if not wait:
|
||||
self.delayed_calls.append(reactor.callLater(0, handler, alert))
|
||||
else:
|
||||
handler(alert)
|
||||
|
||||
def set_alert_queue_size(self, queue_size):
|
||||
"""Sets the maximum size of the libtorrent alert queue"""
|
||||
log.info('Alert Queue Size set to %s', queue_size)
|
||||
self.alert_queue_size = queue_size
|
||||
component.get('Core').apply_session_setting(
|
||||
'alert_queue_size', self.alert_queue_size
|
||||
)
|
||||
alert = self.session.pop_alert()
|
||||
|
||||
@ -1,43 +1,69 @@
|
||||
#
|
||||
# authmanager.py
|
||||
#
|
||||
# Copyright (C) 2009 Andrew Resch <andrewresch@gmail.com>
|
||||
# Copyright (C) 2011 Pedro Algarvio <pedro@algarvio.me>
|
||||
#
|
||||
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
|
||||
# the additional special exception to link portions of this program with the OpenSSL library.
|
||||
# See LICENSE for more details.
|
||||
# Deluge is free software.
|
||||
#
|
||||
# You may redistribute it and/or modify it under the terms of the
|
||||
# GNU General Public License, as published by the Free Software
|
||||
# Foundation; either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# deluge is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with deluge. If not, write to:
|
||||
# The Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor
|
||||
# Boston, MA 02110-1301, USA.
|
||||
#
|
||||
# In addition, as a special exception, the copyright holders give
|
||||
# permission to link the code of portions of this program with the OpenSSL
|
||||
# library.
|
||||
# You must obey the GNU General Public License in all respects for all of
|
||||
# the code used other than OpenSSL. If you modify file(s) with this
|
||||
# exception, you may extend this exception to your version of the file(s),
|
||||
# but you are not obligated to do so. If you do not wish to do so, delete
|
||||
# this exception statement from your version. If you delete this exception
|
||||
# statement from all source files in the program, then also delete it here.
|
||||
#
|
||||
#
|
||||
|
||||
import logging
|
||||
import os
|
||||
import random
|
||||
import stat
|
||||
import shutil
|
||||
import logging
|
||||
|
||||
import deluge.component as component
|
||||
import deluge.configmanager as configmanager
|
||||
from deluge.common import (
|
||||
AUTH_LEVEL_ADMIN,
|
||||
AUTH_LEVEL_DEFAULT,
|
||||
AUTH_LEVEL_NONE,
|
||||
AUTH_LEVEL_NORMAL,
|
||||
AUTH_LEVEL_READONLY,
|
||||
create_localclient_account,
|
||||
)
|
||||
from deluge.error import AuthenticationRequired, AuthManagerError, BadLoginError
|
||||
from deluge.common import (AUTH_LEVEL_ADMIN, AUTH_LEVEL_NONE, AUTH_LEVEL_NORMAL,
|
||||
AUTH_LEVEL_READONLY, AUTH_LEVEL_DEFAULT,
|
||||
create_localclient_account)
|
||||
|
||||
from deluge.error import AuthManagerError, AuthenticationRequired, BadLoginError
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
AUTH_LEVELS_MAPPING = {
|
||||
'NONE': AUTH_LEVEL_NONE,
|
||||
'READONLY': AUTH_LEVEL_READONLY,
|
||||
'DEFAULT': AUTH_LEVEL_DEFAULT,
|
||||
'NORMAL': AUTH_LEVEL_NORMAL,
|
||||
'ADMIN': AUTH_LEVEL_ADMIN,
|
||||
'DEFAULT': AUTH_LEVEL_NORMAL,
|
||||
'NORMAL': AUTH_LEVEL_DEFAULT,
|
||||
'ADMIN': AUTH_LEVEL_ADMIN
|
||||
}
|
||||
AUTH_LEVELS_MAPPING_REVERSE = {v: k for k, v in AUTH_LEVELS_MAPPING.items()}
|
||||
|
||||
AUTH_LEVELS_MAPPING_REVERSE = {}
|
||||
for key, value in AUTH_LEVELS_MAPPING.iteritems():
|
||||
AUTH_LEVELS_MAPPING_REVERSE[value] = key
|
||||
|
||||
class Account:
|
||||
class Account(object):
|
||||
__slots__ = ('username', 'password', 'authlevel')
|
||||
|
||||
def __init__(self, username, password, authlevel):
|
||||
self.username = username
|
||||
self.password = password
|
||||
@ -48,19 +74,17 @@ class Account:
|
||||
'username': self.username,
|
||||
'password': self.password,
|
||||
'authlevel': AUTH_LEVELS_MAPPING_REVERSE[self.authlevel],
|
||||
'authlevel_int': self.authlevel,
|
||||
'authlevel_int': self.authlevel
|
||||
}
|
||||
|
||||
def __repr__(self):
|
||||
return '<Account username="{username}" authlevel={authlevel}>'.format(
|
||||
username=self.username,
|
||||
authlevel=self.authlevel,
|
||||
)
|
||||
return ('<Account username="%(username)s" authlevel=%(authlevel)s>' %
|
||||
self.__dict__)
|
||||
|
||||
|
||||
class AuthManager(component.Component):
|
||||
def __init__(self):
|
||||
component.Component.__init__(self, 'AuthManager', interval=10)
|
||||
component.Component.__init__(self, "AuthManager", interval=10)
|
||||
self.__auth = {}
|
||||
self.__auth_modification_time = None
|
||||
|
||||
@ -74,96 +98,93 @@ class AuthManager(component.Component):
|
||||
pass
|
||||
|
||||
def update(self):
|
||||
auth_file = configmanager.get_config_dir('auth')
|
||||
auth_file = configmanager.get_config_dir("auth")
|
||||
# Check for auth file and create if necessary
|
||||
if not os.path.isfile(auth_file):
|
||||
log.info('Authfile not found, recreating it.')
|
||||
if not os.path.exists(auth_file):
|
||||
log.info("Authfile not found, recreating it.")
|
||||
self.__load_auth_file()
|
||||
return
|
||||
|
||||
auth_file_modification_time = os.stat(auth_file).st_mtime
|
||||
if self.__auth_modification_time != auth_file_modification_time:
|
||||
log.info('Auth file changed, reloading it!')
|
||||
log.info("Auth file changed, reloading it!")
|
||||
self.__load_auth_file()
|
||||
|
||||
def authorize(self, username, password):
|
||||
"""Authorizes users based on username and password.
|
||||
"""
|
||||
Authorizes users based on username and password
|
||||
|
||||
Args:
|
||||
username (str): Username
|
||||
password (str): Password
|
||||
:param username: str, username
|
||||
:param password: str, password
|
||||
:returns: int, the auth level for this user
|
||||
:rtype: int
|
||||
|
||||
Returns:
|
||||
int: The auth level for this user.
|
||||
|
||||
Raises:
|
||||
AuthenticationRequired: If additional details are required to authenticate.
|
||||
BadLoginError: If the username does not exist or password does not match.
|
||||
:raises AuthenticationRequired: if aditional details are required to
|
||||
authenticate.
|
||||
:raises BadLoginError: if the username does not exist or password does
|
||||
not match.
|
||||
|
||||
"""
|
||||
if not username:
|
||||
raise AuthenticationRequired(
|
||||
'Username and Password are required.', username
|
||||
"Username and Password are required.", username
|
||||
)
|
||||
|
||||
if username not in self.__auth:
|
||||
# Let's try to re-load the file.. Maybe it's been updated
|
||||
self.__load_auth_file()
|
||||
if username not in self.__auth:
|
||||
raise BadLoginError('Username does not exist', username)
|
||||
raise BadLoginError("Username does not exist", username)
|
||||
|
||||
if self.__auth[username].password == password:
|
||||
# Return the users auth level
|
||||
return self.__auth[username].authlevel
|
||||
elif not password and self.__auth[username].password:
|
||||
raise AuthenticationRequired('Password is required', username)
|
||||
raise AuthenticationRequired("Password is required", username)
|
||||
else:
|
||||
raise BadLoginError('Password does not match', username)
|
||||
raise BadLoginError("Password does not match", username)
|
||||
|
||||
def has_account(self, username):
|
||||
return username in self.__auth
|
||||
|
||||
def get_known_accounts(self):
|
||||
"""Returns a list of known deluge usernames."""
|
||||
"""
|
||||
Returns a list of known deluge usernames.
|
||||
"""
|
||||
self.__load_auth_file()
|
||||
return [account.data() for account in self.__auth.values()]
|
||||
|
||||
def create_account(self, username, password, authlevel):
|
||||
if username in self.__auth:
|
||||
raise AuthManagerError('Username in use.', username)
|
||||
if authlevel not in AUTH_LEVELS_MAPPING:
|
||||
raise AuthManagerError('Invalid auth level: %s' % authlevel)
|
||||
raise AuthManagerError("Username in use.", username)
|
||||
try:
|
||||
self.__auth[username] = Account(
|
||||
username, password, AUTH_LEVELS_MAPPING[authlevel]
|
||||
)
|
||||
self.__auth[username] = Account(username, password,
|
||||
AUTH_LEVELS_MAPPING[authlevel])
|
||||
self.write_auth_file()
|
||||
return True
|
||||
except Exception as ex:
|
||||
log.exception(ex)
|
||||
raise ex
|
||||
except Exception, err:
|
||||
log.exception(err)
|
||||
raise err
|
||||
|
||||
def update_account(self, username, password, authlevel):
|
||||
if username not in self.__auth:
|
||||
raise AuthManagerError('Username not known', username)
|
||||
if authlevel not in AUTH_LEVELS_MAPPING:
|
||||
raise AuthManagerError('Invalid auth level: %s' % authlevel)
|
||||
raise AuthManagerError("Username not known", username)
|
||||
try:
|
||||
self.__auth[username].username = username
|
||||
self.__auth[username].password = password
|
||||
self.__auth[username].authlevel = AUTH_LEVELS_MAPPING[authlevel]
|
||||
self.write_auth_file()
|
||||
return True
|
||||
except Exception as ex:
|
||||
log.exception(ex)
|
||||
raise ex
|
||||
except Exception, err:
|
||||
log.exception(err)
|
||||
raise err
|
||||
|
||||
def remove_account(self, username):
|
||||
if username not in self.__auth:
|
||||
raise AuthManagerError('Username not known', username)
|
||||
elif username == component.get('RPCServer').get_session_user():
|
||||
raise AuthManagerError("Username not known", username)
|
||||
elif username == component.get("RPCServer").get_session_user():
|
||||
raise AuthManagerError(
|
||||
'You cannot delete your own account while logged in!', username
|
||||
"You cannot delete your own account while logged in!", username
|
||||
)
|
||||
|
||||
del self.__auth[username]
|
||||
@ -171,45 +192,36 @@ class AuthManager(component.Component):
|
||||
return True
|
||||
|
||||
def write_auth_file(self):
|
||||
filename = 'auth'
|
||||
filepath = os.path.join(configmanager.get_config_dir(), filename)
|
||||
filepath_bak = filepath + '.bak'
|
||||
filepath_tmp = filepath + '.tmp'
|
||||
old_auth_file = configmanager.get_config_dir("auth")
|
||||
new_auth_file = old_auth_file + '.new'
|
||||
bak_auth_file = old_auth_file + '.bak'
|
||||
# Let's first create a backup
|
||||
if os.path.exists(old_auth_file):
|
||||
shutil.copy2(old_auth_file, bak_auth_file)
|
||||
|
||||
try:
|
||||
if os.path.isfile(filepath):
|
||||
log.debug('Creating backup of %s at: %s', filename, filepath_bak)
|
||||
shutil.copy2(filepath, filepath_bak)
|
||||
except OSError as ex:
|
||||
log.error('Unable to backup %s to %s: %s', filepath, filepath_bak, ex)
|
||||
else:
|
||||
log.info('Saving the %s at: %s', filename, filepath)
|
||||
try:
|
||||
with open(filepath_tmp, 'w', encoding='utf8') as _file:
|
||||
for account in self.__auth.values():
|
||||
_file.write(
|
||||
'%(username)s:%(password)s:%(authlevel_int)s\n'
|
||||
% account.data()
|
||||
)
|
||||
_file.flush()
|
||||
os.fsync(_file.fileno())
|
||||
shutil.move(filepath_tmp, filepath)
|
||||
except OSError as ex:
|
||||
log.error('Unable to save %s: %s', filename, ex)
|
||||
if os.path.isfile(filepath_bak):
|
||||
log.info('Restoring backup of %s from: %s', filename, filepath_bak)
|
||||
shutil.move(filepath_bak, filepath)
|
||||
fd = open(new_auth_file, "w")
|
||||
for account in self.__auth.values():
|
||||
fd.write(
|
||||
"%(username)s:%(password)s:%(authlevel_int)s\n" %
|
||||
account.data()
|
||||
)
|
||||
fd.flush()
|
||||
os.fsync(fd.fileno())
|
||||
fd.close()
|
||||
os.rename(new_auth_file, old_auth_file)
|
||||
except:
|
||||
# Something failed, let's restore the previous file
|
||||
if os.path.exists(bak_auth_file):
|
||||
os.rename(bak_auth_file, old_auth_file)
|
||||
|
||||
self.__load_auth_file()
|
||||
|
||||
def __load_auth_file(self):
|
||||
save_and_reload = False
|
||||
filename = 'auth'
|
||||
auth_file = configmanager.get_config_dir(filename)
|
||||
auth_file_bak = auth_file + '.bak'
|
||||
|
||||
auth_file = configmanager.get_config_dir("auth")
|
||||
# Check for auth file and create if necessary
|
||||
if not os.path.isfile(auth_file):
|
||||
if not os.path.exists(auth_file):
|
||||
create_localclient_account()
|
||||
return self.__load_auth_file()
|
||||
|
||||
@ -220,33 +232,24 @@ class AuthManager(component.Component):
|
||||
# File didn't change, no need for re-parsing's
|
||||
return
|
||||
|
||||
for _filepath in (auth_file, auth_file_bak):
|
||||
log.info('Opening %s for load: %s', filename, _filepath)
|
||||
try:
|
||||
with open(_filepath, encoding='utf8') as _file:
|
||||
file_data = _file.readlines()
|
||||
except OSError as ex:
|
||||
log.warning('Unable to load %s: %s', _filepath, ex)
|
||||
file_data = []
|
||||
else:
|
||||
log.info('Successfully loaded %s: %s', filename, _filepath)
|
||||
break
|
||||
|
||||
# Load the auth file into a dictionary: {username: Account(...)}
|
||||
for line in file_data:
|
||||
line = line.strip()
|
||||
if line.startswith('#') or not line:
|
||||
# This line is a comment or empty
|
||||
f = open(auth_file, "r").readlines()
|
||||
|
||||
for line in f:
|
||||
if line.startswith("#"):
|
||||
# This is a comment line
|
||||
continue
|
||||
line = line.strip()
|
||||
try:
|
||||
lsplit = line.split(":")
|
||||
except Exception, e:
|
||||
log.error("Your auth file is malformed: %s", e)
|
||||
continue
|
||||
lsplit = line.split(':')
|
||||
if len(lsplit) == 2:
|
||||
username, password = lsplit
|
||||
log.warning(
|
||||
'Your auth entry for %s contains no auth level, '
|
||||
'using AUTH_LEVEL_DEFAULT(%s)..',
|
||||
username,
|
||||
AUTH_LEVEL_DEFAULT,
|
||||
)
|
||||
log.warning("Your auth entry for %s contains no auth level, "
|
||||
"using AUTH_LEVEL_DEFAULT(%s)..", username,
|
||||
AUTH_LEVEL_DEFAULT)
|
||||
if username == 'localclient':
|
||||
authlevel = AUTH_LEVEL_ADMIN
|
||||
else:
|
||||
@ -256,7 +259,8 @@ class AuthManager(component.Component):
|
||||
elif len(lsplit) == 3:
|
||||
username, password, authlevel = lsplit
|
||||
else:
|
||||
log.error('Your auth file is malformed: Incorrect number of fields!')
|
||||
log.error("Your auth file is malformed: "
|
||||
"Incorrect number of fields!")
|
||||
continue
|
||||
|
||||
username = username.strip()
|
||||
@ -267,19 +271,19 @@ class AuthManager(component.Component):
|
||||
try:
|
||||
authlevel = AUTH_LEVELS_MAPPING[authlevel]
|
||||
except KeyError:
|
||||
log.error(
|
||||
'Your auth file is malformed: %r is not a valid auth level',
|
||||
authlevel,
|
||||
)
|
||||
log.error("Your auth file is malformed: %r is not a valid auth "
|
||||
"level" % authlevel)
|
||||
continue
|
||||
|
||||
self.__auth[username] = Account(username, password, authlevel)
|
||||
|
||||
if 'localclient' not in self.__auth:
|
||||
if "localclient" not in self.__auth:
|
||||
create_localclient_account(True)
|
||||
return self.__load_auth_file()
|
||||
|
||||
|
||||
if save_and_reload:
|
||||
log.info('Re-writing auth file (upgrade)')
|
||||
log.info("Re-writing auth file (upgrade)")
|
||||
self.write_auth_file()
|
||||
self.__auth_modification_time = auth_file_modification_time
|
||||
|
||||
|
||||
1485
deluge/core/core.py
1485
deluge/core/core.py
File diff suppressed because it is too large
Load Diff
@ -1,203 +1,201 @@
|
||||
#
|
||||
# daemon.py
|
||||
#
|
||||
# Copyright (C) 2007-2009 Andrew Resch <andrewresch@gmail.com>
|
||||
#
|
||||
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
|
||||
# the additional special exception to link portions of this program with the OpenSSL library.
|
||||
# See LICENSE for more details.
|
||||
# Deluge is free software.
|
||||
#
|
||||
# You may redistribute it and/or modify it under the terms of the
|
||||
# GNU General Public License, as published by the Free Software
|
||||
# Foundation; either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# deluge is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with deluge. If not, write to:
|
||||
# The Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor
|
||||
# Boston, MA 02110-1301, USA.
|
||||
#
|
||||
# In addition, as a special exception, the copyright holders give
|
||||
# permission to link the code of portions of this program with the OpenSSL
|
||||
# library.
|
||||
# You must obey the GNU General Public License in all respects for all of
|
||||
# the code used other than OpenSSL. If you modify file(s) with this
|
||||
# exception, you may extend this exception to your version of the file(s),
|
||||
# but you are not obligated to do so. If you do not wish to do so, delete
|
||||
# this exception statement from your version. If you delete this exception
|
||||
# statement from all source files in the program, then also delete it here.
|
||||
#
|
||||
|
||||
"""The Deluge daemon"""
|
||||
import logging
|
||||
import os
|
||||
import socket
|
||||
|
||||
import logging
|
||||
from twisted.internet import reactor
|
||||
import twisted.internet.error
|
||||
|
||||
import deluge.component as component
|
||||
from deluge.common import get_version, is_ip, is_process_running, windows_check
|
||||
from deluge.configmanager import get_config_dir
|
||||
from deluge.core.core import Core
|
||||
import deluge.configmanager
|
||||
import deluge.common
|
||||
from deluge.core.rpcserver import RPCServer, export
|
||||
from deluge.error import DaemonRunningError
|
||||
|
||||
if windows_check():
|
||||
from win32api import SetConsoleCtrlHandler
|
||||
from win32con import CTRL_CLOSE_EVENT, CTRL_SHUTDOWN_EVENT
|
||||
import deluge.error
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def is_daemon_running(pid_file):
|
||||
"""
|
||||
Check for another running instance of the daemon using the same pid file.
|
||||
|
||||
Args:
|
||||
pid_file: The location of the file with pid, port values.
|
||||
|
||||
Returns:
|
||||
bool: True is daemon is running, False otherwise.
|
||||
|
||||
"""
|
||||
|
||||
try:
|
||||
with open(pid_file) as _file:
|
||||
pid, port = (int(x) for x in _file.readline().strip().split(';'))
|
||||
except (OSError, ValueError):
|
||||
return False
|
||||
|
||||
if is_process_running(pid):
|
||||
# Ensure it's a deluged process by trying to open a socket to it's port.
|
||||
_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
try:
|
||||
_socket.connect(('127.0.0.1', port))
|
||||
except OSError:
|
||||
# Can't connect, so pid is not a deluged process.
|
||||
return False
|
||||
else:
|
||||
# This is a deluged process!
|
||||
_socket.close()
|
||||
return True
|
||||
class Daemon(object):
|
||||
def __init__(self, options=None, args=None, classic=False):
|
||||
# Check for another running instance of the daemon
|
||||
if os.path.isfile(deluge.configmanager.get_config_dir("deluged.pid")):
|
||||
# Get the PID and the port of the supposedly running daemon
|
||||
try:
|
||||
(pid, port) = open(
|
||||
deluge.configmanager.get_config_dir("deluged.pid")
|
||||
).read().strip().split(";")
|
||||
pid = int(pid)
|
||||
port = int(port)
|
||||
except ValueError:
|
||||
pid = None
|
||||
port = None
|
||||
|
||||
|
||||
class Daemon:
|
||||
"""The Deluge Daemon class"""
|
||||
def process_running(pid):
|
||||
if deluge.common.windows_check():
|
||||
# Do some fancy WMI junk to see if the PID exists in Windows
|
||||
from win32com.client import GetObject
|
||||
def get_proclist():
|
||||
WMI = GetObject('winmgmts:')
|
||||
processes = WMI.InstancesOf('Win32_Process')
|
||||
return [process.Properties_('ProcessID').Value for process in processes]
|
||||
return pid in get_proclist()
|
||||
else:
|
||||
# We can just use os.kill on UNIX to test if the process is running
|
||||
try:
|
||||
os.kill(pid, 0)
|
||||
except OSError:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
listen_interface=None,
|
||||
outgoing_interface=None,
|
||||
interface=None,
|
||||
port=None,
|
||||
standalone=False,
|
||||
read_only_config_keys=None,
|
||||
):
|
||||
"""
|
||||
Args:
|
||||
listen_interface (str, optional): The IP address to listen to
|
||||
BitTorrent connections on.
|
||||
outgoing_interface (str, optional): The network interface name or
|
||||
IP address to open outgoing BitTorrent connections on.
|
||||
interface (str, optional): The IP address the daemon will
|
||||
listen for UI connections on.
|
||||
port (int, optional): The port the daemon will listen for UI
|
||||
connections on.
|
||||
standalone (bool, optional): If True the client is in Standalone
|
||||
mode otherwise, if False, start the daemon as separate process.
|
||||
read_only_config_keys (list of str, optional): A list of config
|
||||
keys that will not be altered by core.set_config() RPC method.
|
||||
"""
|
||||
self.standalone = standalone
|
||||
self.pid_file = get_config_dir('deluged.pid')
|
||||
log.info('Deluge daemon %s', get_version())
|
||||
if is_daemon_running(self.pid_file):
|
||||
raise DaemonRunningError(
|
||||
'Deluge daemon already running with this config directory!'
|
||||
)
|
||||
if pid is not None and process_running(pid):
|
||||
# Ok, so a process is running with this PID, let's make doubly-sure
|
||||
# it's a deluged process by trying to open a socket to it's port.
|
||||
import socket
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
try:
|
||||
s.connect(("127.0.0.1", port))
|
||||
except socket.error:
|
||||
# Can't connect, so it must not be a deluged process..
|
||||
pass
|
||||
else:
|
||||
# This is a deluged!
|
||||
s.close()
|
||||
raise deluge.error.DaemonRunningError(
|
||||
"There is a deluge daemon running with this config "
|
||||
"directory!"
|
||||
)
|
||||
|
||||
# Twisted catches signals to terminate, so just have it call the shutdown method.
|
||||
reactor.addSystemEventTrigger('before', 'shutdown', self._shutdown)
|
||||
# Twisted catches signals to terminate, so just have it call the shutdown
|
||||
# method.
|
||||
reactor.addSystemEventTrigger("after", "shutdown", self.shutdown)
|
||||
|
||||
# Catch some Windows specific signals
|
||||
if windows_check():
|
||||
|
||||
if deluge.common.windows_check():
|
||||
from win32api import SetConsoleCtrlHandler
|
||||
from win32con import CTRL_CLOSE_EVENT
|
||||
from win32con import CTRL_SHUTDOWN_EVENT
|
||||
def win_handler(ctrl_type):
|
||||
"""Handle the Windows shutdown or close events."""
|
||||
log.debug('windows handler ctrl_type: %s', ctrl_type)
|
||||
log.debug("ctrl_type: %s", ctrl_type)
|
||||
if ctrl_type == CTRL_CLOSE_EVENT or ctrl_type == CTRL_SHUTDOWN_EVENT:
|
||||
self._shutdown()
|
||||
return 1
|
||||
|
||||
SetConsoleCtrlHandler(win_handler)
|
||||
|
||||
version = deluge.common.get_version()
|
||||
|
||||
log.info("Deluge daemon %s", version)
|
||||
log.debug("options: %s", options)
|
||||
log.debug("args: %s", args)
|
||||
# Set the config directory
|
||||
if options and options.config:
|
||||
deluge.configmanager.set_config_dir(options.config)
|
||||
|
||||
from deluge.core.core import Core
|
||||
# Start the core as a thread and join it until it's done
|
||||
self.core = Core(
|
||||
listen_interface=listen_interface,
|
||||
outgoing_interface=outgoing_interface,
|
||||
read_only_config_keys=read_only_config_keys,
|
||||
)
|
||||
self.core = Core()
|
||||
|
||||
if port is None:
|
||||
port = self.core.config['daemon_port']
|
||||
self.port = port
|
||||
|
||||
if interface and not is_ip(interface):
|
||||
log.error('Invalid UI interface (must be IP Address): %s', interface)
|
||||
interface = None
|
||||
port = self.core.config["daemon_port"]
|
||||
if options and options.port:
|
||||
port = options.port
|
||||
if options and options.ui_interface:
|
||||
interface = options.ui_interface
|
||||
else:
|
||||
interface = ""
|
||||
|
||||
self.rpcserver = RPCServer(
|
||||
port=port,
|
||||
allow_remote=self.core.config['allow_remote'],
|
||||
listen=not standalone,
|
||||
interface=interface,
|
||||
allow_remote=self.core.config["allow_remote"],
|
||||
listen=not classic,
|
||||
interface=interface
|
||||
)
|
||||
|
||||
log.debug(
|
||||
'Listening to UI on: %s:%s and bittorrent on: %s Making connections out on: %s',
|
||||
interface,
|
||||
port,
|
||||
listen_interface,
|
||||
outgoing_interface,
|
||||
)
|
||||
|
||||
def start(self):
|
||||
# Register the daemon and the core RPCs
|
||||
self.rpcserver.register_object(self.core)
|
||||
self.rpcserver.register_object(self)
|
||||
|
||||
# Make sure we start the PreferencesManager first
|
||||
component.start('PreferencesManager')
|
||||
|
||||
if not self.standalone:
|
||||
log.info('Deluge daemon starting...')
|
||||
# Create pid file to track if deluged is running, also includes the port number.
|
||||
pid = os.getpid()
|
||||
log.debug('Storing pid %s & port %s in: %s', pid, self.port, self.pid_file)
|
||||
with open(self.pid_file, 'w') as _file:
|
||||
_file.write(f'{pid};{self.port}\n')
|
||||
# Make sure we start the PreferencesManager first
|
||||
component.start("PreferencesManager")
|
||||
|
||||
if not classic:
|
||||
# Write out a pid file all the time, we use this to see if a deluged is running
|
||||
# We also include the running port number to do an additional test
|
||||
open(deluge.configmanager.get_config_dir("deluged.pid"), "wb").write(
|
||||
"%s;%s\n" % (os.getpid(), port))
|
||||
|
||||
component.start()
|
||||
|
||||
try:
|
||||
reactor.run()
|
||||
finally:
|
||||
log.debug('Remove pid file: %s', self.pid_file)
|
||||
os.remove(self.pid_file)
|
||||
log.info('Deluge daemon shutdown successfully')
|
||||
self._shutdown()
|
||||
|
||||
@export()
|
||||
def shutdown(self, *args, **kwargs):
|
||||
log.debug('Deluge daemon shutdown requested...')
|
||||
reactor.callLater(0, reactor.stop)
|
||||
|
||||
def _shutdown(self, *args, **kwargs):
|
||||
log.info('Deluge daemon shutting down, waiting for components to shutdown...')
|
||||
if not self.standalone:
|
||||
return component.shutdown()
|
||||
try:
|
||||
os.remove(deluge.configmanager.get_config_dir("deluged.pid"))
|
||||
except Exception, e:
|
||||
log.exception(e)
|
||||
log.error("Error removing deluged.pid!")
|
||||
|
||||
component.shutdown()
|
||||
try:
|
||||
reactor.stop()
|
||||
except twisted.internet.error.ReactorNotRunning:
|
||||
log.debug("Tried to stop the reactor but it is not running..")
|
||||
|
||||
@export()
|
||||
def get_method_list(self):
|
||||
"""Returns a list of the exported methods."""
|
||||
"""
|
||||
Returns a list of the exported methods.
|
||||
"""
|
||||
return self.rpcserver.get_method_list()
|
||||
|
||||
@export()
|
||||
def get_version(self):
|
||||
"""Returns the daemon version"""
|
||||
return get_version()
|
||||
|
||||
@export(1)
|
||||
def authorized_call(self, rpc):
|
||||
"""Determines if session auth_level is authorized to call RPC.
|
||||
|
||||
Args:
|
||||
rpc (str): A RPC, e.g. core.get_torrents_status
|
||||
|
||||
Returns:
|
||||
bool: True if authorized to call RPC, otherwise False.
|
||||
"""
|
||||
if rpc not in self.get_method_list():
|
||||
Returns True if authorized to call rpc.
|
||||
|
||||
:param rpc: a rpc, eg, "core.get_torrents_status"
|
||||
:type rpc: string
|
||||
|
||||
"""
|
||||
if not rpc in self.get_method_list():
|
||||
return False
|
||||
|
||||
return (
|
||||
self.rpcserver.get_session_auth_level()
|
||||
>= self.rpcserver.get_rpc_auth_level(rpc)
|
||||
)
|
||||
auth_level = self.rpcserver.get_session_auth_level()
|
||||
return auth_level >= self.rpcserver.get_rpc_auth_level()
|
||||
|
||||
@ -1,140 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2007 Andrew Resch <andrewresch@gmail.com>
|
||||
# Copyright (C) 2010 Pedro Algarvio <pedro@algarvio.me>
|
||||
#
|
||||
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
|
||||
# the additional special exception to link portions of this program with the OpenSSL library.
|
||||
# See LICENSE for more details.
|
||||
#
|
||||
import os
|
||||
import sys
|
||||
from logging import DEBUG, FileHandler, getLogger
|
||||
|
||||
from twisted.internet.error import CannotListenError
|
||||
|
||||
from deluge.argparserbase import ArgParserBase
|
||||
from deluge.common import run_profiled
|
||||
from deluge.configmanager import get_config_dir
|
||||
from deluge.i18n import setup_mock_translation
|
||||
|
||||
|
||||
def add_daemon_options(parser):
|
||||
group = parser.add_argument_group(_('Daemon Options'))
|
||||
group.add_argument(
|
||||
'-u',
|
||||
'--ui-interface',
|
||||
metavar='<ip-addr>',
|
||||
action='store',
|
||||
help=_('IP address to listen for UI connections'),
|
||||
)
|
||||
group.add_argument(
|
||||
'-p',
|
||||
'--port',
|
||||
metavar='<port>',
|
||||
action='store',
|
||||
type=int,
|
||||
help=_('Port to listen for UI connections on'),
|
||||
)
|
||||
group.add_argument(
|
||||
'-i',
|
||||
'--interface',
|
||||
metavar='<ip-addr>',
|
||||
dest='listen_interface',
|
||||
action='store',
|
||||
help=_('IP address to listen for BitTorrent connections'),
|
||||
)
|
||||
group.add_argument(
|
||||
'-o',
|
||||
'--outgoing-interface',
|
||||
metavar='<interface>',
|
||||
dest='outgoing_interface',
|
||||
action='store',
|
||||
help=_(
|
||||
'The network interface name or IP address for outgoing BitTorrent connections.'
|
||||
),
|
||||
)
|
||||
group.add_argument(
|
||||
'--read-only-config-keys',
|
||||
metavar='<comma-separated-keys>',
|
||||
action='store',
|
||||
help=_('Config keys to be unmodified by `set_config` RPC'),
|
||||
type=str,
|
||||
default='',
|
||||
)
|
||||
parser.add_process_arg_group()
|
||||
|
||||
|
||||
def start_daemon(skip_start=False):
|
||||
"""
|
||||
Entry point for daemon script
|
||||
|
||||
Args:
|
||||
skip_start (bool): If starting daemon should be skipped.
|
||||
|
||||
Returns:
|
||||
deluge.core.daemon.Daemon: A new daemon object
|
||||
|
||||
"""
|
||||
setup_mock_translation()
|
||||
|
||||
# Setup the argument parser
|
||||
parser = ArgParserBase()
|
||||
add_daemon_options(parser)
|
||||
|
||||
options = parser.parse_args()
|
||||
|
||||
# Check for any daemons running with this same config
|
||||
from deluge.core.daemon import is_daemon_running
|
||||
|
||||
pid_file = get_config_dir('deluged.pid')
|
||||
if is_daemon_running(pid_file):
|
||||
print(
|
||||
'Cannot run multiple daemons with same config directory.\n'
|
||||
'If you believe this is an error, force starting by deleting: %s' % pid_file
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
log = getLogger(__name__)
|
||||
|
||||
# If no logfile specified add logging to default location (as well as stdout)
|
||||
if not options.logfile:
|
||||
options.logfile = get_config_dir('deluged.log')
|
||||
file_handler = FileHandler(options.logfile)
|
||||
log.addHandler(file_handler)
|
||||
|
||||
def run_daemon(options):
|
||||
try:
|
||||
from deluge.core.daemon import Daemon
|
||||
|
||||
daemon = Daemon(
|
||||
listen_interface=options.listen_interface,
|
||||
outgoing_interface=options.outgoing_interface,
|
||||
interface=options.ui_interface,
|
||||
port=options.port,
|
||||
read_only_config_keys=options.read_only_config_keys.split(','),
|
||||
)
|
||||
if skip_start:
|
||||
return daemon
|
||||
else:
|
||||
daemon.start()
|
||||
except CannotListenError as ex:
|
||||
log.error(
|
||||
'Cannot start deluged, listen port in use.\n'
|
||||
' Check for other running daemons or services using this port: %s:%s',
|
||||
ex.interface,
|
||||
ex.port,
|
||||
)
|
||||
sys.exit(1)
|
||||
except Exception as ex:
|
||||
log.error('Unable to start deluged: %s', ex)
|
||||
if log.isEnabledFor(DEBUG):
|
||||
log.exception(ex)
|
||||
sys.exit(1)
|
||||
finally:
|
||||
log.info('Exiting...')
|
||||
if options.pidfile:
|
||||
os.remove(options.pidfile)
|
||||
|
||||
return run_profiled(
|
||||
run_daemon, options, output_file=options.profile, do_profile=options.profile
|
||||
)
|
||||
@ -1,21 +1,46 @@
|
||||
#
|
||||
# eventmanager.py
|
||||
#
|
||||
# Copyright (C) 2009 Andrew Resch <andrewresch@gmail.com>
|
||||
#
|
||||
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
|
||||
# the additional special exception to link portions of this program with the OpenSSL library.
|
||||
# See LICENSE for more details.
|
||||
# Deluge is free software.
|
||||
#
|
||||
# You may redistribute it and/or modify it under the terms of the
|
||||
# GNU General Public License, as published by the Free Software
|
||||
# Foundation; either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# deluge is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with deluge. If not, write to:
|
||||
# The Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor
|
||||
# Boston, MA 02110-1301, USA.
|
||||
#
|
||||
# In addition, as a special exception, the copyright holders give
|
||||
# permission to link the code of portions of this program with the OpenSSL
|
||||
# library.
|
||||
# You must obey the GNU General Public License in all respects for all of
|
||||
# the code used other than OpenSSL. If you modify file(s) with this
|
||||
# exception, you may extend this exception to your version of the file(s),
|
||||
# but you are not obligated to do so. If you do not wish to do so, delete
|
||||
# this exception statement from your version. If you delete this exception
|
||||
# statement from all source files in the program, then also delete it here.
|
||||
#
|
||||
#
|
||||
|
||||
import logging
|
||||
|
||||
import deluge.component as component
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class EventManager(component.Component):
|
||||
def __init__(self):
|
||||
component.Component.__init__(self, 'EventManager')
|
||||
component.Component.__init__(self, "EventManager")
|
||||
self.handlers = {}
|
||||
|
||||
def emit(self, event):
|
||||
@ -25,20 +50,15 @@ class EventManager(component.Component):
|
||||
:param event: DelugeEvent
|
||||
"""
|
||||
# Emit the event to the interested clients
|
||||
component.get('RPCServer').emit_event(event)
|
||||
component.get("RPCServer").emit_event(event)
|
||||
# Call any handlers for the event
|
||||
if event.name in self.handlers:
|
||||
for handler in self.handlers[event.name]:
|
||||
# log.debug('Running handler %s for event %s with args: %s', event.name, handler, event.args)
|
||||
#log.debug("Running handler %s for event %s with args: %s", event.name, handler, event.args)
|
||||
try:
|
||||
handler(*event.args)
|
||||
except Exception as ex:
|
||||
log.error(
|
||||
'Event handler %s failed in %s with exception %s',
|
||||
event.name,
|
||||
handler,
|
||||
ex,
|
||||
)
|
||||
except:
|
||||
log.error("Event handler %s failed in %s", event.name, handler)
|
||||
|
||||
def register_event_handler(self, event, handler):
|
||||
"""
|
||||
|
||||
@ -1,61 +1,85 @@
|
||||
#
|
||||
# core.py
|
||||
#
|
||||
# Copyright (C) 2008 Martijn Voncken <mvoncken@gmail.com>
|
||||
#
|
||||
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
|
||||
# the additional special exception to link portions of this program with the OpenSSL library.
|
||||
# See LICENSE for more details.
|
||||
# Deluge is free software.
|
||||
#
|
||||
# You may redistribute it and/or modify it under the terms of the
|
||||
# GNU General Public License, as published by the Free Software
|
||||
# Foundation; either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# deluge is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with deluge. If not, write to:
|
||||
# The Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor
|
||||
# Boston, MA 02110-1301, USA.
|
||||
#
|
||||
# In addition, as a special exception, the copyright holders give
|
||||
# permission to link the code of portions of this program with the OpenSSL
|
||||
# library.
|
||||
# You must obey the GNU General Public License in all respects for all of
|
||||
# the code used other than OpenSSL. If you modify file(s) with this
|
||||
# exception, you may extend this exception to your version of the file(s),
|
||||
# but you are not obligated to do so. If you do not wish to do so, delete
|
||||
# this exception statement from your version. If you delete this exception
|
||||
# statement from all source files in the program, then also delete it here.
|
||||
#
|
||||
#
|
||||
|
||||
import logging
|
||||
|
||||
import deluge.component as component
|
||||
from deluge.common import TORRENT_STATE
|
||||
|
||||
STATE_SORT = ["All", "Downloading", "Seeding", "Active", "Paused", "Queued"]
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
STATE_SORT = ['All', 'Active'] + TORRENT_STATE
|
||||
|
||||
|
||||
# Special purpose filters:
|
||||
#special purpose filters:
|
||||
def filter_keywords(torrent_ids, values):
|
||||
# Cleanup
|
||||
keywords = ','.join([v.lower() for v in values])
|
||||
keywords = keywords.split(',')
|
||||
#cleanup.
|
||||
keywords = ",".join([v.lower() for v in values])
|
||||
keywords = keywords.split(",")
|
||||
|
||||
|
||||
for keyword in keywords:
|
||||
torrent_ids = filter_one_keyword(torrent_ids, keyword)
|
||||
return torrent_ids
|
||||
|
||||
|
||||
def filter_one_keyword(torrent_ids, keyword):
|
||||
"""
|
||||
search torrent on keyword.
|
||||
searches title,state,tracker-status,tracker,files
|
||||
"""
|
||||
all_torrents = component.get('TorrentManager').torrents
|
||||
|
||||
all_torrents = component.get("TorrentManager").torrents
|
||||
#filter:
|
||||
found = False
|
||||
for torrent_id in torrent_ids:
|
||||
torrent = all_torrents[torrent_id]
|
||||
if keyword in torrent.filename.lower():
|
||||
yield torrent_id
|
||||
elif keyword in torrent.state.lower():
|
||||
yield torrent_id
|
||||
elif torrent.trackers and keyword in torrent.trackers[0]['url']:
|
||||
elif torrent.trackers and keyword in torrent.trackers[0]["url"]:
|
||||
yield torrent_id
|
||||
elif keyword in torrent_id:
|
||||
yield torrent_id
|
||||
# Want to find broken torrents (search on "error", or "unregistered")
|
||||
#i want to find broken torrents (search on "error", or "unregistered")
|
||||
elif keyword in torrent.tracker_status.lower():
|
||||
yield torrent_id
|
||||
else:
|
||||
for t_file in torrent.get_files():
|
||||
if keyword in t_file['path'].lower():
|
||||
if keyword in t_file["path"].lower():
|
||||
yield torrent_id
|
||||
break
|
||||
|
||||
|
||||
def filter_by_name(torrent_ids, search_string):
|
||||
all_torrents = component.get('TorrentManager').torrents
|
||||
all_torrents = component.get("TorrentManager").torrents
|
||||
try:
|
||||
search_string, match_case = search_string[0].split('::match')
|
||||
except ValueError:
|
||||
@ -75,51 +99,49 @@ def filter_by_name(torrent_ids, search_string):
|
||||
if search_string in torrent_name:
|
||||
yield torrent_id
|
||||
|
||||
|
||||
def tracker_error_filter(torrent_ids, values):
|
||||
filtered_torrent_ids = []
|
||||
tm = component.get('TorrentManager')
|
||||
tm = component.get("TorrentManager")
|
||||
|
||||
# If this is a tracker_host, then we need to filter on it
|
||||
if values[0] != 'Error':
|
||||
if values[0] != "Error":
|
||||
for torrent_id in torrent_ids:
|
||||
if values[0] == tm[torrent_id].get_status(['tracker_host'])['tracker_host']:
|
||||
if values[0] == tm[torrent_id].get_status(["tracker_host"])["tracker_host"]:
|
||||
filtered_torrent_ids.append(torrent_id)
|
||||
return filtered_torrent_ids
|
||||
|
||||
# Check torrent's tracker_status for 'Error:' and return those torrent_ids
|
||||
# Check all the torrent's tracker_status for 'Error:' and only return torrent_ids
|
||||
# that have this substring in their tracker_status
|
||||
for torrent_id in torrent_ids:
|
||||
if 'Error:' in tm[torrent_id].get_status(['tracker_status'])['tracker_status']:
|
||||
if _("Error") + ":" in tm[torrent_id].get_status(["tracker_status"])["tracker_status"]:
|
||||
filtered_torrent_ids.append(torrent_id)
|
||||
|
||||
return filtered_torrent_ids
|
||||
|
||||
|
||||
class FilterManager(component.Component):
|
||||
"""FilterManager"""
|
||||
"""FilterManager
|
||||
|
||||
"""
|
||||
def __init__(self, core):
|
||||
component.Component.__init__(self, 'FilterManager')
|
||||
log.debug('FilterManager init..')
|
||||
component.Component.__init__(self, "FilterManager")
|
||||
log.debug("FilterManager init..")
|
||||
self.core = core
|
||||
self.torrents = core.torrentmanager
|
||||
self.registered_filters = {}
|
||||
self.register_filter('keyword', filter_keywords)
|
||||
self.register_filter('name', filter_by_name)
|
||||
self.register_filter("keyword", filter_keywords)
|
||||
self.register_filter("name", filter_by_name)
|
||||
self.tree_fields = {}
|
||||
|
||||
self.register_tree_field('state', self._init_state_tree)
|
||||
|
||||
self.register_tree_field("state", self._init_state_tree)
|
||||
def _init_tracker_tree():
|
||||
return {'Error': 0}
|
||||
return {"Error": 0}
|
||||
self.register_tree_field("tracker_host", _init_tracker_tree)
|
||||
|
||||
self.register_tree_field('tracker_host', _init_tracker_tree)
|
||||
|
||||
self.register_filter('tracker_host', tracker_error_filter)
|
||||
self.register_filter("tracker_host", tracker_error_filter)
|
||||
|
||||
def _init_users_tree():
|
||||
return {'': 0}
|
||||
|
||||
self.register_tree_field('owner', _init_users_tree)
|
||||
return {"": 0}
|
||||
self.register_tree_field("owner", _init_users_tree)
|
||||
|
||||
def filter_torrent_ids(self, filter_dict):
|
||||
"""
|
||||
@ -129,61 +151,55 @@ class FilterManager(component.Component):
|
||||
if not filter_dict:
|
||||
return self.torrents.get_torrent_list()
|
||||
|
||||
# Sanitize input: filter-value must be a list of strings
|
||||
#sanitize input: filter-value must be a list of strings
|
||||
for key, value in filter_dict.items():
|
||||
if isinstance(value, str):
|
||||
filter_dict[key] = [value]
|
||||
filter_dict[key] = [value]
|
||||
|
||||
# Optimized filter for id
|
||||
if 'id' in filter_dict:
|
||||
torrent_ids = list(filter_dict['id'])
|
||||
del filter_dict['id']
|
||||
|
||||
if "id"in filter_dict: #optimized filter for id:
|
||||
torrent_ids = list(filter_dict["id"])
|
||||
del filter_dict["id"]
|
||||
else:
|
||||
torrent_ids = self.torrents.get_torrent_list()
|
||||
|
||||
# Return if there's nothing more to filter
|
||||
if not filter_dict:
|
||||
if not filter_dict: #return if there's nothing more to filter
|
||||
return torrent_ids
|
||||
|
||||
# Special purpose, state=Active.
|
||||
if 'state' in filter_dict:
|
||||
#special purpose: state=Active.
|
||||
if "state" in filter_dict:
|
||||
# We need to make sure this is a list for the logic below
|
||||
filter_dict['state'] = list(filter_dict['state'])
|
||||
filter_dict["state"] = list(filter_dict["state"])
|
||||
|
||||
if 'state' in filter_dict and 'Active' in filter_dict['state']:
|
||||
filter_dict['state'].remove('Active')
|
||||
if not filter_dict['state']:
|
||||
del filter_dict['state']
|
||||
if "state" in filter_dict and "Active" in filter_dict["state"]:
|
||||
filter_dict["state"].remove("Active")
|
||||
if not filter_dict["state"]:
|
||||
del filter_dict["state"]
|
||||
torrent_ids = self.filter_state_active(torrent_ids)
|
||||
|
||||
if not filter_dict:
|
||||
if not filter_dict: #return if there's nothing more to filter
|
||||
return torrent_ids
|
||||
|
||||
# Registered filters
|
||||
for field, values in list(filter_dict.items()):
|
||||
#Registered filters:
|
||||
for field, values in filter_dict.items():
|
||||
if field in self.registered_filters:
|
||||
# Filters out doubles
|
||||
torrent_ids = list(
|
||||
set(self.registered_filters[field](torrent_ids, values))
|
||||
)
|
||||
# a set filters out the doubles.
|
||||
torrent_ids = list(set(self.registered_filters[field](torrent_ids, values)))
|
||||
del filter_dict[field]
|
||||
|
||||
if not filter_dict:
|
||||
|
||||
if not filter_dict: #return if there's nothing more to filter
|
||||
return torrent_ids
|
||||
|
||||
torrent_keys, plugin_keys = self.torrents.separate_keys(
|
||||
list(filter_dict), torrent_ids
|
||||
)
|
||||
# Leftover filter arguments, default filter on status fields.
|
||||
#leftover filter arguments:
|
||||
#default filter on status fields.
|
||||
status_func = self.core.get_torrent_status #premature optimalisation..
|
||||
for torrent_id in list(torrent_ids):
|
||||
status = self.core.create_torrent_status(
|
||||
torrent_id, torrent_keys, plugin_keys
|
||||
)
|
||||
for field, values in filter_dict.items():
|
||||
if field in status and status[field] in values:
|
||||
continue
|
||||
elif torrent_id in torrent_ids:
|
||||
status = status_func(torrent_id, filter_dict.keys()) #status={key:value}
|
||||
for field, values in filter_dict.iteritems():
|
||||
if (not status[field] in values) and torrent_id in torrent_ids:
|
||||
torrent_ids.remove(torrent_id)
|
||||
|
||||
return torrent_ids
|
||||
|
||||
def get_filter_tree(self, show_zero_hits=True, hide_cat=None):
|
||||
@ -192,58 +208,56 @@ class FilterManager(component.Component):
|
||||
for use in sidebar.
|
||||
"""
|
||||
torrent_ids = self.torrents.get_torrent_list()
|
||||
tree_keys = list(self.tree_fields)
|
||||
status_func = self.core.get_torrent_status #premature optimalisation..
|
||||
tree_keys = list(self.tree_fields.keys())
|
||||
if hide_cat:
|
||||
for cat in hide_cat:
|
||||
tree_keys.remove(cat)
|
||||
|
||||
torrent_keys, plugin_keys = self.torrents.separate_keys(tree_keys, torrent_ids)
|
||||
items = {field: self.tree_fields[field]() for field in tree_keys}
|
||||
items = dict( (field, self.tree_fields[field]()) for field in tree_keys)
|
||||
|
||||
#count status fields.
|
||||
for torrent_id in list(torrent_ids):
|
||||
status = self.core.create_torrent_status(
|
||||
torrent_id, torrent_keys, plugin_keys
|
||||
) # status={key:value}
|
||||
status = status_func(torrent_id, tree_keys) #status={key:value}
|
||||
for field in tree_keys:
|
||||
value = status[field]
|
||||
items[field][value] = items[field].get(value, 0) + 1
|
||||
|
||||
if 'tracker_host' in items:
|
||||
items['tracker_host']['All'] = len(torrent_ids)
|
||||
items['tracker_host']['Error'] = len(
|
||||
tracker_error_filter(torrent_ids, ('Error',))
|
||||
)
|
||||
if "tracker_host" in items:
|
||||
items["tracker_host"]["All"] = len(torrent_ids)
|
||||
items["tracker_host"]["Error"] = len(tracker_error_filter(torrent_ids, ("Error",)))
|
||||
|
||||
if not show_zero_hits:
|
||||
for cat in ['state', 'owner', 'tracker_host']:
|
||||
if cat in tree_keys:
|
||||
self._hide_state_items(items[cat])
|
||||
if "state" in tree_keys and not show_zero_hits:
|
||||
self._hide_state_items(items["state"])
|
||||
|
||||
# Return a dict of tuples:
|
||||
sorted_items = {field: sorted(items[field].items()) for field in tree_keys}
|
||||
#return a dict of tuples:
|
||||
sorted_items = {}
|
||||
for field in tree_keys:
|
||||
sorted_items[field] = sorted(items[field].iteritems())
|
||||
|
||||
if 'state' in tree_keys:
|
||||
sorted_items['state'].sort(key=self._sort_state_item)
|
||||
if "state" in tree_keys:
|
||||
sorted_items["state"].sort(self._sort_state_items)
|
||||
|
||||
return sorted_items
|
||||
|
||||
def _init_state_tree(self):
|
||||
init_state = {}
|
||||
init_state['All'] = len(self.torrents.get_torrent_list())
|
||||
for state in TORRENT_STATE:
|
||||
init_state[state] = 0
|
||||
init_state['Active'] = len(
|
||||
self.filter_state_active(self.torrents.get_torrent_list())
|
||||
)
|
||||
return init_state
|
||||
return {"All":len(self.torrents.get_torrent_list()),
|
||||
"Downloading":0,
|
||||
"Seeding":0,
|
||||
"Paused":0,
|
||||
"Checking":0,
|
||||
"Queued":0,
|
||||
"Error":0,
|
||||
"Active":len(self.filter_state_active(self.torrents.get_torrent_list()))
|
||||
}
|
||||
|
||||
def register_filter(self, filter_id, filter_func, filter_value=None):
|
||||
self.registered_filters[filter_id] = filter_func
|
||||
def register_filter(self, id, filter_func, filter_value = None):
|
||||
self.registered_filters[id] = filter_func
|
||||
|
||||
def deregister_filter(self, filter_id):
|
||||
del self.registered_filters[filter_id]
|
||||
def deregister_filter(self, id):
|
||||
del self.registered_filters[id]
|
||||
|
||||
def register_tree_field(self, field, init_func=lambda: {}):
|
||||
def register_tree_field(self, field, init_func = lambda : {}):
|
||||
self.tree_fields[field] = init_func
|
||||
|
||||
def deregister_tree_field(self, field):
|
||||
@ -251,24 +265,30 @@ class FilterManager(component.Component):
|
||||
del self.tree_fields[field]
|
||||
|
||||
def filter_state_active(self, torrent_ids):
|
||||
get_status = self.core.get_torrent_status
|
||||
for torrent_id in list(torrent_ids):
|
||||
status = self.torrents[torrent_id].get_status(
|
||||
['download_payload_rate', 'upload_payload_rate']
|
||||
)
|
||||
if status['download_payload_rate'] or status['upload_payload_rate']:
|
||||
pass
|
||||
status = get_status(torrent_id, ["download_payload_rate", "upload_payload_rate"])
|
||||
if status["download_payload_rate"] or status["upload_payload_rate"]:
|
||||
pass #ok
|
||||
else:
|
||||
torrent_ids.remove(torrent_id)
|
||||
return torrent_ids
|
||||
|
||||
def _hide_state_items(self, state_items):
|
||||
"""For hide(show)-zero hits"""
|
||||
for value, count in list(state_items.items()):
|
||||
if value != 'All' and count == 0:
|
||||
"for hide(show)-zero hits"
|
||||
for (value, count) in state_items.items():
|
||||
if value != "All" and count == 0:
|
||||
del state_items[value]
|
||||
|
||||
def _sort_state_item(self, item):
|
||||
try:
|
||||
return STATE_SORT.index(item[0])
|
||||
except ValueError:
|
||||
return 99
|
||||
def _sort_state_items(self, x, y):
|
||||
""
|
||||
if x[0] in STATE_SORT:
|
||||
ix = STATE_SORT.index(x[0])
|
||||
else:
|
||||
ix = 99
|
||||
if y[0] in STATE_SORT:
|
||||
iy = STATE_SORT.index(y[0])
|
||||
else:
|
||||
iy = 99
|
||||
|
||||
return ix - iy
|
||||
|
||||
143
deluge/core/oldstateupgrader.py
Normal file
143
deluge/core/oldstateupgrader.py
Normal file
@ -0,0 +1,143 @@
|
||||
#
|
||||
# oldstateupgrader.py
|
||||
#
|
||||
# Copyright (C) 2008 Andrew Resch <andrewresch@gmail.com>
|
||||
#
|
||||
# Deluge is free software.
|
||||
#
|
||||
# You may redistribute it and/or modify it under the terms of the
|
||||
# GNU General Public License, as published by the Free Software
|
||||
# Foundation; either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# deluge is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with deluge. If not, write to:
|
||||
# The Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor
|
||||
# Boston, MA 02110-1301, USA.
|
||||
#
|
||||
# In addition, as a special exception, the copyright holders give
|
||||
# permission to link the code of portions of this program with the OpenSSL
|
||||
# library.
|
||||
# You must obey the GNU General Public License in all respects for all of
|
||||
# the code used other than OpenSSL. If you modify file(s) with this
|
||||
# exception, you may extend this exception to your version of the file(s),
|
||||
# but you are not obligated to do so. If you do not wish to do so, delete
|
||||
# this exception statement from your version. If you delete this exception
|
||||
# statement from all source files in the program, then also delete it here.
|
||||
#
|
||||
#
|
||||
|
||||
|
||||
import os
|
||||
import os.path
|
||||
import pickle
|
||||
import cPickle
|
||||
import shutil
|
||||
import logging
|
||||
|
||||
from deluge._libtorrent import lt
|
||||
|
||||
from deluge.configmanager import ConfigManager, get_config_dir
|
||||
import deluge.core.torrentmanager
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
#start : http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286203
|
||||
def makeFakeClass(module, name):
|
||||
class FakeThing(object):
|
||||
pass
|
||||
FakeThing.__name__ = name
|
||||
FakeThing.__module__ = '(fake)' + module
|
||||
return FakeThing
|
||||
|
||||
class PickleUpgrader(pickle.Unpickler):
|
||||
def find_class(self, module, cname):
|
||||
# Pickle tries to load a couple things like copy_reg and
|
||||
# __builtin__.object even though a pickle file doesn't
|
||||
# explicitly reference them (afaict): allow them to be loaded
|
||||
# normally.
|
||||
if module in ('copy_reg', '__builtin__'):
|
||||
thing = pickle.Unpickler.find_class(self, module, cname)
|
||||
return thing
|
||||
return makeFakeClass(module, cname)
|
||||
# end: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286203
|
||||
|
||||
class OldStateUpgrader:
|
||||
def __init__(self):
|
||||
self.config = ConfigManager("core.conf")
|
||||
self.state05_location = os.path.join(get_config_dir(), "persistent.state")
|
||||
self.state10_location = os.path.join(get_config_dir(), "state", "torrents.state")
|
||||
if os.path.exists(self.state05_location) and not os.path.exists(self.state10_location):
|
||||
# If the 0.5 state file exists and the 1.0 doesn't, then let's upgrade it
|
||||
self.upgrade05()
|
||||
|
||||
def upgrade05(self):
|
||||
try:
|
||||
state = PickleUpgrader(open(self.state05_location, "rb")).load()
|
||||
except Exception, e:
|
||||
log.debug("Unable to open 0.5 state file: %s", e)
|
||||
return
|
||||
|
||||
# Check to see if we can upgrade this file
|
||||
if type(state).__name__ == 'list':
|
||||
log.warning("0.5 state file is too old to upgrade")
|
||||
return
|
||||
|
||||
new_state = deluge.core.torrentmanager.TorrentManagerState()
|
||||
for ti, uid in state.torrents.items():
|
||||
torrent_path = os.path.join(get_config_dir(), "torrentfiles", ti.filename)
|
||||
try:
|
||||
torrent_info = None
|
||||
log.debug("Attempting to create torrent_info from %s", torrent_path)
|
||||
_file = open(torrent_path, "rb")
|
||||
torrent_info = lt.torrent_info(lt.bdecode(_file.read()))
|
||||
_file.close()
|
||||
except (IOError, RuntimeError), e:
|
||||
log.warning("Unable to open %s: %s", torrent_path, e)
|
||||
|
||||
# Copy the torrent file to the new location
|
||||
import shutil
|
||||
shutil.copyfile(torrent_path, os.path.join(get_config_dir(), "state", str(torrent_info.info_hash()) + ".torrent"))
|
||||
|
||||
# Set the file prioritiy property if not already there
|
||||
if not hasattr(ti, "priorities"):
|
||||
ti.priorities = [1] * torrent_info.num_files()
|
||||
|
||||
# Create the new TorrentState object
|
||||
new_torrent = deluge.core.torrentmanager.TorrentState(
|
||||
torrent_id=str(torrent_info.info_hash()),
|
||||
filename=ti.filename,
|
||||
save_path=ti.save_dir,
|
||||
compact=ti.compact,
|
||||
paused=ti.user_paused,
|
||||
total_uploaded=ti.uploaded_memory,
|
||||
max_upload_speed=ti.upload_rate_limit,
|
||||
max_download_speed=ti.download_rate_limit,
|
||||
file_priorities=ti.priorities,
|
||||
queue=state.queue.index(ti)
|
||||
)
|
||||
# Append the object to the state list
|
||||
new_state.torrents.append(new_torrent)
|
||||
|
||||
# Now we need to write out the new state file
|
||||
try:
|
||||
log.debug("Saving torrent state file.")
|
||||
state_file = open(
|
||||
os.path.join(get_config_dir(), "state", "torrents.state"), "wb")
|
||||
cPickle.dump(new_state, state_file)
|
||||
state_file.close()
|
||||
except IOError, e:
|
||||
log.warning("Unable to save state file: %s", e)
|
||||
return
|
||||
|
||||
# Rename the persistent.state file
|
||||
try:
|
||||
os.rename(self.state05_location, self.state05_location + ".old")
|
||||
except Exception, e:
|
||||
log.debug("Unable to rename old persistent.state file! %s", e)
|
||||
@ -1,37 +1,62 @@
|
||||
#
|
||||
# pluginmanager.py
|
||||
#
|
||||
# Copyright (C) 2007 Andrew Resch <andrewresch@gmail.com>
|
||||
#
|
||||
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
|
||||
# the additional special exception to link portions of this program with the OpenSSL library.
|
||||
# See LICENSE for more details.
|
||||
# Deluge is free software.
|
||||
#
|
||||
# You may redistribute it and/or modify it under the terms of the
|
||||
# GNU General Public License, as published by the Free Software
|
||||
# Foundation; either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# deluge is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with deluge. If not, write to:
|
||||
# The Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor
|
||||
# Boston, MA 02110-1301, USA.
|
||||
#
|
||||
# In addition, as a special exception, the copyright holders give
|
||||
# permission to link the code of portions of this program with the OpenSSL
|
||||
# library.
|
||||
# You must obey the GNU General Public License in all respects for all of
|
||||
# the code used other than OpenSSL. If you modify file(s) with this
|
||||
# exception, you may extend this exception to your version of the file(s),
|
||||
# but you are not obligated to do so. If you do not wish to do so, delete
|
||||
# this exception statement from your version. If you delete this exception
|
||||
# statement from all source files in the program, then also delete it here.
|
||||
#
|
||||
#
|
||||
|
||||
|
||||
"""PluginManager for Core"""
|
||||
|
||||
import logging
|
||||
|
||||
from twisted.internet import defer
|
||||
|
||||
import deluge.component as component
|
||||
from deluge.event import PluginEnabledEvent, PluginDisabledEvent
|
||||
import deluge.pluginmanagerbase
|
||||
from deluge.event import PluginDisabledEvent, PluginEnabledEvent
|
||||
import deluge.component as component
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class PluginManager(deluge.pluginmanagerbase.PluginManagerBase, component.Component):
|
||||
class PluginManager(deluge.pluginmanagerbase.PluginManagerBase,
|
||||
component.Component):
|
||||
"""PluginManager handles the loading of plugins and provides plugins with
|
||||
functions to access parts of the core."""
|
||||
|
||||
def __init__(self, core):
|
||||
component.Component.__init__(self, 'CorePluginManager')
|
||||
component.Component.__init__(self, "CorePluginManager")
|
||||
|
||||
self.status_fields = {}
|
||||
|
||||
# Call the PluginManagerBase constructor
|
||||
deluge.pluginmanagerbase.PluginManagerBase.__init__(
|
||||
self, 'core.conf', 'deluge.plugin.core'
|
||||
)
|
||||
self, "core.conf", "deluge.plugin.core")
|
||||
|
||||
def start(self):
|
||||
# Enable plugins that are enabled in the config
|
||||
@ -45,44 +70,28 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase, component.Compon
|
||||
self.stop()
|
||||
|
||||
def update_plugins(self):
|
||||
for plugin in self.plugins:
|
||||
if hasattr(self.plugins[plugin], 'update'):
|
||||
for plugin in self.plugins.keys():
|
||||
if hasattr(self.plugins[plugin], "update"):
|
||||
try:
|
||||
self.plugins[plugin].update()
|
||||
except Exception as ex:
|
||||
log.exception(ex)
|
||||
except Exception, e:
|
||||
log.exception(e)
|
||||
|
||||
def enable_plugin(self, name):
|
||||
d = defer.succeed(True)
|
||||
if name not in self.plugins:
|
||||
d = deluge.pluginmanagerbase.PluginManagerBase.enable_plugin(self, name)
|
||||
|
||||
def on_enable_plugin(result):
|
||||
if result is True and name in self.plugins:
|
||||
component.get('EventManager').emit(PluginEnabledEvent(name))
|
||||
return result
|
||||
|
||||
d.addBoth(on_enable_plugin)
|
||||
return d
|
||||
super(PluginManager, self).enable_plugin(name)
|
||||
if name in self.plugins:
|
||||
component.get("EventManager").emit(PluginEnabledEvent(name))
|
||||
|
||||
def disable_plugin(self, name):
|
||||
d = defer.succeed(True)
|
||||
if name in self.plugins:
|
||||
d = deluge.pluginmanagerbase.PluginManagerBase.disable_plugin(self, name)
|
||||
|
||||
def on_disable_plugin(result):
|
||||
if name not in self.plugins:
|
||||
component.get('EventManager').emit(PluginDisabledEvent(name))
|
||||
return result
|
||||
|
||||
d.addBoth(on_disable_plugin)
|
||||
return d
|
||||
super(PluginManager, self).disable_plugin(name)
|
||||
if name not in self.plugins:
|
||||
component.get("EventManager").emit(PluginDisabledEvent(name))
|
||||
|
||||
def get_status(self, torrent_id, fields):
|
||||
"""Return the value of status fields for the selected torrent_id."""
|
||||
status = {}
|
||||
if len(fields) == 0:
|
||||
fields = list(self.status_fields)
|
||||
for field in fields:
|
||||
try:
|
||||
status[field] = self.status_fields[field](torrent_id)
|
||||
@ -93,13 +102,13 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase, component.Compon
|
||||
def register_status_field(self, field, function):
|
||||
"""Register a new status field. This can be used in the same way the
|
||||
client requests other status information from core."""
|
||||
log.debug('Registering status field %s with PluginManager', field)
|
||||
log.debug("Registering status field %s with PluginManager", field)
|
||||
self.status_fields[field] = function
|
||||
|
||||
def deregister_status_field(self, field):
|
||||
"""Deregisters a status field"""
|
||||
log.debug('Deregistering status field %s with PluginManager', field)
|
||||
log.debug("Deregistering status field %s with PluginManager", field)
|
||||
try:
|
||||
del self.status_fields[field]
|
||||
except Exception:
|
||||
log.warning('Unable to deregister status field %s', field)
|
||||
except:
|
||||
log.warning("Unable to deregister status field %s", field)
|
||||
|
||||
@ -1,158 +1,165 @@
|
||||
#
|
||||
# preferencesmanager.py
|
||||
#
|
||||
# Copyright (C) 2008-2010 Andrew Resch <andrewresch@gmail.com>
|
||||
#
|
||||
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
|
||||
# the additional special exception to link portions of this program with the OpenSSL library.
|
||||
# See LICENSE for more details.
|
||||
# Deluge is free software.
|
||||
#
|
||||
# You may redistribute it and/or modify it under the terms of the
|
||||
# GNU General Public License, as published by the Free Software
|
||||
# Foundation; either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# deluge is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with deluge. If not, write to:
|
||||
# The Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor
|
||||
# Boston, MA 02110-1301, USA.
|
||||
#
|
||||
# In addition, as a special exception, the copyright holders give
|
||||
# permission to link the code of portions of this program with the OpenSSL
|
||||
# library.
|
||||
# You must obey the GNU General Public License in all respects for all of
|
||||
# the code used other than OpenSSL. If you modify file(s) with this
|
||||
# exception, you may extend this exception to your version of the file(s),
|
||||
# but you are not obligated to do so. If you do not wish to do so, delete
|
||||
# this exception statement from your version. If you delete this exception
|
||||
# statement from all source files in the program, then also delete it here.
|
||||
#
|
||||
#
|
||||
|
||||
|
||||
import logging
|
||||
import os
|
||||
import platform
|
||||
import random
|
||||
import logging
|
||||
import threading
|
||||
from urllib.parse import quote_plus
|
||||
from urllib.request import urlopen
|
||||
|
||||
from twisted.internet.task import LoopingCall
|
||||
|
||||
from deluge._libtorrent import lt
|
||||
|
||||
from deluge.event import *
|
||||
import deluge.configmanager
|
||||
import deluge.common
|
||||
import deluge.component as component
|
||||
import deluge.configmanager
|
||||
from deluge._libtorrent import lt
|
||||
from deluge.event import ConfigValueChangedEvent
|
||||
|
||||
GeoIP = None
|
||||
try:
|
||||
from GeoIP import GeoIP
|
||||
except ImportError:
|
||||
try:
|
||||
from pygeoip import GeoIP
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
DEFAULT_PREFS = {
|
||||
'send_info': False,
|
||||
'info_sent': 0.0,
|
||||
'daemon_port': 58846,
|
||||
'allow_remote': False,
|
||||
'pre_allocate_storage': False,
|
||||
'download_location': deluge.common.get_default_download_dir(),
|
||||
'listen_ports': [6881, 6891],
|
||||
'listen_interface': '',
|
||||
'outgoing_interface': '',
|
||||
'random_port': True,
|
||||
'listen_random_port': None,
|
||||
'listen_use_sys_port': False,
|
||||
'listen_reuse_port': True,
|
||||
'outgoing_ports': [0, 0],
|
||||
'random_outgoing_ports': True,
|
||||
'copy_torrent_file': False,
|
||||
'del_copy_torrent_file': False,
|
||||
'torrentfiles_location': deluge.common.get_default_download_dir(),
|
||||
'plugins_location': os.path.join(deluge.configmanager.get_config_dir(), 'plugins'),
|
||||
'prioritize_first_last_pieces': False,
|
||||
'sequential_download': False,
|
||||
'dht': True,
|
||||
'upnp': True,
|
||||
'natpmp': True,
|
||||
'utpex': True,
|
||||
'lsd': True,
|
||||
'enc_in_policy': 1,
|
||||
'enc_out_policy': 1,
|
||||
'enc_level': 2,
|
||||
'max_connections_global': 200,
|
||||
'max_upload_speed': -1.0,
|
||||
'max_download_speed': -1.0,
|
||||
'max_upload_slots_global': 4,
|
||||
'max_half_open_connections': (
|
||||
lambda: deluge.common.windows_check()
|
||||
and (lambda: deluge.common.vista_check() and 4 or 8)()
|
||||
or 50
|
||||
)(),
|
||||
'max_connections_per_second': 20,
|
||||
'ignore_limits_on_local_network': True,
|
||||
'max_connections_per_torrent': -1,
|
||||
'max_upload_slots_per_torrent': -1,
|
||||
'max_upload_speed_per_torrent': -1,
|
||||
'max_download_speed_per_torrent': -1,
|
||||
'enabled_plugins': [],
|
||||
'add_paused': False,
|
||||
'max_active_seeding': 5,
|
||||
'max_active_downloading': 3,
|
||||
'max_active_limit': 8,
|
||||
'dont_count_slow_torrents': False,
|
||||
'queue_new_to_top': False,
|
||||
'stop_seed_at_ratio': False,
|
||||
'remove_seed_at_ratio': False,
|
||||
'stop_seed_ratio': 2.00,
|
||||
'share_ratio_limit': 2.00,
|
||||
'seed_time_ratio_limit': 7.00,
|
||||
'seed_time_limit': 180,
|
||||
'auto_managed': True,
|
||||
'move_completed': False,
|
||||
'move_completed_path': deluge.common.get_default_download_dir(),
|
||||
'move_completed_paths_list': [],
|
||||
'download_location_paths_list': [],
|
||||
'path_chooser_show_chooser_button_on_localhost': True,
|
||||
'path_chooser_auto_complete_enabled': True,
|
||||
'path_chooser_accelerator_string': 'Tab',
|
||||
'path_chooser_max_popup_rows': 20,
|
||||
'path_chooser_show_hidden_files': False,
|
||||
'new_release_check': True,
|
||||
'proxy': {
|
||||
'type': 0,
|
||||
'hostname': '',
|
||||
'username': '',
|
||||
'password': '',
|
||||
'port': 8080,
|
||||
'proxy_hostnames': True,
|
||||
'proxy_peer_connections': True,
|
||||
'proxy_tracker_connections': True,
|
||||
'force_proxy': False,
|
||||
'anonymous_mode': False,
|
||||
},
|
||||
'peer_tos': '0x00',
|
||||
'rate_limit_ip_overhead': True,
|
||||
'geoip_db_location': '/usr/share/GeoIP/GeoIP.dat',
|
||||
'cache_size': 512,
|
||||
'cache_expiry': 60,
|
||||
'auto_manage_prefer_seeds': False,
|
||||
'shared': False,
|
||||
'super_seeding': False,
|
||||
}
|
||||
"send_info": False,
|
||||
"info_sent": 0.0,
|
||||
"daemon_port": 58846,
|
||||
"allow_remote": False,
|
||||
"compact_allocation": False,
|
||||
"download_location": deluge.common.get_default_download_dir(),
|
||||
"listen_ports": [6881, 6891],
|
||||
"listen_interface": "",
|
||||
"copy_torrent_file": False,
|
||||
"del_copy_torrent_file": False,
|
||||
"torrentfiles_location": deluge.common.get_default_download_dir(),
|
||||
"plugins_location": os.path.join(deluge.configmanager.get_config_dir(), "plugins"),
|
||||
"prioritize_first_last_pieces": False,
|
||||
"sequential_download": False,
|
||||
"random_port": True,
|
||||
"dht": True,
|
||||
"upnp": True,
|
||||
"natpmp": True,
|
||||
"utpex": True,
|
||||
"lsd": True,
|
||||
"enc_in_policy": 1,
|
||||
"enc_out_policy": 1,
|
||||
"enc_level": 2,
|
||||
"enc_prefer_rc4": True,
|
||||
"max_connections_global": 200,
|
||||
"max_upload_speed": -1.0,
|
||||
"max_download_speed": -1.0,
|
||||
"max_upload_slots_global": 4,
|
||||
"max_half_open_connections": (lambda: deluge.common.windows_check() and
|
||||
(lambda: deluge.common.vista_check() and 4 or 8)() or 50)(),
|
||||
"max_connections_per_second": 20,
|
||||
"ignore_limits_on_local_network": True,
|
||||
"max_connections_per_torrent": -1,
|
||||
"max_upload_slots_per_torrent": -1,
|
||||
"max_upload_speed_per_torrent": -1,
|
||||
"max_download_speed_per_torrent": -1,
|
||||
"enabled_plugins": [],
|
||||
"add_paused": False,
|
||||
"max_active_seeding": 5,
|
||||
"max_active_downloading": 3,
|
||||
"max_active_limit": 8,
|
||||
"dont_count_slow_torrents": False,
|
||||
"queue_new_to_top": False,
|
||||
"stop_seed_at_ratio": False,
|
||||
"remove_seed_at_ratio": False,
|
||||
"stop_seed_ratio": 2.00,
|
||||
"share_ratio_limit": 2.00,
|
||||
"seed_time_ratio_limit": 7.00,
|
||||
"seed_time_limit": 180,
|
||||
"auto_managed": True,
|
||||
"move_completed": False,
|
||||
"move_completed_path": deluge.common.get_default_download_dir(),
|
||||
"new_release_check": True,
|
||||
"proxies": {
|
||||
"peer": {
|
||||
"type": 0,
|
||||
"hostname": "",
|
||||
"username": "",
|
||||
"password": "",
|
||||
"port": 8080
|
||||
},
|
||||
"web_seed": {
|
||||
"type": 0,
|
||||
"hostname": "",
|
||||
"username": "",
|
||||
"password": "",
|
||||
"port": 8080
|
||||
},
|
||||
"tracker": {
|
||||
"type": 0,
|
||||
"hostname": "",
|
||||
"username": "",
|
||||
"password": "",
|
||||
"port": 8080
|
||||
},
|
||||
"dht": {
|
||||
"type": 0,
|
||||
"hostname": "",
|
||||
"username": "",
|
||||
"password": "",
|
||||
"port": 8080
|
||||
},
|
||||
|
||||
},
|
||||
"outgoing_ports": [0, 0],
|
||||
"random_outgoing_ports": True,
|
||||
"peer_tos": "0x00",
|
||||
"rate_limit_ip_overhead": True,
|
||||
"geoip_db_location": "/usr/share/GeoIP/GeoIP.dat",
|
||||
"cache_size": 512,
|
||||
"cache_expiry": 60,
|
||||
"auto_manage_prefer_seeds": False,
|
||||
"shared": False
|
||||
}
|
||||
|
||||
class PreferencesManager(component.Component):
|
||||
def __init__(self):
|
||||
component.Component.__init__(self, 'PreferencesManager')
|
||||
self.config = deluge.configmanager.ConfigManager('core.conf', DEFAULT_PREFS)
|
||||
if 'proxies' in self.config:
|
||||
log.warning(
|
||||
'Updating config file for proxy, using "peer" values to fill new "proxy" setting'
|
||||
)
|
||||
self.config['proxy'].update(self.config['proxies']['peer'])
|
||||
log.warning('New proxy config is: %s', self.config['proxy'])
|
||||
del self.config['proxies']
|
||||
if 'i2p_proxy' in self.config and self.config['i2p_proxy']['hostname']:
|
||||
self.config['proxy'].update(self.config['i2p_proxy'])
|
||||
self.config['proxy']['type'] = 6
|
||||
del self.config['i2p_proxy']
|
||||
if 'anonymous_mode' in self.config:
|
||||
self.config['proxy']['anonymous_mode'] = self.config['anonymous_mode']
|
||||
del self.config['anonymous_mode']
|
||||
if 'proxy' in self.config:
|
||||
for key in DEFAULT_PREFS['proxy']:
|
||||
if key not in self.config['proxy']:
|
||||
self.config['proxy'][key] = DEFAULT_PREFS['proxy'][key]
|
||||
component.Component.__init__(self, "PreferencesManager")
|
||||
|
||||
self.core = component.get('Core')
|
||||
self.new_release_timer = None
|
||||
self.config = deluge.configmanager.ConfigManager("core.conf", DEFAULT_PREFS)
|
||||
if 'public' in self.config:
|
||||
log.debug("Updating configuration file: Renamed torrent's public "
|
||||
"attribute to shared.")
|
||||
self.config["shared"] = self.config["public"]
|
||||
del self.config["public"]
|
||||
|
||||
def start(self):
|
||||
self.core = component.get("Core")
|
||||
self.session = component.get("Core").session
|
||||
self.new_release_timer = None
|
||||
|
||||
# Set the initial preferences on start-up
|
||||
for key in DEFAULT_PREFS:
|
||||
self.do_config_set_func(key, self.config[key])
|
||||
@ -165,131 +172,123 @@ class PreferencesManager(component.Component):
|
||||
|
||||
# Config set functions
|
||||
def do_config_set_func(self, key, value):
|
||||
on_set_func = getattr(self, '_on_set_' + key, None)
|
||||
on_set_func = getattr(self, "_on_set_" + key, None)
|
||||
if on_set_func:
|
||||
if log.isEnabledFor(logging.DEBUG):
|
||||
log.debug('Config key: %s set to %s..', key, value)
|
||||
on_set_func(key, value)
|
||||
|
||||
def session_set_setting(self, key, value):
|
||||
settings = self.session.settings()
|
||||
setattr(settings, key, value)
|
||||
self.session.set_settings(settings)
|
||||
|
||||
def _on_config_value_change(self, key, value):
|
||||
if self.get_state() == 'Started':
|
||||
self.do_config_set_func(key, value)
|
||||
component.get('EventManager').emit(ConfigValueChangedEvent(key, value))
|
||||
self.do_config_set_func(key, value)
|
||||
component.get("EventManager").emit(ConfigValueChangedEvent(key, value))
|
||||
|
||||
def _on_set_torrentfiles_location(self, key, value):
|
||||
if self.config['copy_torrent_file']:
|
||||
if self.config["copy_torrent_file"]:
|
||||
try:
|
||||
os.makedirs(value)
|
||||
except OSError as ex:
|
||||
log.debug('Unable to make directory: %s', ex)
|
||||
except Exception, e:
|
||||
log.debug("Unable to make directory: %s", e)
|
||||
|
||||
def _on_set_listen_ports(self, key, value):
|
||||
self.__set_listen_on()
|
||||
# Only set the listen ports if random_port is not true
|
||||
if self.config["random_port"] is not True:
|
||||
log.debug("listen port range set to %s-%s", value[0], value[1])
|
||||
self.session.listen_on(
|
||||
value[0], value[1], str(self.config["listen_interface"])
|
||||
)
|
||||
|
||||
def _on_set_listen_interface(self, key, value):
|
||||
self.__set_listen_on()
|
||||
|
||||
def _on_set_outgoing_interface(self, key, value):
|
||||
"""Set interface name or IP address for outgoing BitTorrent connections."""
|
||||
value = value.strip() if value else ''
|
||||
self.core.apply_session_settings({'outgoing_interfaces': value})
|
||||
# Call the random_port callback since it'll do what we need
|
||||
self._on_set_random_port("random_port", self.config["random_port"])
|
||||
|
||||
def _on_set_random_port(self, key, value):
|
||||
self.__set_listen_on()
|
||||
|
||||
def __set_listen_on(self):
|
||||
"""Set the ports and interface address to listen for incoming connections on."""
|
||||
if self.config['random_port']:
|
||||
if not self.config['listen_random_port']:
|
||||
self.config['listen_random_port'] = random.randrange(49152, 65525)
|
||||
listen_ports = [
|
||||
self.config['listen_random_port']
|
||||
] * 2 # use single port range
|
||||
log.debug("random port value set to %s", value)
|
||||
# We need to check if the value has been changed to true and false
|
||||
# and then handle accordingly.
|
||||
if value:
|
||||
import random
|
||||
listen_ports = []
|
||||
randrange = lambda: random.randrange(49152, 65525)
|
||||
listen_ports.append(randrange())
|
||||
listen_ports.append(listen_ports[0]+10)
|
||||
else:
|
||||
self.config['listen_random_port'] = None
|
||||
listen_ports = self.config['listen_ports']
|
||||
listen_ports = self.config["listen_ports"]
|
||||
|
||||
if self.config['listen_interface']:
|
||||
interface = self.config['listen_interface'].strip()
|
||||
else:
|
||||
interface = '0.0.0.0'
|
||||
|
||||
log.debug(
|
||||
'Listen Interface: %s, Ports: %s with use_sys_port: %s',
|
||||
interface,
|
||||
listen_ports,
|
||||
self.config['listen_use_sys_port'],
|
||||
)
|
||||
interfaces = [
|
||||
f'{interface}:{port}'
|
||||
for port in range(listen_ports[0], listen_ports[1] + 1)
|
||||
]
|
||||
self.core.apply_session_settings(
|
||||
{
|
||||
'listen_system_port_fallback': self.config['listen_use_sys_port'],
|
||||
'listen_interfaces': ','.join(interfaces),
|
||||
}
|
||||
# Set the listen ports
|
||||
log.debug("listen port range set to %s-%s", listen_ports[0],
|
||||
listen_ports[1])
|
||||
self.session.listen_on(
|
||||
listen_ports[0], listen_ports[1],
|
||||
str(self.config["listen_interface"])
|
||||
)
|
||||
|
||||
def _on_set_outgoing_ports(self, key, value):
|
||||
self.__set_outgoing_ports()
|
||||
if not self.config["random_outgoing_ports"]:
|
||||
log.debug("outgoing port range set to %s-%s", value[0], value[1])
|
||||
self.session_set_setting("outgoing_ports", (value[0], value[1]))
|
||||
|
||||
def _on_set_random_outgoing_ports(self, key, value):
|
||||
self.__set_outgoing_ports()
|
||||
|
||||
def __set_outgoing_ports(self):
|
||||
port = (
|
||||
0
|
||||
if self.config['random_outgoing_ports']
|
||||
else self.config['outgoing_ports'][0]
|
||||
)
|
||||
if port:
|
||||
num_ports = (
|
||||
self.config['outgoing_ports'][1] - self.config['outgoing_ports'][0]
|
||||
)
|
||||
num_ports = num_ports if num_ports > 1 else 5
|
||||
else:
|
||||
num_ports = 0
|
||||
log.debug('Outgoing port set to %s with range: %s', port, num_ports)
|
||||
self.core.apply_session_settings(
|
||||
{'outgoing_port': port, 'num_outgoing_ports': num_ports}
|
||||
)
|
||||
if value:
|
||||
self.session.outgoing_ports(0, 0)
|
||||
|
||||
def _on_set_peer_tos(self, key, value):
|
||||
log.debug("setting peer_tos to: %s", value)
|
||||
try:
|
||||
self.core.apply_session_setting('peer_tos', int(value, 16))
|
||||
except ValueError as ex:
|
||||
log.error('Invalid tos byte: %s', ex)
|
||||
self.session_set_setting("peer_tos", chr(int(value, 16)))
|
||||
except ValueError, e:
|
||||
log.debug("Invalid tos byte: %s", e)
|
||||
return
|
||||
|
||||
def _on_set_dht(self, key, value):
|
||||
lt_bootstraps = self.core.session.get_settings()['dht_bootstrap_nodes']
|
||||
# Update list of lt bootstraps, using set to remove duplicates.
|
||||
dht_bootstraps = set(
|
||||
lt_bootstraps.split(',')
|
||||
+ [
|
||||
'router.bittorrent.com:6881',
|
||||
'router.utorrent.com:6881',
|
||||
'router.bitcomet.com:6881',
|
||||
'dht.transmissionbt.com:6881',
|
||||
'dht.aelitis.com:6881',
|
||||
]
|
||||
)
|
||||
self.core.apply_session_settings(
|
||||
{'dht_bootstrap_nodes': ','.join(dht_bootstraps), 'enable_dht': value}
|
||||
)
|
||||
log.debug("dht value set to %s", value)
|
||||
state_file = deluge.configmanager.get_config_dir("dht.state")
|
||||
if value:
|
||||
state = None
|
||||
try:
|
||||
state = lt.bdecode(open(state_file, "rb").read())
|
||||
except Exception, e:
|
||||
log.warning("Unable to read DHT state file: %s", e)
|
||||
|
||||
try:
|
||||
self.session.start_dht(state)
|
||||
except Exception, e:
|
||||
log.warning("Restoring old DHT state failed: %s", e)
|
||||
self.session.start_dht(None)
|
||||
self.session.add_dht_router("router.bittorrent.com", 6881)
|
||||
self.session.add_dht_router("router.utorrent.com", 6881)
|
||||
self.session.add_dht_router("router.bitcomet.com", 6881)
|
||||
else:
|
||||
self.core.save_dht_state()
|
||||
self.session.stop_dht()
|
||||
|
||||
def _on_set_upnp(self, key, value):
|
||||
self.core.apply_session_setting('enable_upnp', value)
|
||||
log.debug("upnp value set to %s", value)
|
||||
if value:
|
||||
self.session.start_upnp()
|
||||
else:
|
||||
self.session.stop_upnp()
|
||||
|
||||
def _on_set_natpmp(self, key, value):
|
||||
self.core.apply_session_setting('enable_natpmp', value)
|
||||
log.debug("natpmp value set to %s", value)
|
||||
if value:
|
||||
self.session.start_natpmp()
|
||||
else:
|
||||
self.session.stop_natpmp()
|
||||
|
||||
def _on_set_lsd(self, key, value):
|
||||
self.core.apply_session_setting('enable_lsd', value)
|
||||
log.debug("lsd value set to %s", value)
|
||||
if value:
|
||||
self.session.start_lsd()
|
||||
else:
|
||||
self.session.stop_lsd()
|
||||
|
||||
def _on_set_utpex(self, key, value):
|
||||
log.debug("utpex value set to %s", value)
|
||||
if value:
|
||||
self.core.session.add_extension('ut_pex')
|
||||
self.session.add_extension(lt.create_ut_pex_plugin)
|
||||
|
||||
def _on_set_enc_in_policy(self, key, value):
|
||||
self._on_set_encryption(key, value)
|
||||
@ -300,177 +299,179 @@ class PreferencesManager(component.Component):
|
||||
def _on_set_enc_level(self, key, value):
|
||||
self._on_set_encryption(key, value)
|
||||
|
||||
def _on_set_enc_prefer_rc4(self, key, value):
|
||||
self._on_set_encryption(key, value)
|
||||
|
||||
def _on_set_encryption(self, key, value):
|
||||
# Convert Deluge enc_level values to libtorrent enc_level values.
|
||||
pe_enc_level = {
|
||||
0: lt.enc_level.plaintext,
|
||||
1: lt.enc_level.rc4,
|
||||
2: lt.enc_level.both,
|
||||
}
|
||||
self.core.apply_session_settings(
|
||||
{
|
||||
'out_enc_policy': lt.enc_policy(self.config['enc_out_policy']),
|
||||
'in_enc_policy': lt.enc_policy(self.config['enc_in_policy']),
|
||||
'allowed_enc_level': lt.enc_level(
|
||||
pe_enc_level[self.config['enc_level']]
|
||||
),
|
||||
'prefer_rc4': True,
|
||||
}
|
||||
)
|
||||
log.debug("encryption value %s set to %s..", key, value)
|
||||
pe_settings = lt.pe_settings()
|
||||
pe_settings.out_enc_policy = \
|
||||
lt.enc_policy(self.config["enc_out_policy"])
|
||||
pe_settings.in_enc_policy = lt.enc_policy(self.config["enc_in_policy"])
|
||||
pe_settings.allowed_enc_level = lt.enc_level(self.config["enc_level"])
|
||||
pe_settings.prefer_rc4 = self.config["enc_prefer_rc4"]
|
||||
self.session.set_pe_settings(pe_settings)
|
||||
set = self.session.get_pe_settings()
|
||||
log.debug("encryption settings:\n\t\t\tout_policy: %s\n\t\t\
|
||||
in_policy: %s\n\t\t\tlevel: %s\n\t\t\tprefer_rc4: %s",
|
||||
set.out_enc_policy,
|
||||
set.in_enc_policy,
|
||||
set.allowed_enc_level,
|
||||
set.prefer_rc4)
|
||||
|
||||
def _on_set_max_connections_global(self, key, value):
|
||||
self.core.apply_session_setting('connections_limit', value)
|
||||
log.debug("max_connections_global set to %s..", value)
|
||||
self.session.set_max_connections(value)
|
||||
|
||||
def _on_set_max_upload_speed(self, key, value):
|
||||
log.debug("max_upload_speed set to %s..", value)
|
||||
# We need to convert Kb/s to B/s
|
||||
value = -1 if value < 0 else int(value * 1024)
|
||||
self.core.apply_session_setting('upload_rate_limit', value)
|
||||
if value < 0:
|
||||
v = -1
|
||||
else:
|
||||
v = int(value * 1024)
|
||||
|
||||
self.session.set_upload_rate_limit(v)
|
||||
|
||||
def _on_set_max_download_speed(self, key, value):
|
||||
log.debug("max_download_speed set to %s..", value)
|
||||
# We need to convert Kb/s to B/s
|
||||
value = -1 if value < 0 else int(value * 1024)
|
||||
self.core.apply_session_setting('download_rate_limit', value)
|
||||
if value < 0:
|
||||
v = -1
|
||||
else:
|
||||
v = int(value * 1024)
|
||||
self.session.set_download_rate_limit(v)
|
||||
|
||||
def _on_set_max_upload_slots_global(self, key, value):
|
||||
self.core.apply_session_setting('unchoke_slots_limit', value)
|
||||
log.debug("max_upload_slots_global set to %s..", value)
|
||||
self.session.set_max_uploads(value)
|
||||
|
||||
def _on_set_max_half_open_connections(self, key, value):
|
||||
self.core.apply_session_setting('half_open_limit', value)
|
||||
self.session.set_max_half_open_connections(value)
|
||||
|
||||
def _on_set_max_connections_per_second(self, key, value):
|
||||
self.core.apply_session_setting('connection_speed', value)
|
||||
self.session_set_setting("connection_speed", value)
|
||||
|
||||
def _on_set_ignore_limits_on_local_network(self, key, value):
|
||||
self.core.apply_session_setting('ignore_limits_on_local_network', value)
|
||||
self.session_set_setting("ignore_limits_on_local_network", value)
|
||||
|
||||
def _on_set_share_ratio_limit(self, key, value):
|
||||
# This value is a float percentage in deluge, but libtorrent needs int percentage.
|
||||
self.core.apply_session_setting('share_ratio_limit', int(value * 100))
|
||||
log.debug("%s set to %s..", key, value)
|
||||
self.session_set_setting("share_ratio_limit", value)
|
||||
|
||||
def _on_set_seed_time_ratio_limit(self, key, value):
|
||||
# This value is a float percentage in deluge, but libtorrent needs int percentage.
|
||||
self.core.apply_session_setting('seed_time_ratio_limit', int(value * 100))
|
||||
log.debug("%s set to %s..", key, value)
|
||||
self.session_set_setting("seed_time_ratio_limit", value)
|
||||
|
||||
def _on_set_seed_time_limit(self, key, value):
|
||||
log.debug("%s set to %s..", key, value)
|
||||
# This value is stored in minutes in deluge, but libtorrent wants seconds
|
||||
self.core.apply_session_setting('seed_time_limit', int(value * 60))
|
||||
self.session_set_setting("seed_time_limit", int(value * 60))
|
||||
|
||||
def _on_set_max_active_downloading(self, key, value):
|
||||
self.core.apply_session_setting('active_downloads', value)
|
||||
log.debug("%s set to %s..", key, value)
|
||||
self.session_set_setting("active_downloads", value)
|
||||
|
||||
def _on_set_max_active_seeding(self, key, value):
|
||||
self.core.apply_session_setting('active_seeds', value)
|
||||
log.debug("%s set to %s..", key, value)
|
||||
self.session_set_setting("active_seeds", value)
|
||||
|
||||
def _on_set_max_active_limit(self, key, value):
|
||||
self.core.apply_session_setting('active_limit', value)
|
||||
log.debug("%s set to %s..", key, value)
|
||||
self.session_set_setting("active_limit", value)
|
||||
|
||||
def _on_set_dont_count_slow_torrents(self, key, value):
|
||||
self.core.apply_session_setting('dont_count_slow_torrents', value)
|
||||
log.debug("%s set to %s..", key, value)
|
||||
self.session_set_setting("dont_count_slow_torrents", value)
|
||||
|
||||
def _on_set_send_info(self, key, value):
|
||||
log.debug("Sending anonymous stats..")
|
||||
"""sends anonymous stats home"""
|
||||
log.debug('Sending anonymous stats..')
|
||||
|
||||
class SendInfoThread(threading.Thread):
|
||||
class Send_Info_Thread(threading.Thread):
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
threading.Thread.__init__(self)
|
||||
|
||||
def run(self):
|
||||
import time
|
||||
|
||||
now = time.time()
|
||||
# check if we've done this within the last week or never
|
||||
if (now - self.config['info_sent']) >= (60 * 60 * 24 * 7):
|
||||
if (now - self.config["info_sent"]) >= (60 * 60 * 24 * 7):
|
||||
import deluge.common
|
||||
from urllib import quote_plus
|
||||
from urllib2 import urlopen
|
||||
import platform
|
||||
try:
|
||||
url = (
|
||||
'http://deluge-torrent.org/stats_get.php?processor='
|
||||
+ platform.machine()
|
||||
+ '&python='
|
||||
+ platform.python_version()
|
||||
+ '&deluge='
|
||||
+ deluge.common.get_version()
|
||||
+ '&os='
|
||||
+ platform.system()
|
||||
+ '&plugins='
|
||||
+ quote_plus(':'.join(self.config['enabled_plugins']))
|
||||
)
|
||||
url = "http://deluge-torrent.org/stats_get.php?processor=" + \
|
||||
platform.machine() + "&python=" + platform.python_version() \
|
||||
+ "&deluge=" + deluge.common.get_version() \
|
||||
+ "&os=" + platform.system() \
|
||||
+ "&plugins=" + quote_plus(":".join(self.config["enabled_plugins"]))
|
||||
urlopen(url)
|
||||
except OSError as ex:
|
||||
log.debug('Network error while trying to send info: %s', ex)
|
||||
except IOError, e:
|
||||
log.debug("Network error while trying to send info: %s", e)
|
||||
else:
|
||||
self.config['info_sent'] = now
|
||||
|
||||
self.config["info_sent"] = now
|
||||
if value:
|
||||
SendInfoThread(self.config).start()
|
||||
Send_Info_Thread(self.config).start()
|
||||
|
||||
def _on_set_new_release_check(self, key, value):
|
||||
if value:
|
||||
log.debug('Checking for new release..')
|
||||
log.debug("Checking for new release..")
|
||||
threading.Thread(target=self.core.get_new_release).start()
|
||||
if self.new_release_timer and self.new_release_timer.running:
|
||||
self.new_release_timer.stop()
|
||||
# Set a timer to check for a new release every 3 days
|
||||
self.new_release_timer = LoopingCall(
|
||||
self._on_set_new_release_check, 'new_release_check', True
|
||||
)
|
||||
self._on_set_new_release_check, "new_release_check", True)
|
||||
self.new_release_timer.start(72 * 60 * 60, False)
|
||||
else:
|
||||
if self.new_release_timer and self.new_release_timer.running:
|
||||
self.new_release_timer.stop()
|
||||
|
||||
def _on_set_proxy(self, key, value):
|
||||
# Initialise with type none and blank hostnames.
|
||||
proxy_settings = {
|
||||
'proxy_type': lt.proxy_type_t.none,
|
||||
'i2p_hostname': '',
|
||||
'proxy_hostname': '',
|
||||
'proxy_hostnames': value['proxy_hostnames'],
|
||||
'proxy_peer_connections': value['proxy_peer_connections'],
|
||||
'proxy_tracker_connections': value['proxy_tracker_connections'],
|
||||
'force_proxy': value['force_proxy'],
|
||||
'anonymous_mode': value['anonymous_mode'],
|
||||
}
|
||||
|
||||
if value['type'] == lt.proxy_type_t.i2p_proxy:
|
||||
proxy_settings.update(
|
||||
{
|
||||
'proxy_type': lt.proxy_type_t.i2p_proxy,
|
||||
'i2p_hostname': value['hostname'],
|
||||
'i2p_port': value['port'],
|
||||
}
|
||||
)
|
||||
elif value['type'] != lt.proxy_type_t.none:
|
||||
proxy_settings.update(
|
||||
{
|
||||
'proxy_type': value['type'],
|
||||
'proxy_hostname': value['hostname'],
|
||||
'proxy_port': value['port'],
|
||||
'proxy_username': value['username'],
|
||||
'proxy_password': value['password'],
|
||||
}
|
||||
)
|
||||
|
||||
self.core.apply_session_settings(proxy_settings)
|
||||
def _on_set_proxies(self, key, value):
|
||||
for k, v in value.items():
|
||||
if v["type"]:
|
||||
proxy_settings = lt.proxy_settings()
|
||||
proxy_settings.type = lt.proxy_type(v["type"])
|
||||
proxy_settings.username = str(v["username"])
|
||||
proxy_settings.password = str(v["password"])
|
||||
proxy_settings.hostname = str(v["hostname"])
|
||||
proxy_settings.port = v["port"]
|
||||
log.debug("setting %s proxy settings", k)
|
||||
getattr(self.session, "set_%s_proxy" % k)(proxy_settings)
|
||||
|
||||
def _on_set_rate_limit_ip_overhead(self, key, value):
|
||||
self.core.apply_session_setting('rate_limit_ip_overhead', value)
|
||||
log.debug("%s: %s", key, value)
|
||||
self.session_set_setting("rate_limit_ip_overhead", value)
|
||||
|
||||
def _on_set_geoip_db_location(self, key, geoipdb_path):
|
||||
def _on_set_geoip_db_location(self, key, value):
|
||||
log.debug("%s: %s", key, value)
|
||||
# Load the GeoIP DB for country look-ups if available
|
||||
if os.path.exists(geoipdb_path):
|
||||
try:
|
||||
self.core.geoip_instance = GeoIP(geoipdb_path, 0)
|
||||
except Exception as ex:
|
||||
log.warning('GeoIP Unavailable: %s', ex)
|
||||
geoip_db = ""
|
||||
if os.path.exists(value):
|
||||
geoip_db = value
|
||||
elif os.path.exists(deluge.common.resource_filename("deluge", os.path.join("data", "GeoIP.dat"))):
|
||||
geoip_db = deluge.common.resource_filename(
|
||||
"deluge", os.path.join("data", "GeoIP.dat")
|
||||
)
|
||||
else:
|
||||
log.warning('Unable to find GeoIP database file: %s', geoipdb_path)
|
||||
log.warning("Unable to find GeoIP database file!")
|
||||
|
||||
if geoip_db:
|
||||
try:
|
||||
self.session.load_country_db(str(geoip_db))
|
||||
except Exception, e:
|
||||
log.error("Unable to load geoip database!")
|
||||
log.exception(e)
|
||||
|
||||
def _on_set_cache_size(self, key, value):
|
||||
self.core.apply_session_setting('cache_size', value)
|
||||
log.debug("%s: %s", key, value)
|
||||
self.session_set_setting("cache_size", value)
|
||||
|
||||
def _on_set_cache_expiry(self, key, value):
|
||||
self.core.apply_session_setting('cache_expiry', value)
|
||||
log.debug("%s: %s", key, value)
|
||||
self.session_set_setting("cache_expiry", value)
|
||||
|
||||
def _on_auto_manage_prefer_seeds(self, key, value):
|
||||
self.core.apply_session_setting('auto_manage_prefer_seeds', value)
|
||||
log.debug("%s set to %s..", key, value)
|
||||
self.session_set_setting("auto_manage_prefer_seeds", value)
|
||||
|
||||
@ -1,40 +1,64 @@
|
||||
#
|
||||
# rpcserver.py
|
||||
#
|
||||
# Copyright (C) 2008,2009 Andrew Resch <andrewresch@gmail.com>
|
||||
#
|
||||
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
|
||||
# the additional special exception to link portions of this program with the OpenSSL library.
|
||||
# See LICENSE for more details.
|
||||
# Deluge is free software.
|
||||
#
|
||||
# You may redistribute it and/or modify it under the terms of the
|
||||
# GNU General Public License, as published by the Free Software
|
||||
# Foundation; either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# deluge is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with deluge. If not, write to:
|
||||
# The Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor
|
||||
# Boston, MA 02110-1301, USA.
|
||||
#
|
||||
# In addition, as a special exception, the copyright holders give
|
||||
# permission to link the code of portions of this program with the OpenSSL
|
||||
# library.
|
||||
# You must obey the GNU General Public License in all respects for all of
|
||||
# the code used other than OpenSSL. If you modify file(s) with this
|
||||
# exception, you may extend this exception to your version of the file(s),
|
||||
# but you are not obligated to do so. If you do not wish to do so, delete
|
||||
# this exception statement from your version. If you delete this exception
|
||||
# statement from all source files in the program, then also delete it here.
|
||||
#
|
||||
#
|
||||
|
||||
"""RPCServer Module"""
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import traceback
|
||||
from collections import namedtuple
|
||||
from types import FunctionType
|
||||
from typing import Callable, TypeVar, overload
|
||||
|
||||
from twisted.internet import defer, reactor
|
||||
from twisted.internet.protocol import Factory, connectionDone
|
||||
import sys
|
||||
import zlib
|
||||
import os
|
||||
import stat
|
||||
import logging
|
||||
import traceback
|
||||
|
||||
from twisted.internet.protocol import Factory, Protocol
|
||||
from twisted.internet import reactor, defer
|
||||
|
||||
from OpenSSL import crypto, SSL
|
||||
from types import FunctionType
|
||||
|
||||
try:
|
||||
import rencode
|
||||
except ImportError:
|
||||
import deluge.rencode as rencode
|
||||
|
||||
import deluge.component as component
|
||||
import deluge.configmanager
|
||||
from deluge.core.authmanager import (
|
||||
AUTH_LEVEL_ADMIN,
|
||||
AUTH_LEVEL_DEFAULT,
|
||||
AUTH_LEVEL_NONE,
|
||||
)
|
||||
from deluge.crypto_utils import check_ssl_keys, get_context_factory
|
||||
from deluge.error import (
|
||||
DelugeError,
|
||||
IncompatibleClient,
|
||||
NotAuthorizedError,
|
||||
WrappedException,
|
||||
_ClientSideRecreateError,
|
||||
)
|
||||
from deluge.event import ClientDisconnectedEvent
|
||||
from deluge.transfer import DelugeTransferProtocol
|
||||
from deluge.core.authmanager import (AUTH_LEVEL_NONE, AUTH_LEVEL_DEFAULT,
|
||||
AUTH_LEVEL_ADMIN)
|
||||
from deluge.error import (DelugeError, NotAuthorizedError, WrappedException,
|
||||
_ClientSideRecreateError, IncompatibleClient)
|
||||
|
||||
RPC_RESPONSE = 1
|
||||
RPC_ERROR = 2
|
||||
@ -42,19 +66,6 @@ RPC_EVENT = 3
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
TCallable = TypeVar('TCallable', bound=Callable)
|
||||
|
||||
|
||||
@overload
|
||||
def export(func: TCallable) -> TCallable:
|
||||
...
|
||||
|
||||
|
||||
@overload
|
||||
def export(auth_level: int) -> Callable[[TCallable], TCallable]:
|
||||
...
|
||||
|
||||
|
||||
def export(auth_level=AUTH_LEVEL_DEFAULT):
|
||||
"""
|
||||
Decorator function to register an object's method as an RPC. The object
|
||||
@ -66,27 +77,17 @@ def export(auth_level=AUTH_LEVEL_DEFAULT):
|
||||
:type auth_level: int
|
||||
|
||||
"""
|
||||
|
||||
def wrap(func, *args, **kwargs):
|
||||
func._rpcserver_export = True
|
||||
func._rpcserver_auth_level = auth_level
|
||||
|
||||
rpc_text = '**RPC exported method** (*Auth level: %s*)' % auth_level
|
||||
|
||||
# Append the RPC text while ensuring correct docstring formatting.
|
||||
if func.__doc__:
|
||||
if func.__doc__.endswith(' '):
|
||||
indent = func.__doc__.split('\n')[-1]
|
||||
func.__doc__ += f'\n{indent}'
|
||||
else:
|
||||
func.__doc__ += '\n\n'
|
||||
func.__doc__ += rpc_text
|
||||
else:
|
||||
func.__doc__ = rpc_text
|
||||
doc = func.__doc__
|
||||
func.__doc__ = "**RPC Exported Function** (*Auth Level: %s*)\n\n" % auth_level
|
||||
if doc:
|
||||
func.__doc__ += doc
|
||||
|
||||
return func
|
||||
|
||||
if isinstance(auth_level, FunctionType):
|
||||
if type(auth_level) is FunctionType:
|
||||
func = auth_level
|
||||
auth_level = AUTH_LEVEL_DEFAULT
|
||||
return wrap(func)
|
||||
@ -106,56 +107,83 @@ def format_request(call):
|
||||
|
||||
"""
|
||||
try:
|
||||
s = call[1] + '('
|
||||
s = call[1] + "("
|
||||
if call[2]:
|
||||
s += ', '.join([str(x) for x in call[2]])
|
||||
s += ", ".join([str(x) for x in call[2]])
|
||||
if call[3]:
|
||||
if call[2]:
|
||||
s += ', '
|
||||
s += ', '.join([key + '=' + str(value) for key, value in call[3].items()])
|
||||
s += ')'
|
||||
s += ", "
|
||||
s += ", ".join([key + "=" + str(value) for key, value in call[3].items()])
|
||||
s += ")"
|
||||
except UnicodeEncodeError:
|
||||
return 'UnicodeEncodeError, call: %s' % call
|
||||
return "UnicodeEncodeError, call: %s" % call
|
||||
else:
|
||||
return s
|
||||
|
||||
|
||||
class DelugeRPCProtocol(DelugeTransferProtocol):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
# namedtuple subclass with auth_level, username for the connected session.
|
||||
self.AuthLevel = namedtuple('SessionAuthlevel', 'auth_level, username')
|
||||
|
||||
def message_received(self, request):
|
||||
class ServerContextFactory(object):
|
||||
def getContext(self):
|
||||
"""
|
||||
This method is called whenever a message is received from a client. The
|
||||
Create an SSL context.
|
||||
|
||||
This loads the servers cert/private key SSL files for use with the
|
||||
SSL transport.
|
||||
"""
|
||||
ssl_dir = deluge.configmanager.get_config_dir("ssl")
|
||||
ctx = SSL.Context(SSL.SSLv3_METHOD)
|
||||
ctx.use_certificate_file(os.path.join(ssl_dir, "daemon.cert"))
|
||||
ctx.use_privatekey_file(os.path.join(ssl_dir, "daemon.pkey"))
|
||||
return ctx
|
||||
|
||||
class DelugeRPCProtocol(Protocol):
|
||||
__buffer = None
|
||||
|
||||
def dataReceived(self, data):
|
||||
"""
|
||||
This method is called whenever data is received from a client. The
|
||||
only message that a client sends to the server is a RPC Request message.
|
||||
If the RPC Request message is valid, then the method is called in
|
||||
:meth:`dispatch`.
|
||||
|
||||
:param request: the request from the client.
|
||||
:type data: tuple
|
||||
:param data: the data from the client. It should be a zlib compressed
|
||||
rencoded string.
|
||||
:type data: str
|
||||
|
||||
"""
|
||||
if not isinstance(request, tuple):
|
||||
log.debug('Received invalid message: type is not tuple')
|
||||
return
|
||||
if self.__buffer:
|
||||
# We have some data from the last dataReceived() so lets prepend it
|
||||
data = self.__buffer + data
|
||||
self.__buffer = None
|
||||
|
||||
if len(request) < 1:
|
||||
log.debug('Received invalid message: there are no items')
|
||||
return
|
||||
while data:
|
||||
dobj = zlib.decompressobj()
|
||||
try:
|
||||
request = rencode.loads(dobj.decompress(data))
|
||||
except Exception, e:
|
||||
#log.debug("Received possible invalid message (%r): %s", data, e)
|
||||
# This could be cut-off data, so we'll save this in the buffer
|
||||
# and try to prepend it on the next dataReceived()
|
||||
self.__buffer = data
|
||||
return
|
||||
else:
|
||||
data = dobj.unused_data
|
||||
|
||||
for call in request:
|
||||
if len(call) != 4:
|
||||
log.debug(
|
||||
'Received invalid rpc request: number of items ' 'in request is %s',
|
||||
len(call),
|
||||
)
|
||||
continue
|
||||
# log.debug('RPCRequest: %s', format_request(call))
|
||||
reactor.callLater(0, self.dispatch, *call)
|
||||
if type(request) is not tuple:
|
||||
log.debug("Received invalid message: type is not tuple")
|
||||
return
|
||||
|
||||
def sendData(self, data): # NOQA: N802
|
||||
if len(request) < 1:
|
||||
log.debug("Received invalid message: there are no items")
|
||||
return
|
||||
|
||||
for call in request:
|
||||
if len(call) != 4:
|
||||
log.debug("Received invalid rpc request: number of items "
|
||||
"in request is %s", len(call))
|
||||
continue
|
||||
#log.debug("RPCRequest: %s", format_request(call))
|
||||
reactor.callLater(0, self.dispatch, *call)
|
||||
|
||||
def sendData(self, data):
|
||||
"""
|
||||
Sends the data to the client.
|
||||
|
||||
@ -164,25 +192,19 @@ class DelugeRPCProtocol(DelugeTransferProtocol):
|
||||
:type data: object
|
||||
|
||||
"""
|
||||
try:
|
||||
self.transfer_message(data)
|
||||
except Exception as ex:
|
||||
log.warning('Error occurred when sending message: %s.', ex)
|
||||
log.exception(ex)
|
||||
raise
|
||||
self.transport.write(zlib.compress(rencode.dumps(data)))
|
||||
|
||||
def connectionMade(self): # NOQA: N802
|
||||
def connectionMade(self):
|
||||
"""
|
||||
This method is called when a new client connects.
|
||||
"""
|
||||
peer = self.transport.getPeer()
|
||||
log.info('Deluge Client connection made from: %s:%s', peer.host, peer.port)
|
||||
log.info("Deluge Client connection made from: %s:%s",
|
||||
peer.host, peer.port)
|
||||
# Set the initial auth level of this session to AUTH_LEVEL_NONE
|
||||
self.factory.authorized_sessions[self.transport.sessionno] = self.AuthLevel(
|
||||
AUTH_LEVEL_NONE, ''
|
||||
)
|
||||
self.factory.authorized_sessions[self.transport.sessionno] = AUTH_LEVEL_NONE
|
||||
|
||||
def connectionLost(self, reason=connectionDone): # NOQA: N802
|
||||
def connectionLost(self, reason):
|
||||
"""
|
||||
This method is called when the client is disconnected.
|
||||
|
||||
@ -198,11 +220,7 @@ class DelugeRPCProtocol(DelugeTransferProtocol):
|
||||
if self.transport.sessionno in self.factory.interested_events:
|
||||
del self.factory.interested_events[self.transport.sessionno]
|
||||
|
||||
if self.factory.state == 'running':
|
||||
component.get('EventManager').emit(
|
||||
ClientDisconnectedEvent(self.factory.session_id)
|
||||
)
|
||||
log.info('Deluge client disconnected: %s', reason.value)
|
||||
log.info("Deluge client disconnected: %s", reason.value)
|
||||
|
||||
def valid_session(self):
|
||||
return self.transport.sessionno in self.factory.authorized_sessions
|
||||
@ -223,77 +241,60 @@ class DelugeRPCProtocol(DelugeTransferProtocol):
|
||||
:type kwargs: dict
|
||||
|
||||
"""
|
||||
|
||||
def send_error():
|
||||
def sendError():
|
||||
"""
|
||||
Sends an error response with the contents of the exception that was raised.
|
||||
"""
|
||||
exc_type, exc_value, dummy_exc_trace = sys.exc_info()
|
||||
formated_tb = traceback.format_exc()
|
||||
exceptionType, exceptionValue, exceptionTraceback = sys.exc_info()
|
||||
formated_tb = "".join(traceback.format_tb(exceptionTraceback))
|
||||
try:
|
||||
self.sendData(
|
||||
(
|
||||
RPC_ERROR,
|
||||
request_id,
|
||||
exc_type.__name__,
|
||||
exc_value._args,
|
||||
exc_value._kwargs,
|
||||
formated_tb,
|
||||
)
|
||||
)
|
||||
except AttributeError:
|
||||
# This is not a deluge exception (object has no attribute '_args), let's wrap it
|
||||
log.warning(
|
||||
'An exception occurred while sending RPC_ERROR to '
|
||||
'client. Wrapping it and resending. Error to '
|
||||
'send(causing exception goes next):\n%s',
|
||||
formated_tb,
|
||||
)
|
||||
self.sendData((
|
||||
RPC_ERROR,
|
||||
request_id,
|
||||
exceptionType.__name__,
|
||||
exceptionValue._args,
|
||||
exceptionValue._kwargs,
|
||||
formated_tb
|
||||
))
|
||||
except Exception, err:
|
||||
# This most likely not a deluge exception, let's wrap it
|
||||
log.error("An exception occurred while sending RPC_ERROR to "
|
||||
"client. Wrapping it and resending. Error to "
|
||||
"send(causing exception goes next):\n%s", formated_tb)
|
||||
log.exception(err)
|
||||
try:
|
||||
raise WrappedException(
|
||||
str(exc_value), exc_type.__name__, formated_tb
|
||||
)
|
||||
except WrappedException:
|
||||
send_error()
|
||||
except Exception as ex:
|
||||
log.error(
|
||||
'An exception occurred while sending RPC_ERROR to client: %s', ex
|
||||
)
|
||||
raise WrappedException(str(exceptionValue), exceptionType.__name__, formated_tb)
|
||||
except:
|
||||
sendError()
|
||||
|
||||
if method == 'daemon.info':
|
||||
if method == "daemon.info":
|
||||
# This is a special case and used in the initial connection process
|
||||
self.sendData((RPC_RESPONSE, request_id, deluge.common.get_version()))
|
||||
return
|
||||
elif method == 'daemon.login':
|
||||
elif method == "daemon.login":
|
||||
# This is a special case and used in the initial connection process
|
||||
# We need to authenticate the user here
|
||||
log.debug('RPC dispatch daemon.login')
|
||||
log.debug("RPC dispatch daemon.login")
|
||||
try:
|
||||
client_version = kwargs.pop('client_version', None)
|
||||
if client_version is None:
|
||||
raise IncompatibleClient(deluge.common.get_version())
|
||||
ret = component.get('AuthManager').authorize(*args, **kwargs)
|
||||
ret = component.get("AuthManager").authorize(*args, **kwargs)
|
||||
if ret:
|
||||
self.factory.authorized_sessions[
|
||||
self.transport.sessionno
|
||||
] = self.AuthLevel(ret, args[0])
|
||||
self.factory.authorized_sessions[self.transport.sessionno] = (ret, args[0])
|
||||
self.factory.session_protocols[self.transport.sessionno] = self
|
||||
except Exception as ex:
|
||||
send_error()
|
||||
if not isinstance(ex, _ClientSideRecreateError):
|
||||
log.exception(ex)
|
||||
except Exception, e:
|
||||
sendError()
|
||||
if not isinstance(e, _ClientSideRecreateError):
|
||||
log.exception(e)
|
||||
else:
|
||||
self.sendData((RPC_RESPONSE, request_id, (ret)))
|
||||
if not ret:
|
||||
self.transport.loseConnection()
|
||||
return
|
||||
|
||||
# Anything below requires a valid session
|
||||
if not self.valid_session():
|
||||
return
|
||||
|
||||
if method == 'daemon.set_event_interest':
|
||||
log.debug('RPC dispatch daemon.set_event_interest')
|
||||
finally:
|
||||
return
|
||||
elif method == "daemon.set_event_interest" and self.valid_session():
|
||||
log.debug("RPC dispatch daemon.set_event_interest")
|
||||
# This special case is to allow clients to set which events they are
|
||||
# interested in receiving.
|
||||
# We are expecting a sequence from the client.
|
||||
@ -301,66 +302,51 @@ class DelugeRPCProtocol(DelugeTransferProtocol):
|
||||
if self.transport.sessionno not in self.factory.interested_events:
|
||||
self.factory.interested_events[self.transport.sessionno] = []
|
||||
self.factory.interested_events[self.transport.sessionno].extend(args[0])
|
||||
except Exception:
|
||||
send_error()
|
||||
except Exception, e:
|
||||
sendError()
|
||||
else:
|
||||
self.sendData((RPC_RESPONSE, request_id, (True)))
|
||||
return
|
||||
|
||||
if method not in self.factory.methods:
|
||||
try:
|
||||
# Raise exception to be sent back to client
|
||||
raise AttributeError('RPC call on invalid function: %s' % method)
|
||||
except AttributeError:
|
||||
send_error()
|
||||
finally:
|
||||
return
|
||||
|
||||
log.debug('RPC dispatch %s', method)
|
||||
try:
|
||||
method_auth_requirement = self.factory.methods[method]._rpcserver_auth_level
|
||||
auth_level = self.factory.authorized_sessions[
|
||||
self.transport.sessionno
|
||||
].auth_level
|
||||
if auth_level < method_auth_requirement:
|
||||
# This session is not allowed to call this method
|
||||
log.debug(
|
||||
'Session %s is attempting an unauthorized method call!',
|
||||
self.transport.sessionno,
|
||||
)
|
||||
raise NotAuthorizedError(auth_level, method_auth_requirement)
|
||||
# Set the session_id in the factory so that methods can know
|
||||
# which session is calling it.
|
||||
self.factory.session_id = self.transport.sessionno
|
||||
ret = self.factory.methods[method](*args, **kwargs)
|
||||
except Exception as ex:
|
||||
send_error()
|
||||
# Don't bother printing out DelugeErrors, because they are just
|
||||
# for the client
|
||||
if not isinstance(ex, DelugeError):
|
||||
log.exception('Exception calling RPC request: %s', ex)
|
||||
else:
|
||||
# Check if the return value is a deferred, since we'll need to
|
||||
# wait for it to fire before sending the RPC_RESPONSE
|
||||
if isinstance(ret, defer.Deferred):
|
||||
|
||||
def on_success(result):
|
||||
try:
|
||||
self.sendData((RPC_RESPONSE, request_id, result))
|
||||
except Exception:
|
||||
send_error()
|
||||
return result
|
||||
|
||||
def on_fail(failure):
|
||||
try:
|
||||
failure.raiseException()
|
||||
except Exception:
|
||||
send_error()
|
||||
return failure
|
||||
|
||||
ret.addCallbacks(on_success, on_fail)
|
||||
if method in self.factory.methods and self.valid_session():
|
||||
log.debug("RPC dispatch %s", method)
|
||||
try:
|
||||
method_auth_requirement = self.factory.methods[method]._rpcserver_auth_level
|
||||
auth_level = self.factory.authorized_sessions[self.transport.sessionno][0]
|
||||
if auth_level < method_auth_requirement:
|
||||
# This session is not allowed to call this method
|
||||
log.debug("Session %s is trying to call a method it is not "
|
||||
"authorized to call!", self.transport.sessionno)
|
||||
raise NotAuthorizedError(auth_level, method_auth_requirement)
|
||||
# Set the session_id in the factory so that methods can know
|
||||
# which session is calling it.
|
||||
self.factory.session_id = self.transport.sessionno
|
||||
ret = self.factory.methods[method](*args, **kwargs)
|
||||
except Exception, e:
|
||||
sendError()
|
||||
# Don't bother printing out DelugeErrors, because they are just
|
||||
# for the client
|
||||
if not isinstance(e, DelugeError):
|
||||
log.exception("Exception calling RPC request: %s", e)
|
||||
else:
|
||||
self.sendData((RPC_RESPONSE, request_id, ret))
|
||||
# Check if the return value is a deferred, since we'll need to
|
||||
# wait for it to fire before sending the RPC_RESPONSE
|
||||
if isinstance(ret, defer.Deferred):
|
||||
def on_success(result):
|
||||
self.sendData((RPC_RESPONSE, request_id, result))
|
||||
return result
|
||||
|
||||
def on_fail(failure):
|
||||
try:
|
||||
failure.raiseException()
|
||||
except Exception, e:
|
||||
sendError()
|
||||
return failure
|
||||
|
||||
ret.addCallbacks(on_success, on_fail)
|
||||
else:
|
||||
self.sendData((RPC_RESPONSE, request_id, ret))
|
||||
|
||||
class RPCServer(component.Component):
|
||||
"""
|
||||
@ -378,13 +364,12 @@ class RPCServer(component.Component):
|
||||
:type listen: bool
|
||||
"""
|
||||
|
||||
def __init__(self, port=58846, interface='', allow_remote=False, listen=True):
|
||||
component.Component.__init__(self, 'RPCServer')
|
||||
def __init__(self, port=58846, interface="", allow_remote=False, listen=True):
|
||||
component.Component.__init__(self, "RPCServer")
|
||||
|
||||
self.factory = Factory()
|
||||
self.factory.protocol = DelugeRPCProtocol
|
||||
self.factory.session_id = -1
|
||||
self.factory.state = 'running'
|
||||
|
||||
# Holds the registered methods
|
||||
self.factory.methods = {}
|
||||
@ -400,28 +385,24 @@ class RPCServer(component.Component):
|
||||
return
|
||||
|
||||
if allow_remote:
|
||||
hostname = ''
|
||||
hostname = ""
|
||||
else:
|
||||
hostname = 'localhost'
|
||||
hostname = "localhost"
|
||||
|
||||
if interface:
|
||||
hostname = interface
|
||||
|
||||
log.info('Starting DelugeRPC server %s:%s', hostname, port)
|
||||
log.info("Starting DelugeRPC server %s:%s", hostname, port)
|
||||
|
||||
# Check for SSL keys and generate some if needed
|
||||
check_ssl_keys()
|
||||
|
||||
cert = os.path.join(deluge.configmanager.get_config_dir('ssl'), 'daemon.cert')
|
||||
pkey = os.path.join(deluge.configmanager.get_config_dir('ssl'), 'daemon.pkey')
|
||||
|
||||
try:
|
||||
reactor.listenSSL(
|
||||
port, self.factory, get_context_factory(cert, pkey), interface=hostname
|
||||
)
|
||||
except Exception as ex:
|
||||
log.debug('Daemon already running or port not available.: %s', ex)
|
||||
raise
|
||||
reactor.listenSSL(port, self.factory, ServerContextFactory(), interface=hostname)
|
||||
except Exception, e:
|
||||
log.info("Daemon already running or port not available..")
|
||||
log.error(e)
|
||||
sys.exit(0)
|
||||
|
||||
def register_object(self, obj, name=None):
|
||||
"""
|
||||
@ -437,11 +418,11 @@ class RPCServer(component.Component):
|
||||
name = obj.__class__.__name__.lower()
|
||||
|
||||
for d in dir(obj):
|
||||
if d[0] == '_':
|
||||
if d[0] == "_":
|
||||
continue
|
||||
if getattr(getattr(obj, d), '_rpcserver_export', False):
|
||||
log.debug('Registering method: %s', name + '.' + d)
|
||||
self.factory.methods[name + '.' + d] = getattr(obj, d)
|
||||
log.debug("Registering method: %s", name + "." + d)
|
||||
self.factory.methods[name + "." + d] = getattr(obj, d)
|
||||
|
||||
def deregister_object(self, obj):
|
||||
"""
|
||||
@ -451,7 +432,7 @@ class RPCServer(component.Component):
|
||||
|
||||
"""
|
||||
for key, value in self.factory.methods.items():
|
||||
if value.__self__ == obj:
|
||||
if value.im_self == obj:
|
||||
del self.factory.methods[key]
|
||||
|
||||
def get_object_method(self, name):
|
||||
@ -475,7 +456,7 @@ class RPCServer(component.Component):
|
||||
:returns: the exported methods
|
||||
:rtype: list
|
||||
"""
|
||||
return list(self.factory.methods)
|
||||
return self.factory.methods.keys()
|
||||
|
||||
def get_session_id(self):
|
||||
"""
|
||||
@ -496,13 +477,13 @@ class RPCServer(component.Component):
|
||||
|
||||
"""
|
||||
if not self.listen:
|
||||
return 'localclient'
|
||||
return "localclient"
|
||||
session_id = self.get_session_id()
|
||||
if session_id > -1 and session_id in self.factory.authorized_sessions:
|
||||
return self.factory.authorized_sessions[session_id].username
|
||||
return self.factory.authorized_sessions[session_id][1]
|
||||
else:
|
||||
# No connections made yet
|
||||
return ''
|
||||
return ""
|
||||
|
||||
def get_session_auth_level(self):
|
||||
"""
|
||||
@ -511,9 +492,9 @@ class RPCServer(component.Component):
|
||||
:returns: the auth level
|
||||
:rtype: int
|
||||
"""
|
||||
if not self.listen or not self.is_session_valid(self.get_session_id()):
|
||||
if not self.listen:
|
||||
return AUTH_LEVEL_ADMIN
|
||||
return self.factory.authorized_sessions[self.get_session_id()].auth_level
|
||||
return self.factory.authorized_sessions[self.get_session_id()][0]
|
||||
|
||||
def get_rpc_auth_level(self, rpc):
|
||||
"""
|
||||
@ -522,7 +503,7 @@ class RPCServer(component.Component):
|
||||
:returns: the auth level
|
||||
:rtype: int
|
||||
"""
|
||||
return self.factory.methods[rpc]._rpcserver_auth_level
|
||||
self.factory.methods[rpc]._rpcserver_auth_level
|
||||
|
||||
def is_session_valid(self, session_id):
|
||||
"""
|
||||
@ -544,11 +525,11 @@ class RPCServer(component.Component):
|
||||
:param event: the event to emit
|
||||
:type event: :class:`deluge.event.DelugeEvent`
|
||||
"""
|
||||
log.debug('intevents: %s', self.factory.interested_events)
|
||||
log.debug("intevents: %s", self.factory.interested_events)
|
||||
# Find sessions interested in this event
|
||||
for session_id, interest in self.factory.interested_events.items():
|
||||
for session_id, interest in self.factory.interested_events.iteritems():
|
||||
if event.name in interest:
|
||||
log.debug('Emit Event: %s %s', event.name, event.args)
|
||||
log.debug("Emit Event: %s %s", event.name, event.args)
|
||||
# This session is interested so send a RPC_EVENT
|
||||
self.factory.session_protocols[session_id].sendData(
|
||||
(RPC_EVENT, event.name, event.args)
|
||||
@ -564,35 +545,68 @@ class RPCServer(component.Component):
|
||||
:type event: :class:`deluge.event.DelugeEvent`
|
||||
"""
|
||||
if not self.is_session_valid(session_id):
|
||||
log.debug(
|
||||
'Session ID %s is not valid. Not sending event "%s".',
|
||||
session_id,
|
||||
event.name,
|
||||
)
|
||||
log.debug("Session ID %s is not valid. Not sending event \"%s\".", session_id, event.name)
|
||||
return
|
||||
if session_id not in self.factory.interested_events:
|
||||
log.debug(
|
||||
'Session ID %s is not interested in any events. Not sending event "%s".',
|
||||
session_id,
|
||||
event.name,
|
||||
)
|
||||
log.debug("Session ID %s is not interested in any events. Not sending event \"%s\".", session_id, event.name)
|
||||
return
|
||||
if event.name not in self.factory.interested_events[session_id]:
|
||||
log.debug(
|
||||
'Session ID %s is not interested in event "%s". Not sending it.',
|
||||
session_id,
|
||||
event.name,
|
||||
)
|
||||
log.debug("Session ID %s is not interested in event \"%s\". Not sending it.", session_id, event.name)
|
||||
return
|
||||
log.debug(
|
||||
'Sending event "%s" with args "%s" to session id "%s".',
|
||||
event.name,
|
||||
event.args,
|
||||
session_id,
|
||||
)
|
||||
self.factory.session_protocols[session_id].sendData(
|
||||
(RPC_EVENT, event.name, event.args)
|
||||
)
|
||||
log.debug("Sending event \"%s\" with args \"%s\" to session id \"%s\".",
|
||||
event.name, event.args, session_id)
|
||||
self.factory.session_protocols[session_id].sendData((RPC_EVENT, event.name, event.args))
|
||||
|
||||
def stop(self):
|
||||
self.factory.state = 'stopping'
|
||||
|
||||
def check_ssl_keys():
|
||||
"""
|
||||
Check for SSL cert/key and create them if necessary
|
||||
"""
|
||||
ssl_dir = deluge.configmanager.get_config_dir("ssl")
|
||||
if not os.path.exists(ssl_dir):
|
||||
# The ssl folder doesn't exist so we need to create it
|
||||
os.makedirs(ssl_dir)
|
||||
generate_ssl_keys()
|
||||
else:
|
||||
for f in ("daemon.pkey", "daemon.cert"):
|
||||
if not os.path.exists(os.path.join(ssl_dir, f)):
|
||||
generate_ssl_keys()
|
||||
break
|
||||
|
||||
def generate_ssl_keys():
|
||||
"""
|
||||
This method generates a new SSL key/cert.
|
||||
"""
|
||||
digest = "md5"
|
||||
# Generate key pair
|
||||
pkey = crypto.PKey()
|
||||
pkey.generate_key(crypto.TYPE_RSA, 1024)
|
||||
|
||||
# Generate cert request
|
||||
req = crypto.X509Req()
|
||||
subj = req.get_subject()
|
||||
setattr(subj, "CN", "Deluge Daemon")
|
||||
req.set_pubkey(pkey)
|
||||
req.sign(pkey, digest)
|
||||
|
||||
# Generate certificate
|
||||
cert = crypto.X509()
|
||||
cert.set_serial_number(0)
|
||||
cert.gmtime_adj_notBefore(0)
|
||||
cert.gmtime_adj_notAfter(60*60*24*365*5) # Five Years
|
||||
cert.set_issuer(req.get_subject())
|
||||
cert.set_subject(req.get_subject())
|
||||
cert.set_pubkey(req.get_pubkey())
|
||||
cert.sign(pkey, digest)
|
||||
|
||||
# Write out files
|
||||
ssl_dir = deluge.configmanager.get_config_dir("ssl")
|
||||
open(os.path.join(ssl_dir, "daemon.pkey"), "w").write(
|
||||
crypto.dump_privatekey(crypto.FILETYPE_PEM, pkey)
|
||||
)
|
||||
open(os.path.join(ssl_dir, "daemon.cert"), "w").write(
|
||||
crypto.dump_certificate(crypto.FILETYPE_PEM, cert)
|
||||
)
|
||||
# Make the files only readable by this user
|
||||
for f in ("daemon.pkey", "daemon.cert"):
|
||||
os.chmod(os.path.join(ssl_dir, f), stat.S_IREAD | stat.S_IWRITE)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,136 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2007,2008 Andrew Resch <andrewresch@gmail.com>
|
||||
#
|
||||
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
|
||||
# the additional special exception to link portions of this program with the OpenSSL library.
|
||||
# See LICENSE for more details.
|
||||
#
|
||||
|
||||
import os
|
||||
import stat
|
||||
|
||||
from OpenSSL import crypto
|
||||
from OpenSSL.crypto import FILETYPE_PEM
|
||||
from twisted.internet.ssl import (
|
||||
AcceptableCiphers,
|
||||
Certificate,
|
||||
CertificateOptions,
|
||||
KeyPair,
|
||||
TLSVersion,
|
||||
)
|
||||
|
||||
import deluge.configmanager
|
||||
|
||||
# A TLS ciphers list.
|
||||
# Sources for more information on TLS ciphers:
|
||||
# - https://wiki.mozilla.org/Security/Server_Side_TLS
|
||||
# - https://www.ssllabs.com/projects/best-practices/index.html
|
||||
# - https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
|
||||
#
|
||||
# This list was inspired by the `urllib3` library
|
||||
# - https://github.com/urllib3/urllib3/blob/master/urllib3/util/ssl_.py#L79
|
||||
#
|
||||
# The general intent is:
|
||||
# - prefer cipher suites that offer perfect forward secrecy (ECDHE),
|
||||
# - prefer AES-GCM over ChaCha20 because hardware-accelerated AES is common,
|
||||
# - disable NULL authentication, MD5 MACs and DSS for security reasons.
|
||||
TLS_CIPHERS = ':'.join(
|
||||
[
|
||||
'ECDH+AESGCM',
|
||||
'ECDH+CHACHA20',
|
||||
'AES256-GCM-SHA384',
|
||||
'AES128-GCM-SHA256',
|
||||
'!DSS' '!aNULL',
|
||||
'!eNULL',
|
||||
'!MD5',
|
||||
]
|
||||
)
|
||||
|
||||
# This value tells OpenSSL to disable all SSL/TLS renegotiation.
|
||||
SSL_OP_NO_RENEGOTIATION = 0x40000000
|
||||
|
||||
|
||||
def get_context_factory(cert_path, pkey_path):
|
||||
"""OpenSSL context factory.
|
||||
|
||||
Generates an OpenSSL context factory using Twisted's CertificateOptions class.
|
||||
This will keep a server cipher order.
|
||||
|
||||
Args:
|
||||
cert_path (string): The path to the certificate file
|
||||
pkey_path (string): The path to the private key file
|
||||
|
||||
Returns:
|
||||
twisted.internet.ssl.CertificateOptions: An OpenSSL context factory
|
||||
"""
|
||||
|
||||
with open(cert_path) as cert:
|
||||
certificate = Certificate.loadPEM(cert.read()).original
|
||||
with open(pkey_path) as pkey:
|
||||
private_key = KeyPair.load(pkey.read(), FILETYPE_PEM).original
|
||||
ciphers = AcceptableCiphers.fromOpenSSLCipherString(TLS_CIPHERS)
|
||||
cert_options = CertificateOptions(
|
||||
privateKey=private_key,
|
||||
certificate=certificate,
|
||||
raiseMinimumTo=TLSVersion.TLSv1_2,
|
||||
acceptableCiphers=ciphers,
|
||||
)
|
||||
ctx = cert_options.getContext()
|
||||
ctx.use_certificate_chain_file(cert_path)
|
||||
ctx.set_options(SSL_OP_NO_RENEGOTIATION)
|
||||
|
||||
return cert_options
|
||||
|
||||
|
||||
def check_ssl_keys():
|
||||
"""
|
||||
Check for SSL cert/key and create them if necessary
|
||||
"""
|
||||
ssl_dir = deluge.configmanager.get_config_dir('ssl')
|
||||
if not os.path.exists(ssl_dir):
|
||||
# The ssl folder doesn't exist so we need to create it
|
||||
os.makedirs(ssl_dir)
|
||||
generate_ssl_keys()
|
||||
else:
|
||||
for f in ('daemon.pkey', 'daemon.cert'):
|
||||
if not os.path.exists(os.path.join(ssl_dir, f)):
|
||||
generate_ssl_keys()
|
||||
break
|
||||
|
||||
|
||||
def generate_ssl_keys():
|
||||
"""
|
||||
This method generates a new SSL key/cert.
|
||||
"""
|
||||
digest = 'sha256'
|
||||
|
||||
# Generate key pair
|
||||
pkey = crypto.PKey()
|
||||
pkey.generate_key(crypto.TYPE_RSA, 2048)
|
||||
|
||||
# Generate cert request
|
||||
req = crypto.X509Req()
|
||||
subj = req.get_subject()
|
||||
setattr(subj, 'CN', 'Deluge Daemon')
|
||||
req.set_pubkey(pkey)
|
||||
req.sign(pkey, digest)
|
||||
|
||||
# Generate certificate
|
||||
cert = crypto.X509()
|
||||
cert.set_serial_number(0)
|
||||
cert.gmtime_adj_notBefore(0)
|
||||
cert.gmtime_adj_notAfter(60 * 60 * 24 * 365 * 3) # Three Years
|
||||
cert.set_issuer(req.get_subject())
|
||||
cert.set_subject(req.get_subject())
|
||||
cert.set_pubkey(req.get_pubkey())
|
||||
cert.sign(pkey, digest)
|
||||
|
||||
# Write out files
|
||||
ssl_dir = deluge.configmanager.get_config_dir('ssl')
|
||||
with open(os.path.join(ssl_dir, 'daemon.pkey'), 'wb') as _file:
|
||||
_file.write(crypto.dump_privatekey(crypto.FILETYPE_PEM, pkey))
|
||||
with open(os.path.join(ssl_dir, 'daemon.cert'), 'wb') as _file:
|
||||
_file.write(crypto.dump_certificate(crypto.FILETYPE_PEM, cert))
|
||||
# Make the files only readable by this user
|
||||
for f in ('daemon.pkey', 'daemon.cert'):
|
||||
os.chmod(os.path.join(ssl_dir, f), stat.S_IREAD | stat.S_IWRITE)
|
||||
@ -1,19 +1,39 @@
|
||||
#
|
||||
# decorators.py
|
||||
#
|
||||
# Copyright (C) 2010 John Garland <johnnybg+deluge@gmail.com>
|
||||
#
|
||||
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
|
||||
# the additional special exception to link portions of this program with the OpenSSL library.
|
||||
# See LICENSE for more details.
|
||||
# Deluge is free software.
|
||||
#
|
||||
# You may redistribute it and/or modify it under the terms of the
|
||||
# GNU General Public License, as published by the Free Software
|
||||
# Foundation; either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# deluge is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with deluge. If not, write to:
|
||||
# The Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor
|
||||
# Boston, MA 02110-1301, USA.
|
||||
#
|
||||
# In addition, as a special exception, the copyright holders give
|
||||
# permission to link the code of portions of this program with the OpenSSL
|
||||
# library.
|
||||
# You must obey the GNU General Public License in all respects for all of
|
||||
# the code used other than OpenSSL. If you modify file(s) with this
|
||||
# exception, you may extend this exception to your version of the file(s),
|
||||
# but you are not obligated to do so. If you do not wish to do so, delete
|
||||
# this exception statement from your version. If you delete this exception
|
||||
# statement from all source files in the program, then also delete it here.
|
||||
#
|
||||
#
|
||||
|
||||
import inspect
|
||||
import re
|
||||
import warnings
|
||||
from functools import wraps
|
||||
from typing import Any, Callable, Coroutine, TypeVar
|
||||
|
||||
from twisted.internet import defer
|
||||
|
||||
|
||||
def proxy(proxy_func):
|
||||
"""
|
||||
@ -23,196 +43,9 @@ def proxy(proxy_func):
|
||||
:param proxy_func: the proxy function
|
||||
:type proxy_func: function
|
||||
"""
|
||||
|
||||
def decorator(func):
|
||||
@wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
return proxy_func(func, *args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
def overrides(*args):
|
||||
"""
|
||||
Decorater function to specify when class methods override
|
||||
super class methods.
|
||||
|
||||
When used as
|
||||
@overrides
|
||||
def funcname
|
||||
|
||||
the argument will be the funcname function.
|
||||
|
||||
When used as
|
||||
@overrides(BaseClass)
|
||||
def funcname
|
||||
|
||||
the argument will be the BaseClass
|
||||
|
||||
"""
|
||||
stack = inspect.stack()
|
||||
if inspect.isfunction(args[0]):
|
||||
return _overrides(stack, args[0])
|
||||
else:
|
||||
# One or more classes are specified, so return a function that will be
|
||||
# called with the real function as argument
|
||||
def ret_func(func, **kwargs):
|
||||
return _overrides(stack, func, explicit_base_classes=args)
|
||||
|
||||
return ret_func
|
||||
|
||||
|
||||
def _overrides(stack, method, explicit_base_classes=None):
|
||||
# stack[0]=overrides, stack[1]=inside class def'n, stack[2]=outside class def'n
|
||||
classes = {}
|
||||
derived_class_locals = stack[2][0].f_locals
|
||||
|
||||
# Find all super classes
|
||||
m = re.search(r'class\s(.+)\((.+)\)\s*\:', stack[2][4][0])
|
||||
class_name = m.group(1)
|
||||
base_classes = m.group(2)
|
||||
|
||||
# Handle multiple inheritance
|
||||
base_classes = [s.strip() for s in base_classes.split(',')]
|
||||
check_classes = base_classes
|
||||
|
||||
if not base_classes:
|
||||
raise ValueError(
|
||||
'overrides decorator: unable to determine base class of class "%s"'
|
||||
% class_name
|
||||
)
|
||||
|
||||
def get_class(cls_name):
|
||||
if '.' not in cls_name:
|
||||
return derived_class_locals[cls_name]
|
||||
else:
|
||||
components = cls_name.split('.')
|
||||
# obj is either a module or a class
|
||||
obj = derived_class_locals[components[0]]
|
||||
for c in components[1:]:
|
||||
assert inspect.ismodule(obj) or inspect.isclass(obj)
|
||||
obj = getattr(obj, c)
|
||||
return obj
|
||||
|
||||
if explicit_base_classes:
|
||||
# One or more base classes are explicitly given, check only those classes
|
||||
override_classes = re.search(r'\s*@overrides\((.+)\)\s*', stack[1][4][0]).group(
|
||||
1
|
||||
)
|
||||
override_classes = [c.strip() for c in override_classes.split(',')]
|
||||
check_classes = override_classes
|
||||
|
||||
for c in base_classes + check_classes:
|
||||
classes[c] = get_class(c)
|
||||
|
||||
# Verify that the explicit override class is one of base classes
|
||||
if explicit_base_classes:
|
||||
from itertools import product
|
||||
|
||||
for bc, cc in product(base_classes, check_classes):
|
||||
if issubclass(classes[bc], classes[cc]):
|
||||
break
|
||||
else:
|
||||
raise Exception(
|
||||
'Excplicit override class "%s" is not a super class of: %s'
|
||||
% (explicit_base_classes, class_name)
|
||||
)
|
||||
if not all(hasattr(classes[cls], method.__name__) for cls in check_classes):
|
||||
for cls in check_classes:
|
||||
if not hasattr(classes[cls], method.__name__):
|
||||
raise Exception(
|
||||
'Function override "%s" not found in superclass: %s\n%s'
|
||||
% (
|
||||
method.__name__,
|
||||
cls,
|
||||
f'File: {stack[1][1]}:{stack[1][2]}',
|
||||
)
|
||||
)
|
||||
|
||||
if not any(hasattr(classes[cls], method.__name__) for cls in check_classes):
|
||||
raise Exception(
|
||||
'Function override "%s" not found in any superclass: %s\n%s'
|
||||
% (
|
||||
method.__name__,
|
||||
check_classes,
|
||||
f'File: {stack[1][1]}:{stack[1][2]}',
|
||||
)
|
||||
)
|
||||
return method
|
||||
|
||||
|
||||
def deprecated(func):
|
||||
"""This is a decorator which can be used to mark function as deprecated.
|
||||
|
||||
It will result in a warning being emitted when the function is used.
|
||||
|
||||
"""
|
||||
|
||||
@wraps(func)
|
||||
def depr_func(*args, **kwargs):
|
||||
warnings.simplefilter('always', DeprecationWarning) # Turn off filter
|
||||
warnings.warn(
|
||||
f'Call to deprecated function {func.__name__}.',
|
||||
category=DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
warnings.simplefilter('default', DeprecationWarning) # Reset filter
|
||||
return func(*args, **kwargs)
|
||||
|
||||
return depr_func
|
||||
|
||||
|
||||
class CoroutineDeferred(defer.Deferred):
|
||||
"""Wraps a coroutine in a Deferred.
|
||||
It will dynamically pass through the underlying coroutine without wrapping where apporpriate."""
|
||||
|
||||
def __init__(self, coro: Coroutine):
|
||||
# Delay this import to make sure a reactor was installed first
|
||||
from twisted.internet import reactor
|
||||
|
||||
super().__init__()
|
||||
self.coro = coro
|
||||
self.awaited = None
|
||||
self.activate_deferred = reactor.callLater(0, self.activate)
|
||||
|
||||
def __await__(self):
|
||||
if self.awaited in [None, True]:
|
||||
self.awaited = True
|
||||
return self.coro.__await__()
|
||||
# Already in deferred mode
|
||||
return super().__await__()
|
||||
|
||||
def activate(self):
|
||||
"""If the result wasn't awaited before the next context switch, we turn it into a deferred."""
|
||||
if self.awaited is None:
|
||||
self.awaited = False
|
||||
try:
|
||||
d = defer.Deferred.fromCoroutine(self.coro)
|
||||
except AttributeError:
|
||||
# Fallback for Twisted <= 21.2 without fromCoroutine
|
||||
d = defer.ensureDeferred(self.coro)
|
||||
d.chainDeferred(self)
|
||||
|
||||
def addCallbacks(self, *args, **kwargs): # noqa: N802
|
||||
assert not self.awaited, 'Cannot add callbacks to an already awaited coroutine.'
|
||||
self.activate()
|
||||
return super().addCallbacks(*args, **kwargs)
|
||||
|
||||
|
||||
_RetT = TypeVar('_RetT')
|
||||
|
||||
|
||||
def maybe_coroutine(
|
||||
f: Callable[..., Coroutine[Any, Any, _RetT]]
|
||||
) -> 'Callable[..., defer.Deferred[_RetT]]':
|
||||
"""Wraps a coroutine function to make it usable as a normal function that returns a Deferred."""
|
||||
|
||||
@wraps(f)
|
||||
def wrapper(*args, **kwargs):
|
||||
# Uncomment for quick testing to make sure CoroutineDeferred magic isn't at fault
|
||||
# return defer.ensureDeferred(f(*args, **kwargs))
|
||||
return CoroutineDeferred(f(*args, **kwargs))
|
||||
|
||||
return wrapper
|
||||
|
||||
121
deluge/error.py
121
deluge/error.py
@ -1,96 +1,131 @@
|
||||
#
|
||||
# error.py
|
||||
#
|
||||
# Copyright (C) 2008 Andrew Resch <andrewresch@gmail.com>
|
||||
# Copyright (C) 2011 Pedro Algarvio <pedro@algarvio.me>
|
||||
#
|
||||
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
|
||||
# the additional special exception to link portions of this program with the OpenSSL library.
|
||||
# See LICENSE for more details.
|
||||
# Deluge is free software.
|
||||
#
|
||||
# You may redistribute it and/or modify it under the terms of the
|
||||
# GNU General Public License, as published by the Free Software
|
||||
# Foundation; either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# deluge is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with deluge. If not, write to:
|
||||
# The Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor
|
||||
# Boston, MA 02110-1301, USA.
|
||||
#
|
||||
# In addition, as a special exception, the copyright holders give
|
||||
# permission to link the code of portions of this program with the OpenSSL
|
||||
# library.
|
||||
# You must obey the GNU General Public License in all respects for all of
|
||||
# the code used other than OpenSSL. If you modify file(s) with this
|
||||
# exception, you may extend this exception to your version of the file(s),
|
||||
# but you are not obligated to do so. If you do not wish to do so, delete
|
||||
# this exception statement from your version. If you delete this exception
|
||||
# statement from all source files in the program, then also delete it here.
|
||||
#
|
||||
#
|
||||
|
||||
|
||||
class DelugeError(Exception):
|
||||
def __new__(cls, *args, **kwargs):
|
||||
inst = super().__new__(cls, *args, **kwargs)
|
||||
inst._args = args
|
||||
inst._kwargs = kwargs
|
||||
return inst
|
||||
|
||||
def __init__(self, message=None):
|
||||
super().__init__(message)
|
||||
self.message = message
|
||||
def _get_message(self):
|
||||
return self._message
|
||||
def _set_message(self, message):
|
||||
self._message = message
|
||||
message = property(_get_message, _set_message)
|
||||
del _get_message, _set_message
|
||||
|
||||
def __str__(self):
|
||||
return self.message
|
||||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
inst = super(DelugeError, cls).__new__(cls, *args, **kwargs)
|
||||
inst._args = args
|
||||
inst._kwargs = kwargs
|
||||
return inst
|
||||
|
||||
class NoCoreError(DelugeError):
|
||||
pass
|
||||
|
||||
class DaemonRunningError(DelugeError):
|
||||
pass
|
||||
|
||||
|
||||
class InvalidTorrentError(DelugeError):
|
||||
pass
|
||||
|
||||
|
||||
class AddTorrentError(DelugeError):
|
||||
pass
|
||||
|
||||
|
||||
class InvalidPathError(DelugeError):
|
||||
pass
|
||||
|
||||
|
||||
class WrappedException(DelugeError):
|
||||
def _get_traceback(self):
|
||||
return self._traceback
|
||||
def _set_traceback(self, traceback):
|
||||
self._traceback = traceback
|
||||
traceback = property(_get_traceback, _set_traceback)
|
||||
del _get_traceback, _set_traceback
|
||||
|
||||
def _get_type(self):
|
||||
return self._type
|
||||
def _set_type(self, type):
|
||||
self._type = type
|
||||
type = property(_get_type, _set_type)
|
||||
del _get_type, _set_type
|
||||
|
||||
def __init__(self, message, exception_type, traceback):
|
||||
super().__init__(message)
|
||||
self.message = message
|
||||
self.type = exception_type
|
||||
self.traceback = traceback
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.message}\n{self.traceback}'
|
||||
|
||||
|
||||
class _ClientSideRecreateError(DelugeError):
|
||||
pass
|
||||
|
||||
|
||||
class IncompatibleClient(_ClientSideRecreateError):
|
||||
def __init__(self, daemon_version):
|
||||
self.daemon_version = daemon_version
|
||||
msg = (
|
||||
'Your deluge client is not compatible with the daemon. '
|
||||
'Please upgrade your client to %(daemon_version)s'
|
||||
) % {'daemon_version': self.daemon_version}
|
||||
super().__init__(message=msg)
|
||||
|
||||
self.message = _(
|
||||
"Your deluge client is not compatible with the daemon. "
|
||||
"Please upgrade your client to %(daemon_version)s"
|
||||
) % dict(daemon_version=self.daemon_version)
|
||||
|
||||
class NotAuthorizedError(_ClientSideRecreateError):
|
||||
|
||||
def __init__(self, current_level, required_level):
|
||||
msg = ('Auth level too low: %(current_level)s < %(required_level)s') % {
|
||||
'current_level': current_level,
|
||||
'required_level': required_level,
|
||||
}
|
||||
super().__init__(message=msg)
|
||||
self.message = _(
|
||||
"Auth level too low: %(current_level)s < %(required_level)s" %
|
||||
dict(current_level=current_level, required_level=required_level)
|
||||
)
|
||||
self.current_level = current_level
|
||||
self.required_level = required_level
|
||||
|
||||
|
||||
class _UsernameBasedPasstroughError(_ClientSideRecreateError):
|
||||
|
||||
def _get_username(self):
|
||||
return self._username
|
||||
def _set_username(self, username):
|
||||
self._username = username
|
||||
username = property(_get_username, _set_username)
|
||||
del _get_username, _set_username
|
||||
|
||||
def __init__(self, message, username):
|
||||
super().__init__(message)
|
||||
super(_UsernameBasedPasstroughError, self).__init__(message)
|
||||
self.message = message
|
||||
self.username = username
|
||||
|
||||
|
||||
class BadLoginError(_UsernameBasedPasstroughError):
|
||||
pass
|
||||
|
||||
|
||||
class AuthenticationRequired(_UsernameBasedPasstroughError):
|
||||
pass
|
||||
|
||||
|
||||
class AuthManagerError(_UsernameBasedPasstroughError):
|
||||
pass
|
||||
|
||||
|
||||
class LibtorrentImportError(ImportError):
|
||||
pass
|
||||
|
||||
137
deluge/event.py
137
deluge/event.py
@ -1,9 +1,36 @@
|
||||
#
|
||||
# event.py
|
||||
#
|
||||
# Copyright (C) 2009 Andrew Resch <andrewresch@gmail.com>
|
||||
#
|
||||
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
|
||||
# the additional special exception to link portions of this program with the OpenSSL library.
|
||||
# See LICENSE for more details.
|
||||
# Deluge is free software.
|
||||
#
|
||||
# You may redistribute it and/or modify it under the terms of the
|
||||
# GNU General Public License, as published by the Free Software
|
||||
# Foundation; either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# deluge is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with deluge. If not, write to:
|
||||
# The Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor
|
||||
# Boston, MA 02110-1301, USA.
|
||||
#
|
||||
# In addition, as a special exception, the copyright holders give
|
||||
# permission to link the code of portions of this program with the OpenSSL
|
||||
# library.
|
||||
# You must obey the GNU General Public License in all respects for all of
|
||||
# the code used other than OpenSSL. If you modify file(s) with this
|
||||
# exception, you may extend this exception to your version of the file(s),
|
||||
# but you are not obligated to do so. If you do not wish to do so, delete
|
||||
# this exception statement from your version. If you delete this exception
|
||||
# statement from all source files in the program, then also delete it here.
|
||||
#
|
||||
#
|
||||
|
||||
"""
|
||||
@ -13,21 +40,19 @@ This module describes the types of events that can be generated by the daemon
|
||||
and subsequently emitted to the clients.
|
||||
|
||||
"""
|
||||
known_events = {}
|
||||
|
||||
known_events = {}
|
||||
|
||||
class DelugeEventMetaClass(type):
|
||||
"""
|
||||
This metaclass simply keeps a list of all events classes created.
|
||||
"""
|
||||
|
||||
def __init__(cls, name, bases, dct): # pylint: disable=bad-mcs-method-argument
|
||||
super().__init__(name, bases, dct)
|
||||
if name != 'DelugeEvent':
|
||||
def __init__(cls, name, bases, dct):
|
||||
super(DelugeEventMetaClass, cls).__init__(name, bases, dct)
|
||||
if name != "DelugeEvent":
|
||||
known_events[name] = cls
|
||||
|
||||
|
||||
class DelugeEvent(metaclass=DelugeEventMetaClass):
|
||||
class DelugeEvent(object):
|
||||
"""
|
||||
The base class for all events.
|
||||
|
||||
@ -37,24 +62,23 @@ class DelugeEvent(metaclass=DelugeEventMetaClass):
|
||||
:type args: list
|
||||
|
||||
"""
|
||||
__metaclass__ = DelugeEventMetaClass
|
||||
|
||||
def _get_name(self):
|
||||
return self.__class__.__name__
|
||||
|
||||
def _get_args(self):
|
||||
if not hasattr(self, '_args'):
|
||||
if not hasattr(self, "_args"):
|
||||
return []
|
||||
return self._args
|
||||
|
||||
name = property(fget=_get_name)
|
||||
args = property(fget=_get_args)
|
||||
|
||||
|
||||
class TorrentAddedEvent(DelugeEvent):
|
||||
"""
|
||||
Emitted when a new torrent is successfully added to the session.
|
||||
"""
|
||||
|
||||
def __init__(self, torrent_id, from_state):
|
||||
"""
|
||||
:param torrent_id: the torrent_id of the torrent that was added
|
||||
@ -64,12 +88,10 @@ class TorrentAddedEvent(DelugeEvent):
|
||||
"""
|
||||
self._args = [torrent_id, from_state]
|
||||
|
||||
|
||||
class TorrentRemovedEvent(DelugeEvent):
|
||||
"""
|
||||
Emitted when a torrent has been removed from the session.
|
||||
"""
|
||||
|
||||
def __init__(self, torrent_id):
|
||||
"""
|
||||
:param torrent_id: the torrent_id
|
||||
@ -77,12 +99,10 @@ class TorrentRemovedEvent(DelugeEvent):
|
||||
"""
|
||||
self._args = [torrent_id]
|
||||
|
||||
|
||||
class PreTorrentRemovedEvent(DelugeEvent):
|
||||
"""
|
||||
Emitted when a torrent is about to be removed from the session.
|
||||
"""
|
||||
|
||||
def __init__(self, torrent_id):
|
||||
"""
|
||||
:param torrent_id: the torrent_id
|
||||
@ -90,12 +110,10 @@ class PreTorrentRemovedEvent(DelugeEvent):
|
||||
"""
|
||||
self._args = [torrent_id]
|
||||
|
||||
|
||||
class TorrentStateChangedEvent(DelugeEvent):
|
||||
"""
|
||||
Emitted when a torrent changes state.
|
||||
"""
|
||||
|
||||
def __init__(self, torrent_id, state):
|
||||
"""
|
||||
:param torrent_id: the torrent_id
|
||||
@ -105,34 +123,16 @@ class TorrentStateChangedEvent(DelugeEvent):
|
||||
"""
|
||||
self._args = [torrent_id, state]
|
||||
|
||||
|
||||
class TorrentTrackerStatusEvent(DelugeEvent):
|
||||
"""
|
||||
Emitted when a torrents tracker status changes.
|
||||
"""
|
||||
|
||||
def __init__(self, torrent_id, status):
|
||||
"""
|
||||
Args:
|
||||
torrent_id (str): the torrent_id
|
||||
status (str): the new status
|
||||
"""
|
||||
self._args = [torrent_id, status]
|
||||
|
||||
|
||||
class TorrentQueueChangedEvent(DelugeEvent):
|
||||
"""
|
||||
Emitted when the queue order has changed.
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class TorrentFolderRenamedEvent(DelugeEvent):
|
||||
"""
|
||||
Emitted when a folder within a torrent has been renamed.
|
||||
"""
|
||||
|
||||
def __init__(self, torrent_id, old, new):
|
||||
"""
|
||||
:param torrent_id: the torrent_id
|
||||
@ -144,12 +144,10 @@ class TorrentFolderRenamedEvent(DelugeEvent):
|
||||
"""
|
||||
self._args = [torrent_id, old, new]
|
||||
|
||||
|
||||
class TorrentFileRenamedEvent(DelugeEvent):
|
||||
"""
|
||||
Emitted when a file within a torrent has been renamed.
|
||||
"""
|
||||
|
||||
def __init__(self, torrent_id, index, name):
|
||||
"""
|
||||
:param torrent_id: the torrent_id
|
||||
@ -161,12 +159,10 @@ class TorrentFileRenamedEvent(DelugeEvent):
|
||||
"""
|
||||
self._args = [torrent_id, index, name]
|
||||
|
||||
|
||||
class TorrentFinishedEvent(DelugeEvent):
|
||||
"""
|
||||
Emitted when a torrent finishes downloading.
|
||||
"""
|
||||
|
||||
def __init__(self, torrent_id):
|
||||
"""
|
||||
:param torrent_id: the torrent_id
|
||||
@ -174,12 +170,10 @@ class TorrentFinishedEvent(DelugeEvent):
|
||||
"""
|
||||
self._args = [torrent_id]
|
||||
|
||||
|
||||
class TorrentResumedEvent(DelugeEvent):
|
||||
"""
|
||||
Emitted when a torrent resumes from a paused state.
|
||||
"""
|
||||
|
||||
def __init__(self, torrent_id):
|
||||
"""
|
||||
:param torrent_id: the torrent_id
|
||||
@ -187,12 +181,13 @@ class TorrentResumedEvent(DelugeEvent):
|
||||
"""
|
||||
self._args = [torrent_id]
|
||||
|
||||
|
||||
class TorrentFileCompletedEvent(DelugeEvent):
|
||||
"""
|
||||
Emitted when a file completes.
|
||||
"""
|
||||
|
||||
This will only work with libtorrent 0.15 or greater.
|
||||
|
||||
"""
|
||||
def __init__(self, torrent_id, index):
|
||||
"""
|
||||
:param torrent_id: the torrent_id
|
||||
@ -202,36 +197,17 @@ class TorrentFileCompletedEvent(DelugeEvent):
|
||||
"""
|
||||
self._args = [torrent_id, index]
|
||||
|
||||
|
||||
class TorrentStorageMovedEvent(DelugeEvent):
|
||||
"""
|
||||
Emitted when the storage location for a torrent has been moved.
|
||||
"""
|
||||
|
||||
def __init__(self, torrent_id, path):
|
||||
"""
|
||||
:param torrent_id: the torrent_id
|
||||
:type torrent_id: string
|
||||
:param path: the new location
|
||||
:type path: string
|
||||
"""
|
||||
self._args = [torrent_id, path]
|
||||
|
||||
|
||||
class CreateTorrentProgressEvent(DelugeEvent):
|
||||
"""
|
||||
Emitted when creating a torrent file remotely.
|
||||
"""
|
||||
|
||||
def __init__(self, piece_count, num_pieces):
|
||||
self._args = [piece_count, num_pieces]
|
||||
|
||||
|
||||
class NewVersionAvailableEvent(DelugeEvent):
|
||||
"""
|
||||
Emitted when a more recent version of Deluge is available.
|
||||
"""
|
||||
|
||||
def __init__(self, new_release):
|
||||
"""
|
||||
:param new_release: the new version that is available
|
||||
@ -239,37 +215,29 @@ class NewVersionAvailableEvent(DelugeEvent):
|
||||
"""
|
||||
self._args = [new_release]
|
||||
|
||||
|
||||
class SessionStartedEvent(DelugeEvent):
|
||||
"""
|
||||
Emitted when a session has started. This typically only happens once when
|
||||
the daemon is initially started.
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class SessionPausedEvent(DelugeEvent):
|
||||
"""
|
||||
Emitted when the session has been paused.
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class SessionResumedEvent(DelugeEvent):
|
||||
"""
|
||||
Emitted when the session has been resumed.
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class ConfigValueChangedEvent(DelugeEvent):
|
||||
"""
|
||||
Emitted when a config value changes in the Core.
|
||||
"""
|
||||
|
||||
def __init__(self, key, value):
|
||||
"""
|
||||
:param key: the key that changed
|
||||
@ -278,42 +246,17 @@ class ConfigValueChangedEvent(DelugeEvent):
|
||||
"""
|
||||
self._args = [key, value]
|
||||
|
||||
|
||||
class PluginEnabledEvent(DelugeEvent):
|
||||
"""
|
||||
Emitted when a plugin is enabled in the Core.
|
||||
"""
|
||||
|
||||
def __init__(self, plugin_name):
|
||||
self._args = [plugin_name]
|
||||
|
||||
|
||||
class PluginDisabledEvent(DelugeEvent):
|
||||
"""
|
||||
Emitted when a plugin is disabled in the Core.
|
||||
"""
|
||||
|
||||
def __init__(self, plugin_name):
|
||||
self._args = [plugin_name]
|
||||
|
||||
|
||||
class ClientDisconnectedEvent(DelugeEvent):
|
||||
"""
|
||||
Emitted when a client disconnects.
|
||||
"""
|
||||
|
||||
def __init__(self, session_id):
|
||||
self._args = [session_id]
|
||||
|
||||
|
||||
class ExternalIPEvent(DelugeEvent):
|
||||
"""
|
||||
Emitted when the external ip address is received from libtorrent.
|
||||
"""
|
||||
|
||||
def __init__(self, external_ip):
|
||||
"""
|
||||
Args:
|
||||
external_ip (str): The IP address.
|
||||
"""
|
||||
self._args = [external_ip]
|
||||
|
||||
@ -1,333 +1,207 @@
|
||||
#
|
||||
# httpdownloader.py
|
||||
#
|
||||
# Copyright (C) 2009 Andrew Resch <andrewresch@gmail.com>
|
||||
#
|
||||
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
|
||||
# the additional special exception to link portions of this program with the OpenSSL library.
|
||||
# See LICENSE for more details.
|
||||
# Deluge is free software.
|
||||
#
|
||||
# You may redistribute it and/or modify it under the terms of the
|
||||
# GNU General Public License, as published by the Free Software
|
||||
# Foundation; either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# deluge is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with deluge. If not, write to:
|
||||
# The Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor
|
||||
# Boston, MA 02110-1301, USA.
|
||||
#
|
||||
# In addition, as a special exception, the copyright holders give
|
||||
# permission to link the code of portions of this program with the OpenSSL
|
||||
# library.
|
||||
# You must obey the GNU General Public License in all respects for all of
|
||||
# the code used other than OpenSSL. If you modify file(s) with this
|
||||
# exception, you may extend this exception to your version of the file(s),
|
||||
# but you are not obligated to do so. If you do not wish to do so, delete
|
||||
# this exception statement from your version. If you delete this exception
|
||||
# statement from all source files in the program, then also delete it here.
|
||||
#
|
||||
|
||||
import cgi
|
||||
from twisted.web import client, http
|
||||
from twisted.web.error import PageRedirect
|
||||
from twisted.python.failure import Failure
|
||||
from twisted.internet import reactor
|
||||
from common import get_version
|
||||
import logging
|
||||
import os.path
|
||||
import zlib
|
||||
|
||||
from twisted.internet import reactor
|
||||
from twisted.internet.defer import Deferred
|
||||
from twisted.python.failure import Failure
|
||||
from twisted.web import client, http
|
||||
from twisted.web._newclient import HTTPClientParser
|
||||
from twisted.web.error import Error, PageRedirect
|
||||
from twisted.web.http_headers import Headers
|
||||
from twisted.web.iweb import IAgent
|
||||
from zope.interface import implementer
|
||||
|
||||
from deluge.common import get_version
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class CompressionDecoder(client.GzipDecoder):
|
||||
"""A compression decoder for gzip, x-gzip and deflate."""
|
||||
|
||||
def deliverBody(self, protocol): # NOQA: N802
|
||||
self.original.deliverBody(CompressionDecoderProtocol(protocol, self.original))
|
||||
|
||||
|
||||
class CompressionDecoderProtocol(client._GzipProtocol):
|
||||
"""A compression decoder protocol for CompressionDecoder."""
|
||||
|
||||
def __init__(self, protocol, response):
|
||||
super().__init__(protocol, response)
|
||||
self._zlibDecompress = zlib.decompressobj(32 + zlib.MAX_WBITS)
|
||||
|
||||
|
||||
class BodyHandler(HTTPClientParser):
|
||||
"""An HTTP parser that saves the response to a file."""
|
||||
|
||||
def __init__(self, request, finished, length, agent, encoding=None):
|
||||
"""BodyHandler init.
|
||||
|
||||
Args:
|
||||
request (t.w.i.IClientRequest): The parser request.
|
||||
finished (Deferred): A Deferred to handle the finished response.
|
||||
length (int): The length of the response.
|
||||
agent (t.w.i.IAgent): The agent from which the request was sent.
|
||||
class HTTPDownloader(client.HTTPDownloader):
|
||||
"""
|
||||
Factory class for downloading files and keeping track of progress.
|
||||
"""
|
||||
def __init__(self, url, filename, part_callback=None, headers=None,
|
||||
force_filename=False, allow_compression=True):
|
||||
"""
|
||||
super().__init__(request, finished)
|
||||
self.agent = agent
|
||||
self.finished = finished
|
||||
self.total_length = length
|
||||
self.current_length = 0
|
||||
self.data = b''
|
||||
self.encoding = encoding
|
||||
|
||||
def dataReceived(self, data): # NOQA: N802
|
||||
self.current_length += len(data)
|
||||
self.data += data
|
||||
if self.agent.part_callback:
|
||||
self.agent.part_callback(data, self.current_length, self.total_length)
|
||||
|
||||
def connectionLost(self, reason): # NOQA: N802
|
||||
if self.encoding:
|
||||
self.data = self.data.decode(self.encoding).encode('utf8')
|
||||
with open(self.agent.filename, 'wb') as _file:
|
||||
_file.write(self.data)
|
||||
self.finished.callback(self.agent.filename)
|
||||
self.state = 'DONE'
|
||||
HTTPClientParser.connectionLost(self, reason)
|
||||
|
||||
|
||||
@implementer(IAgent)
|
||||
class HTTPDownloaderAgent:
|
||||
"""A File Downloader Agent."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
agent,
|
||||
filename,
|
||||
part_callback=None,
|
||||
force_filename=False,
|
||||
allow_compression=True,
|
||||
handle_redirect=True,
|
||||
):
|
||||
"""HTTPDownloaderAgent init.
|
||||
|
||||
Args:
|
||||
agent (t.w.c.Agent): The agent which will send the requests.
|
||||
filename (str): The filename to save the file as.
|
||||
force_filename (bool): Forces use of the supplied filename,
|
||||
regardless of header content.
|
||||
part_callback (func): A function to be called when a part of data
|
||||
is received, it's signature should be:
|
||||
func(data, current_length, total_length)
|
||||
:param url: the url to download from
|
||||
:type url: string
|
||||
:param filename: the filename to save the file as
|
||||
:type filename: string
|
||||
:param force_filename: forces use of the supplied filename, regardless of header content
|
||||
:type force_filename: bool
|
||||
:param part_callback: a function to be called when a part of data
|
||||
is received, it's signature should be: func(data, current_length, total_length)
|
||||
:type part_callback: function
|
||||
:param headers: any optional headers to send
|
||||
:type headers: dictionary
|
||||
"""
|
||||
|
||||
self.handle_redirect = handle_redirect
|
||||
self.agent = agent
|
||||
self.filename = filename
|
||||
self.part_callback = part_callback
|
||||
self.current_length = 0
|
||||
self.decoder = None
|
||||
self.value = filename
|
||||
self.force_filename = force_filename
|
||||
self.allow_compression = allow_compression
|
||||
self.decoder = None
|
||||
agent = "Deluge/%s (http://deluge-torrent.org)" % get_version()
|
||||
client.HTTPDownloader.__init__(self, url, filename, headers=headers, agent=agent)
|
||||
|
||||
def request_callback(self, response):
|
||||
finished = Deferred()
|
||||
def gotStatus(self, version, status, message):
|
||||
self.code = int(status)
|
||||
client.HTTPDownloader.gotStatus(self, version, status, message)
|
||||
|
||||
if not self.handle_redirect and response.code in (
|
||||
http.MOVED_PERMANENTLY,
|
||||
http.FOUND,
|
||||
http.SEE_OTHER,
|
||||
http.TEMPORARY_REDIRECT,
|
||||
):
|
||||
location = response.headers.getRawHeaders(b'location')[0]
|
||||
error = PageRedirect(response.code, location=location)
|
||||
finished.errback(Failure(error))
|
||||
elif response.code >= 400:
|
||||
error = Error(response.code)
|
||||
finished.errback(Failure(error))
|
||||
else:
|
||||
headers = response.headers
|
||||
body_length = int(headers.getRawHeaders(b'content-length', default=[0])[0])
|
||||
def gotHeaders(self, headers):
|
||||
if self.code == http.OK:
|
||||
if "content-length" in headers:
|
||||
self.total_length = int(headers["content-length"][0])
|
||||
else:
|
||||
self.total_length = 0
|
||||
|
||||
if headers.hasHeader(b'content-disposition') and not self.force_filename:
|
||||
content_disp = headers.getRawHeaders(b'content-disposition')[0].decode(
|
||||
'utf-8'
|
||||
)
|
||||
content_disp_params = cgi.parse_header(content_disp)[1]
|
||||
if 'filename' in content_disp_params:
|
||||
new_file_name = content_disp_params['filename']
|
||||
new_file_name = sanitise_filename(new_file_name)
|
||||
new_file_name = os.path.join(
|
||||
os.path.split(self.filename)[0], new_file_name
|
||||
)
|
||||
if self.allow_compression and "content-encoding" in headers and \
|
||||
headers["content-encoding"][0] in ("gzip", "x-gzip", "deflate"):
|
||||
# Adding 32 to the wbits enables gzip & zlib decoding (with automatic header detection)
|
||||
# Adding 16 just enables gzip decoding (no zlib)
|
||||
self.decoder = zlib.decompressobj(zlib.MAX_WBITS + 32)
|
||||
|
||||
count = 1
|
||||
fileroot = os.path.splitext(new_file_name)[0]
|
||||
fileext = os.path.splitext(new_file_name)[1]
|
||||
while os.path.isfile(new_file_name):
|
||||
# Increment filename if already exists
|
||||
new_file_name = f'{fileroot}-{count}{fileext}'
|
||||
count += 1
|
||||
if "content-disposition" in headers and not self.force_filename:
|
||||
new_file_name = str(headers["content-disposition"][0]).split(";")[1].split("=")[1]
|
||||
new_file_name = sanitise_filename(new_file_name)
|
||||
new_file_name = os.path.join(os.path.split(self.fileName)[0], new_file_name)
|
||||
|
||||
self.filename = new_file_name
|
||||
count = 1
|
||||
fileroot = os.path.splitext(new_file_name)[0]
|
||||
fileext = os.path.splitext(new_file_name)[1]
|
||||
while os.path.isfile(new_file_name):
|
||||
# Increment filename if already exists
|
||||
new_file_name = "%s-%s%s" % (fileroot, count, fileext)
|
||||
count += 1
|
||||
|
||||
cont_type_header = headers.getRawHeaders(b'content-type')[0].decode()
|
||||
cont_type, params = cgi.parse_header(cont_type_header)
|
||||
# Only re-ecode text content types.
|
||||
encoding = None
|
||||
if cont_type.startswith('text/'):
|
||||
encoding = params.get('charset', None)
|
||||
response.deliverBody(
|
||||
BodyHandler(response.request, finished, body_length, self, encoding)
|
||||
)
|
||||
self.fileName = new_file_name
|
||||
self.value = new_file_name
|
||||
|
||||
return finished
|
||||
elif self.code in (http.MOVED_PERMANENTLY, http.FOUND, http.SEE_OTHER, http.TEMPORARY_REDIRECT):
|
||||
location = headers["location"][0]
|
||||
error = PageRedirect(self.code, location=location)
|
||||
self.noPage(Failure(error))
|
||||
|
||||
def request(self, method, uri, headers=None, body_producer=None):
|
||||
"""Issue a new request to the wrapped agent.
|
||||
return client.HTTPDownloader.gotHeaders(self, headers)
|
||||
|
||||
Args:
|
||||
method (bytes): The HTTP method to use.
|
||||
uri (bytes): The url to download from.
|
||||
headers (t.w.h.Headers, optional): Any extra headers to send.
|
||||
body_producer (t.w.i.IBodyProducer, optional): Request body data.
|
||||
def pagePart(self, data):
|
||||
if self.code == http.OK:
|
||||
self.current_length += len(data)
|
||||
if self.decoder:
|
||||
data = self.decoder.decompress(data)
|
||||
if self.part_callback:
|
||||
self.part_callback(data, self.current_length, self.total_length)
|
||||
|
||||
Returns:
|
||||
Deferred: The filename of the of the downloaded file.
|
||||
"""
|
||||
if headers is None:
|
||||
headers = Headers()
|
||||
return client.HTTPDownloader.pagePart(self, data)
|
||||
|
||||
if not headers.hasHeader(b'User-Agent'):
|
||||
version = get_version()
|
||||
user_agent = 'Deluge/%s (https://deluge-torrent.org)' % version
|
||||
headers.addRawHeader('User-Agent', user_agent)
|
||||
|
||||
d = self.agent.request(
|
||||
method=method, uri=uri, headers=headers, bodyProducer=body_producer
|
||||
)
|
||||
d.addCallback(self.request_callback)
|
||||
return d
|
||||
def pageEnd(self):
|
||||
if self.decoder:
|
||||
data = self.decoder.flush()
|
||||
self.current_length -= len(data)
|
||||
self.decoder = None
|
||||
self.pagePart(data)
|
||||
|
||||
return client.HTTPDownloader.pageEnd(self)
|
||||
|
||||
def sanitise_filename(filename):
|
||||
"""Sanitises a filename to use as a download destination file.
|
||||
|
||||
"""
|
||||
Sanitises a filename to use as a download destination file.
|
||||
Logs any filenames that could be considered malicious.
|
||||
|
||||
filename (str): The filename to sanitise.
|
||||
|
||||
Returns:
|
||||
str: The sanitised filename.
|
||||
:param filename: the filename to sanitise
|
||||
:type filename: string
|
||||
:returns: the sanitised filename
|
||||
:rtype: string
|
||||
"""
|
||||
|
||||
# Remove any quotes
|
||||
filename = filename.strip('\'"')
|
||||
filename = filename.strip("'\"")
|
||||
|
||||
if os.path.basename(filename) != filename:
|
||||
# Dodgy server, log it
|
||||
log.warning(
|
||||
'Potentially malicious server: trying to write to file: %s', filename
|
||||
)
|
||||
log.warning("Potentially malicious server: trying to write to file '%s'" % filename)
|
||||
# Only use the basename
|
||||
filename = os.path.basename(filename)
|
||||
|
||||
filename = filename.strip()
|
||||
if filename.startswith('.') or ';' in filename or '|' in filename:
|
||||
if filename.startswith(".") or ";" in filename or "|" in filename:
|
||||
# Dodgy server, log it
|
||||
log.warning(
|
||||
'Potentially malicious server: trying to write to file: %s', filename
|
||||
)
|
||||
log.warning("Potentially malicious server: trying to write to file '%s'" % filename)
|
||||
|
||||
return filename
|
||||
|
||||
|
||||
def _download_file(
|
||||
url,
|
||||
filename,
|
||||
callback=None,
|
||||
headers=None,
|
||||
force_filename=False,
|
||||
allow_compression=True,
|
||||
handle_redirects=True,
|
||||
):
|
||||
"""Downloads a file from a specific URL and returns a Deferred.
|
||||
|
||||
A callback function can be specified to be called as parts are received.
|
||||
|
||||
Args:
|
||||
url (str): The url to download from.
|
||||
filename (str): The filename to save the file as.
|
||||
callback (func): A function to be called when partial data is received,
|
||||
it's signature should be: func(data, current_length, total_length)
|
||||
headers (dict): Any optional headers to send.
|
||||
force_filename (bool): Force using the filename specified rather than
|
||||
one the server may suggest.
|
||||
allow_compression (bool): Allows gzip & deflate decoding.
|
||||
|
||||
Returns:
|
||||
Deferred: The filename of the downloaded file.
|
||||
|
||||
Raises:
|
||||
t.w.e.PageRedirect
|
||||
t.w.e.Error: for all other HTTP response errors
|
||||
def download_file(url, filename, callback=None, headers=None,
|
||||
force_filename=False, allow_compression=True):
|
||||
"""
|
||||
Downloads a file from a specific URL and returns a Deferred. You can also
|
||||
specify a callback function to be called as parts are received.
|
||||
|
||||
agent = client.Agent(reactor)
|
||||
:param url: the url to download from
|
||||
:type url: string
|
||||
:param filename: the filename to save the file as
|
||||
:type filename: string
|
||||
:param callback: a function to be called when a part of data is received,
|
||||
it's signature should be: func(data, current_length, total_length)
|
||||
:type callback: function
|
||||
:param headers: any optional headers to send
|
||||
:type headers: dictionary
|
||||
:param force_filename: force us to use the filename specified rather than
|
||||
one the server may suggest
|
||||
:type force_filename: boolean
|
||||
:param allow_compression: allows gzip & deflate decoding
|
||||
:type allow_compression: boolean
|
||||
|
||||
:returns: the filename of the downloaded file
|
||||
:rtype: Deferred
|
||||
|
||||
:raises t.w.e.PageRedirect: when server responds with a temporary redirect
|
||||
or permanently moved.
|
||||
:raises t.w.e.Error: for all other HTTP response errors (besides OK)
|
||||
"""
|
||||
url = str(url)
|
||||
filename = str(filename)
|
||||
if headers:
|
||||
for key, value in headers.items():
|
||||
headers[str(key)] = str(value)
|
||||
|
||||
if allow_compression:
|
||||
enc_accepted = ['gzip', 'x-gzip', 'deflate']
|
||||
decoders = [(enc.encode(), CompressionDecoder) for enc in enc_accepted]
|
||||
agent = client.ContentDecoderAgent(agent, decoders)
|
||||
if handle_redirects:
|
||||
agent = client.RedirectAgent(agent)
|
||||
if not headers:
|
||||
headers = {}
|
||||
headers["accept-encoding"] = "deflate, gzip, x-gzip"
|
||||
|
||||
agent = HTTPDownloaderAgent(
|
||||
agent, filename, callback, force_filename, allow_compression, handle_redirects
|
||||
)
|
||||
scheme, host, port, path = client._parse(url)
|
||||
factory = HTTPDownloader(url, filename, callback, headers, force_filename, allow_compression)
|
||||
if scheme == "https":
|
||||
from twisted.internet import ssl
|
||||
reactor.connectSSL(host, port, factory, ssl.ClientContextFactory())
|
||||
else:
|
||||
reactor.connectTCP(host, port, factory)
|
||||
|
||||
# The Headers init expects dict values to be a list.
|
||||
if headers:
|
||||
for name, value in list(headers.items()):
|
||||
if not isinstance(value, list):
|
||||
headers[name] = [value]
|
||||
|
||||
return agent.request(b'GET', url.encode(), Headers(headers))
|
||||
|
||||
|
||||
def download_file(
|
||||
url,
|
||||
filename,
|
||||
callback=None,
|
||||
headers=None,
|
||||
force_filename=False,
|
||||
allow_compression=True,
|
||||
handle_redirects=True,
|
||||
):
|
||||
"""Downloads a file from a specific URL and returns a Deferred.
|
||||
|
||||
A callback function can be specified to be called as parts are received.
|
||||
|
||||
Args:
|
||||
url (str): The url to download from.
|
||||
filename (str): The filename to save the file as.
|
||||
callback (func): A function to be called when partial data is received,
|
||||
it's signature should be: func(data, current_length, total_length).
|
||||
headers (dict): Any optional headers to send.
|
||||
force_filename (bool): Force the filename specified rather than one the
|
||||
server may suggest.
|
||||
allow_compression (bool): Allows gzip & deflate decoding.
|
||||
handle_redirects (bool): HTTP redirects handled automatically or not.
|
||||
|
||||
Returns:
|
||||
Deferred: The filename of the downloaded file.
|
||||
|
||||
Raises:
|
||||
t.w.e.PageRedirect: If handle_redirects is False.
|
||||
t.w.e.Error: For all other HTTP response errors.
|
||||
"""
|
||||
|
||||
def on_download_success(result):
|
||||
log.debug('Download success!')
|
||||
return result
|
||||
|
||||
def on_download_fail(failure):
|
||||
log.warning(
|
||||
'Error occurred downloading file from "%s": %s',
|
||||
url,
|
||||
failure.getErrorMessage(),
|
||||
)
|
||||
result = failure
|
||||
return result
|
||||
|
||||
d = _download_file(
|
||||
url,
|
||||
filename,
|
||||
callback=callback,
|
||||
headers=headers,
|
||||
force_filename=force_filename,
|
||||
allow_compression=allow_compression,
|
||||
handle_redirects=handle_redirects,
|
||||
)
|
||||
d.addCallbacks(on_download_success, on_download_fail)
|
||||
return d
|
||||
return factory.deferred
|
||||
|
||||
@ -1,15 +0,0 @@
|
||||
from .util import (
|
||||
I18N_DOMAIN,
|
||||
get_languages,
|
||||
set_language,
|
||||
setup_mock_translation,
|
||||
setup_translation,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
'I18N_DOMAIN',
|
||||
'set_language',
|
||||
'get_languages',
|
||||
'setup_translation',
|
||||
'setup_mock_translation',
|
||||
]
|
||||
6178
deluge/i18n/af.po
6178
deluge/i18n/af.po
File diff suppressed because it is too large
Load Diff
7426
deluge/i18n/ar.po
7426
deluge/i18n/ar.po
File diff suppressed because it is too large
Load Diff
7788
deluge/i18n/ast.po
7788
deluge/i18n/ast.po
File diff suppressed because it is too large
Load Diff
6874
deluge/i18n/be.po
6874
deluge/i18n/be.po
File diff suppressed because it is too large
Load Diff
7876
deluge/i18n/bg.po
7876
deluge/i18n/bg.po
File diff suppressed because it is too large
Load Diff
6423
deluge/i18n/bn.po
6423
deluge/i18n/bn.po
File diff suppressed because it is too large
Load Diff
6442
deluge/i18n/bs.po
6442
deluge/i18n/bs.po
File diff suppressed because it is too large
Load Diff
7634
deluge/i18n/ca.po
7634
deluge/i18n/ca.po
File diff suppressed because it is too large
Load Diff
7898
deluge/i18n/cs.po
7898
deluge/i18n/cs.po
File diff suppressed because it is too large
Load Diff
6488
deluge/i18n/cy.po
6488
deluge/i18n/cy.po
File diff suppressed because it is too large
Load Diff
8001
deluge/i18n/da.po
8001
deluge/i18n/da.po
File diff suppressed because it is too large
Load Diff
8269
deluge/i18n/de.po
8269
deluge/i18n/de.po
File diff suppressed because it is too large
Load Diff
8024
deluge/i18n/el.po
8024
deluge/i18n/el.po
File diff suppressed because it is too large
Load Diff
8566
deluge/i18n/en_AU.po
8566
deluge/i18n/en_AU.po
File diff suppressed because it is too large
Load Diff
8204
deluge/i18n/en_CA.po
8204
deluge/i18n/en_CA.po
File diff suppressed because it is too large
Load Diff
8208
deluge/i18n/en_GB.po
8208
deluge/i18n/en_GB.po
File diff suppressed because it is too large
Load Diff
6431
deluge/i18n/eo.po
6431
deluge/i18n/eo.po
File diff suppressed because it is too large
Load Diff
7795
deluge/i18n/es.po
7795
deluge/i18n/es.po
File diff suppressed because it is too large
Load Diff
7931
deluge/i18n/et.po
7931
deluge/i18n/et.po
File diff suppressed because it is too large
Load Diff
7360
deluge/i18n/eu.po
7360
deluge/i18n/eu.po
File diff suppressed because it is too large
Load Diff
6625
deluge/i18n/fa.po
6625
deluge/i18n/fa.po
File diff suppressed because it is too large
Load Diff
7861
deluge/i18n/fi.po
7861
deluge/i18n/fi.po
File diff suppressed because it is too large
Load Diff
6164
deluge/i18n/fo.po
6164
deluge/i18n/fo.po
File diff suppressed because it is too large
Load Diff
8145
deluge/i18n/fr.po
8145
deluge/i18n/fr.po
File diff suppressed because it is too large
Load Diff
7344
deluge/i18n/fy.po
7344
deluge/i18n/fy.po
File diff suppressed because it is too large
Load Diff
6164
deluge/i18n/ga.po
6164
deluge/i18n/ga.po
File diff suppressed because it is too large
Load Diff
7676
deluge/i18n/gl.po
7676
deluge/i18n/gl.po
File diff suppressed because it is too large
Load Diff
7757
deluge/i18n/he.po
7757
deluge/i18n/he.po
File diff suppressed because it is too large
Load Diff
7547
deluge/i18n/hi.po
7547
deluge/i18n/hi.po
File diff suppressed because it is too large
Load Diff
7351
deluge/i18n/hr.po
7351
deluge/i18n/hr.po
File diff suppressed because it is too large
Load Diff
7959
deluge/i18n/hu.po
7959
deluge/i18n/hu.po
File diff suppressed because it is too large
Load Diff
6806
deluge/i18n/id.po
6806
deluge/i18n/id.po
File diff suppressed because it is too large
Load Diff
7796
deluge/i18n/is.po
7796
deluge/i18n/is.po
File diff suppressed because it is too large
Load Diff
7835
deluge/i18n/it.po
7835
deluge/i18n/it.po
File diff suppressed because it is too large
Load Diff
6388
deluge/i18n/iu.po
6388
deluge/i18n/iu.po
File diff suppressed because it is too large
Load Diff
7603
deluge/i18n/ja.po
7603
deluge/i18n/ja.po
File diff suppressed because it is too large
Load Diff
7419
deluge/i18n/ka.po
7419
deluge/i18n/ka.po
File diff suppressed because it is too large
Load Diff
7809
deluge/i18n/kk.po
7809
deluge/i18n/kk.po
File diff suppressed because it is too large
Load Diff
6172
deluge/i18n/km.po
6172
deluge/i18n/km.po
File diff suppressed because it is too large
Load Diff
6576
deluge/i18n/kn.po
6576
deluge/i18n/kn.po
File diff suppressed because it is too large
Load Diff
7649
deluge/i18n/ko.po
7649
deluge/i18n/ko.po
File diff suppressed because it is too large
Load Diff
6438
deluge/i18n/ku.po
6438
deluge/i18n/ku.po
File diff suppressed because it is too large
Load Diff
6164
deluge/i18n/ky.po
6164
deluge/i18n/ky.po
File diff suppressed because it is too large
Load Diff
6417
deluge/i18n/la.po
6417
deluge/i18n/la.po
File diff suppressed because it is too large
Load Diff
@ -1,114 +0,0 @@
|
||||
#
|
||||
# This file is public domain.
|
||||
#
|
||||
|
||||
# Language code for this installation. All choices can be found here:
|
||||
# http://www.i18nguy.com/unicode/language-identifiers.html
|
||||
LANGUAGE_CODE = 'en-us'
|
||||
|
||||
|
||||
# Deferred translation
|
||||
def _(message):
|
||||
return message
|
||||
|
||||
|
||||
# Languages we provide translations for, out of the box.
|
||||
LANGUAGES = {
|
||||
'af': _('Afrikaans'),
|
||||
'ar': _('Arabic'),
|
||||
'ast': _('Asturian'),
|
||||
'az': _('Azerbaijani'),
|
||||
'bg': _('Bulgarian'),
|
||||
'be': _('Belarusian'),
|
||||
'bn': _('Bengali'),
|
||||
'br': _('Breton'),
|
||||
'bs': _('Bosnian'),
|
||||
'ca': _('Catalan'),
|
||||
'cs': _('Czech'),
|
||||
'cy': _('Welsh'),
|
||||
'da': _('Danish'),
|
||||
'de': _('German'),
|
||||
'el': _('Greek'),
|
||||
'en': _('English'),
|
||||
'en_AU': _('English (Australia)'),
|
||||
'en_CA': _('English (Canada)'),
|
||||
'en_GB': _('English (United Kingdom)'),
|
||||
'eo': _('Esperanto'),
|
||||
'es': _('Spanish'),
|
||||
'es-ar': _('Argentinian Spanish'),
|
||||
'es-mx': _('Mexican Spanish'),
|
||||
'es-ni': _('Nicaraguan Spanish'),
|
||||
'es-ve': _('Venezuelan Spanish'),
|
||||
'et': _('Estonian'),
|
||||
'eu': _('Basque'),
|
||||
'fa': _('Persian'),
|
||||
'fi': _('Finnish'),
|
||||
'fr': _('French'),
|
||||
'fy': _('Frisian'),
|
||||
'ga': _('Irish'),
|
||||
'gl': _('Galician'),
|
||||
'he': _('Hebrew'),
|
||||
'hi': _('Hindi'),
|
||||
'hr': _('Croatian'),
|
||||
'hu': _('Hungarian'),
|
||||
'ia': _('Interlingua'),
|
||||
'id': _('Indonesian'),
|
||||
'is': _('Icelandic'),
|
||||
'it': _('Italian'),
|
||||
'iu': _('Inuktitut'),
|
||||
'ja': _('Japanese'),
|
||||
'ka': _('Georgian'),
|
||||
'kk': _('Kazakh'),
|
||||
'km': _('Khmer'),
|
||||
'kn': _('Kannada'),
|
||||
'ko': _('Korean'),
|
||||
'ku': _('Kurdish'),
|
||||
'la': _('Latin'),
|
||||
'lb': _('Luxembourgish'),
|
||||
'lt': _('Lithuanian'),
|
||||
'lv': _('Latvian'),
|
||||
'mk': _('Macedonian'),
|
||||
'ml': _('Malayalam'),
|
||||
'mn': _('Mongolian'),
|
||||
'ms': _('Mayaly'),
|
||||
'my': _('Burmese'),
|
||||
'nb': _('Norwegian Bokmal'),
|
||||
'ne': _('Nepali'),
|
||||
'nds': _('Low German'),
|
||||
'nl': _('Dutch'),
|
||||
'nn': _('Norwegian Nynorsk'),
|
||||
'os': _('Ossetic'),
|
||||
'pa': _('Punjabi'),
|
||||
'pl': _('Polish'),
|
||||
'pms': _('Piedmontese'),
|
||||
'pt': _('Portuguese'),
|
||||
'pt_BR': _('Brazilian Portuguese'),
|
||||
'ro': _('Romanian'),
|
||||
'ru': _('Russian'),
|
||||
'sk': _('Slovak'),
|
||||
'sl': _('Slovenian'),
|
||||
'si': _('Sinhalese'),
|
||||
'sq': _('Albanian'),
|
||||
'sr': _('Serbian'),
|
||||
'sr-latn': _('Serbian Latin'),
|
||||
'sv': _('Swedish'),
|
||||
'sw': _('Swahili'),
|
||||
'ta': _('Tamil'),
|
||||
'te': _('Telugu'),
|
||||
'th': _('Thai'),
|
||||
'tl': _('Tagalog'),
|
||||
'tlh': _('Klingon'),
|
||||
'tr': _('Turkish'),
|
||||
'tt': _('Tatar'),
|
||||
'udm': _('Udmurt'),
|
||||
'uk': _('Ukrainian'),
|
||||
'ur': _('Urdu'),
|
||||
'vi': _('Vietnamese'),
|
||||
'zh_CN': _('Chinese (Simplified)'),
|
||||
'zh_HK': _('Chinese (Hong Kong)'),
|
||||
'zh-hans': _('Simplified Chinese'),
|
||||
'zh-hant': _('Traditional Chinese'),
|
||||
'zh_TW': _('Chinese (Taiwan)'),
|
||||
}
|
||||
|
||||
del _
|
||||
6164
deluge/i18n/lb.po
6164
deluge/i18n/lb.po
File diff suppressed because it is too large
Load Diff
8112
deluge/i18n/lt.po
8112
deluge/i18n/lt.po
File diff suppressed because it is too large
Load Diff
7869
deluge/i18n/lv.po
7869
deluge/i18n/lv.po
File diff suppressed because it is too large
Load Diff
7091
deluge/i18n/mk.po
7091
deluge/i18n/mk.po
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user