<s> import os <EOL> import subprocess <EOL> root_dir = os . path . abspath ( os . path . join ( os . path . dirname ( __file__ ) , "<STR_LIT:..>" ) ) <EOL> tarfile = os . path . join ( root_dir , "<STR_LIT>" ) <EOL> def _is_any_file_newer ( paths , reference_filename ) : <EOL> file_mtime = os . stat ( reference_filename ) . st_mtime <EOL> for path in paths : <EOL> if os . stat ( os . path . join ( root_dir , path ) ) . st_mtime > file_mtime : <EOL> return True <EOL> return False <EOL> def _tar ( paths ) : <EOL> if <NUM_LIT:0> != subprocess . call ( "<STR_LIT>" . format ( tarfile , "<STR_LIT:U+0020>" . join ( paths ) ) , shell = True , cwd = root_dir ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> def _get_paths_to_tar ( ) : <EOL> p = subprocess . Popen ( "<STR_LIT>" , stdout = subprocess . PIPE , cwd = root_dir , shell = True ) <EOL> returned = set ( ) <EOL> for subpath in p . stdout . readlines ( ) : <EOL> subpath = subpath . strip ( ) <EOL> returned . add ( os . path . dirname ( subpath ) ) <EOL> returned . add ( subpath ) <EOL> if <NUM_LIT:0> != p . wait ( ) : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> return returned <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> paths = _get_paths_to_tar ( ) <EOL> if not os . path . exists ( tarfile ) or _is_any_file_newer ( paths , tarfile ) : <EOL> _tar ( paths ) </s>
