Skip to content
Permalink
Browse files

Document all commands

Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Jul 28, 2015
1 parent 81d2391 commit 27b2de4073e2eb8ffc48f7070f466144a773f7f9
@@ -23,3 +23,5 @@
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

"""Commands for Nikola."""
@@ -24,6 +24,8 @@
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

"""Automatic rebuilds for Nikola."""

from __future__ import print_function

import json
@@ -75,7 +77,9 @@


class CommandAuto(Command):
"""Start debugging console."""

"""Automatic rebuilds for Nikola."""

name = "auto"
logger = None
has_server = True
@@ -124,7 +128,6 @@ class CommandAuto(Command):

def _execute(self, options, args):
"""Start the watcher."""

self.logger = get_logger('auto', STDERR_HANDLER)
LRSocket.logger = self.logger

@@ -203,7 +206,9 @@ def _execute(self, options, args):
parent = self

class Mixed(WebSocketWSGIApplication):
"""A class that supports WS and HTTP protocols in the same port."""

"""A class that supports WS and HTTP protocols on the same port."""

def __call__(self, environ, start_response):
if environ.get('HTTP_UPGRADE') is None:
return parent.serve_static(environ, start_response)
@@ -248,6 +253,7 @@ def __call__(self, environ, start_response):
os.kill(os.getpid(), 15)

def do_rebuild(self, event):
"""Rebuild the site."""
# Move events have a dest_path, some editors like gedit use a
# move on larger save operations for write protection
event_path = event.dest_path if hasattr(event, 'dest_path') else event.src_path
@@ -267,6 +273,7 @@ def do_rebuild(self, event):
print(errord)

def do_refresh(self, event):
"""Refresh the page."""
# Move events have a dest_path, some editors like gedit use a
# move on larger save operations for write protection
event_path = event.dest_path if hasattr(event, 'dest_path') else event.src_path
@@ -310,14 +317,17 @@ def inject_js(self, mimetype, data):


class LRSocket(WebSocket):

"""Speak Livereload protocol."""

def __init__(self, *a, **kw):
"""Initialize protocol handler."""
refresh_signal.connect(self.notify)
error_signal.connect(self.send_error)
super(LRSocket, self).__init__(*a, **kw)

def received_message(self, message):
"""Handle received message."""
message = json.loads(message.data.decode('utf8'))
self.logger.info('<--- {0}'.format(message))
response = None
@@ -24,6 +24,8 @@
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

"""Given a swatch name from bootswatch.com and a parent theme, creates a custom theme."""

from __future__ import print_function
import os
import requests
@@ -35,6 +37,7 @@


class CommandBootswatchTheme(Command):

"""Given a swatch name from bootswatch.com and a parent theme, creates a custom theme."""

name = "bootswatch_theme"
@@ -24,6 +24,8 @@
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

"""Check the generated site."""

from __future__ import print_function
from collections import defaultdict
import os
@@ -58,6 +60,7 @@ def _call_nikola_list(site):


def real_scan_files(site):
"""Scan for files."""
task_fnames = set([])
real_fnames = set([])
output_folder = site.config['OUTPUT_FOLDER']
@@ -80,7 +83,8 @@ def real_scan_files(site):


def fs_relpath_from_url_path(url_path):
"""Expects as input an urlparse(s).path"""
"""Create a filesystem relative path from an URL path."""
# Expects as input an urlparse(s).path
url_path = unquote(url_path)
# in windows relative paths don't begin with os.sep
if sys.platform == 'win32' and len(url_path):
@@ -89,6 +93,7 @@ def fs_relpath_from_url_path(url_path):


class CommandCheck(Command):

"""Check the generated site."""

name = "check"
@@ -169,6 +174,7 @@ def _execute(self, options, args):
checked_remote_targets = {}

def analyze(self, fname, find_sources=False, check_remote=False):
"""Analyze links on a page."""
rv = False
self.whitelist = [re.compile(x) for x in self.site.config['LINK_CHECK_WHITELIST']]
base_url = urlparse(self.site.config['BASE_URL'])
@@ -271,6 +277,7 @@ def analyze(self, fname, find_sources=False, check_remote=False):
return rv

