Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Document all commands
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Jul 28, 2015
1 parent 81d2391 commit 27b2de4
Show file tree
Hide file tree
Showing 18 changed files with 141 additions and 33 deletions.
2 changes: 2 additions & 0 deletions nikola/plugins/command/__init__.py
Expand Up @@ -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."""
16 changes: 13 additions & 3 deletions nikola/plugins/command/auto/__init__.py
Expand Up @@ -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
Expand Down Expand Up @@ -75,7 +77,9 @@


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

"""Automatic rebuilds for Nikola."""

name = "auto"
logger = None
has_server = True
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions nikola/plugins/command/bootswatch_theme.py
Expand Up @@ -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
Expand All @@ -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"
Expand Down
11 changes: 10 additions & 1 deletion nikola/plugins/command/check.py
Expand Up @@ -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
Expand Down Expand Up @@ -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']
Expand All @@ -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):
Expand All @@ -89,6 +93,7 @@ def fs_relpath_from_url_path(url_path):


class CommandCheck(Command):

"""Check the generated site."""

name = "check"
Expand Down Expand Up @@ -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'])
Expand Down Expand Up @@ -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']))
Expand All @@ -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")
Expand All @@ -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))
Expand Down
4 changes: 4 additions & 0 deletions nikola/plugins/command/console.py
Expand Up @@ -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
Expand All @@ -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"
Expand Down
8 changes: 6 additions & 2 deletions nikola/plugins/command/deploy.py
Expand Up @@ -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
Expand All @@ -39,7 +41,9 @@


class CommandDeploy(Command):

"""Deploy site."""

name = "deploy"

doc_usage = "[[preset [preset...]]"
Expand All @@ -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')
Expand Down Expand Up @@ -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.
Expand All @@ -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,
Expand Down
13 changes: 9 additions & 4 deletions nikola/plugins/command/github_deploy.py
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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 = ''
Expand All @@ -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
Expand All @@ -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']
Expand Down

0 comments on commit 27b2de4

Please sign in to comment.