Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
looyolo
scrapy
提交
25bd3b3f
S
scrapy
项目概览
looyolo
/
scrapy
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
scrapy
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
25bd3b3f
编写于
9月 29, 2016
作者:
E
Elias Dorneles
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add .scrapy when outside spider too, add tests
上级
8e4947ef
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
44 addition
and
3 deletion
+44
-3
scrapy/utils/project.py
scrapy/utils/project.py
+10
-3
tests/test_utils_project.py
tests/test_utils_project.py
+34
-0
未找到文件。
scrapy/utils/project.py
浏览文件 @
25bd3b3f
...
...
@@ -12,6 +12,7 @@ from scrapy.exceptions import NotConfigured
ENVVAR
=
'SCRAPY_SETTINGS_MODULE'
DATADIR_CFG_SECTION
=
'datadir'
def
inside_project
():
scrapy_module
=
os
.
environ
.
get
(
'SCRAPY_SETTINGS_MODULE'
)
if
scrapy_module
is
not
None
:
...
...
@@ -23,6 +24,7 @@ def inside_project():
return
True
return
bool
(
closest_scrapy_cfg
())
def
project_data_dir
(
project
=
'default'
):
"""Return the current project data dir, creating it if it doesn't exist"""
if
not
inside_project
():
...
...
@@ -39,16 +41,21 @@ def project_data_dir(project='default'):
os
.
makedirs
(
d
)
return
d
def
data_path
(
path
,
createdir
=
False
):
"""If inside the project and path is relative, return the given path
as relative the project data dir, otherwise return it unmodified
as relative t
o t
he project data dir, otherwise return it unmodified
"""
if
inside_project
()
and
not
isabs
(
path
):
path
=
join
(
project_data_dir
(),
path
)
if
not
isabs
(
path
):
if
inside_project
():
path
=
join
(
project_data_dir
(),
path
)
else
:
path
=
join
(
'.scrapy'
,
path
)
if
createdir
and
not
exists
(
path
):
os
.
makedirs
(
path
)
return
path
def
get_project_settings
():
if
ENVVAR
not
in
os
.
environ
:
project
=
os
.
environ
.
get
(
'SCRAPY_PROJECT'
,
'default'
)
...
...
tests/test_utils_project.py
0 → 100644
浏览文件 @
25bd3b3f
import
unittest
import
os
import
tempfile
import
shutil
import
contextlib
from
scrapy.utils.project
import
data_path
@
contextlib
.
contextmanager
def
inside_a_project
():
prev_dir
=
os
.
getcwd
()
project_dir
=
tempfile
.
mkdtemp
()
try
:
os
.
chdir
(
project_dir
)
with
open
(
'scrapy.cfg'
,
'w'
)
as
f
:
# create an empty scrapy.cfg
f
.
close
()
yield
project_dir
finally
:
os
.
chdir
(
prev_dir
)
shutil
.
rmtree
(
project_dir
)
class
ProjectUtilsTest
(
unittest
.
TestCase
):
def
test_data_path_outside_project
(
self
):
self
.
assertEquals
(
'.scrapy/somepath'
,
data_path
(
'somepath'
))
def
test_data_path_inside_project
(
self
):
with
inside_a_project
()
as
proj_path
:
expected
=
os
.
path
.
join
(
proj_path
,
'.scrapy'
,
'somepath'
)
self
.
assertEquals
(
expected
,
data_path
(
'somepath'
))
self
.
assertEquals
(
'/absolute/path'
,
data_path
(
'/absolute/path'
))
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录