Skip to content

Commit

Permalink
Refactor main into some reusable functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
mblayman committed Jan 3, 2016
1 parent c9bca03 commit ed3a0dd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
22 changes: 11 additions & 11 deletions handroll/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,8 @@ def main(argv=sys.argv):
scaffolder.make(args.scaffold, args.site)
finish()

site = Site(args.site)
valid, message = site.is_valid()
if not valid:
raise AbortError(_('Invalid site source: {0}').format(message))

loader = ExtensionLoader()
loader.load()

config = build_config(site.config_file, args)
extensions = loader.get_active_extensions(config)
director = Director(config, site, extensions)
site = Site.build(args)
director = prepare_director(args, site)
director.produce()

if args.watch:
Expand Down Expand Up @@ -89,6 +80,15 @@ def parse_args(argv):
return args


def prepare_director(args, site):
"""Prepare the director to produce a site."""
loader = ExtensionLoader()
loader.load()
config = build_config(site.config_file, args)
extensions = loader.get_active_extensions(config)
return Director(config, site, extensions)


def finish():
print(_('Complete.'))
sys.exit()
9 changes: 9 additions & 0 deletions handroll/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ def __init__(self, path=None):
if os.path.isdir(self.path):
self.path = os.path.abspath(self.path)

@classmethod
def build(cls, args):
"""Build a validated site."""
site = cls(args.site)
valid, message = site.is_valid()
if not valid:
raise AbortError(_('Invalid site source: {0}').format(message))
return site

@property
def config_file(self):
return os.path.join(self.path, self.CONFIG)
Expand Down

0 comments on commit ed3a0dd

Please sign in to comment.