Skip to content
This repository has been archived by the owner on Jan 15, 2019. It is now read-only.

Installable Templates 2 #18

Open
wants to merge 16 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
24 changes: 14 additions & 10 deletions armstrong/cli/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
import shutil
import codecs
import json
import argparse
from random import choice

CWD = os.getcwd()
ENTRY_POINT = 'armstrong.templates'


class MissingTemplate(RuntimeError):
pass


class InitCommand(object):
Expand All @@ -29,13 +33,14 @@ def __call__(self, template='standard', demo=False, path=CWD, **kwargs):
# TODO: interactive mode to ask questions for each variable
from django.conf import settings

# TODO: appropriate error output if non-existant template chosen
template_dir = os.path.realpath(os.path.join(
os.path.dirname(__file__),
'..',
"templates",
template,
))
from pkg_resources import iter_entry_points
try:
entry_point = iter_entry_points(ENTRY_POINT, template).next()
except StopIteration:
raise MissingTemplate("No template named: %s" % template)

module = entry_point.load()
template_dir = module.__path__[0]

settings.configure(DEBUG=False, TEMPLATE_DEBUG=False,
TEMPLATE_DIRS=[template_dir, ])
Expand All @@ -44,7 +49,7 @@ def __call__(self, template='standard', demo=False, path=CWD, **kwargs):
# TODO: allow this to be passed in via command line
project_name = os.path.basename(path)

# The secret key generate is borrowed directly from Django's startproject
# Secret key generation: borrowed directly from Django's startproject
CHOICES = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
secret_key = ''.join([choice(CHOICES) for i in range(50)])
context = Context({
Expand All @@ -64,7 +69,6 @@ def source_files():
if not name.endswith(".pyc"):
yield os.path.join(dirpath, name)


existing_files = []
files = []
excluded_files = [
Expand Down
10 changes: 5 additions & 5 deletions armstrong/cli/commands/list_templates.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from pkg_resources import iter_entry_points
import os

from .init import ENTRY_POINT


def command():
# TODO: make this look for entry_points so third-party templates can be used
# TODO: make this verify that there's a manifest.json present
# TODO: make this display manifest.json's description along side template names
import armstrong.cli.templates
p = armstrong.cli.templates.__path__[0]
templates = [a for a in os.listdir(p) if os.path.isdir(os.path.join(p, a))]
print "The following templates are available:"
print "\n %s" % "\n ".join(templates)
for entry_point in iter_entry_points(ENTRY_POINT):
print " %s" % entry_point.name
2 changes: 0 additions & 2 deletions armstrong/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import sys
import argparse

from .commands.init import init

# TODO: use logging throughout for output
ENTRY_POINT = 'armstrong.commands'
CONFIGURATION_MODULE = "settings"
Expand Down
13 changes: 0 additions & 13 deletions armstrong/cli/templates/paywall/README.rst

This file was deleted.

Empty file.
Binary file removed armstrong/cli/templates/paywall/database.sqlite3
Binary file not shown.
8 changes: 0 additions & 8 deletions armstrong/cli/templates/paywall/manifest.json

This file was deleted.

2 changes: 0 additions & 2 deletions armstrong/cli/templates/paywall/requirements/development.txt

This file was deleted.

5 changes: 0 additions & 5 deletions armstrong/cli/templates/paywall/requirements/project.txt

This file was deleted.

2 changes: 0 additions & 2 deletions armstrong/cli/templates/paywall/settings/__init__.py

This file was deleted.

160 changes: 0 additions & 160 deletions armstrong/cli/templates/paywall/settings/defaults.py

This file was deleted.

28 changes: 0 additions & 28 deletions armstrong/cli/templates/paywall/settings/development.py

This file was deleted.

27 changes: 0 additions & 27 deletions armstrong/cli/templates/paywall/settings/production.py

This file was deleted.

13 changes: 0 additions & 13 deletions armstrong/cli/templates/paywall/templates/article.html

This file was deleted.

47 changes: 0 additions & 47 deletions armstrong/cli/templates/paywall/templates/base.html

This file was deleted.

Loading