Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
喜羊羊3508
Dak
提交
0fe78641
D
Dak
项目概览
喜羊羊3508
/
Dak
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
未验证
提交
0fe78641
编写于
8月 22, 2014
作者:
A
Ansgar Burchardt
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
HashedFile: Raise FileDoesNotExist if referring to a non-existing file
A custom exception is nicer to handle in the caller.
上级
731d594c
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
22 addition
and
13 deletion
+22
-13
daklib/checks.py
daklib/checks.py
+6
-8
daklib/upload.py
daklib/upload.py
+16
-5
未找到文件。
daklib/checks.py
浏览文件 @
0fe78641
...
...
@@ -31,7 +31,7 @@ from daklib.regexes import *
from
daklib.textutils
import
fix_maintainer
,
ParseMaintError
import
daklib.lintian
as
lintian
import
daklib.utils
as
utils
from
daklib.upload
import
InvalidHashException
import
daklib.upload
import
apt_inst
import
apt_pkg
...
...
@@ -160,13 +160,11 @@ class SignatureAndHashesCheck(Check):
try
:
for
f
in
files
:
f
.
check
(
upload
.
directory
)
except
IOError
as
e
:
if
e
.
errno
==
errno
.
ENOENT
:
raise
Reject
(
'{0} refers to non-existing file: {1}
\n
'
'Perhaps you need to include it in your upload?'
.
format
(
filename
,
os
.
path
.
basename
(
e
.
filename
)))
raise
except
InvalidHashException
as
e
:
except
daklib
.
upload
.
FileDoesNotExist
as
e
:
raise
Reject
(
'{0}: {1}
\n
'
'Perhaps you need to include the file in your upload?'
.
format
(
filename
,
unicode
(
e
)))
except
daklib
.
upload
.
UploadException
as
e
:
raise
Reject
(
'{0}: {1}'
.
format
(
filename
,
unicode
(
e
)))
class
ChangesCheck
(
Check
):
...
...
daklib/upload.py
浏览文件 @
0fe78641
...
...
@@ -63,6 +63,12 @@ class InvalidFilenameException(UploadException):
def
__str__
(
self
):
return
"Invalid filename '{0}'."
.
format
(
self
.
filename
)
class
FileDoesNotExist
(
UploadException
):
def
__init__
(
self
,
filename
):
self
.
filename
=
filename
def
__str__
(
self
):
return
"Refers to non-existing file '{0}'"
.
format
(
self
.
filename
)
class
HashedFile
(
object
):
"""file with checksums
"""
...
...
@@ -124,8 +130,8 @@ class HashedFile(object):
@return: C{HashedFile} object for the given file
"""
path
=
os
.
path
.
join
(
directory
,
filename
)
size
=
os
.
stat
(
path
).
st_size
with
open
(
path
,
'r'
)
as
fh
:
size
=
os
.
fstat
(
fh
.
fileno
()).
st_size
hashes
=
apt_pkg
.
Hashes
(
fh
)
return
cls
(
filename
,
size
,
hashes
.
md5
,
hashes
.
sha1
,
hashes
.
sha256
,
section
,
priority
)
...
...
@@ -141,12 +147,17 @@ class HashedFile(object):
"""
path
=
os
.
path
.
join
(
directory
,
self
.
filename
)
size
=
os
.
stat
(
path
).
st_size
if
size
!=
self
.
size
:
raise
InvalidHashException
(
self
.
filename
,
'size'
,
self
.
size
,
size
)
try
:
with
open
(
path
)
as
fh
:
size
=
os
.
fstat
(
fh
.
fileno
()).
st_size
hashes
=
apt_pkg
.
Hashes
(
fh
)
except
IOError
as
e
:
if
e
.
errno
==
errno
.
ENOENT
:
raise
FileDoesNotExist
(
self
.
filename
)
raise
if
size
!=
self
.
size
:
raise
InvalidHashException
(
self
.
filename
,
'size'
,
self
.
size
,
size
)
if
hashes
.
md5
!=
self
.
md5sum
:
raise
InvalidHashException
(
self
.
filename
,
'md5sum'
,
self
.
md5sum
,
hashes
.
md5
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录