def scan_links(self, find_sources=False, check_remote=False):
"""Check links on the site."""
self.logger.info("Checking Links:")
self.logger.info("===============\n")
self.logger.notice("{0} mode".format(self.site.config['URL_TYPE']))
@@ -286,6 +293,7 @@ def scan_links(self, find_sources=False, check_remote=False):
return failure

def scan_files(self):
"""Check files in the site, find missing and orphaned files."""
failure = False
self.logger.info("Checking Files:")
self.logger.info("===============\n")
@@ -311,6 +319,7 @@ def scan_files(self):
return failure

def clean_files(self):
"""Remove orphaned files."""
only_on_output, _ = real_scan_files(self.site)
for f in only_on_output:
self.logger.info('removed: {0}'.format(f))
@@ -24,6 +24,8 @@
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

"""Start debugging console."""

from __future__ import print_function, unicode_literals

import os
@@ -36,7 +38,9 @@


class CommandConsole(Command):

"""Start debugging console."""

name = "console"
shells = ['ipython', 'bpython', 'plain']
doc_purpose = "start an interactive Python console with access to your site"
@@ -24,6 +24,8 @@
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

"""Deploy site."""

from __future__ import print_function
import io
from datetime import datetime
@@ -39,7 +41,9 @@


class CommandDeploy(Command):

"""Deploy site."""

name = "deploy"

doc_usage = "[[preset [preset...]]"
@@ -48,6 +52,7 @@ class CommandDeploy(Command):
logger = None

def _execute(self, command, args):
"""Execute the deploy command."""
self.logger = get_logger('deploy', STDERR_HANDLER)
# Get last successful deploy date
timestamp_path = os.path.join(self.site.config['CACHE_FOLDER'], 'lastdeploy')
@@ -116,7 +121,7 @@ def _execute(self, command, args):
outf.write(unicode_str(new_deploy.isoformat()))

def _emit_deploy_event(self, last_deploy, new_deploy, clean=False, undeployed=None):
""" Emit events for all timeline entries newer than last deploy.
"""Emit events for all timeline entries newer than last deploy.
last_deploy: datetime
Time stamp of the last successful deployment.
@@ -128,7 +133,6 @@ def _emit_deploy_event(self, last_deploy, new_deploy, clean=False, undeployed=No
True when it appears like deploy is being run after a clean.
"""

event = {
'last_deploy': last_deploy,
'new_deploy': new_deploy,
@@ -24,6 +24,8 @@
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

"""Deploy site to GitHub Pages."""

from __future__ import print_function
from datetime import datetime
import io
@@ -39,11 +41,13 @@


def uni_check_output(*args, **kwargs):
"""Run command and return output as Unicode (UTf-8)."""
o = subprocess.check_output(*args, **kwargs)
return o.decode('utf-8')


def check_ghp_import_installed():
"""Check if ghp-import is installed."""
try:
subprocess.check_output(['ghp-import', '-h'])
except OSError:
@@ -53,7 +57,9 @@ def check_ghp_import_installed():


class CommandGitHubDeploy(Command):
""" Deploy site to GitHub Pages. """

"""Deploy site to GitHub Pages."""

name = 'github_deploy'

doc_usage = ''
@@ -70,7 +76,7 @@ class CommandGitHubDeploy(Command):
logger = None

def _execute(self, command, args):

"""Run the deployment."""
self.logger = get_logger(CommandGitHubDeploy.name, STDERR_HANDLER)

# Check if ghp-import is installed
@@ -93,8 +99,7 @@ def _execute(self, command, args):
return

def _commit_and_push(self):
""" Commit all the files and push. """

"""Commit all the files and push."""
source = self.site.config['GITHUB_SOURCE_BRANCH']
deploy = self.site.config['GITHUB_DEPLOY_BRANCH']
remote = self.site.config['GITHUB_REMOTE_NAME']

0 comments on commit 27b2de4

Please sign in to comment.
You can’t perform that action at this time.