<s> import pwd <EOL> import os <EOL> import sys <EOL> import itertools <EOL> import subprocess <EOL> def __fix_perms ( userinfo ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> target = sys . _MEIPASS <EOL> except : <EOL> return <EOL> try : <EOL> with open ( '<STR_LIT>' , '<STR_LIT:wb>' ) as devnull : <EOL> subprocess . check_call ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' % ( userinfo . pw_uid , userinfo . pw_gid ) , target ] , stdout = devnull , stderr = devnull ) <EOL> except ( OSError , subprocess . CalledProcessError ) : <EOL> os . chown ( target , userinfo . pw_uid , userinfo . pw_gid ) <EOL> for root , dirs , files in os . walk ( target ) : <EOL> for f in itertools . chain ( dirs , files ) : <EOL> os . chown ( os . path . join ( root , f ) , userinfo . pw_uid , userinfo . pw_gid ) <EOL> def setuser ( user_or_pid ) : <EOL> try : <EOL> try : <EOL> userinfo = pwd . getpwuid ( int ( user_or_pid ) ) <EOL> except ValueError : <EOL> userinfo = pwd . getpwnam ( user_or_pid ) <EOL> __fix_perms ( userinfo ) <EOL> os . setgid ( userinfo . pw_gid ) <EOL> os . setuid ( userinfo . pw_uid ) <EOL> return True <EOL> except KeyError as e : <EOL> print ( str ( e ) ) <EOL> return False </s>
