Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
喜羊羊3508
Dak
提交
0012d9e8
D
Dak
项目概览
喜羊羊3508
/
Dak
8 个月 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Dak
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
0012d9e8
编写于
4月 13, 2019
作者:
N
Niels Thykier
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
dak admin: Add suite-config {list,get,set}
Signed-off-by:
N
Niels Thykier
<
niels@thykier.net
>
上级
aada594f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
241 addition
and
0 deletion
+241
-0
dak/admin.py
dak/admin.py
+129
-0
daklib/utils.py
daklib/utils.py
+11
-0
integration-tests/tests/0003-dak-admin-suite-config
integration-tests/tests/0003-dak-admin-suite-config
+101
-0
未找到文件。
dak/admin.py
浏览文件 @
0012d9e8
...
...
@@ -131,6 +131,14 @@ Perform administrative work on the dak database.
s-c rm SUITE COMPONENT remove component from suite (will only work if
no packages remain for the component in the suite)
suite-config / s-cfg:
s-cfg list show the names of the configurations
s-cfg list SUITE show the configuration values for SUITE
s-cfg get SUITE NAME ...
show the value for NAME in SUITE
s-cfg set SUITE NAME=VALUE ...
set NAME to VALUE in SUITE
archive:
archive list list all archives
archive add NAME ROOT DESCRIPTION [primary-mirror=MIRROR] [tainted=1]
...
...
@@ -719,6 +727,127 @@ def suite_component(command):
dispatch
[
'suite-component'
]
=
suite_component
dispatch
[
's-c'
]
=
suite_component
################################################################################
# Sentinal for detecting read-only configurations
SUITE_CONFIG_READ_ONLY
=
object
()
ALLOWED_SUITE_CONFIGS
=
{
'accept_binary_uploads'
:
utils
.
parse_boolean_from_user
,
'accept_source_uploads'
:
utils
.
parse_boolean_from_user
,
'allowcsset'
:
utils
.
parse_boolean_from_user
,
'announce'
:
SUITE_CONFIG_READ_ONLY
,
'butautomaticupgrades'
:
utils
.
parse_boolean_from_user
,
'byhash'
:
utils
.
parse_boolean_from_user
,
'changelog'
:
str
,
'changelog_url'
:
str
,
# TODO: Create a validator/parser for this
'checksums'
:
SUITE_CONFIG_READ_ONLY
,
'description'
:
str
,
'include_long_description'
:
utils
.
parse_boolean_from_user
,
'indices_compression'
:
SUITE_CONFIG_READ_ONLY
,
'label'
:
str
,
'mail_whitelist'
:
str
,
'notautomatic'
:
utils
.
parse_boolean_from_user
,
'origin'
:
str
,
'priority'
:
int
,
'signingkeys'
:
SUITE_CONFIG_READ_ONLY
,
'untouchable'
:
utils
.
parse_boolean_from_user
,
'validtime'
:
int
,
}
def
__suite_config_get
(
d
,
args
):
die_arglen
(
args
,
4
,
"E: suite-config get needs the name of a configuration"
)
session
=
d
.
session
()
suite_name
=
args
[
2
]
suite
=
get_suite
(
suite_name
,
session
)
for
arg
in
args
[
3
:]:
if
arg
not
in
ALLOWED_SUITE_CONFIGS
:
die
(
"Unknown (or unsupported) suite configuration variable"
)
value
=
getattr
(
suite
,
arg
)
print
(
"%s=%s"
%
(
arg
,
value
))
def
__suite_config_set
(
d
,
args
):
die_arglen
(
args
,
4
,
"E: suite-config set needs the name of a configuration"
)
session
=
d
.
session
()
suite_name
=
args
[
2
]
suite
=
get_suite
(
suite_name
,
session
)
for
arg
in
args
[
3
:]:
if
'='
not
in
arg
:
die
(
"Missing value for configuration %s: Use key=value format"
%
arg
)
conf_name
,
new_value_str
=
arg
.
split
(
'='
,
1
)
converter
=
ALLOWED_SUITE_CONFIGS
.
get
(
conf_name
)
if
converter
is
None
:
die
(
"Unknown (or unsupported) suite configuration variable"
)
if
converter
is
SUITE_CONFIG_READ_ONLY
:
die
(
"Cannot change %s from the command line"
%
arg
)
try
:
new_value
=
converter
(
new_value_str
)
except
RuntimeError
as
e
:
warn
(
"Could not convert value %s for %s"
%
(
conf_name
,
new_value_str
))
raise
e
setattr
(
suite
,
conf_name
,
new_value
)
print
(
"%s=%s"
%
(
conf_name
,
new_value
))
if
dryrun
:
session
.
rollback
()
print
()
print
(
"This was a dryrun; changes have been rolled back"
)
else
:
session
.
commit
()
def
__suite_config_list
(
d
,
args
):
suite
=
None
session
=
d
.
session
()
if
len
(
args
)
>
3
:
warn
(
"W: Ignoring extra argument after the suite name"
)
if
len
(
args
)
==
3
:
suite_name
=
args
[
2
]
suite
=
get_suite
(
suite_name
,
session
)
else
:
print
(
"Valid suite-config options managable by this command:"
)
print
()
for
arg
in
sorted
(
ALLOWED_SUITE_CONFIGS
):
mode
=
'writable'
if
ALLOWED_SUITE_CONFIGS
[
arg
]
is
SUITE_CONFIG_READ_ONLY
:
mode
=
'read-ony'
if
suite
is
not
None
:
value
=
getattr
(
suite
,
arg
)
print
(
"%s=%s"
%
(
arg
,
value
))
else
:
print
(
" * %s (%s)"
%
(
arg
,
mode
))
def
suite_config
(
command
):
args
=
[
str
(
x
)
for
x
in
command
]
Cnf
=
utils
.
get_conf
()
d
=
DBConn
()
die_arglen
(
args
,
2
,
"E: suite-config needs a command"
)
mode
=
args
[
1
].
lower
()
if
mode
==
'get'
:
__suite_config_get
(
d
,
args
)
elif
mode
==
'set'
:
__suite_config_set
(
d
,
args
)
elif
mode
==
'list'
:
__suite_config_list
(
d
,
args
)
else
:
suite
=
get_suite
(
mode
,
d
.
session
())
if
suite
is
not
None
:
warn
(
"Did you get the order of the suite and the subcommand wrong?"
)
warn
(
"Syntax: dak admin %s {get,set,...} <suite>"
%
args
[
0
])
die
(
"E: suite-config command unknown"
)
dispatch
[
'suite-config'
]
=
suite_config
dispatch
[
's-cfg'
]
=
suite_config
################################################################################
...
...
daklib/utils.py
浏览文件 @
0012d9e8
...
...
@@ -1434,3 +1434,14 @@ def find_possibly_compressed_file(filename):
return
_file
raise
FileNotFoundError
(
errno
.
ENOENT
,
os
.
strerror
(
errno
.
ENOENT
),
filename
)
################################################################################
def
parse_boolean_from_user
(
value
):
value
=
value
.
lower
()
if
value
in
{
'yes'
,
'true'
,
'enable'
,
'enabled'
}:
return
True
if
value
in
{
'no'
,
'false'
,
'disable'
,
'disabled'
}:
return
False
raise
ValueError
(
"Not sure whether %s should be a True or a False"
%
value
)
integration-tests/tests/0003-dak-admin-suite-config
0 → 100755
浏览文件 @
0012d9e8
#! /bin/bash
#
# © 2019 Niels Thykier <niels@thykier.net>
# License: GPL-2+
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
set
-e
set
-u
.
${
DAK_ROOT
:?
}
/integration-tests/common
.
${
DAK_ROOT
:?
}
/integration-tests/setup
# add a unstable suite with amd64
dak admin architecture add amd64 AMD64
for
suite
in
testing stable
;
do
dak admin suite add
"
${
suite
}
"
""
dak admin suite-architecture add
"
${
suite
}
"
source
all amd64
dak admin suite-component add
"
${
suite
}
"
main contrib non-free
done
echo
"---- testing ----"
# Play a bit with testing
(
dak admin suite-config
set
testing
allowcsset
=
yes
accept_source_uploads
=
no
\
accept_binary_uploads
=
no
changelog
=
"dists/testing/ChangeLog"
\
changelog_url
=
"http://metadata.ftp-master.debian.org/changelogs/@CHANGEPATH@_changelog"
)
# Verify that the values match our changes
(
expected
=
"
$(
cat
<<
EOF
allowcsset=True
accept_source_uploads=False
accept_binary_uploads=False
changelog=dists/testing/ChangeLog
changelog_url=http://metadata.ftp-master.debian.org/changelogs/@CHANGEPATH@_changelog
EOF
)
"
actual
=
$(
dak admin suite-config get testing allowcsset accept_source_uploads accept_binary_uploads
\
changelog changelog_url
)
assert-equal
"dak admin s-cfg get allowcsset accept_source_uploads accept_binary_uploads"
\
"
${
actual
}
"
"
${
expected
}
"
# Also try to do a listing
dak admin suite-config list testing
)
echo
"---- stable ----"
# Set stable to be untouchable (and set allowcsset to a known value)
(
dak admin suite-config
set
stable
allowcsset
=
no
untouchable
=
yes
)
# Verify the new state
(
expected
=
"
$(
cat
<<
EOF
allowcsset=False
untouchable=True
EOF
)
"
actual
=
"
$(
dak admin s-cfg get stable allowcsset untouchable
)
"
assert-equal
"dak admin s-cfg get stable allowcsset untouchable"
\
"
${
actual
}
"
"
${
expected
}
"
dak admin suite-config
--dry-run
set
stable
allowcsset
=
yes
dak admin suite-config
--dry-run
set
stable
untouchable
=
no
# And it is nothing really changed anything with dry-run
actual
=
"
$(
dak admin s-cfg get stable allowcsset untouchable
)
"
assert-equal
"dak admin s-cfg get stable allowcsset untouchable"
\
"
${
actual
}
"
"
${
expected
}
"
dak admin suite-config list stable
# And reset/changes the configs for real
dak admin suite-config
set
stable
allowcsset
=
yes
untouchable
=
no
expected
=
"
$(
cat
<<
EOF
allowcsset=True
untouchable=False
EOF
)
"
actual
=
"
$(
dak admin s-cfg get stable allowcsset untouchable
)
"
assert-equal
"dak admin s-cfg get stable allowcsset untouchable"
\
"
${
actual
}
"
"
${
expected
}
"
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录