<s> from conans . util . log import logger <EOL> from conans . errors import ConanException <EOL> from conans . model . ref import PackageReference <EOL> from conans . paths import SYSTEM_REQS <EOL> import os <EOL> from conans . util . files import rmdir <EOL> class DiskRemover ( object ) : <EOL> def __init__ ( self , paths ) : <EOL> self . _paths = paths <EOL> def _remove ( self , path , conan_ref , msg = "<STR_LIT>" ) : <EOL> try : <EOL> logger . debug ( "<STR_LIT>" % path ) <EOL> rmdir ( path ) <EOL> except OSError as e : <EOL> raise ConanException ( "<STR_LIT>" % ( repr ( conan_ref ) , msg , str ( e ) ) ) <EOL> def _remove_file ( self , path , conan_ref , msg = "<STR_LIT>" ) : <EOL> try : <EOL> logger . debug ( "<STR_LIT>" % path ) <EOL> if os . path . exists ( path ) : <EOL> os . remove ( path ) <EOL> except OSError as e : <EOL> raise ConanException ( "<STR_LIT>" % ( repr ( conan_ref ) , msg , str ( e ) ) ) <EOL> def remove ( self , conan_ref ) : <EOL> self . _remove ( self . _paths . conan ( conan_ref ) , conan_ref ) <EOL> def remove_src ( self , conan_ref ) : <EOL> self . _remove ( self . _paths . source ( conan_ref ) , conan_ref , "<STR_LIT>" ) <EOL> def remove_builds ( self , conan_ref , ids = None ) : <EOL> if not ids : <EOL> self . _remove ( self . _paths . builds ( conan_ref ) , conan_ref , "<STR_LIT>" ) <EOL> else : <EOL> for id_ in ids : <EOL> self . _remove ( self . _paths . build ( PackageReference ( conan_ref , id_ ) ) , conan_ref , <EOL> "<STR_LIT>" % id_ ) <EOL> def remove_packages ( self , conan_ref , ids_filter = None ) : <EOL> if not ids_filter : <EOL> self . _remove ( self . _paths . packages ( conan_ref ) , conan_ref , "<STR_LIT>" ) <EOL> self . _remove_file ( self . _paths . system_reqs ( conan_ref ) , conan_ref , SYSTEM_REQS ) <EOL> else : <EOL> for id_ in ids_filter : <EOL> package_ref = PackageReference ( conan_ref , id_ ) <EOL> self . _remove ( self . _paths . package ( package_ref ) , conan_ref , "<STR_LIT>" % id_ ) <EOL> self . _remove_file ( self . _paths . system_reqs_package ( package_ref ) , <EOL> conan_ref , "<STR_LIT>" % ( id_ , SYSTEM_REQS ) ) </s>
