<s> """<STR_LIT>""" <EOL> __credits__ = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> import importlib <EOL> from os import remove <EOL> from os . path import split , splitext <EOL> import sys <EOL> from subprocess import Popen , PIPE <EOL> from pyqi . core . log import StdErrLogger <EOL> from pyqi . core . exception import MissingVersionInfoError <EOL> def is_py2 ( ) : <EOL> """<STR_LIT>""" <EOL> if sys . version_info . major == <NUM_LIT:2> : <EOL> return True <EOL> else : <EOL> return False <EOL> def pyqi_system_call ( cmd , shell = True , dry_run = False ) : <EOL> """<STR_LIT>""" <EOL> if dry_run : <EOL> if isinstance ( cmd , list ) : <EOL> sys . stderr . write ( '<STR_LIT:U+0020>' . join ( cmd ) ) <EOL> else : <EOL> sys . stderr . write ( cmd ) <EOL> sys . stderr . write ( '<STR_LIT:\n>' ) <EOL> return "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:0> <EOL> else : <EOL> proc = Popen ( cmd , <EOL> shell = shell , <EOL> universal_newlines = True , <EOL> stdout = PIPE , <EOL> stderr = PIPE ) <EOL> stdout , stderr = proc . communicate ( ) <EOL> return_value = proc . returncode <EOL> return stdout , stderr , return_value <EOL> def remove_files ( list_of_filepaths , error_on_missing = True ) : <EOL> """<STR_LIT>""" <EOL> missing = [ ] <EOL> for fp in list_of_filepaths : <EOL> try : <EOL> remove ( fp ) <EOL> except OSError : <EOL> missing . append ( fp ) <EOL> if error_on_missing and missing : <EOL> raise OSError ( "<STR_LIT>" % '<STR_LIT:\t>' . join ( <EOL> missing ) ) <EOL> def old_to_new_command ( driver_name , project_title , local_argv ) : <EOL> """<STR_LIT>""" <EOL> logger = StdErrLogger ( ) <EOL> cmd_name = splitext ( split ( local_argv [ <NUM_LIT:0> ] ) [ <NUM_LIT:1> ] ) [ <NUM_LIT:0> ] <EOL> base_cmd = "<STR_LIT>" % ( driver_name , cmd_name ) <EOL> command = '<STR_LIT>' % ( base_cmd , '<STR_LIT:U+0020>' . join ( local_argv [ <NUM_LIT:1> : ] ) ) <EOL> logger . info ( "<STR_LIT>" <EOL> "<STR_LIT:%s>" % ( project_title , base_cmd ) ) <EOL> logger . info ( "<STR_LIT>" % command ) <EOL> result_stdout , result_stderr , result_retval = pyqi_system_call ( command ) <EOL> sys . stdout . write ( result_stdout ) <EOL> sys . stderr . write ( result_stderr ) <EOL> return result_retval <EOL> def get_version_string ( module_str ) : <EOL> """<STR_LIT>""" <EOL> top_level_name = module_str . split ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] <EOL> try : <EOL> top_level_module = importlib . import_module ( top_level_name ) <EOL> except ImportError : <EOL> raise ImportError ( "<STR_LIT>" % top_level_name ) <EOL> try : <EOL> version_string = top_level_module . __version__ <EOL> except AttributeError : <EOL> raise MissingVersionInfoError ( "<STR_LIT>" <EOL> "<STR_LIT>" % top_level_name ) <EOL> return version_string </s>
