mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
fulfil pep8 standard
This commit is contained in:
parent
44f9cfaaf1
commit
8993c55e6e
31 changed files with 1259 additions and 868 deletions
|
|
@ -1,18 +1,20 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals, print_function
|
||||
import six
|
||||
from __future__ import print_function, unicode_literals
|
||||
|
||||
import argparse
|
||||
import codecs
|
||||
import os
|
||||
import string
|
||||
import argparse
|
||||
import sys
|
||||
import codecs
|
||||
|
||||
import pytz
|
||||
|
||||
import six
|
||||
|
||||
from pelican import __version__
|
||||
|
||||
|
||||
_TEMPLATES_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)),
|
||||
"templates")
|
||||
|
||||
|
|
@ -44,9 +46,10 @@ CONF = {
|
|||
'timezone': 'Europe/Paris'
|
||||
}
|
||||
|
||||
#url for list of valid timezones
|
||||
# url for list of valid timezones
|
||||
_TZ_URL = 'http://en.wikipedia.org/wiki/List_of_tz_database_time_zones'
|
||||
|
||||
|
||||
def _input_compat(prompt):
|
||||
if six.PY3:
|
||||
r = input(prompt)
|
||||
|
|
@ -59,6 +62,7 @@ if six.PY3:
|
|||
else:
|
||||
str_compat = unicode
|
||||
|
||||
|
||||
# Create a 'marked' default path, to determine if someone has supplied
|
||||
# a path on the command-line.
|
||||
class _DEFAULT_PATH_TYPE(str_compat):
|
||||
|
|
@ -66,6 +70,7 @@ class _DEFAULT_PATH_TYPE(str_compat):
|
|||
|
||||
_DEFAULT_PATH = _DEFAULT_PATH_TYPE(os.curdir)
|
||||
|
||||
|
||||
def decoding_strings(f):
|
||||
def wrapper(*args, **kwargs):
|
||||
out = f(*args, **kwargs)
|
||||
|
|
@ -164,7 +169,8 @@ def ask(question, answer=str_compat, default=None, l=None):
|
|||
print('You must enter an integer')
|
||||
return r
|
||||
else:
|
||||
raise NotImplemented('Argument `answer` must be str_compat, bool, or integer')
|
||||
raise NotImplemented(
|
||||
'Argument `answer` must be str_compat, bool, or integer')
|
||||
|
||||
|
||||
def ask_timezone(question, default, tzurl):
|
||||
|
|
@ -177,7 +183,8 @@ def ask_timezone(question, default, tzurl):
|
|||
r = pytz.all_timezones[lower_tz.index(r)]
|
||||
break
|
||||
else:
|
||||
print('Please enter a valid time zone:\n (check [{0}])'.format(tzurl))
|
||||
print('Please enter a valid time zone:\n'
|
||||
' (check [{0}])'.format(tzurl))
|
||||
return r
|
||||
|
||||
|
||||
|
|
@ -186,13 +193,13 @@ def main():
|
|||
description="A kickstarter for Pelican",
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
||||
parser.add_argument('-p', '--path', default=_DEFAULT_PATH,
|
||||
help="The path to generate the blog into")
|
||||
help="The path to generate the blog into")
|
||||
parser.add_argument('-t', '--title', metavar="title",
|
||||
help='Set the title of the website')
|
||||
help='Set the title of the website')
|
||||
parser.add_argument('-a', '--author', metavar="author",
|
||||
help='Set the author name of the website')
|
||||
help='Set the author name of the website')
|
||||
parser.add_argument('-l', '--lang', metavar="lang",
|
||||
help='Set the default web site language')
|
||||
help='Set the default web site language')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
|
|
@ -214,50 +221,94 @@ needed by Pelican.
|
|||
'Will save to:\n%s\n' % CONF['basedir'])
|
||||
else:
|
||||
CONF['basedir'] = os.path.abspath(os.path.expanduser(
|
||||
ask('Where do you want to create your new web site?', answer=str_compat, default=args.path)))
|
||||
ask('Where do you want to create your new web site?',
|
||||
answer=str_compat, default=args.path)))
|
||||
|
||||
CONF['sitename'] = ask('What will be the title of this web site?', answer=str_compat, default=args.title)
|
||||
CONF['author'] = ask('Who will be the author of this web site?', answer=str_compat, default=args.author)
|
||||
CONF['lang'] = ask('What will be the default language of this web site?', str_compat, args.lang or CONF['lang'], 2)
|
||||
CONF['sitename'] = ask('What will be the title of this web site?',
|
||||
answer=str_compat, default=args.title)
|
||||
CONF['author'] = ask('Who will be the author of this web site?',
|
||||
answer=str_compat, default=args.author)
|
||||
CONF['lang'] = ask('What will be the default language of this web site?',
|
||||
str_compat, args.lang or CONF['lang'], 2)
|
||||
|
||||
if ask('Do you want to specify a URL prefix? e.g., http://example.com ', answer=bool, default=True):
|
||||
CONF['siteurl'] = ask('What is your URL prefix? (see above example; no trailing slash)', str_compat, CONF['siteurl'])
|
||||
if ask('Do you want to specify a URL prefix? e.g., http://example.com ',
|
||||
answer=bool, default=True):
|
||||
CONF['siteurl'] = ask('What is your URL prefix? (see '
|
||||
'above example; no trailing slash)',
|
||||
str_compat, CONF['siteurl'])
|
||||
|
||||
CONF['with_pagination'] = ask('Do you want to enable article pagination?', bool, bool(CONF['default_pagination']))
|
||||
CONF['with_pagination'] = ask('Do you want to enable article pagination?',
|
||||
bool, bool(CONF['default_pagination']))
|
||||
|
||||
if CONF['with_pagination']:
|
||||
CONF['default_pagination'] = ask('How many articles per page do you want?', int, CONF['default_pagination'])
|
||||
CONF['default_pagination'] = ask('How many articles per page '
|
||||
'do you want?',
|
||||
int, CONF['default_pagination'])
|
||||
else:
|
||||
CONF['default_pagination'] = False
|
||||
|
||||
CONF['timezone'] = ask_timezone('What is your time zone?', CONF['timezone'], _TZ_URL)
|
||||
CONF['timezone'] = ask_timezone('What is your time zone?',
|
||||
CONF['timezone'], _TZ_URL)
|
||||
|
||||
automation = ask('Do you want to generate a Fabfile/Makefile to automate generation and publishing?', bool, True)
|
||||
develop = ask('Do you want an auto-reload & simpleHTTP script to assist with theme and site development?', bool, True)
|
||||
automation = ask('Do you want to generate a Fabfile/Makefile '
|
||||
'to automate generation and publishing?', bool, True)
|
||||
develop = ask('Do you want an auto-reload & simpleHTTP script '
|
||||
'to assist with theme and site development?', bool, True)
|
||||
|
||||
if automation:
|
||||
if ask('Do you want to upload your website using FTP?', answer=bool, default=False):
|
||||
CONF['ftp_host'] = ask('What is the hostname of your FTP server?', str_compat, CONF['ftp_host'])
|
||||
CONF['ftp_user'] = ask('What is your username on that server?', str_compat, CONF['ftp_user'])
|
||||
CONF['ftp_target_dir'] = ask('Where do you want to put your web site on that server?', str_compat, CONF['ftp_target_dir'])
|
||||
if ask('Do you want to upload your website using SSH?', answer=bool, default=False):
|
||||
CONF['ssh_host'] = ask('What is the hostname of your SSH server?', str_compat, CONF['ssh_host'])
|
||||
CONF['ssh_port'] = ask('What is the port of your SSH server?', int, CONF['ssh_port'])
|
||||
CONF['ssh_user'] = ask('What is your username on that server?', str_compat, CONF['ssh_user'])
|
||||
CONF['ssh_target_dir'] = ask('Where do you want to put your web site on that server?', str_compat, CONF['ssh_target_dir'])
|
||||
if ask('Do you want to upload your website using Dropbox?', answer=bool, default=False):
|
||||
CONF['dropbox_dir'] = ask('Where is your Dropbox directory?', str_compat, CONF['dropbox_dir'])
|
||||
if ask('Do you want to upload your website using S3?', answer=bool, default=False):
|
||||
CONF['s3_bucket'] = ask('What is the name of your S3 bucket?', str_compat, CONF['s3_bucket'])
|
||||
if ask('Do you want to upload your website using Rackspace Cloud Files?', answer=bool, default=False):
|
||||
CONF['cloudfiles_username'] = ask('What is your Rackspace Cloud username?', str_compat, CONF['cloudfiles_username'])
|
||||
CONF['cloudfiles_api_key'] = ask('What is your Rackspace Cloud API key?', str_compat, CONF['cloudfiles_api_key'])
|
||||
CONF['cloudfiles_container'] = ask('What is the name of your Cloud Files container?', str_compat, CONF['cloudfiles_container'])
|
||||
if ask('Do you want to upload your website using GitHub Pages?', answer=bool, default=False):
|
||||
if ask('Is this your personal page (username.github.io)?', answer=bool, default=False):
|
||||
CONF['github_pages_branch'] = _GITHUB_PAGES_BRANCHES['personal']
|
||||
if ask('Do you want to upload your website using FTP?',
|
||||
answer=bool, default=False):
|
||||
CONF['ftp_host'] = ask('What is the hostname of your FTP server?',
|
||||
str_compat, CONF['ftp_host'])
|
||||
CONF['ftp_user'] = ask('What is your username on that server?',
|
||||
str_compat, CONF['ftp_user'])
|
||||
CONF['ftp_target_dir'] = ask('Where do you want to put your '
|
||||
'web site on that server?',
|
||||
str_compat, CONF['ftp_target_dir'])
|
||||
if ask('Do you want to upload your website using SSH?',
|
||||
answer=bool, default=False):
|
||||
CONF['ssh_host'] = ask('What is the hostname of your SSH server?',
|
||||
str_compat, CONF['ssh_host'])
|
||||
CONF['ssh_port'] = ask('What is the port of your SSH server?',
|
||||
int, CONF['ssh_port'])
|
||||
CONF['ssh_user'] = ask('What is your username on that server?',
|
||||
str_compat, CONF['ssh_user'])
|
||||
CONF['ssh_target_dir'] = ask('Where do you want to put your '
|
||||
'web site on that server?',
|
||||
str_compat, CONF['ssh_target_dir'])
|
||||
|
||||
if ask('Do you want to upload your website using Dropbox?',
|
||||
answer=bool, default=False):
|
||||
CONF['dropbox_dir'] = ask('Where is your Dropbox directory?',
|
||||
str_compat, CONF['dropbox_dir'])
|
||||
|
||||
if ask('Do you want to upload your website using S3?',
|
||||
answer=bool, default=False):
|
||||
CONF['s3_bucket'] = ask('What is the name of your S3 bucket?',
|
||||
str_compat, CONF['s3_bucket'])
|
||||
|
||||
if ask('Do you want to upload your website using '
|
||||
'Rackspace Cloud Files?', answer=bool, default=False):
|
||||
CONF['cloudfiles_username'] = ask('What is your Rackspace '
|
||||
'Cloud username?', str_compat,
|
||||
CONF['cloudfiles_username'])
|
||||
CONF['cloudfiles_api_key'] = ask('What is your Rackspace '
|
||||
'Cloud API key?', str_compat,
|
||||
CONF['cloudfiles_api_key'])
|
||||
CONF['cloudfiles_container'] = ask('What is the name of your '
|
||||
'Cloud Files container?',
|
||||
str_compat,
|
||||
CONF['cloudfiles_container'])
|
||||
|
||||
if ask('Do you want to upload your website using GitHub Pages?',
|
||||
answer=bool, default=False):
|
||||
if ask('Is this your personal page (username.github.io)?',
|
||||
answer=bool, default=False):
|
||||
CONF['github_pages_branch'] = \
|
||||
_GITHUB_PAGES_BRANCHES['personal']
|
||||
else:
|
||||
CONF['github_pages_branch'] = _GITHUB_PAGES_BRANCHES['project']
|
||||
CONF['github_pages_branch'] = \
|
||||
_GITHUB_PAGES_BRANCHES['project']
|
||||
|
||||
try:
|
||||
os.makedirs(os.path.join(CONF['basedir'], 'content'))
|
||||
|
|
@ -270,7 +321,8 @@ needed by Pelican.
|
|||
print('Error: {0}'.format(e))
|
||||
|
||||
try:
|
||||
with codecs.open(os.path.join(CONF['basedir'], 'pelicanconf.py'), 'w', 'utf-8') as fd:
|
||||
with codecs.open(os.path.join(CONF['basedir'], 'pelicanconf.py'),
|
||||
'w', 'utf-8') as fd:
|
||||
conf_python = dict()
|
||||
for key, value in CONF.items():
|
||||
conf_python[key] = repr(value)
|
||||
|
|
@ -283,7 +335,8 @@ needed by Pelican.
|
|||
print('Error: {0}'.format(e))
|
||||
|
||||
try:
|
||||
with codecs.open(os.path.join(CONF['basedir'], 'publishconf.py'), 'w', 'utf-8') as fd:
|
||||
with codecs.open(os.path.join(CONF['basedir'], 'publishconf.py'),
|
||||
'w', 'utf-8') as fd:
|
||||
for line in get_template('publishconf.py'):
|
||||
template = string.Template(line)
|
||||
fd.write(template.safe_substitute(CONF))
|
||||
|
|
@ -293,7 +346,8 @@ needed by Pelican.
|
|||
|
||||
if automation:
|
||||
try:
|
||||
with codecs.open(os.path.join(CONF['basedir'], 'fabfile.py'), 'w', 'utf-8') as fd:
|
||||
with codecs.open(os.path.join(CONF['basedir'], 'fabfile.py'),
|
||||
'w', 'utf-8') as fd:
|
||||
for line in get_template('fabfile.py'):
|
||||
template = string.Template(line)
|
||||
fd.write(template.safe_substitute(CONF))
|
||||
|
|
@ -301,7 +355,8 @@ needed by Pelican.
|
|||
except OSError as e:
|
||||
print('Error: {0}'.format(e))
|
||||
try:
|
||||
with codecs.open(os.path.join(CONF['basedir'], 'Makefile'), 'w', 'utf-8') as fd:
|
||||
with codecs.open(os.path.join(CONF['basedir'], 'Makefile'),
|
||||
'w', 'utf-8') as fd:
|
||||
mkfile_template_name = 'Makefile'
|
||||
py_v = 'PY?=python'
|
||||
if six.PY3:
|
||||
|
|
@ -323,7 +378,9 @@ needed by Pelican.
|
|||
value = '"' + value.replace('"', '\\"') + '"'
|
||||
conf_shell[key] = value
|
||||
try:
|
||||
with codecs.open(os.path.join(CONF['basedir'], 'develop_server.sh'), 'w', 'utf-8') as fd:
|
||||
with codecs.open(os.path.join(CONF['basedir'],
|
||||
'develop_server.sh'),
|
||||
'w', 'utf-8') as fd:
|
||||
lines = list(get_template('develop_server.sh'))
|
||||
py_v = 'PY=${PY:-python}\n'
|
||||
if six.PY3:
|
||||
|
|
@ -333,7 +390,10 @@ needed by Pelican.
|
|||
template = string.Template(line)
|
||||
fd.write(template.safe_substitute(conf_shell))
|
||||
fd.close()
|
||||
os.chmod((os.path.join(CONF['basedir'], 'develop_server.sh')), 493) # mode 0o755
|
||||
|
||||
# mode 0o755
|
||||
os.chmod((os.path.join(CONF['basedir'],
|
||||
'develop_server.sh')), 493)
|
||||
except OSError as e:
|
||||
print('Error: {0}'.format(e))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue