<s> '''<STR_LIT>''' <EOL> import argparse <EOL> from datetime import datetime <EOL> import os <EOL> import shutil <EOL> import subprocess <EOL> import tinkerer <EOL> from tinkerer import draft , output , page , paths , post , writer <EOL> def setup ( ) : <EOL> '''<STR_LIT>''' <EOL> new_blog = writer . setup_blog ( ) <EOL> output . filename . info ( "<STR_LIT>" ) <EOL> if new_blog : <EOL> output . write . info ( "<STR_LIT>" ) <EOL> output . write . info ( "<STR_LIT>" % <EOL> ( os . path . relpath ( paths . conf_file ) , ) ) <EOL> else : <EOL> output . write . info ( "<STR_LIT>" ) <EOL> def build ( ) : <EOL> '''<STR_LIT>''' <EOL> if os . path . exists ( paths . blog ) : <EOL> shutil . rmtree ( paths . blog ) <EOL> flags = [ "<STR_LIT>" ] <EOL> if output . quiet : <EOL> flags . append ( "<STR_LIT>" ) <EOL> flags += [ "<STR_LIT>" , paths . doctree , "<STR_LIT>" , "<STR_LIT:html>" , paths . root , paths . html ] <EOL> output . filename . info ( "<STR_LIT>" ) <EOL> if os . path . exists ( "<STR_LIT>" ) : <EOL> shutil . copytree ( "<STR_LIT>" , paths . html ) <EOL> return subprocess . call ( flags ) <EOL> def create_post ( title , date , template ) : <EOL> '''<STR_LIT>''' <EOL> move = os . path . exists ( title ) <EOL> if move : <EOL> new_post = post . move ( title , date ) <EOL> else : <EOL> new_post = post . create ( title , date , template ) <EOL> output . filename . info ( new_post . path ) <EOL> if move : <EOL> output . write . info ( "<STR_LIT>" % new_post . path ) <EOL> else : <EOL> output . write . info ( "<STR_LIT>" % new_post . path ) <EOL> def create_page ( title , template ) : <EOL> '''<STR_LIT>''' <EOL> move = os . path . exists ( title ) <EOL> if move : <EOL> new_page = page . move ( title ) <EOL> else : <EOL> new_page = page . create ( title , template ) <EOL> output . filename . info ( new_page . path ) <EOL> if move : <EOL> output . write . info ( "<STR_LIT>" % new_page . path ) <EOL> else : <EOL> output . write . info ( "<STR_LIT>" % new_page . path ) <EOL> def create_draft ( title , template ) : <EOL> '''<STR_LIT>''' <EOL> move = os . path . exists ( title ) <EOL> if move : <EOL> new_draft = draft . move ( title ) <EOL> else : <EOL> new_draft = draft . create ( title , template ) <EOL> output . filename . info ( new_draft ) <EOL> if move : <EOL> output . write . info ( "<STR_LIT>" % new_draft ) <EOL> else : <EOL> output . write . info ( "<STR_LIT>" % new_draft ) <EOL> def preview_draft ( draft_file ) : <EOL> '''<STR_LIT>''' <EOL> if not os . path . exists ( draft_file ) : <EOL> raise Exception ( "<STR_LIT>" % draft_file ) <EOL> preview_post = post . move ( draft_file ) <EOL> try : <EOL> result = build ( ) <EOL> finally : <EOL> draft . move ( preview_post . path ) <EOL> return result <EOL> def main ( argv = None ) : <EOL> '''<STR_LIT>''' <EOL> parser = argparse . ArgumentParser ( ) <EOL> group = parser . add_mutually_exclusive_group ( ) <EOL> group . add_argument ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> group . add_argument ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store_true>" , help = "<STR_LIT>" ) <EOL> group . add_argument ( <EOL> "<STR_LIT>" , "<STR_LIT>" , nargs = <NUM_LIT:1> , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> group . add_argument ( <EOL> "<STR_LIT>" , nargs = <NUM_LIT:1> , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> group . add_argument ( <EOL> "<STR_LIT>" , "<STR_LIT>" , nargs = <NUM_LIT:1> , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> group . add_argument ( <EOL> "<STR_LIT>" , nargs = <NUM_LIT:1> , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> group . add_argument ( <EOL> "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store>' , default = None , <EOL> help = "<STR_LIT>" , <EOL> ) <EOL> parser . add_argument ( <EOL> "<STR_LIT>" , nargs = <NUM_LIT:1> , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> group = parser . add_mutually_exclusive_group ( ) <EOL> group . add_argument ( "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store_true>" , help = "<STR_LIT>" ) <EOL> group . add_argument ( <EOL> "<STR_LIT>" , "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> command = parser . parse_args ( argv ) <EOL> output . init ( command . quiet , command . filename ) <EOL> if ( not command . setup and not command . version and not <EOL> os . path . exists ( paths . conf_file ) ) : <EOL> output . write . error ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return - <NUM_LIT:1> <EOL> post_date = None <EOL> if command . date : <EOL> if not command . post : <EOL> output . write . error ( "<STR_LIT>" ) <EOL> return - <NUM_LIT:1> <EOL> try : <EOL> post_date = datetime . strptime ( command . date [ <NUM_LIT:0> ] , "<STR_LIT>" ) <EOL> except : <EOL> output . write . error ( <EOL> "<STR_LIT>" <EOL> ) <EOL> return - <NUM_LIT:1> <EOL> if command . template : <EOL> if not os . path . exists ( os . path . join ( paths . templates , command . template ) ) : <EOL> output . write . error ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return - <NUM_LIT:1> <EOL> if command . setup : <EOL> setup ( ) <EOL> elif command . build : <EOL> return build ( ) <EOL> elif command . post : <EOL> create_post ( command . post [ <NUM_LIT:0> ] , post_date , command . template ) <EOL> elif command . page : <EOL> create_page ( command . page [ <NUM_LIT:0> ] , command . template ) <EOL> elif command . draft : <EOL> create_draft ( command . draft [ <NUM_LIT:0> ] , command . template ) <EOL> elif command . preview : <EOL> preview_draft ( command . preview [ <NUM_LIT:0> ] ) <EOL> elif command . version : <EOL> output . write . info ( "<STR_LIT>" % tinkerer . __version__ ) <EOL> else : <EOL> parser . print_help ( ) <EOL> return <NUM_LIT:0> </s>
