Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Benjen now supports command-line argument to specify a directory #10

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 9 additions & 5 deletions benjen.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ def load_all(dir):
return [file(fn, 'r').read().decode('utf-8') for fn in glob(dir + '/*')]

class Benjen(object):
def __init__(self):
self.lookup = TemplateLookup(directories=['templates'])
def __init__(self, entries_dir=None):
if entries_dir is not None:
self.path_prefix = entries_dir + '/'
else:
self.path_prefix = ''
self.lookup = TemplateLookup(directories=[self.path_prefix + 'templates'])

self.config = yaml.load(file('config.yaml'))
self.config = yaml.load(file(self.path_prefix + 'config.yaml'))

self.out = self.config['path']
if self.out[-1] != '/':
self.out += '/'
shutil.rmtree(self.out, ignore_errors=True)
shutil.copytree('static', self.out)
shutil.copytree(self.path_prefix + 'static', self.out)

self.load_entries()

Expand All @@ -31,7 +35,7 @@ def render(self, name, **kwargs):

title_sub = partial(re.compile(r'[^a-zA-Z0-9_\-]').sub, '_')
def load_entries(self):
raw = load_all('entries')
raw = load_all(self.path_prefix + 'entries')

self.entries = []
for entry in raw:
Expand Down