Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
settingsd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
settingsd
Commits
2d2663f0
Commit
2d2663f0
authored
Dec 17, 2010
by
Devaev Maxim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added module for rtorrentd configuration
parent
d590305a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
200 additions
and
0 deletions
+200
-0
rtorrentd_config.conf
configs/settingsd/rtorrentd_config.conf
+3
-0
fmod_rtorrentd_config.py
plugins/functions/fmod_rtorrentd_config.py
+197
-0
No files found.
configs/settingsd/rtorrentd_config.conf
0 → 100644
View file @
2d2663f0
[
rtorrentd_config
]
enabled
=
yes
plugins/functions/fmod_rtorrentd_config.py
0 → 100644
View file @
2d2663f0
# -*- coding: utf-8 -*-
import
os
import
re
import
shutil
from
settingsd
import
const
from
settingsd
import
config
from
settingsd
import
service
from
settingsd
import
shared
from
settingsd
import
tools
##### Private constants #####
SERVICE_NAME
=
"rtorrentd_config"
DAEMON_METHODS_NAMESPACE
=
"rtorrent.daemon"
##### Private classes #####
class
RTorrentd
(
service
.
FunctionObject
)
:
### DBus methods ###
@service.functionMethod
(
DAEMON_METHODS_NAMESPACE
,
in_signature
=
"s"
)
def
setUser
(
self
,
user_name
)
:
self
.
setConfigValue
(
"RTORRENTD_USER"
,
user_name
)
@service.functionMethod
(
DAEMON_METHODS_NAMESPACE
,
out_signature
=
"s"
)
def
user
(
self
)
:
return
self
.
configValue
(
"RTORRENTD_USER"
)[
0
]
###
@service.functionMethod
(
DAEMON_METHODS_NAMESPACE
,
in_signature
=
"s"
)
def
setDownloadsDir
(
self
,
downloads_dir_path
)
:
self
.
setConfigValue
(
"RTORRENTD_DOWNLOADS"
,
downloads_dir_path
)
@service.functionMethod
(
DAEMON_METHODS_NAMESPACE
,
out_signature
=
"s"
)
def
downloadsDir
(
self
)
:
return
self
.
configValue
(
"RTORRENTD_DOWNLOADS"
)[
0
]
###
@service.functionMethod
(
DAEMON_METHODS_NAMESPACE
,
in_signature
=
"s"
)
def
setSessionDir
(
self
,
session_dir_path
)
:
self
.
setConfigValue
(
"RTORRENTD_SESSION"
,
session_dir_path
)
@service.functionMethod
(
DAEMON_METHODS_NAMESPACE
,
out_signature
=
"s"
)
def
sessionDir
(
self
)
:
return
self
.
configValue
(
"RTORRENTD_SESSION"
)[
0
]
###
@service.functionMethod
(
DAEMON_METHODS_NAMESPACE
,
in_signature
=
"s"
)
def
setTmpDir
(
self
,
tmp_dir_path
)
:
self
.
setConfigValue
(
"RTORRENTD_TMP"
,
tmp_dir_path
)
@service.functionMethod
(
DAEMON_METHODS_NAMESPACE
,
out_signature
=
"s"
)
def
tmpDir
(
self
)
:
return
self
.
configValue
(
"RTORRENTD_TMP"
)[
0
]
###
@service.functionMethod
(
DAEMON_METHODS_NAMESPACE
,
in_signature
=
"s"
)
def
setSocketPath
(
self
,
socket_path
)
:
self
.
setConfigValue
(
"RTORRENTD_SOCKET"
,
socket_path
)
@service.functionMethod
(
DAEMON_METHODS_NAMESPACE
,
out_signature
=
"s"
)
def
socketPath
(
self
)
:
return
self
.
configValue
(
"RTORRENTD_SOCKET"
)[
0
]
###
@service.functionMethod
(
DAEMON_METHODS_NAMESPACE
,
in_signature
=
"s"
)
def
setSocketUser
(
self
,
user_name
)
:
socket_owner_list
=
self
.
configValue
(
"RTORRENT_SOCKET_OWNER"
)[
0
]
.
split
(
":"
)
if
len
(
socket_owner_list
)
!=
2
:
socket_owner_list
=
(
user_name
,
""
)
else
:
socket_owner_list
[
0
]
=
user_name
self
.
setConfigValue
(
"RTORRENT_SOCKET_OWNER"
,
":"
.
join
(
socket_owner_list
))
@service.functionMethod
(
DAEMON_METHODS_NAMESPACE
,
in_signature
=
"s"
)
def
setSocketGroup
(
self
,
group_name
)
:
socket_owner_list
=
self
.
configValue
(
"RTORRENT_SOCKET_OWNER"
)[
0
]
.
split
(
":"
)
if
len
(
socket_owner_list
)
!=
2
:
socket_owner_list
=
(
""
,
group_name
)
else
:
socket_owner_list
[
1
]
=
group_name
self
.
setConfigValue
(
"RTORRENT_SOCKET_OWNER"
,
":"
.
join
(
socket_owner_list
))
@service.functionMethod
(
DAEMON_METHODS_NAMESPACE
,
out_signature
=
"s"
)
def
socketUser
(
self
)
:
return
self
.
configValue
(
"RTORRENT_SOCKET_OWNER"
)[
0
]
.
split
(
":"
)[
0
]
@service.functionMethod
(
DAEMON_METHODS_NAMESPACE
,
out_signature
=
"s"
)
def
socketGroup
(
self
)
:
socket_owner_list
=
self
.
configValue
(
"RTORRENT_SOCKET_OWNER"
)[
0
]
.
split
(
":"
)
if
len
(
socket_owner_list
)
!=
2
:
return
""
return
socket_owner_list
[
1
]
###
@service.functionMethod
(
DAEMON_METHODS_NAMESPACE
,
in_signature
=
"i"
)
def
setSocketMode
(
self
,
socket_mode
)
:
self
.
setConfigValue
(
"RTORRENT_SOCKET_PERMISSIONS"
,
int
(
socket_mode
))
@service.functionMethod
(
DAEMON_METHODS_NAMESPACE
,
out_signature
=
"i"
)
def
socketMode
(
self
)
:
return
int
(
self
.
configValue
(
"RTORRENT_SOCKET_PERMISSIONS"
))
### Private ###
def
setConfigValue
(
self
,
variable_name
,
values_list
,
replace_flag
=
True
)
:
if
not
type
(
values_list
)
.
__name__
in
(
"list"
,
"tuple"
)
:
values_list
=
[
values_list
]
rtorrentd_config_file_path
=
config
.
value
(
SERVICE_NAME
,
"rtorrentd_config_file_path"
)
###
rtorrentd_config_file_path_sample
=
config
.
value
(
SERVICE_NAME
,
"rtorrentd_config_file_path_sample"
)
if
not
os
.
access
(
rtorrentd_config_file_path
,
os
.
F_OK
)
:
if
access
(
rtorrentd_config_file_path_sample
,
os
.
F_OK
)
:
shutil
.
copy2
(
rtorrentd_config_file_path_sample
,
rtorrentd_config_file_path
)
else
:
open
(
rtorrentd_config_file_path
,
"w"
)
.
close
()
###
rtorrentd_config_file
=
open
(
rtorrentd_config_file_path
,
"r+"
)
rtorrentd_config_file_data
=
rtorrentd_config_file
.
read
()
variable_regexp
=
re
.
compile
(
r"(((\n|\A)
%
s=[^\n]*)+)"
%
(
variable_name
))
variable
=
"
\n
"
.
join
([
"
%
s=
\"
%
s
\"
"
%
(
variable_name
,
values_list_item
)
for
values_list_item
in
values_list
])
if
variable_regexp
.
search
(
rtorrentd_config_file_data
)
:
if
len
(
variable
)
!=
0
:
variable
=
(
"
\n
"
if
replace_flag
else
"
\\
1
\n
"
)
+
variable
rtorrentd_config_file_data
=
variable_regexp
.
sub
(
variable
,
rtorrentd_config_file_data
)
elif
len
(
variable
)
!=
0
:
rtorrentd_config_file_data
+=
(
"
\n
"
if
rtorrentd_config_file_data
[
-
1
]
!=
"
\n
"
else
""
)
+
variable
+
"
\n
"
rtorrentd_config_file
.
seek
(
0
)
rtorrentd_config_file
.
truncate
()
rtorrentd_config_file
.
write
(
rtorrentd_config_file_data
)
try
:
rtorrentd_config_file_data
.
close
()
except
:
pass
def
configValue
(
self
,
variable_name
)
:
if
os
.
access
(
config
.
value
(
SERVICE_NAME
,
"rtorrentd_config_file_path"
),
os
.
F_OK
)
:
rtorrentd_config_file
=
open
(
config
.
value
(
SERVICE_NAME
,
"rtorrentd_config_file_path"
),
"r"
)
rtorrentd_config_file_list
=
rtorrentd_config_file
.
read
()
.
split
(
"
\n
"
)
try
:
rtorrentd_config_file
.
close
()
except
:
pass
variable_regexp
=
re
.
compile
(
r"^
%
s=[\"\']?([^\n\"\']*)"
%
(
variable_name
))
variables_list
=
[]
for
rtorrentd_config_file_list_item
in
rtorrentd_config_file_list
:
if
len
(
rtorrentd_config_file_list_item
)
==
0
:
continue
variable_match
=
variable_regexp
.
match
(
rtorrentd_config_file_list_item
)
if
variable_match
!=
None
:
variables_list
.
append
(
variable_match
.
group
(
1
))
return
variables_list
return
[]
##### Public classes #####
class
Service
(
service
.
Service
)
:
### Public ###
def
initService
(
self
)
:
shared
.
Functions
.
addSharedObject
(
SERVICE_NAME
,
RTorrentd
(
SERVICE_NAME
,
self
))
### Private ###
@classmethod
def
serviceName
(
self
)
:
return
SERVICE_NAME
@classmethod
def
options
(
self
)
:
return
[
(
SERVICE_NAME
,
"rtorrentd_config_file_path"
,
"/etc/sysconfig/rtorrent"
,
str
),
(
SERVICE_NAME
,
"rtorrentd_config_file_path_sample"
,
os
.
path
.
join
(
const
.
FUNCTIONS_DATA_DIR
,
SERVICE_NAME
,
"rtorrent"
),
str
)
]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment