<s> from __future__ import print_function <EOL> import os <EOL> import datetime <EOL> import transaction <EOL> from optparse import OptionParser <EOL> from subprocess import Popen <EOL> from subprocess import PIPE <EOL> def main ( ) : <EOL> from pyramid . paster import get_app <EOL> from pyramid . scripting import get_root <EOL> from . . resources import BlogEntry <EOL> parser = OptionParser ( description = __doc__ , usage = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT:-c>' , '<STR_LIT>' , dest = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT:name>' , default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> options , args = parser . parse_args ( ) <EOL> config = options . config <EOL> name = options . name <EOL> if config is None : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> config = os . path . abspath ( os . path . normpath ( config ) ) <EOL> app = get_app ( config , name ) <EOL> root , closer = get_root ( app ) <EOL> for arg in args : <EOL> print ( "<STR_LIT>" , arg ) <EOL> if not os . path . isfile ( arg ) : <EOL> print ( '<STR_LIT>' ) <EOL> continue <EOL> path , filename = os . path . split ( arg ) <EOL> id , ext = os . path . splitext ( filename ) <EOL> print ( "<STR_LIT>" , id ) <EOL> lines = open ( arg , '<STR_LIT:r>' ) . readlines ( ) <EOL> title = lines [ <NUM_LIT:0> ] <EOL> print ( '<STR_LIT>' , title ) <EOL> entry = '<STR_LIT:\n>' . join ( lines [ <NUM_LIT:2> : ] ) <EOL> print ( '<STR_LIT>' , entry [ : <NUM_LIT> ] ) <EOL> pieces = id . split ( '<STR_LIT:->' ) <EOL> last = pieces [ - <NUM_LIT:1> ] <EOL> pubdate = None <EOL> if last . startswith ( '<STR_LIT>' ) : <EOL> if len ( last ) == <NUM_LIT:8> : <EOL> year , month , day = last [ <NUM_LIT:0> : <NUM_LIT:4> ] , last [ <NUM_LIT:4> : <NUM_LIT:6> ] , last [ <NUM_LIT:6> : <NUM_LIT:8> ] <EOL> pubdate = datetime . date ( int ( year ) , int ( month ) , int ( day ) ) <EOL> if pubdate is None : <EOL> p1 = Popen ( [ "<STR_LIT>" , "<STR_LIT:info>" , arg ] , stdout = PIPE ) <EOL> p2 = Popen ( [ "<STR_LIT>" , "<STR_LIT>" ] , stdin = p1 . stdout , <EOL> stdout = PIPE ) <EOL> output = p2 . communicate ( ) [ <NUM_LIT:0> ] <EOL> lines = output . split ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> datestr = lines [ <NUM_LIT:1> ] . strip ( ) <EOL> datestr = datestr . split ( '<STR_LIT:U+0020>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> year , month , day = datestr [ <NUM_LIT:0> : <NUM_LIT:4> ] , datestr [ <NUM_LIT:5> : <NUM_LIT:7> ] , datestr [ <NUM_LIT:8> : <NUM_LIT:10> ] <EOL> pubdate = datetime . date ( int ( year ) , int ( month ) , int ( day ) ) <EOL> print ( '<STR_LIT>' , pubdate ) <EOL> entry = BlogEntry ( title . decode ( '<STR_LIT>' ) , entry . decode ( '<STR_LIT>' ) , <EOL> id . decode ( '<STR_LIT>' ) , pubdate , '<STR_LIT:html>' , None , None ) <EOL> root [ id ] = entry <EOL> transaction . commit ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
