<s> from __future__ import print_function <EOL> from collections import defaultdict <EOL> from luigi import six <EOL> import luigi <EOL> from luigi . contrib . ssh import RemoteContext , RemoteTarget <EOL> from luigi . mock import MockFile <EOL> SSH_HOST = "<STR_LIT>" <EOL> class CreateRemoteData ( luigi . Task ) : <EOL> """<STR_LIT>""" <EOL> def output ( self ) : <EOL> """<STR_LIT>""" <EOL> return RemoteTarget ( <EOL> "<STR_LIT>" , <EOL> SSH_HOST <EOL> ) <EOL> def run ( self ) : <EOL> remote = RemoteContext ( SSH_HOST ) <EOL> print ( remote . check_output ( [ <EOL> "<STR_LIT>" . format ( self . output ( ) . path ) <EOL> ] ) ) <EOL> class ProcessRemoteData ( luigi . Task ) : <EOL> """<STR_LIT>""" <EOL> def requires ( self ) : <EOL> """<STR_LIT>""" <EOL> return CreateRemoteData ( ) <EOL> def run ( self ) : <EOL> processes_per_user = defaultdict ( int ) <EOL> with self . input ( ) . open ( '<STR_LIT:r>' ) as infile : <EOL> for line in infile : <EOL> username = line . split ( ) [ <NUM_LIT:0> ] <EOL> processes_per_user [ username ] += <NUM_LIT:1> <EOL> toplist = sorted ( <EOL> six . iteritems ( processes_per_user ) , <EOL> key = lambda x : x [ <NUM_LIT:1> ] , <EOL> reverse = True <EOL> ) <EOL> with self . output ( ) . open ( '<STR_LIT:w>' ) as outfile : <EOL> for user , n_processes in toplist : <EOL> print ( n_processes , user , file = outfile ) <EOL> def output ( self ) : <EOL> """<STR_LIT>""" <EOL> return MockFile ( "<STR_LIT>" , mirror_on_stderr = True ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> luigi . run ( ) </s>
