#NEWLINE# def run( ) : #NEWLINE# #INDENT# 'Run this action.' #NEWLINE# log . debug ( 'run()' ) #NEWLINE# old_cwd = os . getcwd ( ) #NEWLINE# arguments = mdepub . arguments #NEWLINE# project_path = mdepub . project_path #NEWLINE# if ( arguments . fromfile is None ) : #NEWLINE# #INDENT# log . fatal ( 'No input file specified.' ) #NEWLINE# sys . exit ( 0 ) #NEWLINE# #UNINDENT# fromf = abspath ( arguments . fromfile ) #NEWLINE# with ZipFile ( fromf , 'r' ) as epub : #NEWLINE# #INDENT# with epub . open ( 'META-INF/source/mdepub_source.zip' , 'r' ) as src_item : #NEWLINE# #INDENT# src_stream = StringIO ( src_item . read ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# with ZipFile ( src_stream , 'r' ) as src_zip : #NEWLINE# #INDENT# with src_zip . open ( 'options.yaml' , 'r' ) as src_opt_item : #NEWLINE# #INDENT# src_opt = yaml . load ( src_opt_item ) #NEWLINE# #UNINDENT# if ( src_stream . to is None ) : #NEWLINE# #INDENT# arguments . to = join ( old_cwd , clean ( src_opt . get ( 'title' ) ) ) #NEWLINE# #UNINDENT# if ( arguments . to is None ) : #NEWLINE# #INDENT# log . fatal ( "Can't determine output path name" ) #NEWLINE# sys . exit ( 1 ) #NEWLINE# #UNINDENT# if ( not exists ( arguments . to ) ) : #NEWLINE# #INDENT# os . makedirs ( arguments . to ) #NEWLINE# #UNINDENT# os . chdir ( arguments . to ) #NEWLINE# src_zip . extractall ( ) #NEWLINE# #UNINDENT# src_stream . close ( ) #NEWLINE# os . chdir ( old_cwd )