Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix cmds-new problem with windows #196

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
让我们来创建第一个项目 helloworld:

```
$ sea new --skip-peewee --skip-cache --skip-async_task --skip-bus --skip-sentry helloworld
$ sea new --skip-peewee --skip-cache --skip-async-task --skip-bus --skip-sentry helloworld
```

这条命令会自动生成以下目录及文件:
Expand Down
2 changes: 1 addition & 1 deletion docs/structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
> `extensions.py`:

声明了项目需要的 "扩展",`sea` 支持通过 "扩展" 的方式来集成第三方的库,例如 orm, cache 等等。
每个扩展往往包括一个“扩展类”和需要的相应的配置,在 `extensions.py`中实力化这个“扩展类”,并在项目中设置好这些配置,就可以使用了。
每个扩展往往包括一个“扩展类”和需要的相应的配置,在 `extensions.py`中实例化这个“扩展类”,并在项目中设置好这些配置,就可以使用了。

以 [`cache`](https://github.com/shanbay/cachext) 扩展为例:

Expand Down
53 changes: 30 additions & 23 deletions sea/cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,45 +81,52 @@ def new(project, **extra):
PACKAGE_DIR = os.path.dirname(__file__)
TMPLPATH = os.path.join(PACKAGE_DIR, 'template')
IGNORED_FILES = {
'git': ['gitignore'],
'peewee': ['configs/default/peewee.py.tmpl',
'app/models.py.tmpl'],
'cache': ['configs/default/cache.py.tmpl'],
'git': [['gitignore']],
'peewee': [['configs', 'default', 'peewee.py.tmpl'],
['app', 'models.py.tmpl']],
'cache': [['configs', 'default', 'cache.py.tmpl']],
'sentry': [],
'async_task': ['configs/default/async_task.py.tmpl',
'app/tasks.py.tmpl'],
'bus': ['configs/default/bus.py.tmpl', 'app/buses.py.tmpl'],
'async_task': [['configs', 'default', 'async_task.py.tmpl'],
['app', 'async_tasks.py.tmpl']],
'bus': [['configs', 'default', 'bus.py.tmpl'], ['app', 'buses.py.tmpl']],
}

def _build_skip_files(extra):
skipped = set()
for ignore_key in IGNORED_FILES.keys():
if extra[('skip_' + ignore_key)]:
for f in IGNORED_FILES[ignore_key]:
skipped.add(os.path.join(TMPLPATH, f))
for fp in IGNORED_FILES[ignore_key]:
f = TMPLPATH
for c in fp:
f = os.path.join(f, c)
skipped.add(f)
return skipped

def _gen_project(path, skip=set(), ctx={}):
def _gen_project_file(path, tmpl_file, env, ctx):
import shutil
relfn = os.path.relpath(tmpl_file, TMPLPATH)
dst = os.path.join(path, relfn)
# create the parentdir if not exists
os.makedirs(os.path.dirname(dst), exist_ok=True)
r, ext = os.path.splitext(dst)
if ext == '.tmpl':
with open(r, 'w') as f:
# jinja2 always expect forward slashes here
tmpl = env.get_template(relfn.replace(os.path.sep, '/'))
f.write(tmpl.render(**ctx))
else:
shutil.copyfile(tmpl_file, dst)

print('created: {}'.format(dst))

def _gen_project(path, skip=set(), ctx={}):
from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader(TMPLPATH))
for dirpath, dirnames, filenames in os.walk(TMPLPATH):
for fn in filenames:
src = os.path.join(dirpath, fn)
if src not in skip:
relfn = os.path.relpath(src, TMPLPATH)
dst = os.path.join(path, relfn)
# create the parentdir if not exists
os.makedirs(os.path.dirname(dst), exist_ok=True)
r, ext = os.path.splitext(dst)
if ext == '.tmpl':
with open(r, 'w') as f:
tmpl = env.get_template(relfn)
f.write(tmpl.render(**ctx))
else:
shutil.copyfile(src, dst)

print('created: {}'.format(dst))
_gen_project_file(path, src, env, ctx)

path = os.path.join(os.getcwd(), project)
if os.path.exists(path):
Expand Down