Permalink
Browse files

create settings available

  • Loading branch information...
lepture
lepture committed Sep 11, 2012
1 parent 01fa5e3 commit 63086972f3f457e26079f3d1744c3038353cd7ec
Showing with 31 additions and 117 deletions.
  1. +3 −0 MANIFEST.in
  2. +3 −4 liquidluck/cli.py
  3. +24 −1 liquidluck/generator.py
  4. +0 −111 liquidluck/tools/creator.py
  5. +1 −1 liquidluck/utils.py
View
@@ -1,3 +1,6 @@
recursive-include liquidluck/_themes *.*
include liquidluck/tools/livereload.js
+include liquidluck/tools/_settings.json
+include liquidluck/tools/_settings.yml
+include liquidluck/tools/_settings.py
include README.rst
View
@@ -3,7 +3,6 @@
import sys
import liquidluck
from liquidluck.tools import theme
-from liquidluck.tools import creator
from liquidluck.tools import webhook
from liquidluck.tools import server
from liquidluck import generator
@@ -112,16 +111,16 @@ def main():
arg_settings = args['--settings'] or generator.find_settings()
if command == 'create':
- creator.create(arg_settings)
+ generator.create_settings(arg_settings)
elif command == 'build':
- if not os.path.exists(arg_settings):
+ if not arg_settings:
answer = raw_input(
"Can't find your setting files, "
"would you like to create one?(Y/n) "
)
if answer.lower() == 'n':
return
- creator.create(arg_settings)
+ generator.create_settings(arg_settings)
else:
g.detail_logging = args['--verbose']
generator.build(arg_settings)
View
@@ -6,11 +6,34 @@
import sys
import logging
from liquidluck.options import g, settings
-from liquidluck.utils import import_object, walk_dir
+from liquidluck.utils import import_object, walk_dir, copy_to
from liquidluck.writers.base import load_jinja
+def create_settings(filepath):
+ if not filepath:
+ filetype = raw_input(
+ 'Select a config format ([yaml], python, json): '
+ )
+ if not filetype:
+ filetype = 'yaml'
+
+ if filetype not in ['yaml', 'python', 'json']:
+ print('format not supported')
+ return
+
+ suffix = {'yaml': '.yml', 'python': '.py', 'json': '.json'}
+ filepath = 'settings%s' % suffix[filetype]
+
+ if filepath.endswith('.py'):
+ copy_to(os.path.join(PROJDIR, 'tools', '_settings.py'), filepath)
+ elif filepath.endswith('.json'):
+ copy_to(os.path.join(PROJDIR, 'tools', '_settings.json'), filepath)
+ else:
+ copy_to(os.path.join(PROJDIR, 'tools', '_settings.yml'), filepath)
+
+
def find_settings():
config = [
'settings.yml', 'settings.json', 'settings.yaml', 'settings.py',
View
@@ -1,111 +0,0 @@
-import os
-
-
-DEFAULT_SETTING = """
-# permalink settings
-# http://liquidluck.readthedocs.org/en/latest/config.html#permalink
-#
-# Examples:
-# {{filename}}.html
-# {{date.year}}/{{filename}}.html
-# {{date.year}}/{{date.month}}/{{filename}}.html
-# {{category}}/{{filename}}.html
-permalink = '{{date.year}}/{{filename}}'
-
-# if you want to use relative url, set it to True
-use_relative_url = False
-
-# how many posts can be in one page
-perpage = 30
-
-# how many posts can be in a feed
-feedcount = 20
-timezone = "+00:00"
-
-# default author
-# you can set the author in your post::
-#
-# - author: yourname
-#
-author = 'nickname' # choose a nickname
-
-# multi author support
-# http://liquidluck.readthedocs.org/en/latest/config.html#multiple-authors
-# authors = {
-# 'nickname': {
-# 'name': 'Full Name',
-# 'email': 'admin@example.com',
-# 'website': 'http://example.com',
-# },
-# }
-
-
-theme = 'default'
-# theme variables are defined by theme creator
-# find all the theme variables in the theme settings.py file
-theme_variables = {}
-
-# http://liquidluck.readthedocs.org/en/latest/config.html#readers
-# readers = {
- # if you want to enable reStructuredText, uncomment this line
- # and you need install doctutils by yourself
- # 'rst': 'liquidluck.readers.restructuredtext.RestructuredTextReader',
-# }
-readers_variables = {}
-
-# http://liquidluck.readthedocs.org/en/latest/config.html#writers
-# writers = {
-# # the writers enabled by default
-# # 'post': 'liquidluck.writers.core.PostWriter',
-# # 'page': 'liquidluck.writers.core.PageWriter',
-# # 'archive': 'liquidluck.writers.core.ArchiveWriter',
-# # 'archive_feed': 'liquidluck.writers.core.ArchiveFeedWriter',
-# # 'file': 'liquidluck.writers.core.FileWriter',
-# # 'static': 'liquidluck.writers.core.StaticWriter',
-# # 'year': 'liquidluck.writers.core.YearWriter',
-# # 'tag': 'liquidluck.writers.core.TagWriter',
-# # 'category': 'liquidluck.writers.core.CategoryWriter',
-# # 'category_feed': 'liquidluck.writers.core.CategoryFeedWriter',
-#
-# # you can disable a writer with:
-# # 'year': None,
-# }
-writers_variables = {}
-
-# template_variables = {}
-# template_filters = {}
-"""
-
-
-def create(config):
- #: require site information
- site_name = raw_input("Site Name: ")
- site_url = raw_input("Site URL: ")
- code = (
- '#!/usr/bin/env python\n'
- '# -*- coding: utf-8 -*-\n\n'
- "site = {\n"
- ' "name": "%s",\n'
- ' "url": "%s",\n'
- ' # "prefix": "blog",\n'
- '}\n\n'
- ) % (site_name, site_url)
-
- source = raw_input("What is your directory for posts(content): ")
- source = source or 'content'
- code += "source = '%s'\n" % source
- if not os.path.isdir(source):
- os.makedirs(source)
-
- output = raw_input("Where is your directory for output(deploy): ")
- output = output or 'deploy'
- code += "output = '%s'\n" % output
- code += "static_output = '%s/static'\n" % output
- code += "static_prefix = '/static/'\n"
- code += DEFAULT_SETTING
-
- f = open(config, 'w')
- f.write(code)
- f.close()
- print("\nYour site is created.\n\n\n")
- print("Get help: http://liquidluck.readthedocs.org")
View
@@ -59,7 +59,7 @@ def copy_to(source, dest):
folder = os.path.split(dest)[0]
# on Mac OSX, `folder` == `FOLDER`
# then make sure destination is lowercase
- if not os.path.isdir(folder):
+ if folder and not os.path.isdir(folder):
os.makedirs(folder)
shutil.copy(source, dest)

0 comments on commit 6308697

Please sign in to comment.